|
1 | 1 | import * as React from 'react';
|
2 |
| -import { Label, makeStyles, Radio, RadioGroup, tokens, useId } from '@fluentui/react-components'; |
3 | 2 |
|
4 |
| -const useStyles = makeStyles({ |
5 |
| - field: { |
6 |
| - display: 'grid', |
7 |
| - gridRowGap: tokens.spacingVerticalS, |
8 |
| - }, |
9 |
| -}); |
| 3 | +import { Field, Radio, RadioGroup, Button } from '@fluentui/react-components'; |
10 | 4 |
|
11 | 5 | export const ControlledValue = () => {
|
12 | 6 | const [value, setValue] = React.useState('banana');
|
13 |
| - const styles = useStyles(); |
14 |
| - const labelId = useId('label'); |
15 | 7 | return (
|
16 |
| - <div className={styles.field}> |
17 |
| - <Label id={labelId}>Favorite Fruit</Label> |
18 |
| - <RadioGroup value={value} onChange={(_, data) => setValue(data.value)} aria-labelledby={labelId}> |
19 |
| - <Radio value="apple" label="Apple" /> |
20 |
| - <Radio value="pear" label="Pear" /> |
21 |
| - <Radio value="banana" label="Banana" /> |
22 |
| - <Radio value="orange" label="Orange" /> |
23 |
| - </RadioGroup> |
24 |
| - <div>Current value: {value}</div> |
25 |
| - </div> |
| 8 | + <> |
| 9 | + <Field label="Favorite Fruit"> |
| 10 | + <RadioGroup value={value} onChange={(_, data) => setValue(data.value)}> |
| 11 | + <Radio value="apple" label="Apple" /> |
| 12 | + <Radio value="pear" label="Pear" /> |
| 13 | + <Radio value="banana" label="Banana" /> |
| 14 | + <Radio value="orange" label="Orange" /> |
| 15 | + </RadioGroup> |
| 16 | + </Field> |
| 17 | + <Button disabled={!value} onClick={() => setValue('')}> |
| 18 | + Clear selection |
| 19 | + </Button> |
| 20 | + </> |
26 | 21 | );
|
27 | 22 | };
|
| 23 | + |
28 | 24 | ControlledValue.parameters = {
|
29 | 25 | docs: {
|
30 | 26 | description: {
|
|
0 commit comments