-
-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4740 from kobotoolbox/button-disabled-improve-styles
Add tooltip Component for disabled buttons
- Loading branch information
Showing
10 changed files
with
303 additions
and
145 deletions.
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
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,56 @@ | ||
import React from 'react'; | ||
import type {Meta, Story} from '@storybook/react'; | ||
|
||
import type {TooltipProps, TooltipAlignment} from './tooltip'; | ||
import Tooltip from './tooltip'; | ||
|
||
const tooltipPositions: TooltipAlignment[] = ['right', 'left', 'center']; | ||
|
||
export default { | ||
title: 'Common/Tooltip', | ||
component: Tooltip, | ||
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', | ||
control: 'text', | ||
}, | ||
alignment: { | ||
description: | ||
'Position of the tooltip (centered as default)', | ||
options: tooltipPositions, | ||
control: 'radio', | ||
}, | ||
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. | ||
*/ | ||
const Tooltip: React.FC<TooltipProps> = ({ | ||
text, | ||
ariaLabel, | ||
alignment, | ||
children, | ||
}) => ( | ||
<span | ||
data-tip={text} | ||
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.