-
-
Notifications
You must be signed in to change notification settings - Fork 181
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
Add tooltip Component for disabled buttons #4740
Merged
Merged
Changes from 11 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
6e991e8
inital testing
RuthShryock 29cbba3
adding storybook documetation, aria-element, and span
RuthShryock d734ce0
adding Tooltip to Button component and updating usage for project qui…
RuthShryock 9eb4e4e
updating names and cleaning up code
RuthShryock ff9c003
fixing export of TooltipProps
RuthShryock a6915d7
removing comment
RuthShryock 0a1083f
requested changes for styling, adding comments, and moving scss file
RuthShryock 5089067
removing auto formatting of quotations
RuthShryock 68c57d9
Merge branch 'beta' of github.com:kobotoolbox/kpi into button-disable…
RuthShryock 6c15036
adjusting alignment values and fixing comments for parameters in the …
RuthShryock 0e077e8
improve button storybook definition
magicznyleszek 0c6fcdc
fixed button rendering
RuthShryock 3ebac00
Merge branch 'beta' of github.com:kobotoolbox/kpi into button-disable…
RuthShryock 278b48c
Merge branch 'beta' of github.com:kobotoolbox/kpi into button-disable…
RuthShryock fd2cbc1
change Button to be inline-flex so that tooltips work correctly
magicznyleszek 13ff9d1
Merge branch 'beta' into button-disabled-improve-styles
magicznyleszek e8be5b2
Merge branch 'beta' into button-disabled-improve-styles
magicznyleszek 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
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
File renamed without changes.
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,54 @@ | ||
import React from 'react'; | ||
import type {Meta, Story} from '@storybook/react'; | ||
|
||
import type {TooltipProps} from './tooltip'; | ||
import Tooltip from './tooltip'; | ||
|
||
export default { | ||
title: 'Common/Tooltip', | ||
component: Tooltip, | ||
magicznyleszek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
description: | ||
'This is a component that displays a tooltip on a button that is hovered over.', | ||
argTypes: { | ||
text: { | ||
description: 'Content of the tooltip shown on hover over button', | ||
}, | ||
alignment: { | ||
description: | ||
'Position of the tooltip (centered as default)', | ||
options: ['right', 'left', 'center'], | ||
control: 'select', | ||
defaultValue: 'center', | ||
}, | ||
ariaLabel: { | ||
description: 'Accessible label for screen readers', | ||
}, | ||
}, | ||
} as Meta; | ||
|
||
const Template: Story<TooltipProps> = (args) => ( | ||
<Tooltip {...args}> | ||
<button>Your Button</button> | ||
</Tooltip> | ||
); | ||
|
||
export const Default = Template.bind({}); | ||
Default.args = { | ||
text: 'Default Tooltip Text', | ||
alignment: 'center', | ||
ariaLabel: 'Default Tooltip Text', | ||
}; | ||
|
||
export const Right = Template.bind({}); | ||
Right.args = { | ||
text: 'Right Aligned Tooltip Text', | ||
alignment: 'right', | ||
ariaLabel: 'Right Aligned Tooltip Text', | ||
}; | ||
|
||
export const Left = Template.bind({}); | ||
Left.args = { | ||
text: 'Left Aligned Tooltip Text', | ||
alignment: 'left', | ||
ariaLabel: 'Left Aligned Tooltip Text', | ||
}; |
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,34 @@ | ||
import React from 'react'; | ||
|
||
export type TooltipAlignment = 'right' | 'left' | 'center'; | ||
|
||
export interface TooltipProps { | ||
/** Content of the tooltip */ | ||
text: string; | ||
/** Accessible label for screen readers */ | ||
ariaLabel: string; | ||
/** Position of the tooltip (centered as default) */ | ||
alignment?: TooltipAlignment; | ||
} | ||
|
||
/** | ||
* Tooltip component that is necessary for managing dynamic content and | ||
* accessibility features, such as readability. While we have the tooltip.scss | ||
* component, that provides styling but not other functionaltiy such as | ||
* allowing tooltips to work on disabled buttons. | ||
*/ | ||
magicznyleszek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const Tooltip: React.FC<TooltipProps> = ({ | ||
magicznyleszek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
text, | ||
ariaLabel, | ||
alignment, | ||
children, | ||
}) => ( | ||
<span | ||
data-tip={text} | ||
magicznyleszek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
className={`${alignment || 'center'}-tooltip`} | ||
aria-label={ariaLabel} | ||
> | ||
{children} | ||
</span> | ||
); | ||
export default Tooltip; |
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
Oops, something went wrong.
Oops, something went wrong.
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.
I've noticed that if you don't add tooltip, this renders nothing. We need the button to be rendered with or without a tooltip :)
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.
I thought that somethign is wrong with Storybook, because it wasn't rendering anything for Button, so I've added a commit that improves
button.stories.tsx
. Please take a look at what it does when testing the tooltip: