From f786d67f46347b955950e808bedcc22443872d58 Mon Sep 17 00:00:00 2001 From: "Collin Sutton (from Dev Box)" Date: Thu, 26 Sep 2024 12:40:30 -0700 Subject: [PATCH] Add Legends controlled selection example --- .../Legends/Legends.Controlled.Example.tsx | 49 +++++++++++++++++++ .../react-charting/Legends/Legends.doc.tsx | 8 +++ .../react-charting/Legends/LegendsPage.tsx | 7 +++ .../react-charting/Legends/index.stories.tsx | 3 ++ 4 files changed, 67 insertions(+) create mode 100644 packages/react-examples/src/react-charting/Legends/Legends.Controlled.Example.tsx diff --git a/packages/react-examples/src/react-charting/Legends/Legends.Controlled.Example.tsx b/packages/react-examples/src/react-charting/Legends/Legends.Controlled.Example.tsx new file mode 100644 index 0000000000000..64860a5cde000 --- /dev/null +++ b/packages/react-examples/src/react-charting/Legends/Legends.Controlled.Example.tsx @@ -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([]); + + const onChange = (keys: string[]) => { + setSelectedLegends(keys); + }; + + return ( +
+ + + + + + Selected legends: {selectedLegends.join(', ')} +
+ ); +}; diff --git a/packages/react-examples/src/react-charting/Legends/Legends.doc.tsx b/packages/react-examples/src/react-charting/Legends/Legends.doc.tsx index 807597849769d..49297923eaab6 100644 --- a/packages/react-examples/src/react-charting/Legends/Legends.doc.tsx +++ b/packages/react-examples/src/react-charting/Legends/Legends.doc.tsx @@ -6,6 +6,7 @@ import { LegendOverflowExample } from './Legends.Overflow.Example'; import { LegendBasicExample } from './Legends.Basic.Example'; import { LegendWrapLinesExample } from './Legends.WrapLines.Example'; import { LegendStyledExample } from './Legends.Styled.Example'; +import { LegendsControlledExample } from './Legends.Controlled.Example'; const LegendsOverflowExampleCode = require('!raw-loader?esModule=false!@fluentui/react-examples/src/react-charting/Legends/Legends.Overflow.Example.tsx') as string; @@ -15,6 +16,8 @@ const LegendsBasicExampleCode = require('!raw-loader?esModule=false!@fluentui/react-examples/src/react-charting/Legends/Legends.Basic.Example.tsx') as string; const LegendsStyledExampleCode = require('!raw-loader?esModule=false!@fluentui/react-examples/src/react-charting/Legends/Legends.Styled.Example.tsx') as string; +const LegendsControlledExampleCode = + require('!raw-loader?esModule=false!@fluentui/react-examples/src/react-charting/Legends/Legends.Controlled.Example.tsx') as string; export const LegendsPageProps: IDocPageProps = { title: 'Legends', @@ -41,6 +44,11 @@ export const LegendsPageProps: IDocPageProps = { code: LegendsStyledExampleCode, view: , }, + { + title: 'Legend controlled selection', + code: LegendsControlledExampleCode, + view: , + }, ], overview: require('!raw-loader?esModule=false!@fluentui/react-examples/src/react-charting/Legends/docs/LegendsOverview.md'), bestPractices: require('!raw-loader?esModule=false!@fluentui/react-examples/src/react-charting/Legends/docs/LegendsBestPractices.md'), diff --git a/packages/react-examples/src/react-charting/Legends/LegendsPage.tsx b/packages/react-examples/src/react-charting/Legends/LegendsPage.tsx index 6b10896df2a18..d4cbe324a27b8 100644 --- a/packages/react-examples/src/react-charting/Legends/LegendsPage.tsx +++ b/packages/react-examples/src/react-charting/Legends/LegendsPage.tsx @@ -13,6 +13,7 @@ import { LegendBasicExample } from './Legends.Basic.Example'; import { LegendWrapLinesExample } from './Legends.WrapLines.Example'; import { LegendStyledExample } from './Legends.Styled.Example'; import { LegendsOnChangeExample } from './Legends.OnChange.Example'; +import { LegendsControlledExample } from './Legends.Controlled.Example'; const LegendsOverflowExampleCode = require('!raw-loader?esModule=false!@fluentui/react-examples/src/react-charting/Legends/Legends.Overflow.Example.tsx') as string; @@ -24,6 +25,8 @@ const LegendsStyledExampleCode = require('!raw-loader?esModule=false!@fluentui/react-examples/src/react-charting/Legends/Legends.Styled.Example.tsx') as string; const LegendsOnChangeExampleCode = require('!raw-loader?esModule=false!@fluentui/react-examples/src/react-charting/Legends/Legends.OnChange.Example.tsx') as string; +const LegendsControlledExampleCode = + require('!raw-loader?esModule=false!@fluentui/react-examples/src/react-charting/Legends/Legends.Controlled.Example.tsx') as string; export class LegendsPage extends React.Component { public render(): JSX.Element { @@ -52,6 +55,10 @@ export class LegendsPage extends React.Component { + + + + } propertiesTables={ diff --git a/packages/react-examples/src/react-charting/Legends/index.stories.tsx b/packages/react-examples/src/react-charting/Legends/index.stories.tsx index d8d3d731b3b3c..0dc6d687b0794 100644 --- a/packages/react-examples/src/react-charting/Legends/index.stories.tsx +++ b/packages/react-examples/src/react-charting/Legends/index.stories.tsx @@ -5,6 +5,7 @@ import { LegendsOnChangeExample } from './Legends.OnChange.Example'; import { LegendOverflowExample } from './Legends.Overflow.Example'; import { LegendStyledExample } from './Legends.Styled.Example'; import { LegendWrapLinesExample } from './Legends.WrapLines.Example'; +import { LegendsControlledExample } from './Legends.Controlled.Example'; export const Basic = () => ; @@ -16,6 +17,8 @@ export const Styled = () => ; export const WrapLines = () => ; +export const Controlled = () => ; + export default { title: 'Components/Legends', };