-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Legends controlled selection example
- Loading branch information
Collin Sutton (from Dev Box)
committed
Sep 26, 2024
1 parent
32d8336
commit f786d67
Showing
4 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
packages/react-examples/src/react-charting/Legends/Legends.Controlled.Example.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,49 @@ | ||
import * as React from 'react'; | ||
import { Legends, ILegend, DataVizPalette, getColorFromToken } from '@fluentui/react-charting'; | ||
import { Button, Stack } from '@fluentui/react'; | ||
|
||
const legends: ILegend[] = [ | ||
{ | ||
title: 'Legend 1', | ||
color: getColorFromToken(DataVizPalette.color1), | ||
}, | ||
{ | ||
title: 'Legend 2', | ||
color: getColorFromToken(DataVizPalette.color2), | ||
}, | ||
{ | ||
title: 'Legend 3', | ||
color: getColorFromToken(DataVizPalette.color3), | ||
shape: 'diamond', | ||
}, | ||
{ | ||
title: 'Legend 4', | ||
color: getColorFromToken(DataVizPalette.color4), | ||
shape: 'triangle', | ||
}, | ||
]; | ||
|
||
export const LegendsControlledExample: React.FunctionComponent = () => { | ||
const [selectedLegends, setSelectedLegends] = React.useState<string[]>([]); | ||
|
||
const onChange = (keys: string[]) => { | ||
setSelectedLegends(keys); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<Stack horizontal tokens={{ childrenGap: 10 }}> | ||
<Button onClick={() => setSelectedLegends([])}>Select none</Button> | ||
<Button onClick={() => setSelectedLegends(legends.map(legend => legend.title))}>Select all</Button> | ||
</Stack> | ||
<Legends | ||
legends={legends} | ||
canSelectMultipleLegends | ||
selectedLegends={selectedLegends} | ||
// eslint-disable-next-line react/jsx-no-bind | ||
onChange={onChange} | ||
/> | ||
Selected legends: {selectedLegends.join(', ')} | ||
</div> | ||
); | ||
}; |
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