@ilo-org/react 0.7.7 → 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.
Files changed (174) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/lib/cjs/components/Checkbox/Checkbox.js +28 -16
  3. package/lib/cjs/components/Checkbox/index.js +25 -3
  4. package/lib/cjs/components/DatePicker/DatePicker.js +21 -16
  5. package/lib/cjs/components/DatePicker/index.js +4 -4
  6. package/lib/cjs/components/Dropdown/Dropdown.js +19 -15
  7. package/lib/cjs/components/Dropdown/index.js +3 -3
  8. package/lib/cjs/components/Fieldset/Fieldset.js +33 -9
  9. package/lib/cjs/components/Fieldset/index.js +2 -2
  10. package/lib/cjs/components/FileUpload/FileUpload.js +29 -15
  11. package/lib/cjs/components/FileUpload/index.js +3 -3
  12. package/lib/cjs/components/Form/Form.js +8 -55
  13. package/lib/cjs/components/Form/index.js +10 -20
  14. package/lib/cjs/components/FormControl/FormControl.js +79 -0
  15. package/lib/cjs/components/FormControl/index.js +16 -0
  16. package/lib/cjs/components/Input/Input.js +1 -1
  17. package/lib/cjs/components/NumberPicker/NumberPicker.js +21 -16
  18. package/lib/cjs/components/NumberPicker/index.js +4 -4
  19. package/lib/cjs/components/Radio/Radio.js +34 -17
  20. package/lib/cjs/components/Radio/index.js +19 -4
  21. package/lib/cjs/components/TextInput/TextInput.js +30 -0
  22. package/lib/cjs/components/TextInput/index.js +52 -0
  23. package/lib/cjs/components/Textarea/Textarea.js +19 -19
  24. package/lib/cjs/components/Textarea/index.js +26 -5
  25. package/lib/cjs/components/Toggle/Toggle.js +33 -0
  26. package/lib/cjs/components/Toggle/index.js +51 -0
  27. package/lib/cjs/components/Tooltip/Tooltip.js +2 -2
  28. package/lib/cjs/components/index.js +10 -11
  29. package/lib/cjs/hooks/usePrevious.js +20 -0
  30. package/lib/cjs/index.js +10 -11
  31. package/lib/esm/components/Checkbox/Checkbox.js +31 -19
  32. package/lib/esm/components/Checkbox/index.js +27 -2
  33. package/lib/esm/components/DatePicker/DatePicker.js +22 -17
  34. package/lib/esm/components/DatePicker/index.js +4 -4
  35. package/lib/esm/components/Dropdown/Dropdown.js +20 -16
  36. package/lib/esm/components/Dropdown/index.js +3 -3
  37. package/lib/esm/components/Fieldset/Fieldset.js +31 -11
  38. package/lib/esm/components/Fieldset/index.js +1 -1
  39. package/lib/esm/components/FileUpload/FileUpload.js +31 -17
  40. package/lib/esm/components/FileUpload/index.js +3 -3
  41. package/lib/esm/components/Form/Form.js +10 -57
  42. package/lib/esm/components/Form/index.js +13 -20
  43. package/lib/esm/components/FormControl/FormControl.js +73 -0
  44. package/lib/esm/components/{ChoiceGroup → FormControl}/index.js +3 -6
  45. package/lib/esm/components/NumberPicker/NumberPicker.js +21 -16
  46. package/lib/esm/components/NumberPicker/index.js +4 -4
  47. package/lib/esm/components/Radio/Radio.js +34 -17
  48. package/lib/esm/components/Radio/index.js +21 -3
  49. package/lib/esm/components/TextInput/TextInput.js +28 -0
  50. package/lib/esm/components/TextInput/index.js +49 -0
  51. package/lib/esm/components/Textarea/Textarea.js +19 -19
  52. package/lib/esm/components/Textarea/index.js +28 -4
  53. package/lib/esm/components/Toggle/Toggle.js +31 -0
  54. package/lib/esm/components/Toggle/index.js +48 -0
  55. package/lib/esm/components/Tooltip/Tooltip.js +2 -2
  56. package/lib/esm/components/index.js +8 -5
  57. package/lib/esm/hooks/usePrevious.js +15 -0
  58. package/lib/esm/index.js +8 -5
  59. package/lib/types/react/src/components/Checkbox/Checkbox.args.d.ts +52 -0
  60. package/lib/types/react/src/components/Checkbox/Checkbox.d.ts +5 -3
  61. package/lib/types/react/src/components/Checkbox/Checkbox.props.d.ts +4 -13
  62. package/lib/types/react/src/components/Checkbox/index.d.ts +1 -0
  63. package/lib/types/react/src/components/DatePicker/DatePicker.d.ts +4 -3
  64. package/lib/types/react/src/components/DatePicker/DatePicker.props.d.ts +10 -43
  65. package/lib/types/react/src/components/Dropdown/Dropdown.d.ts +5 -3
  66. package/lib/types/react/src/components/Dropdown/Dropdown.props.d.ts +16 -42
  67. package/lib/types/react/src/components/Fieldset/Fieldset.d.ts +6 -0
  68. package/lib/types/react/src/components/Fieldset/Fieldset.props.d.ts +14 -21
  69. package/lib/types/react/src/components/FileUpload/FileUpload.d.ts +5 -3
  70. package/lib/types/react/src/components/FileUpload/FileUpload.props.d.ts +7 -44
  71. package/lib/types/react/src/components/Form/Form.args.d.ts +2 -0
  72. package/lib/types/react/src/components/Form/Form.d.ts +1 -2
  73. package/lib/types/react/src/components/Form/Form.props.d.ts +4 -111
  74. package/lib/types/react/src/components/Form/index.d.ts +1 -0
  75. package/lib/types/react/src/components/FormControl/FormControl.d.ts +9 -0
  76. package/lib/types/react/src/components/FormControl/FormControl.props.d.ts +55 -0
  77. package/lib/types/react/src/components/FormControl/index.d.ts +2 -0
  78. package/lib/types/react/src/components/FormElement/FormElement.props.d.ts +2 -2
  79. package/lib/types/react/src/components/Input/Input.props.d.ts +2 -2
  80. package/lib/types/react/src/components/NumberPicker/NumberPicker.d.ts +5 -3
  81. package/lib/types/react/src/components/NumberPicker/NumberPicker.props.d.ts +5 -42
  82. package/lib/types/react/src/components/Radio/Radio.args.d.ts +8 -0
  83. package/lib/types/react/src/components/Radio/Radio.d.ts +5 -3
  84. package/lib/types/react/src/components/Radio/Radio.props.d.ts +4 -14
  85. package/lib/types/react/src/components/Radio/index.d.ts +1 -0
  86. package/lib/types/react/src/components/TextInput/TextInput.args.d.ts +10 -0
  87. package/lib/types/react/src/components/TextInput/TextInput.d.ts +6 -0
  88. package/lib/types/react/src/components/TextInput/TextInput.props.d.ts +17 -0
  89. package/lib/types/react/src/components/TextInput/index.d.ts +2 -0
  90. package/lib/types/react/src/components/Textarea/Textarea.args.d.ts +10 -0
  91. package/lib/types/react/src/components/Textarea/Textarea.d.ts +5 -3
  92. package/lib/types/react/src/components/Textarea/Textarea.props.d.ts +17 -39
  93. package/lib/types/react/src/components/Textarea/index.d.ts +2 -0
  94. package/lib/types/react/src/components/Toggle/Toggle.args.d.ts +12 -0
  95. package/lib/types/react/src/components/Toggle/Toggle.d.ts +5 -0
  96. package/lib/types/react/src/components/Toggle/Toggle.props.d.ts +22 -0
  97. package/lib/types/react/src/components/Toggle/index.d.ts +3 -0
  98. package/lib/types/react/src/components/Tooltip/Tooltip.props.d.ts +4 -0
  99. package/lib/types/react/src/components/index.d.ts +1 -5
  100. package/lib/types/react/src/hooks/usePrevious.d.ts +2 -0
  101. package/lib/types/react/src/types/index.d.ts +57 -1
  102. package/package.json +19 -18
  103. package/src/components/Checkbox/Checkbox.args.ts +31 -9
  104. package/src/components/Checkbox/Checkbox.props.ts +5 -13
  105. package/src/components/Checkbox/Checkbox.tsx +78 -76
  106. package/src/components/Checkbox/index.ts +1 -0
  107. package/src/components/DatePicker/DatePicker.args.ts +6 -32
  108. package/src/components/DatePicker/DatePicker.props.ts +11 -51
  109. package/src/components/DatePicker/DatePicker.tsx +71 -110
  110. package/src/components/Dropdown/Dropdown.args.ts +42 -192
  111. package/src/components/Dropdown/Dropdown.props.ts +18 -49
  112. package/src/components/Dropdown/Dropdown.tsx +73 -62
  113. package/src/components/Fieldset/Fieldset.props.ts +14 -23
  114. package/src/components/Fieldset/Fieldset.tsx +75 -69
  115. package/src/components/FileUpload/FileUpload.args.ts +25 -27
  116. package/src/components/FileUpload/FileUpload.props.ts +8 -53
  117. package/src/components/FileUpload/FileUpload.tsx +103 -72
  118. package/src/components/Form/Form.args.ts +2 -184
  119. package/src/components/Form/Form.props.ts +4 -133
  120. package/src/components/Form/Form.tsx +17 -77
  121. package/src/components/Form/index.ts +1 -0
  122. package/src/components/FormControl/FormControl.props.ts +72 -0
  123. package/src/components/FormControl/FormControl.tsx +169 -0
  124. package/src/components/FormControl/index.ts +2 -0
  125. package/src/components/FormElement/FormElement.props.ts +2 -2
  126. package/src/components/Input/Input.props.ts +2 -2
  127. package/src/components/Navigation/Navigation.args.ts +2 -1
  128. package/src/components/NumberPicker/NumberPicker.args.ts +18 -26
  129. package/src/components/NumberPicker/NumberPicker.props.ts +7 -52
  130. package/src/components/NumberPicker/NumberPicker.tsx +73 -56
  131. package/src/components/Radio/Radio.args.ts +1 -7
  132. package/src/components/Radio/Radio.props.ts +6 -14
  133. package/src/components/Radio/Radio.tsx +90 -52
  134. package/src/components/Radio/index.ts +1 -0
  135. package/src/components/TextInput/TextInput.args.ts +75 -0
  136. package/src/components/TextInput/TextInput.props.ts +20 -0
  137. package/src/components/TextInput/TextInput.tsx +71 -0
  138. package/src/components/TextInput/index.ts +2 -0
  139. package/src/components/Textarea/Textarea.args.ts +19 -37
  140. package/src/components/Textarea/Textarea.props.ts +18 -46
  141. package/src/components/Textarea/Textarea.tsx +44 -59
  142. package/src/components/Textarea/index.ts +2 -0
  143. package/src/components/Toggle/Toggle.args.ts +62 -0
  144. package/src/components/Toggle/Toggle.props.ts +27 -0
  145. package/src/components/Toggle/Toggle.tsx +85 -0
  146. package/src/components/Toggle/index.ts +3 -0
  147. package/src/components/Tooltip/Tooltip.props.ts +5 -0
  148. package/src/components/Tooltip/Tooltip.tsx +2 -0
  149. package/src/components/index.ts +1 -5
  150. package/src/hooks/usePrevious.ts +15 -0
  151. package/src/types/forms.args.ts +288 -0
  152. package/src/types/index.ts +69 -1
  153. package/tsconfig.json +2 -1
  154. package/lib/cjs/components/ChoiceGroup/ChoiceGroup.js +0 -34
  155. package/lib/cjs/components/ChoiceGroup/index.js +0 -19
  156. package/lib/cjs/components/FormGroup/FormGroup.js +0 -58
  157. package/lib/cjs/components/FormGroup/index.js +0 -26
  158. package/lib/esm/components/ChoiceGroup/ChoiceGroup.js +0 -32
  159. package/lib/esm/components/FormGroup/FormGroup.js +0 -56
  160. package/lib/esm/components/FormGroup/index.js +0 -20
  161. package/lib/types/react/src/components/ChoiceGroup/ChoiceGroup.d.ts +0 -4
  162. package/lib/types/react/src/components/ChoiceGroup/ChoiceGroup.props.d.ts +0 -20
  163. package/lib/types/react/src/components/ChoiceGroup/index.d.ts +0 -1
  164. package/lib/types/react/src/components/FormGroup/FormGroup.d.ts +0 -4
  165. package/lib/types/react/src/components/FormGroup/FormGroup.props.d.ts +0 -81
  166. package/lib/types/react/src/components/FormGroup/index.d.ts +0 -1
  167. package/src/components/ChoiceGroup/ChoiceGroup.args.ts +0 -95
  168. package/src/components/ChoiceGroup/ChoiceGroup.props.ts +0 -25
  169. package/src/components/ChoiceGroup/ChoiceGroup.tsx +0 -54
  170. package/src/components/ChoiceGroup/index.ts +0 -1
  171. package/src/components/FormGroup/FormGroup.args.ts +0 -85
  172. package/src/components/FormGroup/FormGroup.props.ts +0 -102
  173. package/src/components/FormGroup/FormGroup.tsx +0 -73
  174. package/src/components/FormGroup/index.ts +0 -1
@@ -1,214 +1,64 @@
1
- import { DropdownProps } from "./Dropdown.props";
1
+ import { LabelledDropdownProps } from "./Dropdown.props";
2
2
 
3
- const basic: DropdownProps = {
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: DropdownProps = {
45
- autocomplete: "false",
46
- callback: () => {},
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: DropdownProps = {
86
- autocomplete: "false",
87
- callback: () => {},
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: DropdownProps = {
127
- autocomplete: "false",
128
- callback: () => {},
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: DropdownProps = {
169
- autocomplete: "false",
170
- callback: () => {},
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: Required<string>;
13
+ label: string;
11
14
 
12
15
  /**
13
16
  * The option's value
14
17
  */
15
- value?: Required<string>;
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
- * Does the Dropdown have an error?
23
+ * A string providing a hint for a user agent's autocomplete feature.
42
24
  */
43
- error?: string | false;
25
+ autocomplete?: string;
44
26
 
45
27
  /**
46
- * The Dropdown's helper text
28
+ * The form element to associate the Dropdown with if it's not nested in a form element.
47
29
  */
48
- helper: string | false;
30
+ form?: string;
49
31
 
50
32
  /**
51
- * The Dropdown's id attribute
33
+ * Indicates that multiple options can be selected from the list.
52
34
  */
53
- id?: string;
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?: Required<Array<OptionProps>>;
69
-
70
- /**
71
- * Is a selection required?
72
- */
73
- required?: boolean;
40
+ options?: OptionProps[];
74
41
 
75
42
  /**
76
- * Does this Dropdown have a tooltip?
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
- tooltip?: string;
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: string;
50
+ value?: string;
84
51
  }
52
+
53
+ export type LabelledDropdownProps = LabelledFormFieldProps<DropdownProps>;
@@ -1,82 +1,93 @@
1
- import { FC, useState } from "react";
1
+ import React, { forwardRef, useState } from "react";
2
2
  import classNames from "classnames";
3
- import useGlobalSettings from "../../hooks/useGlobalSettings";
4
- import { DropdownProps } from "./Dropdown.props";
5
- import { Fieldset } from "../Fieldset";
6
- import { FormElement } from "../FormElement";
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
- if (callback) {
40
- callback(e);
38
+ if (onChange) {
39
+ onChange(e);
41
40
  }
42
41
  };
43
42
 
44
43
  return (
45
- <Fieldset>
46
- <FormElement
47
- elemid={name as any}
48
- label={label}
49
- helper={helper as any}
50
- error={error as any}
51
- required={required as any}
52
- tooltip={tooltip}
53
- type={"dropdown"}
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
- <div className={`${baseClass}--wrapper`}>
56
- <select
57
- id={id ? id : name}
58
- autoComplete={autocomplete}
59
- name={name}
60
- required={required}
61
- onChange={handleChange}
62
- disabled={disabled}
63
- className={dropdownClasses}
64
- value={currentvalue}
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 Dropdown;
93
+ export default LabelledDropdown;
@@ -1,42 +1,33 @@
1
- import { ReactElement } from "react";
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
- * Specify an optional className to be added to your Fieldset component.
5
+ * Optional helper text for the fieldset
15
6
  */
16
- className?: string;
7
+ helper?: string;
17
8
 
18
9
  /**
19
- * The fieldset's id
10
+ * Optional error text for the fieldset
20
11
  */
21
- fieldsetid?: string;
12
+ errorMessage?: string;
22
13
 
23
14
  /**
24
- * Optional error text for the fieldset
15
+ * Optional tooltip text for the fieldset
25
16
  */
26
- grouperror?: string;
17
+ tooltip?: string;
27
18
 
28
19
  /**
29
- * Optional helper text for the fieldset
20
+ * The fieldset's legend
30
21
  */
31
- grouphelper?: string;
22
+ legend?: string;
32
23
 
33
24
  /**
34
- * Optional tooltip text for the fieldset
25
+ * The direction of the Fieldset's children
35
26
  */
36
- grouptooltip?: string;
27
+ direction?: "row" | "column" | "row-reverse" | "column-reverse";
37
28
 
38
29
  /**
39
- * The fieldset's legend
30
+ * How the Fieldset children will wrap
40
31
  */
41
- legend?: string;
32
+ wrap?: "reverse" | "nowrap" | "wrap" | "wrap-reverse";
42
33
  }