|
1 | 1 | import * as React from 'react'; |
2 | | -import { Icon } from '@fluentui/react/lib/Icon'; |
| 2 | +import { DefaultButton } from '@fluentui/react/lib/Button'; |
3 | 3 | import { Stack, IStackTokens } from '@fluentui/react/lib/Stack'; |
4 | 4 | import { Toggle } from '@fluentui/react/lib/Toggle'; |
5 | 5 | import { TooltipHost } from '@fluentui/react/lib/Tooltip'; |
| 6 | +import { useId } from '@fluentui/react-hooks'; |
6 | 7 |
|
7 | 8 | const stackTokens: IStackTokens = { childrenGap: 10 }; |
8 | 9 |
|
| 10 | +const buttonStyles = { |
| 11 | + root: { |
| 12 | + background: 'transparent', |
| 13 | + border: 'none', |
| 14 | + minWidth: '16px', |
| 15 | + padding: 0, |
| 16 | + }, |
| 17 | +}; |
| 18 | + |
9 | 19 | export const ToggleCustomLabelExample: React.FunctionComponent = () => { |
| 20 | + const [showTooltip, setShowTooltip] = React.useState(false); |
| 21 | + const tooltipId = useId('tooltipId'); |
| 22 | + |
| 23 | + const iconWithTooltip = ( |
| 24 | + <> |
| 25 | + <TooltipHost content={showTooltip ? 'Info tooltip' : undefined} id={tooltipId}> |
| 26 | + <DefaultButton |
| 27 | + aria-label={'more info'} |
| 28 | + aria-describedby={showTooltip ? tooltipId : undefined} |
| 29 | + // eslint-disable-next-line react/jsx-no-bind |
| 30 | + onClick={() => setShowTooltip(!showTooltip)} |
| 31 | + styles={buttonStyles} |
| 32 | + iconProps={{ iconName: 'Info' }} |
| 33 | + /> |
| 34 | + </TooltipHost> |
| 35 | + </> |
| 36 | + ); |
| 37 | + |
10 | 38 | return ( |
11 | 39 | <Stack tokens={stackTokens}> |
12 | | - <Toggle |
13 | | - label={ |
14 | | - <div> |
15 | | - Custom label{' '} |
16 | | - <TooltipHost content="Info tooltip"> |
17 | | - <Icon iconName="Info" aria-label="Info tooltip" /> |
18 | | - </TooltipHost> |
19 | | - </div> |
20 | | - } |
21 | | - onText="On" |
22 | | - offText="Off" |
23 | | - onChange={_onChange} |
24 | | - /> |
| 40 | + <Toggle label={<div>Custom label {iconWithTooltip}</div>} onText="On" offText="Off" onChange={_onChange} /> |
25 | 41 |
|
26 | 42 | <Toggle |
27 | | - label={ |
28 | | - <div> |
29 | | - Custom inline label{' '} |
30 | | - <TooltipHost content="Info tooltip"> |
31 | | - <Icon iconName="Info" aria-label="Info tooltip" /> |
32 | | - </TooltipHost> |
33 | | - </div> |
34 | | - } |
| 43 | + label={<div>Custom inline label {iconWithTooltip}</div>} |
35 | 44 | inlineLabel |
36 | 45 | onText="On" |
37 | 46 | offText="Off" |
|
0 commit comments