Skip to content

Commit 789f7ae

Browse files
committed
Improve Select and RadioButtons documentation
1 parent 0f65495 commit 789f7ae

File tree

2 files changed

+102
-17
lines changed

2 files changed

+102
-17
lines changed

stories/RadioButtons.stories.tsx

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,92 @@ const { meta, getStory } = getStoryFactory({
99
"wrappedComponent": { RadioButtons },
1010
"description": `
1111
- [See DSFR documentation](https://www.systeme-de-design.gouv.fr/elements-d-interface/composants/boutons-radio)
12-
- [See source code](https://github.com/codegouvfr/react-dsfr/blob/main/src/RadioButtons.tsx)`,
12+
- [See source code](https://github.com/codegouvfr/react-dsfr/blob/main/src/RadioButtons.tsx)
13+
14+
## Controlled
15+
16+
\`\`\`tsx
17+
import { useState } from "react";
18+
import { RadioButtons } from "@codegouvfr/react-dsfr/RadioButtons";
19+
20+
function MyComponent(){
21+
22+
const [ value, setValue ] = useState<"one" | "two" | "three" | undefined>(undefined);
23+
24+
return (
25+
<RadioButtons
26+
label="Label"
27+
options={[
28+
{
29+
label: "Label radio",
30+
nativeInputProps: {
31+
checked: value === "one"
32+
onChange: ()=> setValue("one")
33+
}
34+
},
35+
{
36+
label: "Label radio 2",
37+
nativeInputProps: {
38+
checked: value === "two"
39+
onChange: ()=> setValue("two")
40+
}
41+
},
42+
{
43+
label: "Label radio 3",
44+
nativeInputProps: {
45+
checked: value === "three"
46+
onChange: ()=> setValue("three")
47+
}
48+
}
49+
]}
50+
/>
51+
);
52+
53+
}
54+
\`\`\`
55+
56+
## Uncontrolled
57+
58+
\`\`\`tsx
59+
import { useState } from "react";
60+
import { RadioButtons } from "@codegouvfr/react-dsfr/RadioButtons";
61+
62+
function MyComponent(){
63+
64+
return (
65+
<form>
66+
<RadioButtons
67+
label="Label"
68+
name="my-radio"
69+
options={[
70+
{
71+
label: "Label radio",
72+
nativeInputProps: {
73+
value: "one"
74+
}
75+
},
76+
{
77+
label: "Label radio 2",
78+
nativeInputProps: {
79+
value: "two"
80+
}
81+
},
82+
{
83+
label: "Label radio 3",
84+
nativeInputProps: {
85+
value: "three"
86+
}
87+
}
88+
]}
89+
/>
90+
</form>
91+
);
92+
93+
}
94+
\`\`\`
95+
96+
97+
`,
1398
"argTypes": {
1499
"name": {
15100
"description":

stories/Select.stories.tsx

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const { meta, getStory } = getStoryFactory({
1616
1717
\`\`\`tsx
1818
import { useState } from "react";
19-
import { Select } from "../../dist/Select";
19+
import { Select } from "@codegouvfr/react-dsfr/Select";
2020
2121
function MyComponent(){
2222
@@ -45,25 +45,25 @@ function MyComponent(){
4545
4646
\`\`\`tsx
4747
import { useState } from "react";
48-
import { Select } from "../../dist/Select";
48+
import { Select } from "@codegouvfr/react-dsfr/Select";
4949
5050
function MyComponent(){
5151
52-
const [ value, setValue ] = useState("");
53-
5452
return (
55-
<Select
56-
label="Label"
57-
nativeSelectProps={{
58-
name: "my-select"
59-
}}
60-
>
61-
<option value="" selected disabled hidden>Selectionnez une option</option>
62-
<option value="1">Option 1</option>
63-
<option value="2">Option 2</option>
64-
<option value="3">Option 3</option>
65-
<option value="4">Option 4</option>
66-
</Select>
53+
<form>
54+
<Select
55+
label="Label"
56+
nativeSelectProps={{
57+
name: "my-select"
58+
}}
59+
>
60+
<option value="" selected disabled hidden>Selectionnez une option</option>
61+
<option value="1">Option 1</option>
62+
<option value="2">Option 2</option>
63+
<option value="3">Option 3</option>
64+
<option value="4">Option 4</option>
65+
</Select>
66+
</form>
6767
);
6868
6969
}

0 commit comments

Comments
 (0)