|
1 | 1 | import { type Meta, type StoryObj } from '@storybook/react-vite'; |
2 | | -import { useState } from 'react'; |
3 | 2 |
|
4 | 3 | import { Select } from '#components/form-elements/select/index.js'; |
5 | | -import { TextInput } from '#components/form-elements/text-input/index.js'; |
6 | 4 |
|
7 | 5 | const meta: Meta<typeof Select> = { |
8 | 6 | title: 'Form Elements/Select', |
9 | 7 | component: Select, |
10 | 8 | args: { |
11 | | - label: 'Label text goes here', |
12 | | - labelProps: { isPageHeading: true, size: 'l' }, |
| 9 | + label: 'Sort by', |
| 10 | + labelProps: { isPageHeading: true }, |
13 | 11 | }, |
| 12 | + render: (args) => ( |
| 13 | + <Select {...args}> |
| 14 | + <Select.Option>Choose location</Select.Option> |
| 15 | + <Select.Option value="eastmidlands">East Midlands</Select.Option> |
| 16 | + <Select.Option value="eastofengland">East of England</Select.Option> |
| 17 | + <Select.Option value="london">London</Select.Option> |
| 18 | + <Select.Option value="northeast">North East</Select.Option> |
| 19 | + <Select.Option value="northwest">North West</Select.Option> |
| 20 | + <Select.Option value="southeast">South East</Select.Option> |
| 21 | + <Select.Option value="southwest">South West</Select.Option> |
| 22 | + <Select.Option value="westmidlands">West Midlands</Select.Option> |
| 23 | + <Select.Option value="yorkshire">Yorkshire and the Humber</Select.Option> |
| 24 | + </Select> |
| 25 | + ), |
14 | 26 | }; |
15 | 27 | export default meta; |
16 | 28 | type Story = StoryObj<typeof Select>; |
17 | 29 |
|
18 | 30 | export const Standard: Story = { |
19 | | - args: { |
20 | | - defaultValue: '2', |
21 | | - }, |
22 | 31 | render: (args) => ( |
23 | 32 | <Select {...args}> |
24 | | - <Select.Option value="1">NHS.UK frontend option 1</Select.Option> |
25 | | - <Select.Option value="2">NHS.UK frontend option 2</Select.Option> |
26 | | - <Select.Option value="3" disabled> |
27 | | - NHS.UK frontend option 3 |
28 | | - </Select.Option> |
| 33 | + <Select.Option value="published">Recently published</Select.Option> |
| 34 | + <Select.Option value="updated">Recently updated</Select.Option> |
| 35 | + <Select.Option value="views">Most view</Select.Option> |
| 36 | + <Select.Option value="comments">Most comments</Select.Option> |
29 | 37 | </Select> |
30 | 38 | ), |
31 | 39 | }; |
32 | 40 |
|
33 | 41 | export const SelectWithHintText: Story = { |
34 | 42 | args: { |
35 | | - hint: 'Hint text goes here', |
| 43 | + hint: 'This can be different to where you went before', |
36 | 44 | }, |
37 | | - render: (args) => ( |
38 | | - <Select {...args}> |
39 | | - <Select.Option value="1">NHS.UK frontend option 1</Select.Option> |
40 | | - <Select.Option value="2">NHS.UK frontend option 2</Select.Option> |
41 | | - <Select.Option value="3">NHS.UK frontend option 3</Select.Option> |
42 | | - </Select> |
43 | | - ), |
44 | 45 | }; |
45 | 46 |
|
46 | 47 | export const SelectWithError: Story = { |
47 | | - render: function SelectWithErrorRender(args) { |
48 | | - const [error, setError] = useState<string>('Error message goes here'); |
49 | | - return ( |
50 | | - <> |
51 | | - <Select error={error} {...args}> |
52 | | - <Select.Option value="1">NHS.UK frontend option 1</Select.Option> |
53 | | - <Select.Option value="2">NHS.UK frontend option 2</Select.Option> |
54 | | - <Select.Option value="3">NHS.UK frontend option 3</Select.Option> |
55 | | - </Select> |
56 | | - <TextInput onChange={(e) => setError(e.currentTarget.value)} value={error} /> |
57 | | - </> |
58 | | - ); |
| 48 | + args: { |
| 49 | + error: 'Select a location', |
59 | 50 | }, |
60 | | - |
61 | | - name: 'Select With Error (String)', |
62 | 51 | }; |
63 | 52 |
|
64 | 53 | export const SelectWithErrorAndHintText: Story = { |
65 | 54 | args: { |
66 | | - hint: 'Hint text goes here', |
67 | | - }, |
68 | | - render: function SelectWithErrorAndHintTextRender(args) { |
69 | | - const [error, setError] = useState<string>('Error message goes here'); |
70 | | - return ( |
71 | | - <> |
72 | | - <Select error={error} {...args}> |
73 | | - <Select.Option value="1">NHS.UK frontend option 1</Select.Option> |
74 | | - <Select.Option value="2">NHS.UK frontend option 2</Select.Option> |
75 | | - <Select.Option value="3">NHS.UK frontend option 3</Select.Option> |
76 | | - </Select> |
77 | | - <TextInput onChange={(e) => setError(e.currentTarget.value)} value={error} /> |
78 | | - </> |
79 | | - ); |
| 55 | + hint: 'This can be different to where you went before', |
| 56 | + error: 'Select a location', |
80 | 57 | }, |
81 | | - |
82 | | - name: 'Select With Error and Hint (String)', |
83 | 58 | }; |
0 commit comments