-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Add info text to Upcoming Length control #3639
Merged
youngcw
merged 14 commits into
actualbudget:master
from
SamBobBarnes:Upcoming-length-help-text
Oct 17, 2024
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
db16c0a
added info circle and box on click
SamBobBarnes 6d61bd1
hover working
SamBobBarnes a7df8ab
moved title
SamBobBarnes ed4f776
release notes
SamBobBarnes e890cf3
updated release notes category
SamBobBarnes 5338043
split info bubble into its own component
SamBobBarnes 9713b6b
text longer than 500px will be split
SamBobBarnes 53c9794
extracted text width into its own file
SamBobBarnes 7e3c44e
wip tests
SamBobBarnes cd8f94a
Merge branch 'master' into Upcoming-length-help-text
SamBobBarnes 38fffc5
wip testing
SamBobBarnes fb97969
removed separate method and tests
SamBobBarnes b43180d
added textWidth option to Info Bubble
SamBobBarnes d144421
updated shadow
SamBobBarnes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
packages/desktop-client/src/components/common/InfoBubble.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import React, { useState } from 'react'; | ||
import { useLocation } from 'react-router-dom'; | ||
|
||
import { SvgInformationCircle } from '../../icons/v2'; | ||
import { theme } from '../../style'; | ||
|
||
import { Text } from './Text'; | ||
import { View } from './View'; | ||
|
||
type InfoBubbleProps = { | ||
label: string; | ||
textWidth?: number; | ||
}; | ||
|
||
export function InfoBubble({ label, textWidth }: InfoBubbleProps) { | ||
const location = useLocation(); | ||
const [visible, setVisible] = useState(location.hash === '#info'); | ||
|
||
const width = textWidth || getStringWidth(label); | ||
|
||
return visible ? ( | ||
<View style={{ userSelect: 'none' }}> | ||
<SvgInformationCircle | ||
style={{ height: '15px', cursor: 'pointer' }} | ||
onClick={() => setVisible(false)} | ||
onMouseLeave={() => setVisible(false)} | ||
/> | ||
<View | ||
style={{ | ||
position: 'absolute', | ||
left: '20px', | ||
top: '-7px', | ||
color: theme.buttonNormalText, | ||
backgroundColor: theme.buttonNormalBackground, | ||
padding: 5, | ||
borderRadius: 4, | ||
border: '1px solid ' + theme.buttonNormalBorder, | ||
zIndex: 300, | ||
boxShadow: theme.buttonPrimaryShadow, | ||
}} | ||
> | ||
<Text | ||
style={{ | ||
width, | ||
}} | ||
> | ||
{label} | ||
</Text> | ||
</View> | ||
</View> | ||
) : ( | ||
<View style={{ userSelect: 'none' }}> | ||
<SvgInformationCircle | ||
style={{ height: '15px', cursor: 'pointer' }} | ||
onClick={() => setVisible(true)} | ||
onMouseOver={() => setTimeout(() => setVisible(true), 500)} | ||
/> | ||
</View> | ||
); | ||
} | ||
|
||
function getStringWidth(text: string): number { | ||
const canvas = document.createElement('canvas'); | ||
const context = canvas.getContext('2d')!; | ||
context.font = getComputedStyle(document.body).font; | ||
|
||
return Math.ceil(context.measureText(text).width); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
category: Enhancements | ||
authors: [ SamBobBarnes ] | ||
--- | ||
|
||
Add info text to Upcoming Length control. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Improve hover behavior and event consistency.
The current implementation has a few potential issues:
Consider the following improvements:
This implementation:
These changes will make the component's behavior more predictable and consistent.