forked from microsoft/fluentui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(react-tooltip): Add info icon + tooltip story to Tooltip stories (…
…microsoft#28611) * docs: Add info tooltip story to Tooltip stories. * removing space * fix story * rename
- Loading branch information
1 parent
1082207
commit 6720471
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
packages/react-components/react-tooltip/stories/Tooltip/TooltipIcon.stories.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,53 @@ | ||
import * as React from 'react'; | ||
import { Label, makeStyles, mergeClasses, tokens, Tooltip, useId } from '@fluentui/react-components'; | ||
import { Info16Regular } from '@fluentui/react-icons'; | ||
import type { TooltipProps } from '@fluentui/react-components'; | ||
|
||
const useStyles = makeStyles({ | ||
root: { | ||
display: 'flex', | ||
columnGap: tokens.spacingVerticalS, | ||
}, | ||
visible: { | ||
color: tokens.colorNeutralForeground2BrandSelected, | ||
}, | ||
}); | ||
|
||
export const Icon = (props: Partial<TooltipProps>) => { | ||
const styles = useStyles(); | ||
const iconId = useId('icon'); | ||
const contentId = useId('content'); | ||
const [visible, setVisible] = React.useState(false); | ||
|
||
return ( | ||
<div aria-owns={visible ? contentId : undefined} className={styles.root}> | ||
<Label>This is an icon with a Tooltip to show extra information</Label> | ||
<Tooltip | ||
content={{ | ||
children: 'Content must never contain focusable elements.', | ||
id: contentId, | ||
}} | ||
positioning="above-start" | ||
withArrow | ||
relationship="label" | ||
onVisibleChange={(e, data) => setVisible(data.visible)} | ||
{...props} | ||
> | ||
<Info16Regular | ||
tabIndex={0} | ||
id={iconId} | ||
aria-labelledby={`${iconId} ${contentId}`} | ||
className={mergeClasses(visible && styles.visible)} | ||
/> | ||
</Tooltip> | ||
</div> | ||
); | ||
}; | ||
|
||
Icon.parameters = { | ||
docs: { | ||
description: { | ||
story: `Tooltips can be attached to icons to create an info icon.`, | ||
}, | ||
}, | ||
}; |
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