@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,64 +1,17 @@
1
- import { jsxs, jsx } from 'react/jsx-runtime';
2
- import { createElement } from 'react';
3
- import classNames from 'classnames';
1
+ import { __rest } from 'tslib';
2
+ import { jsx } from 'react/jsx-runtime';
3
+ import { forwardRef } from 'react';
4
4
  import useGlobalSettings from '../../hooks/useGlobalSettings.js';
5
- import Button from '../Button/Button.js';
6
- import FormGroup from '../FormGroup/FormGroup.js';
7
- import Checkbox from '../Checkbox/Checkbox.js';
8
- import ChoiceGroup from '../ChoiceGroup/ChoiceGroup.js';
9
- import DatePicker from '../DatePicker/DatePicker.js';
10
- import Dropdown from '../Dropdown/Dropdown.js';
11
- import FileUpload from '../FileUpload/FileUpload.js';
12
- import Input from '../Input/Input.js';
13
- import NumberPicker from '../NumberPicker/NumberPicker.js';
14
- import Textarea from '../Textarea/Textarea.js';
15
- import 'tslib';
5
+ import classNames from 'classnames';
16
6
  import '../../GlobalCtx-7fb23cfa.js';
17
- import '../Link/Link.js';
18
- import '../Icon/Icon.js';
19
- import '@ilo-org/icons-react';
20
- import '../Fieldset/Fieldset.js';
21
- import '../Tooltip/Tooltip.js';
22
- import 'react-dom';
23
- import '../FormElement/FormElement.js';
24
- import '../Radio/Radio.js';
25
7
 
26
- const Form = ({ action, className, formid, items, submitlabel, }) => {
8
+ const Form = forwardRef((_a, ref) => {
9
+ var { children, theme = "light" } = _a, props = __rest(_a, ["children", "theme"]);
27
10
  const { prefix } = useGlobalSettings();
28
11
  const baseClass = `${prefix}--form`;
29
- const formClasses = classNames(className, {
30
- [baseClass]: true,
31
- });
32
- return (jsxs("form", Object.assign({ className: formClasses, id: formid, action: action }, { children: [items.map((item, i) => {
33
- if ((item === null || item === void 0 ? void 0 : item.type) === "input") {
34
- return createElement(Input, Object.assign({}, item === null || item === void 0 ? void 0 : item.field, { key: i }));
35
- }
36
- if ((item === null || item === void 0 ? void 0 : item.type) === "dropdown") {
37
- return createElement(Dropdown, Object.assign({}, item === null || item === void 0 ? void 0 : item.field, { key: i }));
38
- }
39
- if ((item === null || item === void 0 ? void 0 : item.type) === "checkbox" && Array.isArray(item === null || item === void 0 ? void 0 : item.field) === false) {
40
- return createElement(Checkbox, Object.assign({}, item === null || item === void 0 ? void 0 : item.field, { key: i }));
41
- }
42
- if (((item === null || item === void 0 ? void 0 : item.type) === "checkbox" || (item === null || item === void 0 ? void 0 : item.type) === "radio") &&
43
- Array.isArray(item === null || item === void 0 ? void 0 : item.field)) {
44
- return (jsx(ChoiceGroup, { items: item === null || item === void 0 ? void 0 : item.field, legend: item === null || item === void 0 ? void 0 : item.legend, choicegroupid: item === null || item === void 0 ? void 0 : item.choicegroupid, grouperror: item === null || item === void 0 ? void 0 : item.grouperror, grouphelper: item === null || item === void 0 ? void 0 : item.grouphelper, grouptooltip: item === null || item === void 0 ? void 0 : item.grouptooltip }, i));
45
- }
46
- if ((item === null || item === void 0 ? void 0 : item.type) === "file") {
47
- return createElement(FileUpload, Object.assign({}, item === null || item === void 0 ? void 0 : item.field, { key: i }));
48
- }
49
- if ((item === null || item === void 0 ? void 0 : item.type) === "date") {
50
- return createElement(DatePicker, Object.assign({}, item === null || item === void 0 ? void 0 : item.field, { key: i }));
51
- }
52
- if ((item === null || item === void 0 ? void 0 : item.type) === "number") {
53
- return createElement(NumberPicker, Object.assign({}, item === null || item === void 0 ? void 0 : item.field, { key: i }));
54
- }
55
- if ((item === null || item === void 0 ? void 0 : item.type) === "textarea") {
56
- return createElement(Textarea, Object.assign({}, item === null || item === void 0 ? void 0 : item.field, { key: i }));
57
- }
58
- if ((item === null || item === void 0 ? void 0 : item.type) === "formgroup") {
59
- return createElement(FormGroup, Object.assign({}, item === null || item === void 0 ? void 0 : item.field, { key: i }));
60
- }
61
- }), jsx(Button, { kind: "submit", label: submitlabel, size: "large", type: "primary" })] })));
62
- };
12
+ const themeClass = `${baseClass}__theme__${theme}`;
13
+ const formClasses = classNames(baseClass, themeClass);
14
+ return (jsx("form", Object.assign({ ref: ref, className: formClasses }, props, { children: children })));
15
+ });
63
16
 
64
17
  export { Form as default };
@@ -1,25 +1,18 @@
1
1
  export { default as Form } from './Form.js';
2
+ import 'tslib';
2
3
  import 'react/jsx-runtime';
3
4
  import 'react';
4
- import 'classnames';
5
5
  import '../../hooks/useGlobalSettings.js';
6
- import 'tslib';
7
6
  import '../../GlobalCtx-7fb23cfa.js';
8
- import '../Button/Button.js';
9
- import '../Link/Link.js';
10
- import '../Icon/Icon.js';
11
- import '@ilo-org/icons-react';
12
- import '../FormGroup/FormGroup.js';
13
- import '../Checkbox/Checkbox.js';
14
- import '../Fieldset/Fieldset.js';
15
- import '../Tooltip/Tooltip.js';
16
- import 'react-dom';
17
- import '../FormElement/FormElement.js';
18
- import '../ChoiceGroup/ChoiceGroup.js';
19
- import '../Radio/Radio.js';
20
- import '../DatePicker/DatePicker.js';
21
- import '../Dropdown/Dropdown.js';
22
- import '../FileUpload/FileUpload.js';
23
- import '../Input/Input.js';
24
- import '../NumberPicker/NumberPicker.js';
25
- import '../Textarea/Textarea.js';
7
+ import 'classnames';
8
+
9
+ const basic = {
10
+ theme: "light",
11
+ };
12
+
13
+ var Form_args = /*#__PURE__*/Object.freeze({
14
+ __proto__: null,
15
+ basic: basic
16
+ });
17
+
18
+ export { Form_args as FormArgs };
@@ -0,0 +1,73 @@
1
+ import { jsx, jsxs } from 'react/jsx-runtime';
2
+ import classNames from 'classnames';
3
+ import { nanoid } from 'nanoid';
4
+ import { createContext, useContext, useMemo, useState, useEffect } from 'react';
5
+ import useGlobalSettings from '../../hooks/useGlobalSettings.js';
6
+ import Tooltip from '../Tooltip/Tooltip.js';
7
+ import 'tslib';
8
+ import '../../GlobalCtx-7fb23cfa.js';
9
+ import 'react-dom';
10
+
11
+ // Calculates unique IDs for the internal accessibility elements
12
+ // TODO: When we upgrade to React 8, this should use useId instead
13
+ function getA11yFields(baseClass = "", { tooltip, helper, errorMessage } = {}) {
14
+ return {
15
+ tooltipId: tooltip && `${baseClass}--tooltip--${nanoid()}`,
16
+ helperId: helper && `${baseClass}--helper--${nanoid()}`,
17
+ errorId: errorMessage && `${baseClass}--error--${nanoid()}`,
18
+ };
19
+ }
20
+ // Calculates the aria-describedby attribute value based on whether or not there's an error
21
+ function getAriaDescribedBy(getAllyFields, hasError) {
22
+ const { tooltipId, helperId, errorId } = getAllyFields;
23
+ const ariaDescribedBy = classNames(tooltipId, {
24
+ [`${helperId}`]: !hasError,
25
+ [`${errorId}`]: hasError,
26
+ });
27
+ // For some reason, classnames seems to return "undefined" as a string sometimes
28
+ if (!ariaDescribedBy || ariaDescribedBy === "undefined") {
29
+ return undefined;
30
+ }
31
+ return ariaDescribedBy;
32
+ }
33
+ // The context passed down to form elements wrapped by the form control
34
+ const FormControlContext = createContext({});
35
+ // Hook to get the context value
36
+ const useFormControl = () => useContext(FormControlContext);
37
+ const FormControl = ({ children, className, label, helper, errorMessage, tooltip, style, error, disabled, fieldId, labelSize = "medium", labelPlacement = "top", }) => {
38
+ const { prefix } = useGlobalSettings();
39
+ // Classes applied to the outer container
40
+ const baseClass = `${prefix}--form-control`;
41
+ // The ids of the tooltip, helper, and error only get calculated on first render
42
+ const a11yFields = useMemo(() => getA11yFields(baseClass, { helper, errorMessage, tooltip }), [baseClass, helper, errorMessage, tooltip]);
43
+ // The ids of the tooltip, helper, and error
44
+ const { tooltipId, helperId, errorId } = a11yFields;
45
+ // The aria-describedby attribute value
46
+ const [ariaDescribedBy, setAriaDescribedBy] = useState(undefined);
47
+ // Update the aria-describedby attribute value when the error changes
48
+ useEffect(() => {
49
+ setAriaDescribedBy(getAriaDescribedBy({ tooltipId, helperId, errorId }, error));
50
+ }, [tooltipId, helperId, errorId, error]);
51
+ // The context passed down to form elements wrapped by the form control
52
+ const contextValue = {
53
+ ariaDescribedBy,
54
+ };
55
+ // Classes applied to the outer container
56
+ const errorClass = `${baseClass}__error`;
57
+ const disabledClass = `${baseClass}__disabled`;
58
+ const labelPlacementClass = `${baseClass}__label-placement__${labelPlacement}`;
59
+ const formControlClass = classNames(baseClass, className, labelPlacementClass, [{ [errorClass]: error }, { [disabledClass]: disabled }]);
60
+ // Classes applies to the label
61
+ const labelBaseClass = `${baseClass}--label`;
62
+ const labelSizeClass = `${labelBaseClass}__size__${labelSize}`;
63
+ const labelClass = classNames(labelBaseClass, labelSizeClass);
64
+ // Helper class
65
+ const helperClass = `${baseClass}--helper`;
66
+ // Show the error message if there is an error and an error message
67
+ const showError = !!error && !!errorMessage;
68
+ // Show the helper text if there is no error and a helper text
69
+ const showHelper = !showError && !!helper;
70
+ return (jsx(FormControlContext.Provider, Object.assign({ value: contextValue }, { children: jsxs("div", Object.assign({ className: formControlClass, style: style }, { children: [jsxs("span", Object.assign({ className: labelClass }, { children: [jsx("label", Object.assign({ htmlFor: fieldId }, { children: label })), tooltip && (jsx(Tooltip, { id: tooltipId, className: `${baseClass}--legend--tooltip`, icon: true, label: tooltip, theme: "dark" }))] })), children, showHelper && (jsx("span", Object.assign({ id: helperId, className: helperClass }, { children: helper }))), showError && (jsx("span", Object.assign({ id: errorId, className: helperClass, "aria-live": "assertive" }, { children: errorMessage })))] })) })));
71
+ };
72
+
73
+ export { FormControlContext, FormControl as default, useFormControl };
@@ -1,13 +1,10 @@
1
- export { default as ChoiceGroup } from './ChoiceGroup.js';
1
+ export { default as FormControl } from './FormControl.js';
2
2
  import 'react/jsx-runtime';
3
- import 'react';
4
- import '../Checkbox/Checkbox.js';
5
3
  import 'classnames';
4
+ import 'nanoid';
5
+ import 'react';
6
6
  import '../../hooks/useGlobalSettings.js';
7
7
  import 'tslib';
8
8
  import '../../GlobalCtx-7fb23cfa.js';
9
- import '../Fieldset/Fieldset.js';
10
9
  import '../Tooltip/Tooltip.js';
11
10
  import 'react-dom';
12
- import '../FormElement/FormElement.js';
13
- import '../Radio/Radio.js';
@@ -1,30 +1,35 @@
1
+ import { __rest } from 'tslib';
1
2
  import { jsx } from 'react/jsx-runtime';
3
+ import require$$0 from 'react';
2
4
  import classNames from 'classnames';
3
5
  import useGlobalSettings from '../../hooks/useGlobalSettings.js';
4
- import Fieldset from '../Fieldset/Fieldset.js';
5
- import FormElement from '../FormElement/FormElement.js';
6
- import 'tslib';
7
- import 'react';
6
+ import FormControl, { useFormControl } from '../FormControl/FormControl.js';
8
7
  import '../../GlobalCtx-7fb23cfa.js';
8
+ import 'nanoid';
9
9
  import '../Tooltip/Tooltip.js';
10
10
  import 'react-dom';
11
11
 
12
- const NumberPicker = ({ callback, disabled = false, error, helper, id, label, name, placeholder, required, tooltip, }) => {
12
+ const NumberPicker = require$$0.forwardRef(({ onChange, onBlur, disabled = false, error, id, name, placeholder, required, }, ref) => {
13
13
  const { prefix } = useGlobalSettings();
14
+ const formControlCtx = useFormControl();
15
+ const { ariaDescribedBy } = formControlCtx;
16
+ const inputClass = `${prefix}--input`;
14
17
  const baseClass = `${prefix}--numberpicker`;
15
- const NumberPickerClasses = classNames("", {
16
- [baseClass]: true,
17
- [`error`]: error,
18
+ const hasError = !disabled && !!error;
19
+ const numberPickerClasses = classNames(inputClass, baseClass, {
20
+ error: hasError,
18
21
  });
19
- /**
20
- * On change, if there is a callback, call it
21
- */
22
22
  const handleChange = (e) => {
23
- if (callback) {
24
- callback(e);
23
+ if (onChange) {
24
+ onChange(e);
25
25
  }
26
26
  };
27
- return (jsx(Fieldset, { children: jsx(FormElement, Object.assign({ elemid: name, label: label, helper: helper, error: error, required: required, tooltip: tooltip, type: "text" }, { children: jsx("input", { id: id ? id : name, name: name, onChange: handleChange, disabled: disabled, placeholder: placeholder, required: required, type: "text", className: `${NumberPickerClasses} ${prefix}--input`, pattern: "[0-9]*", inputMode: "numeric" }) })) }));
28
- };
27
+ return (jsx("input", { ref: ref, id: id ? id : name, name: name, onChange: handleChange, onBlur: onBlur, disabled: disabled, placeholder: placeholder, required: required, type: "number", className: numberPickerClasses, pattern: "[0-9]*", inputMode: "numeric", "aria-describedby": ariaDescribedBy }));
28
+ });
29
+ const LabelledNumberPicker = require$$0.forwardRef((props, ref) => {
30
+ const { style, inputStyle, className } = props, rest = __rest(props, ["style", "inputStyle", "className"]);
31
+ const fieldId = props.id ? props.id : props.name;
32
+ return (jsx(FormControl, Object.assign({ fieldId: fieldId, style: style, className: className }, rest, { children: jsx(NumberPicker, Object.assign({ ref: ref, style: inputStyle }, rest)) })));
33
+ });
29
34
 
30
- export { NumberPicker as default };
35
+ export { LabelledNumberPicker as default };
@@ -1,11 +1,11 @@
1
1
  export { default as NumberPicker } from './NumberPicker.js';
2
+ import 'tslib';
2
3
  import 'react/jsx-runtime';
4
+ import 'react';
3
5
  import 'classnames';
4
6
  import '../../hooks/useGlobalSettings.js';
5
- import 'tslib';
6
- import 'react';
7
7
  import '../../GlobalCtx-7fb23cfa.js';
8
- import '../Fieldset/Fieldset.js';
8
+ import '../FormControl/FormControl.js';
9
+ import 'nanoid';
9
10
  import '../Tooltip/Tooltip.js';
10
11
  import 'react-dom';
11
- import '../FormElement/FormElement.js';
@@ -1,27 +1,44 @@
1
+ import { __rest } from 'tslib';
1
2
  import { jsx } from 'react/jsx-runtime';
3
+ import require$$0, { useEffect } from 'react';
2
4
  import classNames from 'classnames';
3
5
  import useGlobalSettings from '../../hooks/useGlobalSettings.js';
4
- import FormElement from '../FormElement/FormElement.js';
5
- import 'tslib';
6
- import 'react';
6
+ import { useFieldsetError } from '../Fieldset/Fieldset.js';
7
+ import FormControl, { useFormControl } from '../FormControl/FormControl.js';
8
+ import { usePrevious } from '../../hooks/usePrevious.js';
7
9
  import '../../GlobalCtx-7fb23cfa.js';
10
+ import '../Tooltip/Tooltip.js';
11
+ import 'react-dom';
12
+ import 'nanoid';
8
13
 
9
- const Radio = ({ callback, disabled = false, error, helper, id, label, name, required, selected, tooltip, value, }) => {
14
+ const Radio = require$$0.forwardRef(({ onChange, onBlur, disabled = false, error, id, name, required, checked, defaultChecked = false, value, }, ref) => {
10
15
  const { prefix } = useGlobalSettings();
11
- const baseClass = `${prefix}--radio`;
12
- const RadioClasses = classNames("", {
13
- [baseClass]: true,
14
- [`error`]: error,
15
- });
16
- /**
17
- * On change, if there is a callback, call it
18
- */
16
+ const { setHasError } = useFieldsetError();
17
+ const formControlCtx = useFormControl();
18
+ const prevError = usePrevious(error);
19
+ useEffect(() => {
20
+ if (error !== prevError) {
21
+ setHasError(!!error);
22
+ }
23
+ }, [error, prevError, setHasError]);
24
+ const { ariaDescribedBy } = formControlCtx;
19
25
  const handleChange = (e) => {
20
- if (callback) {
21
- callback(e);
26
+ console.log(e.target.value);
27
+ if (onChange) {
28
+ onChange(e);
22
29
  }
23
30
  };
24
- return (jsx(FormElement, Object.assign({ elemid: id, label: label, helper: helper, error: error, required: required, tooltip: tooltip }, { children: jsx("input", { id: id, name: name, onChange: handleChange, disabled: disabled, required: required, type: "radio", className: RadioClasses, checked: selected === value, value: value }) })));
25
- };
31
+ const baseClass = `${prefix}--radio`;
32
+ const errorClass = `${baseClass}__error`;
33
+ const RadioClasses = classNames(baseClass, {
34
+ [errorClass]: error,
35
+ });
36
+ return (jsx("input", { ref: ref, id: id ? id : name, name: name, onChange: handleChange, onBlur: onBlur, disabled: disabled, required: required, type: "radio", className: RadioClasses, defaultChecked: defaultChecked, "aria-describedby": ariaDescribedBy, checked: checked, value: value }));
37
+ });
38
+ const LabelledRadio = require$$0.forwardRef((props, ref) => {
39
+ const { style, inputStyle, className, labelPlacement = "end", labelSize = "small" } = props, rest = __rest(props, ["style", "inputStyle", "className", "labelPlacement", "labelSize"]);
40
+ const fieldId = props.id ? props.id : props.name;
41
+ return (jsx(FormControl, Object.assign({ fieldId: fieldId, style: style, className: className, labelPlacement: labelPlacement, labelSize: labelSize }, rest, { children: jsx(Radio, Object.assign({ ref: ref, style: inputStyle }, rest)) })));
42
+ });
26
43
 
27
- export { Radio as default };
44
+ export { LabelledRadio as default };
@@ -1,8 +1,26 @@
1
1
  export { default as Radio } from './Radio.js';
2
+ import 'tslib';
2
3
  import 'react/jsx-runtime';
4
+ import 'react';
3
5
  import 'classnames';
4
6
  import '../../hooks/useGlobalSettings.js';
5
- import 'tslib';
6
- import 'react';
7
7
  import '../../GlobalCtx-7fb23cfa.js';
8
- import '../FormElement/FormElement.js';
8
+ import '../Fieldset/Fieldset.js';
9
+ import '../Tooltip/Tooltip.js';
10
+ import 'react-dom';
11
+ import '../FormControl/FormControl.js';
12
+ import 'nanoid';
13
+ import '../../hooks/usePrevious.js';
14
+
15
+ const basic = {
16
+ className: "Radio",
17
+ name: "radio",
18
+ };
19
+ /**
20
+ * Sample prop definitions Radio's enumerable properties (imported in stories and test)
21
+ */
22
+ const RadioArgs = {
23
+ basic,
24
+ };
25
+
26
+ export { RadioArgs };
@@ -0,0 +1,28 @@
1
+ import { __rest } from 'tslib';
2
+ import { jsx } from 'react/jsx-runtime';
3
+ import require$$0 from 'react';
4
+ import classNames from 'classnames';
5
+ import useGlobalSettings from '../../hooks/useGlobalSettings.js';
6
+ import FormControl, { useFormControl } from '../FormControl/FormControl.js';
7
+ import '../../GlobalCtx-7fb23cfa.js';
8
+ import 'nanoid';
9
+ import '../Tooltip/Tooltip.js';
10
+ import 'react-dom';
11
+
12
+ const TextInput = require$$0.forwardRef(({ onChange, onBlur, error, id, name, placeholder, required, pattern, disabled = false, type = "text", }, ref) => {
13
+ const { prefix } = useGlobalSettings();
14
+ const formControlCtx = useFormControl();
15
+ const { ariaDescribedBy } = formControlCtx;
16
+ const baseClass = `${prefix}--text-input`;
17
+ const inputClass = classNames(baseClass, {
18
+ [`${baseClass}__error`]: error,
19
+ });
20
+ return (jsx("input", { ref: ref, id: id ? id : name, name: name, onChange: onChange, onBlur: onBlur, disabled: disabled, placeholder: placeholder, required: required, type: type, className: inputClass, pattern: pattern, "aria-describedby": ariaDescribedBy }));
21
+ });
22
+ const LabelledTextInput = require$$0.forwardRef((props, ref) => {
23
+ const { style, inputStyle, className } = props, rest = __rest(props, ["style", "inputStyle", "className"]);
24
+ const fieldId = props.id ? props.id : props.name;
25
+ return (jsx(FormControl, Object.assign({ fieldId: fieldId, style: style, className: className }, rest, { children: jsx(TextInput, Object.assign({ ref: ref, style: inputStyle }, rest)) })));
26
+ });
27
+
28
+ export { LabelledTextInput as default };
@@ -0,0 +1,49 @@
1
+ export { default as TextInput } from './TextInput.js';
2
+ import 'tslib';
3
+ import 'react/jsx-runtime';
4
+ import 'react';
5
+ import 'classnames';
6
+ import '../../hooks/useGlobalSettings.js';
7
+ import '../../GlobalCtx-7fb23cfa.js';
8
+ import '../FormControl/FormControl.js';
9
+ import 'nanoid';
10
+ import '../Tooltip/Tooltip.js';
11
+ import 'react-dom';
12
+
13
+ const basic = {
14
+ disabled: false,
15
+ errorMessage: "This is an error message",
16
+ error: false,
17
+ style: { width: "100%" },
18
+ id: "text-input",
19
+ label: "Insert your name here",
20
+ labelPlacement: "top",
21
+ labelSize: "medium",
22
+ name: "text",
23
+ placeholder: "This is a text field",
24
+ required: false,
25
+ type: "text",
26
+ };
27
+ const isdisabled = Object.assign(Object.assign({}, basic), { disabled: true, placeholder: "Disabled Text Field" });
28
+ const hashelper = Object.assign(Object.assign({}, basic), { placeholder: "This has a helper text" });
29
+ const haserror = Object.assign(Object.assign({}, basic), { placeholder: "This has an error", error: true });
30
+ const hastooltip = Object.assign(Object.assign({}, basic), { placeholder: "This has an tooltip", tooltip: "This is a tooltip" });
31
+ const email = Object.assign(Object.assign({}, basic), { label: "Enter your email address", placeholder: "my@email.com", type: "email", id: "email-input" });
32
+ const password = Object.assign(Object.assign({}, basic), { label: "Enter your password", placeholder: "Must be 8 digits long", type: "password", id: "password-input" });
33
+ const telephone = Object.assign(Object.assign({}, basic), { name: "tel", label: "Enter your telephone number", placeholder: "###-###-####", required: false, type: "tel", pattern: "[0-9]{3}-[0-9]{3}-[0-9]{4}" });
34
+ const url = Object.assign(Object.assign({}, basic), { label: "Enter website address", id: "url-input", name: "url", placeholder: "https://www.example.com", required: false, type: "url" });
35
+
36
+ var TextInput_args = /*#__PURE__*/Object.freeze({
37
+ __proto__: null,
38
+ basic: basic,
39
+ email: email,
40
+ haserror: haserror,
41
+ hashelper: hashelper,
42
+ hastooltip: hastooltip,
43
+ isdisabled: isdisabled,
44
+ password: password,
45
+ telephone: telephone,
46
+ url: url
47
+ });
48
+
49
+ export { TextInput_args as TextInputArgs };
@@ -1,30 +1,30 @@
1
+ import { __rest } from 'tslib';
1
2
  import { jsx } from 'react/jsx-runtime';
3
+ import require$$0 from 'react';
2
4
  import classNames from 'classnames';
3
5
  import useGlobalSettings from '../../hooks/useGlobalSettings.js';
4
- import Fieldset from '../Fieldset/Fieldset.js';
5
- import FormElement from '../FormElement/FormElement.js';
6
- import 'tslib';
7
- import 'react';
6
+ import FormControl, { useFormControl } from '../FormControl/FormControl.js';
8
7
  import '../../GlobalCtx-7fb23cfa.js';
8
+ import 'nanoid';
9
9
  import '../Tooltip/Tooltip.js';
10
10
  import 'react-dom';
11
11
 
12
- const Textarea = ({ callback, disabled = false, error, helper, id, label, maxlength, minlength, name, placeholder, required, spellcheck, tooltip, }) => {
12
+ const Textarea = require$$0.forwardRef((_a, ref) => {
13
+ var { error, className, name, id } = _a, props = __rest(_a, ["error", "className", "name", "id"]);
13
14
  const { prefix } = useGlobalSettings();
15
+ const formControlCtx = useFormControl();
16
+ const { ariaDescribedBy } = formControlCtx;
14
17
  const baseClass = `${prefix}--textarea`;
15
- const TextareaClasses = classNames("", {
16
- [baseClass]: true,
17
- [`error`]: error,
18
+ const errorClass = `${baseClass}__error`;
19
+ const textAreaClass = classNames(baseClass, className, {
20
+ [errorClass]: error,
18
21
  });
19
- /**
20
- * On change, if there is a callback, call it
21
- */
22
- const handleChange = (e) => {
23
- if (callback) {
24
- callback(e);
25
- }
26
- };
27
- return (jsx(Fieldset, { children: jsx(FormElement, Object.assign({ elemid: name, label: label, helper: helper, error: error, required: required, tooltip: tooltip }, { children: jsx("textarea", { id: id, name: name, onChange: handleChange, disabled: disabled, placeholder: placeholder, required: required, className: TextareaClasses, maxLength: maxlength, minLength: minlength, spellCheck: spellcheck }) })) }));
28
- };
22
+ return (jsx("textarea", Object.assign({ ref: ref, className: textAreaClass, name: name, id: id ? id : name, "aria-describedby": ariaDescribedBy }, props)));
23
+ });
24
+ const LabelledTextarea = require$$0.forwardRef((props, ref) => {
25
+ const { style, inputStyle, className } = props, rest = __rest(props, ["style", "inputStyle", "className"]);
26
+ const fieldId = props.id ? props.id : props.name;
27
+ return (jsx(FormControl, Object.assign({ fieldId: fieldId, style: style, className: className }, rest, { children: jsx(Textarea, Object.assign({ ref: ref, style: inputStyle }, rest)) })));
28
+ });
29
29
 
30
- export { Textarea as default };
30
+ export { LabelledTextarea as default };
@@ -1,11 +1,35 @@
1
1
  export { default as Textarea } from './Textarea.js';
2
+ import 'tslib';
2
3
  import 'react/jsx-runtime';
4
+ import 'react';
3
5
  import 'classnames';
4
6
  import '../../hooks/useGlobalSettings.js';
5
- import 'tslib';
6
- import 'react';
7
7
  import '../../GlobalCtx-7fb23cfa.js';
8
- import '../Fieldset/Fieldset.js';
8
+ import '../FormControl/FormControl.js';
9
+ import 'nanoid';
9
10
  import '../Tooltip/Tooltip.js';
10
11
  import 'react-dom';
11
- import '../FormElement/FormElement.js';
12
+
13
+ const placeholder = "It was a cold day in April and the clocks were striking thirteen....";
14
+ const basic = {
15
+ id: "textarea",
16
+ disabled: false,
17
+ name: "textarea",
18
+ placeholder,
19
+ required: false,
20
+ spellcheck: false,
21
+ label: "Insert your life story here",
22
+ labelPlacement: "top",
23
+ labelSize: "medium",
24
+ style: { width: "100%" },
25
+ errorMessage: "This is an error message",
26
+ };
27
+ const haserror = Object.assign(Object.assign({}, basic), { error: true });
28
+ const disabled = Object.assign(Object.assign({}, basic), { disabled: true });
29
+ var Textarea_args = {
30
+ basic,
31
+ haserror,
32
+ disabled,
33
+ };
34
+
35
+ export { Textarea_args as TextareaArgs };
@@ -0,0 +1,31 @@
1
+ import { __rest } from 'tslib';
2
+ import { jsxs, jsx } from 'react/jsx-runtime';
3
+ import { forwardRef } from 'react';
4
+ import useGlobalSettings from '../../hooks/useGlobalSettings.js';
5
+ import classNames from 'classnames';
6
+ import FormControl, { useFormControl } from '../FormControl/FormControl.js';
7
+ import '../../GlobalCtx-7fb23cfa.js';
8
+ import 'nanoid';
9
+ import '../Tooltip/Tooltip.js';
10
+ import 'react-dom';
11
+
12
+ const Toggle = forwardRef(({ size = "medium", error = false, disabled = false, defaultChecked = false, required = false, id, name, onChange, onBlur, onClick, checked, className, }, ref) => {
13
+ const { prefix } = useGlobalSettings();
14
+ const formControlCtx = useFormControl();
15
+ const { ariaDescribedBy } = formControlCtx;
16
+ const hasError = !disabled && !!error;
17
+ const baseClass = `${prefix}--input--toggle`;
18
+ const sliderClass = `${baseClass}--slider`;
19
+ const toggleClass = classNames(baseClass, className, `${baseClass}__size__${size}`, [
20
+ { [`${baseClass}__error`]: hasError },
21
+ { [`${baseClass}__disabled`]: disabled },
22
+ ]);
23
+ return (jsxs("div", Object.assign({ className: toggleClass }, { children: [jsx("input", { ref: ref, checked: checked, disabled: disabled, defaultChecked: defaultChecked, name: name, id: id ? id : name, type: "checkbox", role: "switch", required: required, onChange: onChange, onBlur: onBlur, onClick: onClick, "aria-describedby": ariaDescribedBy }), jsx("span", { className: sliderClass })] })));
24
+ });
25
+ const LabelledToggle = forwardRef((props, ref) => {
26
+ const fieldId = props.id ? props.id : props.name;
27
+ const { style, inputStyle, className } = props, rest = __rest(props, ["style", "inputStyle", "className"]);
28
+ return (jsx(FormControl, Object.assign({ fieldId: fieldId, style: style, className: className }, rest, { children: jsx(Toggle, Object.assign({ ref: ref, style: inputStyle }, rest)) })));
29
+ });
30
+
31
+ export { LabelledToggle as default };
@@ -0,0 +1,48 @@
1
+ export { default as Toggle } from './Toggle.js';
2
+ import 'tslib';
3
+ import 'react/jsx-runtime';
4
+ import 'react';
5
+ import '../../hooks/useGlobalSettings.js';
6
+ import '../../GlobalCtx-7fb23cfa.js';
7
+ import 'classnames';
8
+ import '../FormControl/FormControl.js';
9
+ import 'nanoid';
10
+ import '../Tooltip/Tooltip.js';
11
+ import 'react-dom';
12
+
13
+ const Default = {
14
+ defaultChecked: false,
15
+ errorMessage: "Invalid option",
16
+ name: "my-toggle",
17
+ size: "medium",
18
+ label: "Show details",
19
+ labelPlacement: "end",
20
+ labelSize: "small",
21
+ };
22
+ const Checked = Object.assign(Object.assign({}, Default), { defaultChecked: true });
23
+ const Disabled = Object.assign(Object.assign({}, Default), { disabled: true });
24
+ const Helper = Object.assign(Object.assign({}, Default), { helper: "This is a helper text" });
25
+ const Tooltip = Object.assign(Object.assign({}, Helper), { tooltip: "This is a tooltip" });
26
+ const Error = Object.assign(Object.assign({}, Default), { error: true });
27
+ const DefaultChecked = Object.assign(Object.assign({}, Default), { defaultChecked: true });
28
+ const Controlled = Object.assign(Object.assign({}, Default), { onClick: () => console.log("clicked"), checked: true });
29
+ const Large = Object.assign(Object.assign({}, Default), { size: "large" });
30
+ const Medium = Object.assign(Object.assign({}, Default), { size: "medium" });
31
+ const Small = Object.assign(Object.assign({}, Default), { size: "small" });
32
+
33
+ var Toggle_args = /*#__PURE__*/Object.freeze({
34
+ __proto__: null,
35
+ Checked: Checked,
36
+ Controlled: Controlled,
37
+ Default: Default,
38
+ DefaultChecked: DefaultChecked,
39
+ Disabled: Disabled,
40
+ Error: Error,
41
+ Helper: Helper,
42
+ Large: Large,
43
+ Medium: Medium,
44
+ Small: Small,
45
+ Tooltip: Tooltip
46
+ });
47
+
48
+ export { Toggle_args as ToggleArgs };
@@ -6,7 +6,7 @@ import ReactDOM from 'react-dom';
6
6
  import 'tslib';
7
7
  import '../../GlobalCtx-7fb23cfa.js';
8
8
 
9
- const Tooltip = ({ className, children, icon, label, theme, }) => {
9
+ const Tooltip = ({ className, children, icon, label, theme, id, }) => {
10
10
  const { prefix } = useGlobalSettings();
11
11
  const baseClass = `${prefix}--tooltip`;
12
12
  const [isVisible, setIsVisible] = useState(false);
@@ -95,7 +95,7 @@ const Tooltip = ({ className, children, icon, label, theme, }) => {
95
95
  left: position.x + "px",
96
96
  top: position.y + "px",
97
97
  };
98
- return (jsxs("div", Object.assign({ className: `${baseClass}--wrapper ${icon && "has-icon"}`, onMouseOver: handleOnMouseOver, onFocus: handleOnMouseOver, onMouseOut: handleOnMouseOut, onBlur: handleOnMouseOut }, { children: [!icon && jsx(Fragment, { children: children }), jsxs("span", Object.assign({ className: tooltipClasses, style: style, ref: tooltipRef }, { children: [jsx("span", { className: tooltipArrowClasses, role: "presentation" }), label] }))] })));
98
+ return (jsxs("div", Object.assign({ className: `${baseClass}--wrapper ${icon && "has-icon"}`, onMouseOver: handleOnMouseOver, onFocus: handleOnMouseOver, onMouseOut: handleOnMouseOut, onBlur: handleOnMouseOut, id: id }, { children: [!icon && jsx(Fragment, { children: children }), jsxs("span", Object.assign({ className: tooltipClasses, style: style, ref: tooltipRef }, { children: [jsx("span", { className: tooltipArrowClasses, role: "presentation" }), label] }))] })));
99
99
  };
100
100
 
101
101
  export { Tooltip as default };