Skip to content

Commit 67405d5

Browse files
committed
more readable example with typed option values
1 parent eac8438 commit 67405d5

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

src/Select.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export type SelectProps<OptionValue> = {
2626
placeholder?: string;
2727
};
2828
export type GenericOption<OptionValue> = {
29-
value: OptionValue | number | readonly string[] | undefined;
29+
value: OptionValue;
3030
label: string;
3131
disabled?: boolean;
3232
hidden?: boolean;

stories/Select.stories.tsx

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -133,21 +133,24 @@ const defaultOptions = [
133133
}
134134
];
135135

136-
const optionsWithTypedValues: GenericOption<number>[] = [
137-
{
138-
value: 1,
139-
label: "Option 1"
140-
},
141-
{
142-
value: 2,
143-
label: "Option 2"
144-
},
145-
{
146-
value: 3,
147-
label: "Option 3"
148-
}
136+
type MyFakeValueSet =
137+
| "dc9d15ee-7794-470e-9dcf-a8d1dd1a6fcf"
138+
| "1bda4f79-a199-40ce-985b-fa217809d568"
139+
| "e91b2cac-48f6-4d60-b86f-ece02f076837"
140+
| "66a9d7ac-9b25-4e52-9de3-4b7238135b39";
141+
142+
const myFakeValueSet: MyFakeValueSet[] = [
143+
"dc9d15ee-7794-470e-9dcf-a8d1dd1a6fcf",
144+
"1bda4f79-a199-40ce-985b-fa217809d568",
145+
"e91b2cac-48f6-4d60-b86f-ece02f076837",
146+
"66a9d7ac-9b25-4e52-9de3-4b7238135b39"
149147
];
150148

149+
const optionsWithTypedValues: GenericOption<MyFakeValueSet>[] = myFakeValueSet.map(fakeValue => ({
150+
value: fakeValue,
151+
label: fakeValue
152+
}));
153+
151154
export const Default = getStory({
152155
"label": "Label pour liste déroulante",
153156
"nativeSelectProps": {},
@@ -207,6 +210,6 @@ export const TypedSelect = getStory({
207210
"placeholder": "Sélectionnez une option",
208211
"options": optionsWithTypedValues,
209212
"nativeSelectProps": {
210-
"value": "2"
213+
"defaultValue": "dc9d15ee-7794-470e-9dcf-a8d1dd1a6fcf"
211214
}
212215
});

0 commit comments

Comments
 (0)