1
1
import * as React from 'react' ;
2
- import { Dropdown , IDropdownOption } from '@fluentui/react/lib/Dropdown' ;
3
2
import { TextField , ITextFieldStyles } from '@fluentui/react/lib/TextField' ;
3
+ import {
4
+ Dropdown ,
5
+ Option ,
6
+ SelectionEvents ,
7
+ OptionOnSelectData ,
8
+ Subtitle2
9
+ } from '@fluentui/react-components' ;
4
10
import { DeclarativeChart , DeclarativeChartProps , IDeclarativeChart , Schema } from '@fluentui/react-charting' ;
5
11
6
12
interface IErrorBoundaryProps {
@@ -46,11 +52,6 @@ const schemasData = requireContext.keys().map((fileName: string) => ({
46
52
schema : requireContext ( fileName ) ,
47
53
} ) ) ;
48
54
49
- const options : IDropdownOption [ ] = schemasData . map ( ( data ) => ( {
50
- key : ( data . schema as { id : string } ) . id ,
51
- text : data . fileName ,
52
- } ) ) ;
53
-
54
55
const dropdownStyles = { dropdown : { width : 200 } } ;
55
56
56
57
const textFieldStyles : Partial < ITextFieldStyles > = { root : { maxWidth : 300 } } ;
@@ -64,7 +65,7 @@ export class DeclarativeChartBasicExample extends React.Component<{}, IDeclarati
64
65
const selectedSchema = schemasData [ 0 ] ?. schema || { } ;
65
66
const { selectedLegends } = selectedSchema as any ;
66
67
this . state = {
67
- selectedChoice : ( schemasData [ 0 ] . schema as { id : string } ) . id || 'unknown' , // Set the first file as the default choice if available
68
+ selectedChoice : ( schemasData [ 0 ] . fileName ) || 'unknown' , // Set the first file as the default choice if available
68
69
selectedSchema : selectedSchema ,
69
70
schemasData : schemasData ,
70
71
selectedLegends : JSON . stringify ( selectedLegends ) ,
@@ -80,9 +81,9 @@ export class DeclarativeChartBasicExample extends React.Component<{}, IDeclarati
80
81
} ) ;
81
82
}
82
83
83
- private _onChange = ( ev : any , option ?: IDropdownOption ) : void => {
84
- const selectedChoice = option ?. key as string ;
85
- const selectedSchema = this . state . schemasData . find ( ( data ) => ( data . schema as { id : string } ) . id === selectedChoice ) ?. schema ;
84
+ private _onChange = ( event : SelectionEvents , data : OptionOnSelectData ) : void => {
85
+ const selectedChoice = data . optionText ! ;
86
+ const selectedSchema = this . state . schemasData . find ( ( s ) => ( s . schema as { id : string } ) . id === data . optionValue ! ) ?. schema ;
86
87
const { selectedLegends } = selectedSchema as any ;
87
88
this . setState ( { selectedChoice, selectedSchema, selectedLegends : JSON . stringify ( selectedLegends ) } ) ;
88
89
} ;
@@ -130,13 +131,15 @@ export class DeclarativeChartBasicExample extends React.Component<{}, IDeclarati
130
131
return (
131
132
< >
132
133
< div style = { { display : 'flex' } } >
133
- < Dropdown
134
- label = "Select a schema"
135
- options = { options }
136
- onChange = { this . _onChange }
137
- selectedKey = { this . state . selectedChoice }
138
- styles = { dropdownStyles }
139
- />
134
+ < label > Select a schema:</ label >
135
+ < Dropdown
136
+ value = { this . state . selectedChoice }
137
+ onOptionSelect = { this . _onChange }
138
+ >
139
+ { schemasData . map ( ( data ) => (
140
+ < Option value = { ( data . schema as { id : string } ) . id } > { data . fileName } </ Option >
141
+ ) ) }
142
+ </ Dropdown >
140
143
141
144
</ div >
142
145
< br />
@@ -147,12 +150,12 @@ export class DeclarativeChartBasicExample extends React.Component<{}, IDeclarati
147
150
} ) ;
148
151
} }
149
152
>
150
- Download
153
+ Download as Image
151
154
</ button >
152
155
< div data-testid = "chart-container" >
153
156
< br />
154
157
< br />
155
- < h2 > { this . state . selectedChoice } . { selectedSchema . layout . title } </ h2 >
158
+ < Subtitle2 > { selectedSchema . layout . title } </ Subtitle2 >
156
159
< br />
157
160
< br />
158
161
< ErrorBoundary >
0 commit comments