@ilo-org/react 0.7.8 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/lib/cjs/components/Checkbox/Checkbox.js +28 -16
- package/lib/cjs/components/Checkbox/index.js +25 -3
- package/lib/cjs/components/DatePicker/DatePicker.js +21 -16
- package/lib/cjs/components/DatePicker/index.js +4 -4
- package/lib/cjs/components/Dropdown/Dropdown.js +19 -15
- package/lib/cjs/components/Dropdown/index.js +3 -3
- package/lib/cjs/components/Fieldset/Fieldset.js +33 -9
- package/lib/cjs/components/Fieldset/index.js +2 -2
- package/lib/cjs/components/FileUpload/FileUpload.js +29 -15
- package/lib/cjs/components/FileUpload/index.js +3 -3
- package/lib/cjs/components/Form/Form.js +8 -55
- package/lib/cjs/components/Form/index.js +10 -20
- package/lib/cjs/components/FormControl/FormControl.js +79 -0
- package/lib/cjs/components/FormControl/index.js +16 -0
- package/lib/cjs/components/Input/Input.js +1 -1
- package/lib/cjs/components/NumberPicker/NumberPicker.js +21 -16
- package/lib/cjs/components/NumberPicker/index.js +4 -4
- package/lib/cjs/components/Radio/Radio.js +34 -17
- package/lib/cjs/components/Radio/index.js +19 -4
- package/lib/cjs/components/TextInput/TextInput.js +30 -0
- package/lib/cjs/components/TextInput/index.js +52 -0
- package/lib/cjs/components/Textarea/Textarea.js +19 -19
- package/lib/cjs/components/Textarea/index.js +26 -5
- package/lib/cjs/components/Toggle/Toggle.js +33 -0
- package/lib/cjs/components/Toggle/index.js +51 -0
- package/lib/cjs/components/Tooltip/Tooltip.js +2 -2
- package/lib/cjs/components/index.js +10 -11
- package/lib/cjs/hooks/usePrevious.js +20 -0
- package/lib/cjs/index.js +10 -11
- package/lib/esm/components/Checkbox/Checkbox.js +31 -19
- package/lib/esm/components/Checkbox/index.js +27 -2
- package/lib/esm/components/DatePicker/DatePicker.js +22 -17
- package/lib/esm/components/DatePicker/index.js +4 -4
- package/lib/esm/components/Dropdown/Dropdown.js +20 -16
- package/lib/esm/components/Dropdown/index.js +3 -3
- package/lib/esm/components/Fieldset/Fieldset.js +31 -11
- package/lib/esm/components/Fieldset/index.js +1 -1
- package/lib/esm/components/FileUpload/FileUpload.js +31 -17
- package/lib/esm/components/FileUpload/index.js +3 -3
- package/lib/esm/components/Form/Form.js +10 -57
- package/lib/esm/components/Form/index.js +13 -20
- package/lib/esm/components/FormControl/FormControl.js +73 -0
- package/lib/esm/components/{ChoiceGroup → FormControl}/index.js +3 -6
- package/lib/esm/components/NumberPicker/NumberPicker.js +21 -16
- package/lib/esm/components/NumberPicker/index.js +4 -4
- package/lib/esm/components/Radio/Radio.js +34 -17
- package/lib/esm/components/Radio/index.js +21 -3
- package/lib/esm/components/TextInput/TextInput.js +28 -0
- package/lib/esm/components/TextInput/index.js +49 -0
- package/lib/esm/components/Textarea/Textarea.js +19 -19
- package/lib/esm/components/Textarea/index.js +28 -4
- package/lib/esm/components/Toggle/Toggle.js +31 -0
- package/lib/esm/components/Toggle/index.js +48 -0
- package/lib/esm/components/Tooltip/Tooltip.js +2 -2
- package/lib/esm/components/index.js +8 -5
- package/lib/esm/hooks/usePrevious.js +15 -0
- package/lib/esm/index.js +8 -5
- package/lib/types/react/src/components/Checkbox/Checkbox.args.d.ts +52 -0
- package/lib/types/react/src/components/Checkbox/Checkbox.d.ts +5 -3
- package/lib/types/react/src/components/Checkbox/Checkbox.props.d.ts +4 -13
- package/lib/types/react/src/components/Checkbox/index.d.ts +1 -0
- package/lib/types/react/src/components/DatePicker/DatePicker.d.ts +4 -3
- package/lib/types/react/src/components/DatePicker/DatePicker.props.d.ts +10 -43
- package/lib/types/react/src/components/Dropdown/Dropdown.d.ts +5 -3
- package/lib/types/react/src/components/Dropdown/Dropdown.props.d.ts +16 -42
- package/lib/types/react/src/components/Fieldset/Fieldset.d.ts +6 -0
- package/lib/types/react/src/components/Fieldset/Fieldset.props.d.ts +14 -21
- package/lib/types/react/src/components/FileUpload/FileUpload.d.ts +5 -3
- package/lib/types/react/src/components/FileUpload/FileUpload.props.d.ts +7 -44
- package/lib/types/react/src/components/Form/Form.args.d.ts +2 -0
- package/lib/types/react/src/components/Form/Form.d.ts +1 -2
- package/lib/types/react/src/components/Form/Form.props.d.ts +4 -111
- package/lib/types/react/src/components/Form/index.d.ts +1 -0
- package/lib/types/react/src/components/FormControl/FormControl.d.ts +9 -0
- package/lib/types/react/src/components/FormControl/FormControl.props.d.ts +55 -0
- package/lib/types/react/src/components/FormControl/index.d.ts +2 -0
- package/lib/types/react/src/components/FormElement/FormElement.props.d.ts +2 -2
- package/lib/types/react/src/components/Input/Input.props.d.ts +2 -2
- package/lib/types/react/src/components/NumberPicker/NumberPicker.d.ts +5 -3
- package/lib/types/react/src/components/NumberPicker/NumberPicker.props.d.ts +5 -42
- package/lib/types/react/src/components/Radio/Radio.args.d.ts +8 -0
- package/lib/types/react/src/components/Radio/Radio.d.ts +5 -3
- package/lib/types/react/src/components/Radio/Radio.props.d.ts +4 -14
- package/lib/types/react/src/components/Radio/index.d.ts +1 -0
- package/lib/types/react/src/components/TextInput/TextInput.args.d.ts +10 -0
- package/lib/types/react/src/components/TextInput/TextInput.d.ts +6 -0
- package/lib/types/react/src/components/TextInput/TextInput.props.d.ts +17 -0
- package/lib/types/react/src/components/TextInput/index.d.ts +2 -0
- package/lib/types/react/src/components/Textarea/Textarea.args.d.ts +10 -0
- package/lib/types/react/src/components/Textarea/Textarea.d.ts +5 -3
- package/lib/types/react/src/components/Textarea/Textarea.props.d.ts +17 -39
- package/lib/types/react/src/components/Textarea/index.d.ts +2 -0
- package/lib/types/react/src/components/Toggle/Toggle.args.d.ts +12 -0
- package/lib/types/react/src/components/Toggle/Toggle.d.ts +5 -0
- package/lib/types/react/src/components/Toggle/Toggle.props.d.ts +22 -0
- package/lib/types/react/src/components/Toggle/index.d.ts +3 -0
- package/lib/types/react/src/components/Tooltip/Tooltip.props.d.ts +4 -0
- package/lib/types/react/src/components/index.d.ts +1 -5
- package/lib/types/react/src/hooks/usePrevious.d.ts +2 -0
- package/lib/types/react/src/types/index.d.ts +57 -1
- package/package.json +19 -18
- package/src/components/Checkbox/Checkbox.args.ts +31 -9
- package/src/components/Checkbox/Checkbox.props.ts +5 -13
- package/src/components/Checkbox/Checkbox.tsx +78 -76
- package/src/components/Checkbox/index.ts +1 -0
- package/src/components/DatePicker/DatePicker.args.ts +6 -32
- package/src/components/DatePicker/DatePicker.props.ts +11 -51
- package/src/components/DatePicker/DatePicker.tsx +71 -110
- package/src/components/Dropdown/Dropdown.args.ts +42 -192
- package/src/components/Dropdown/Dropdown.props.ts +18 -49
- package/src/components/Dropdown/Dropdown.tsx +73 -62
- package/src/components/Fieldset/Fieldset.props.ts +14 -23
- package/src/components/Fieldset/Fieldset.tsx +75 -69
- package/src/components/FileUpload/FileUpload.args.ts +25 -27
- package/src/components/FileUpload/FileUpload.props.ts +8 -53
- package/src/components/FileUpload/FileUpload.tsx +103 -72
- package/src/components/Form/Form.args.ts +2 -184
- package/src/components/Form/Form.props.ts +4 -133
- package/src/components/Form/Form.tsx +17 -77
- package/src/components/Form/index.ts +1 -0
- package/src/components/FormControl/FormControl.props.ts +72 -0
- package/src/components/FormControl/FormControl.tsx +169 -0
- package/src/components/FormControl/index.ts +2 -0
- package/src/components/FormElement/FormElement.props.ts +2 -2
- package/src/components/Input/Input.props.ts +2 -2
- package/src/components/Navigation/Navigation.args.ts +2 -1
- package/src/components/NumberPicker/NumberPicker.args.ts +18 -26
- package/src/components/NumberPicker/NumberPicker.props.ts +7 -52
- package/src/components/NumberPicker/NumberPicker.tsx +73 -56
- package/src/components/Radio/Radio.args.ts +1 -7
- package/src/components/Radio/Radio.props.ts +6 -14
- package/src/components/Radio/Radio.tsx +90 -52
- package/src/components/Radio/index.ts +1 -0
- package/src/components/TextInput/TextInput.args.ts +75 -0
- package/src/components/TextInput/TextInput.props.ts +20 -0
- package/src/components/TextInput/TextInput.tsx +71 -0
- package/src/components/TextInput/index.ts +2 -0
- package/src/components/Textarea/Textarea.args.ts +19 -37
- package/src/components/Textarea/Textarea.props.ts +18 -46
- package/src/components/Textarea/Textarea.tsx +44 -59
- package/src/components/Textarea/index.ts +2 -0
- package/src/components/Toggle/Toggle.args.ts +62 -0
- package/src/components/Toggle/Toggle.props.ts +27 -0
- package/src/components/Toggle/Toggle.tsx +85 -0
- package/src/components/Toggle/index.ts +3 -0
- package/src/components/Tooltip/Tooltip.props.ts +5 -0
- package/src/components/Tooltip/Tooltip.tsx +2 -0
- package/src/components/index.ts +1 -5
- package/src/hooks/usePrevious.ts +15 -0
- package/src/types/forms.args.ts +288 -0
- package/src/types/index.ts +69 -1
- package/tsconfig.json +2 -1
- package/lib/cjs/components/ChoiceGroup/ChoiceGroup.js +0 -34
- package/lib/cjs/components/ChoiceGroup/index.js +0 -19
- package/lib/cjs/components/FormGroup/FormGroup.js +0 -58
- package/lib/cjs/components/FormGroup/index.js +0 -26
- package/lib/esm/components/ChoiceGroup/ChoiceGroup.js +0 -32
- package/lib/esm/components/FormGroup/FormGroup.js +0 -56
- package/lib/esm/components/FormGroup/index.js +0 -20
- package/lib/types/react/src/components/ChoiceGroup/ChoiceGroup.d.ts +0 -4
- package/lib/types/react/src/components/ChoiceGroup/ChoiceGroup.props.d.ts +0 -20
- package/lib/types/react/src/components/ChoiceGroup/index.d.ts +0 -1
- package/lib/types/react/src/components/FormGroup/FormGroup.d.ts +0 -4
- package/lib/types/react/src/components/FormGroup/FormGroup.props.d.ts +0 -81
- package/lib/types/react/src/components/FormGroup/index.d.ts +0 -1
- package/src/components/ChoiceGroup/ChoiceGroup.args.ts +0 -95
- package/src/components/ChoiceGroup/ChoiceGroup.props.ts +0 -25
- package/src/components/ChoiceGroup/ChoiceGroup.tsx +0 -54
- package/src/components/ChoiceGroup/index.ts +0 -1
- package/src/components/FormGroup/FormGroup.args.ts +0 -85
- package/src/components/FormGroup/FormGroup.props.ts +0 -102
- package/src/components/FormGroup/FormGroup.tsx +0 -73
- package/src/components/FormGroup/index.ts +0 -1
|
@@ -1,214 +1,64 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LabelledDropdownProps } from "./Dropdown.props";
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
export const options = [
|
|
4
|
+
{ label: "Switzerland", value: "CH" },
|
|
5
|
+
{ label: "Côte d'Ivoire ", value: "CI" },
|
|
6
|
+
{ label: "Thailand", value: "TH" },
|
|
7
|
+
{ label: "United States", value: "US" },
|
|
8
|
+
{ label: "Zimbabwe", value: "ZW" },
|
|
9
|
+
{ label: "Afghanistan", value: "AF" },
|
|
10
|
+
{ label: "Åland Islands", value: "AX" },
|
|
11
|
+
{ label: "Albania", value: "AL" },
|
|
12
|
+
{ label: "Algeria", value: "DZ" },
|
|
13
|
+
{ label: "American Samoa", value: "AS" },
|
|
14
|
+
{ label: "AndorrA", value: "AD" },
|
|
15
|
+
{ label: "Angola", value: "AO" },
|
|
16
|
+
{ label: "Anguilla", value: "AI" },
|
|
17
|
+
{ label: "Antarctica", value: "AQ" },
|
|
18
|
+
{ label: "Antigua and Barbuda", value: "AG" },
|
|
19
|
+
{ label: "Argentina", value: "AR" },
|
|
20
|
+
{ label: "Armenia", value: "AM" },
|
|
21
|
+
{ label: "Aruba", value: "AW" },
|
|
22
|
+
{ label: "Australia", value: "AU" },
|
|
23
|
+
{ label: "Austria", value: "AT" },
|
|
24
|
+
{ label: "Azerbaijan", value: "AZ" },
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
const basic: LabelledDropdownProps = {
|
|
28
|
+
label: "Select a country",
|
|
29
|
+
errorMessage: "Please select a country",
|
|
4
30
|
autocomplete: "false",
|
|
5
|
-
callback: () => {},
|
|
6
31
|
className: "storybook",
|
|
7
32
|
disabled: false,
|
|
8
33
|
error: false,
|
|
9
|
-
helper: false,
|
|
10
34
|
id: "dropdown",
|
|
11
|
-
label: "Dropdown Label",
|
|
12
35
|
name: "dropdown",
|
|
13
|
-
options
|
|
14
|
-
{
|
|
15
|
-
disabled: false,
|
|
16
|
-
label: "Option One",
|
|
17
|
-
value: "option one",
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
disabled: false,
|
|
21
|
-
label: "Option Two",
|
|
22
|
-
value: "option two",
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
disabled: false,
|
|
26
|
-
label: "Option Three",
|
|
27
|
-
value: "option three",
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
disabled: false,
|
|
31
|
-
label: "Option Four",
|
|
32
|
-
value: "four",
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
disabled: false,
|
|
36
|
-
label: "Option Five",
|
|
37
|
-
value: "the fifth",
|
|
38
|
-
},
|
|
39
|
-
],
|
|
36
|
+
options,
|
|
40
37
|
required: false,
|
|
41
38
|
value: "option one",
|
|
39
|
+
style: { width: "100%" },
|
|
42
40
|
};
|
|
43
41
|
|
|
44
|
-
const haserror:
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
className: "storybook",
|
|
48
|
-
disabled: false,
|
|
49
|
-
error: "This is an error message",
|
|
50
|
-
helper: "Example Helper Text",
|
|
51
|
-
id: "dropdown",
|
|
52
|
-
label: "Dropdown Label",
|
|
53
|
-
name: "dropdown",
|
|
54
|
-
options: [
|
|
55
|
-
{
|
|
56
|
-
disabled: false,
|
|
57
|
-
label: "Option One",
|
|
58
|
-
value: "option one",
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
disabled: false,
|
|
62
|
-
label: "Option Two",
|
|
63
|
-
value: "option two",
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
disabled: false,
|
|
67
|
-
label: "Option Three",
|
|
68
|
-
value: "option three",
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
disabled: false,
|
|
72
|
-
label: "Option Four",
|
|
73
|
-
value: "four",
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
disabled: false,
|
|
77
|
-
label: "Option Five",
|
|
78
|
-
value: "the fifth",
|
|
79
|
-
},
|
|
80
|
-
],
|
|
81
|
-
required: false,
|
|
82
|
-
value: "option one",
|
|
42
|
+
const haserror: LabelledDropdownProps = {
|
|
43
|
+
...basic,
|
|
44
|
+
error: true,
|
|
83
45
|
};
|
|
84
46
|
|
|
85
|
-
const hashelper:
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
className: "storybook",
|
|
89
|
-
disabled: false,
|
|
90
|
-
error: false,
|
|
91
|
-
helper: "Example Helper Text",
|
|
92
|
-
id: "dropdown",
|
|
93
|
-
label: "Dropdown Label",
|
|
94
|
-
name: "dropdown",
|
|
95
|
-
options: [
|
|
96
|
-
{
|
|
97
|
-
disabled: false,
|
|
98
|
-
label: "Option One",
|
|
99
|
-
value: "option one",
|
|
100
|
-
},
|
|
101
|
-
{
|
|
102
|
-
disabled: false,
|
|
103
|
-
label: "Option Two",
|
|
104
|
-
value: "option two",
|
|
105
|
-
},
|
|
106
|
-
{
|
|
107
|
-
disabled: false,
|
|
108
|
-
label: "Option Three",
|
|
109
|
-
value: "option three",
|
|
110
|
-
},
|
|
111
|
-
{
|
|
112
|
-
disabled: false,
|
|
113
|
-
label: "Option Four",
|
|
114
|
-
value: "four",
|
|
115
|
-
},
|
|
116
|
-
{
|
|
117
|
-
disabled: false,
|
|
118
|
-
label: "Option Five",
|
|
119
|
-
value: "the fifth",
|
|
120
|
-
},
|
|
121
|
-
],
|
|
122
|
-
required: false,
|
|
123
|
-
value: "option one",
|
|
47
|
+
const hashelper: LabelledDropdownProps = {
|
|
48
|
+
...basic,
|
|
49
|
+
helper: "Please select a country",
|
|
124
50
|
};
|
|
125
51
|
|
|
126
|
-
const hastooltip:
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
className: "storybook",
|
|
130
|
-
disabled: false,
|
|
131
|
-
error: false,
|
|
132
|
-
helper: false,
|
|
133
|
-
id: "dropdown",
|
|
134
|
-
label: "Dropdown Label",
|
|
135
|
-
name: "dropdown",
|
|
136
|
-
options: [
|
|
137
|
-
{
|
|
138
|
-
disabled: false,
|
|
139
|
-
label: "Option One",
|
|
140
|
-
value: "option one",
|
|
141
|
-
},
|
|
142
|
-
{
|
|
143
|
-
disabled: false,
|
|
144
|
-
label: "Option Two",
|
|
145
|
-
value: "option two",
|
|
146
|
-
},
|
|
147
|
-
{
|
|
148
|
-
disabled: false,
|
|
149
|
-
label: "Option Three",
|
|
150
|
-
value: "option three",
|
|
151
|
-
},
|
|
152
|
-
{
|
|
153
|
-
disabled: false,
|
|
154
|
-
label: "Option Four",
|
|
155
|
-
value: "four",
|
|
156
|
-
},
|
|
157
|
-
{
|
|
158
|
-
disabled: false,
|
|
159
|
-
label: "Option Five",
|
|
160
|
-
value: "the fifth",
|
|
161
|
-
},
|
|
162
|
-
],
|
|
163
|
-
required: false,
|
|
164
|
-
tooltip: "This is my tooltip text.",
|
|
165
|
-
value: "option one",
|
|
52
|
+
const hastooltip: LabelledDropdownProps = {
|
|
53
|
+
...basic,
|
|
54
|
+
tooltip: "Please select a country",
|
|
166
55
|
};
|
|
167
56
|
|
|
168
|
-
const isdisabled:
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
className: "storybook",
|
|
172
|
-
disabled: false,
|
|
173
|
-
error: false,
|
|
174
|
-
helper: false,
|
|
175
|
-
id: "dropdown",
|
|
176
|
-
label: "Dropdown Label",
|
|
177
|
-
name: "dropdown",
|
|
178
|
-
options: [
|
|
179
|
-
{
|
|
180
|
-
disabled: false,
|
|
181
|
-
label: "Option One",
|
|
182
|
-
value: "option one",
|
|
183
|
-
},
|
|
184
|
-
{
|
|
185
|
-
disabled: false,
|
|
186
|
-
label: "Option Two",
|
|
187
|
-
value: "option two",
|
|
188
|
-
},
|
|
189
|
-
{
|
|
190
|
-
disabled: false,
|
|
191
|
-
label: "Option Three",
|
|
192
|
-
value: "option three",
|
|
193
|
-
},
|
|
194
|
-
{
|
|
195
|
-
disabled: false,
|
|
196
|
-
label: "Option Four",
|
|
197
|
-
value: "four",
|
|
198
|
-
},
|
|
199
|
-
{
|
|
200
|
-
disabled: false,
|
|
201
|
-
label: "Option Five",
|
|
202
|
-
value: "the fifth",
|
|
203
|
-
},
|
|
204
|
-
],
|
|
205
|
-
required: false,
|
|
206
|
-
value: "option one",
|
|
57
|
+
const isdisabled: LabelledDropdownProps = {
|
|
58
|
+
...basic,
|
|
59
|
+
disabled: true,
|
|
207
60
|
};
|
|
208
61
|
|
|
209
|
-
/**
|
|
210
|
-
* Sample prop definitions Dropdown's enumerable properties (imported in stories and test)
|
|
211
|
-
*/
|
|
212
62
|
const DropdownArgs = {
|
|
213
63
|
basic,
|
|
214
64
|
haserror,
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { FormFieldProps } from "../../types";
|
|
2
|
+
import { LabelledFormFieldProps } from "../../types";
|
|
3
|
+
|
|
1
4
|
export interface OptionProps {
|
|
2
5
|
/**
|
|
3
6
|
* Is this option disabled?
|
|
@@ -7,78 +10,44 @@ export interface OptionProps {
|
|
|
7
10
|
/**
|
|
8
11
|
* The option's label
|
|
9
12
|
*/
|
|
10
|
-
label:
|
|
13
|
+
label: string;
|
|
11
14
|
|
|
12
15
|
/**
|
|
13
16
|
* The option's value
|
|
14
17
|
*/
|
|
15
|
-
value?:
|
|
18
|
+
value?: string;
|
|
16
19
|
}
|
|
17
20
|
|
|
18
|
-
export interface DropdownProps {
|
|
19
|
-
/**
|
|
20
|
-
* Should the Dropdown allow default browser autocomplete functionality?
|
|
21
|
-
* Ideally this would be boolean but for some reason React expects a string. So: "true" if true.
|
|
22
|
-
*/
|
|
23
|
-
autocomplete: string;
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* The Dropdown's onChange callback.
|
|
27
|
-
*/
|
|
28
|
-
callback?: (e: React.ChangeEvent<HTMLSelectElement>) => any;
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Specify an optional className to be added to your Profile component.
|
|
32
|
-
*/
|
|
33
|
-
className?: string;
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Is the Dropdown disabled?
|
|
37
|
-
*/
|
|
38
|
-
disabled?: boolean;
|
|
39
|
-
|
|
21
|
+
export interface DropdownProps extends FormFieldProps<HTMLSelectElement> {
|
|
40
22
|
/**
|
|
41
|
-
*
|
|
23
|
+
* A string providing a hint for a user agent's autocomplete feature.
|
|
42
24
|
*/
|
|
43
|
-
|
|
25
|
+
autocomplete?: string;
|
|
44
26
|
|
|
45
27
|
/**
|
|
46
|
-
* The Dropdown's
|
|
28
|
+
* The form element to associate the Dropdown with if it's not nested in a form element.
|
|
47
29
|
*/
|
|
48
|
-
|
|
30
|
+
form?: string;
|
|
49
31
|
|
|
50
32
|
/**
|
|
51
|
-
*
|
|
33
|
+
* Indicates that multiple options can be selected from the list.
|
|
52
34
|
*/
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* The Dropdown's label
|
|
57
|
-
*/
|
|
58
|
-
label: string;
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* The Dropdown's name attribute
|
|
62
|
-
*/
|
|
63
|
-
name?: Required<string>;
|
|
35
|
+
multiple?: boolean;
|
|
64
36
|
|
|
65
37
|
/**
|
|
66
38
|
* The Dropdown's options
|
|
67
39
|
*/
|
|
68
|
-
options?:
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Is a selection required?
|
|
72
|
-
*/
|
|
73
|
-
required?: boolean;
|
|
40
|
+
options?: OptionProps[];
|
|
74
41
|
|
|
75
42
|
/**
|
|
76
|
-
*
|
|
43
|
+
* Number of rows in the list that should be visible at one time. Corresponds to the select element's size attribute.
|
|
77
44
|
*/
|
|
78
|
-
|
|
45
|
+
selectSize?: number;
|
|
79
46
|
|
|
80
47
|
/**
|
|
81
48
|
* The Dropdown's default selection; should match one of the values in `options`
|
|
82
49
|
*/
|
|
83
|
-
value
|
|
50
|
+
value?: string;
|
|
84
51
|
}
|
|
52
|
+
|
|
53
|
+
export type LabelledDropdownProps = LabelledFormFieldProps<DropdownProps>;
|
|
@@ -1,82 +1,93 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import React, { forwardRef, useState } from "react";
|
|
2
2
|
import classNames from "classnames";
|
|
3
|
-
import useGlobalSettings from "../../hooks
|
|
4
|
-
import { DropdownProps } from "./Dropdown.props";
|
|
5
|
-
import {
|
|
6
|
-
|
|
3
|
+
import { useGlobalSettings } from "../../hooks";
|
|
4
|
+
import { DropdownProps, LabelledDropdownProps } from "./Dropdown.props";
|
|
5
|
+
import FormControl, { useFormControl } from "../FormControl/FormControl";
|
|
6
|
+
|
|
7
|
+
const Dropdown = forwardRef<HTMLSelectElement, DropdownProps>((props, ref) => {
|
|
8
|
+
const {
|
|
9
|
+
autocomplete,
|
|
10
|
+
onChange,
|
|
11
|
+
onBlur,
|
|
12
|
+
disabled = false,
|
|
13
|
+
error,
|
|
14
|
+
id,
|
|
15
|
+
name,
|
|
16
|
+
options,
|
|
17
|
+
required,
|
|
18
|
+
value,
|
|
19
|
+
form,
|
|
20
|
+
multiple,
|
|
21
|
+
selectSize,
|
|
22
|
+
} = props;
|
|
7
23
|
|
|
8
|
-
const Dropdown: FC<DropdownProps> = ({
|
|
9
|
-
autocomplete,
|
|
10
|
-
callback,
|
|
11
|
-
disabled = false,
|
|
12
|
-
error,
|
|
13
|
-
helper,
|
|
14
|
-
id,
|
|
15
|
-
label,
|
|
16
|
-
name,
|
|
17
|
-
options,
|
|
18
|
-
required,
|
|
19
|
-
tooltip,
|
|
20
|
-
value,
|
|
21
|
-
}) => {
|
|
22
24
|
const { prefix } = useGlobalSettings();
|
|
25
|
+
const formControlCtx = useFormControl();
|
|
26
|
+
const { ariaDescribedBy } = formControlCtx;
|
|
23
27
|
|
|
24
28
|
const baseClass = `${prefix}--dropdown`;
|
|
25
29
|
|
|
26
|
-
const dropdownClasses = classNames(
|
|
27
|
-
[baseClass]: true,
|
|
30
|
+
const dropdownClasses = classNames(baseClass, {
|
|
28
31
|
[`error`]: error,
|
|
29
32
|
});
|
|
30
33
|
|
|
31
34
|
const [currentvalue, setValue] = useState(value);
|
|
32
35
|
|
|
33
|
-
/**
|
|
34
|
-
* On change, if there is a callback, call it
|
|
35
|
-
*/
|
|
36
36
|
const handleChange = (e: React.ChangeEvent<HTMLSelectElement>) => {
|
|
37
37
|
setValue(e.target.value);
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
callback(e);
|
|
38
|
+
if (onChange) {
|
|
39
|
+
onChange(e);
|
|
41
40
|
}
|
|
42
41
|
};
|
|
43
42
|
|
|
44
43
|
return (
|
|
45
|
-
<
|
|
46
|
-
<
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
required={required
|
|
52
|
-
|
|
53
|
-
|
|
44
|
+
<div className={`${baseClass}--wrapper`}>
|
|
45
|
+
<select
|
|
46
|
+
ref={ref}
|
|
47
|
+
id={id ? id : name}
|
|
48
|
+
autoComplete={autocomplete}
|
|
49
|
+
name={name}
|
|
50
|
+
required={required}
|
|
51
|
+
onChange={handleChange}
|
|
52
|
+
onBlur={onBlur}
|
|
53
|
+
disabled={disabled}
|
|
54
|
+
className={dropdownClasses}
|
|
55
|
+
value={currentvalue}
|
|
56
|
+
form={form}
|
|
57
|
+
multiple={multiple}
|
|
58
|
+
size={selectSize}
|
|
59
|
+
aria-describedby={ariaDescribedBy}
|
|
54
60
|
>
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
{options &&
|
|
67
|
-
options.map((option, i) => (
|
|
68
|
-
<option
|
|
69
|
-
disabled={option.disabled}
|
|
70
|
-
label={option.label}
|
|
71
|
-
value={option.value}
|
|
72
|
-
key={`${baseClass}--option--${i}`}
|
|
73
|
-
/>
|
|
74
|
-
))}
|
|
75
|
-
</select>
|
|
76
|
-
</div>
|
|
77
|
-
</FormElement>
|
|
78
|
-
</Fieldset>
|
|
61
|
+
{options &&
|
|
62
|
+
options.map((option, i) => (
|
|
63
|
+
<option
|
|
64
|
+
disabled={option.disabled}
|
|
65
|
+
label={option.label}
|
|
66
|
+
value={option.value}
|
|
67
|
+
key={`${baseClass}--option--${i}`}
|
|
68
|
+
/>
|
|
69
|
+
))}
|
|
70
|
+
</select>
|
|
71
|
+
</div>
|
|
79
72
|
);
|
|
80
|
-
};
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
const LabelledDropdown = forwardRef<HTMLSelectElement, LabelledDropdownProps>(
|
|
76
|
+
(props, ref) => {
|
|
77
|
+
const { style, inputStyle, className, ...rest } = props;
|
|
78
|
+
const fieldId = props.id ? props.id : props.name;
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<FormControl
|
|
82
|
+
fieldId={fieldId}
|
|
83
|
+
style={style}
|
|
84
|
+
className={className}
|
|
85
|
+
{...rest}
|
|
86
|
+
>
|
|
87
|
+
<Dropdown ref={ref} style={inputStyle} {...rest} />
|
|
88
|
+
</FormControl>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
);
|
|
81
92
|
|
|
82
|
-
export default
|
|
93
|
+
export default LabelledDropdown;
|
|
@@ -1,42 +1,33 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { InputProps } from "../Input/Input.props";
|
|
3
|
-
import { TextareaProps } from "../Textarea/Textarea.props";
|
|
4
|
-
|
|
5
|
-
export type FieldsetChild = ReactElement<InputProps | TextareaProps>;
|
|
6
|
-
|
|
7
|
-
export interface FieldsetProps {
|
|
8
|
-
/**
|
|
9
|
-
* Specify the content of your Fieldset.
|
|
10
|
-
*/
|
|
11
|
-
children: (null | false | FieldsetChild) | (null | false | FieldsetChild)[];
|
|
1
|
+
import { HTMLProps } from "react";
|
|
12
2
|
|
|
3
|
+
export interface FieldsetProps extends HTMLProps<HTMLFieldSetElement> {
|
|
13
4
|
/**
|
|
14
|
-
*
|
|
5
|
+
* Optional helper text for the fieldset
|
|
15
6
|
*/
|
|
16
|
-
|
|
7
|
+
helper?: string;
|
|
17
8
|
|
|
18
9
|
/**
|
|
19
|
-
*
|
|
10
|
+
* Optional error text for the fieldset
|
|
20
11
|
*/
|
|
21
|
-
|
|
12
|
+
errorMessage?: string;
|
|
22
13
|
|
|
23
14
|
/**
|
|
24
|
-
* Optional
|
|
15
|
+
* Optional tooltip text for the fieldset
|
|
25
16
|
*/
|
|
26
|
-
|
|
17
|
+
tooltip?: string;
|
|
27
18
|
|
|
28
19
|
/**
|
|
29
|
-
*
|
|
20
|
+
* The fieldset's legend
|
|
30
21
|
*/
|
|
31
|
-
|
|
22
|
+
legend?: string;
|
|
32
23
|
|
|
33
24
|
/**
|
|
34
|
-
*
|
|
25
|
+
* The direction of the Fieldset's children
|
|
35
26
|
*/
|
|
36
|
-
|
|
27
|
+
direction?: "row" | "column" | "row-reverse" | "column-reverse";
|
|
37
28
|
|
|
38
29
|
/**
|
|
39
|
-
*
|
|
30
|
+
* How the Fieldset children will wrap
|
|
40
31
|
*/
|
|
41
|
-
|
|
32
|
+
wrap?: "reverse" | "nowrap" | "wrap" | "wrap-reverse";
|
|
42
33
|
}
|