@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,65 +1,82 @@
1
- import { FC } from "react";
1
+ import React from "react";
2
2
  import classNames from "classnames";
3
3
  import useGlobalSettings from "../../hooks/useGlobalSettings";
4
- import { NumberPickerProps } from "./NumberPicker.props";
5
- import { Fieldset } from "../Fieldset";
6
- import { FormElement } from "../FormElement";
4
+ import FormControl, { useFormControl } from "../FormControl/FormControl";
5
+ import {
6
+ NumberPickerProps,
7
+ LabelledNumberPickerProps,
8
+ } from "./NumberPicker.props";
7
9
 
8
- const NumberPicker: FC<NumberPickerProps> = ({
9
- callback,
10
- disabled = false,
11
- error,
12
- helper,
13
- id,
14
- label,
15
- name,
16
- placeholder,
17
- required,
18
- tooltip,
19
- }) => {
20
- const { prefix } = useGlobalSettings();
21
- const baseClass = `${prefix}--numberpicker`;
10
+ const NumberPicker = React.forwardRef<HTMLInputElement, NumberPickerProps>(
11
+ (
12
+ {
13
+ onChange,
14
+ onBlur,
15
+ disabled = false,
16
+ error,
17
+ id,
18
+ name,
19
+ placeholder,
20
+ required,
21
+ },
22
+ ref
23
+ ) => {
24
+ const { prefix } = useGlobalSettings();
25
+ const formControlCtx = useFormControl();
26
+ const { ariaDescribedBy } = formControlCtx;
22
27
 
23
- const NumberPickerClasses = classNames("", {
24
- [baseClass]: true,
25
- [`error`]: error,
26
- });
28
+ const inputClass = `${prefix}--input`;
29
+ const baseClass = `${prefix}--numberpicker`;
27
30
 
28
- /**
29
- * On change, if there is a callback, call it
30
- */
31
- const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
32
- if (callback) {
33
- callback(e);
34
- }
35
- };
31
+ const hasError = !disabled && !!error;
32
+
33
+ const numberPickerClasses = classNames(inputClass, baseClass, {
34
+ error: hasError,
35
+ });
36
+
37
+ const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
38
+ if (onChange) {
39
+ onChange(e);
40
+ }
41
+ };
42
+
43
+ return (
44
+ <input
45
+ ref={ref}
46
+ id={id ? id : name}
47
+ name={name}
48
+ onChange={handleChange}
49
+ onBlur={onBlur}
50
+ disabled={disabled}
51
+ placeholder={placeholder}
52
+ required={required}
53
+ type="number"
54
+ className={numberPickerClasses}
55
+ pattern="[0-9]*"
56
+ inputMode="numeric"
57
+ aria-describedby={ariaDescribedBy}
58
+ />
59
+ );
60
+ }
61
+ );
62
+
63
+ const LabelledNumberPicker = React.forwardRef<
64
+ HTMLInputElement,
65
+ LabelledNumberPickerProps
66
+ >((props, ref) => {
67
+ const { style, inputStyle, className, ...rest } = props;
68
+ const fieldId = props.id ? props.id : props.name;
36
69
 
37
70
  return (
38
- <Fieldset>
39
- <FormElement
40
- elemid={name as any}
41
- label={label}
42
- helper={helper as any}
43
- error={error as any}
44
- required={required as any}
45
- tooltip={tooltip}
46
- type={"text"}
47
- >
48
- <input
49
- id={id ? id : name}
50
- name={name}
51
- onChange={handleChange}
52
- disabled={disabled}
53
- placeholder={placeholder}
54
- required={required as any}
55
- type={"text"}
56
- className={`${NumberPickerClasses} ${prefix}--input`}
57
- pattern="[0-9]*"
58
- inputMode="numeric"
59
- />
60
- </FormElement>
61
- </Fieldset>
71
+ <FormControl
72
+ fieldId={fieldId}
73
+ style={style}
74
+ className={className}
75
+ {...rest}
76
+ >
77
+ <NumberPicker ref={ref} style={inputStyle} {...rest} />
78
+ </FormControl>
62
79
  );
63
- };
80
+ });
64
81
 
65
- export default NumberPicker;
82
+ export default LabelledNumberPicker;
@@ -1,14 +1,8 @@
1
1
  import { RadioProps } from "./Radio.props";
2
2
 
3
3
  const basic: RadioProps = {
4
- callback: () => {},
5
- disabled: false,
6
- error: "",
7
- helper: "",
8
- label: "Radio Field Label",
4
+ className: "Radio",
9
5
  name: "radio",
10
- required: false,
11
- value: "radio",
12
6
  };
13
7
 
14
8
  /**
@@ -1,14 +1,6 @@
1
- export interface RadioProps {
2
- callback?: (e: React.ChangeEvent<HTMLInputElement>) => any;
3
- className?: string;
4
- disabled?: boolean;
5
- error?: string;
6
- helper?: string;
7
- id?: string;
8
- label?: string;
9
- name: string;
10
- required?: boolean;
11
- tooltip?: string;
12
- value: string;
13
- selected?: string;
14
- }
1
+ import { ChoiceFieldProps } from "../../types";
2
+ import { LabelledFormFieldProps } from "../../types";
3
+
4
+ export type RadioProps = ChoiceFieldProps<HTMLInputElement>;
5
+
6
+ export type LabelledRadioProps = LabelledFormFieldProps<RadioProps>;
@@ -1,61 +1,99 @@
1
- import { FC } from "react";
1
+ import React, { useEffect } from "react";
2
2
  import classNames from "classnames";
3
- import useGlobalSettings from "../../hooks/useGlobalSettings";
4
- import { RadioProps } from "./Radio.props";
5
- import { FormElement } from "../FormElement";
6
-
7
- const Radio: FC<RadioProps> = ({
8
- callback,
9
- disabled = false,
10
- error,
11
- helper,
12
- id,
13
- label,
14
- name,
15
- required,
16
- selected,
17
- tooltip,
18
- value,
19
- }) => {
20
- const { prefix } = useGlobalSettings();
21
- const baseClass = `${prefix}--radio`;
22
-
23
- const RadioClasses = classNames("", {
24
- [baseClass]: true,
25
- [`error`]: error,
26
- });
27
-
28
- /**
29
- * On change, if there is a callback, call it
30
- */
31
- const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
32
- if (callback) {
33
- callback(e);
34
- }
35
- };
36
-
37
- return (
38
- <FormElement
39
- elemid={id as any}
40
- label={label}
41
- helper={helper as any}
42
- error={error as any}
43
- required={required as any}
44
- tooltip={tooltip}
45
- >
3
+ import { useGlobalSettings } from "../../hooks";
4
+ import { LabelledRadioProps, RadioProps } from "./Radio.props";
5
+ import { useFieldsetError } from "../Fieldset/Fieldset";
6
+ import FormControl, { useFormControl } from "../FormControl/FormControl";
7
+ import usePrevious from "../../hooks/usePrevious";
8
+
9
+ const Radio = React.forwardRef<HTMLInputElement, RadioProps>(
10
+ (
11
+ {
12
+ onChange,
13
+ onBlur,
14
+ disabled = false,
15
+ error,
16
+ id,
17
+ name,
18
+ required,
19
+ checked,
20
+ defaultChecked = false,
21
+ value,
22
+ },
23
+ ref
24
+ ) => {
25
+ const { prefix } = useGlobalSettings();
26
+ const { setHasError } = useFieldsetError();
27
+ const formControlCtx = useFormControl();
28
+ const prevError = usePrevious(error);
29
+
30
+ useEffect(() => {
31
+ if (error !== prevError) {
32
+ setHasError(!!error);
33
+ }
34
+ }, [error, prevError, setHasError]);
35
+
36
+ const { ariaDescribedBy } = formControlCtx;
37
+
38
+ const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
39
+ console.log(e.target.value);
40
+ if (onChange) {
41
+ onChange(e);
42
+ }
43
+ };
44
+
45
+ const baseClass = `${prefix}--radio`;
46
+ const errorClass = `${baseClass}__error`;
47
+
48
+ const RadioClasses = classNames(baseClass, {
49
+ [errorClass]: error,
50
+ });
51
+
52
+ return (
46
53
  <input
47
- id={id}
54
+ ref={ref}
55
+ id={id ? id : name}
48
56
  name={name}
49
57
  onChange={handleChange}
58
+ onBlur={onBlur}
50
59
  disabled={disabled}
51
- required={required as any}
52
- type={"radio"}
60
+ required={required}
61
+ type="radio"
53
62
  className={RadioClasses}
54
- checked={selected === value}
63
+ defaultChecked={defaultChecked}
64
+ aria-describedby={ariaDescribedBy}
65
+ checked={checked}
55
66
  value={value}
56
67
  />
57
- </FormElement>
58
- );
59
- };
68
+ );
69
+ }
70
+ );
71
+
72
+ const LabelledRadio = React.forwardRef<HTMLInputElement, LabelledRadioProps>(
73
+ (props, ref) => {
74
+ const {
75
+ style,
76
+ inputStyle,
77
+ className,
78
+ labelPlacement = "end",
79
+ labelSize = "small",
80
+ ...rest
81
+ } = props;
82
+ const fieldId = props.id ? props.id : props.name;
83
+
84
+ return (
85
+ <FormControl
86
+ fieldId={fieldId}
87
+ style={style}
88
+ className={className}
89
+ labelPlacement={labelPlacement}
90
+ labelSize={labelSize}
91
+ {...rest}
92
+ >
93
+ <Radio ref={ref} style={inputStyle} {...rest} />
94
+ </FormControl>
95
+ );
96
+ }
97
+ );
60
98
 
61
- export default Radio;
99
+ export default LabelledRadio;
@@ -1 +1,2 @@
1
1
  export { default as Radio } from "./Radio";
2
+ export { default as RadioArgs } from "./Radio.args";
@@ -0,0 +1,75 @@
1
+ import { LabelledTextInputProps } from "./TextInput.props";
2
+
3
+ export const basic: LabelledTextInputProps = {
4
+ disabled: false,
5
+ errorMessage: "This is an error message",
6
+ error: false,
7
+ style: { width: "100%" },
8
+ id: "text-input",
9
+ label: "Insert your name here",
10
+ labelPlacement: "top",
11
+ labelSize: "medium",
12
+ name: "text",
13
+ placeholder: "This is a text field",
14
+ required: false,
15
+ type: "text",
16
+ };
17
+
18
+ export const isdisabled: LabelledTextInputProps = {
19
+ ...basic,
20
+ disabled: true,
21
+ placeholder: "Disabled Text Field",
22
+ };
23
+
24
+ export const hashelper: LabelledTextInputProps = {
25
+ ...basic,
26
+ placeholder: "This has a helper text",
27
+ };
28
+
29
+ export const haserror: LabelledTextInputProps = {
30
+ ...basic,
31
+ placeholder: "This has an error",
32
+ error: true,
33
+ };
34
+
35
+ export const hastooltip: LabelledTextInputProps = {
36
+ ...basic,
37
+ placeholder: "This has an tooltip",
38
+ tooltip: "This is a tooltip",
39
+ };
40
+
41
+ export const email: LabelledTextInputProps = {
42
+ ...basic,
43
+ label: "Enter your email address",
44
+ placeholder: "my@email.com",
45
+ type: "email",
46
+ id: "email-input",
47
+ };
48
+
49
+ export const password: LabelledTextInputProps = {
50
+ ...basic,
51
+ label: "Enter your password",
52
+ placeholder: "Must be 8 digits long",
53
+ type: "password",
54
+ id: "password-input",
55
+ };
56
+
57
+ export const telephone: LabelledTextInputProps = {
58
+ ...basic,
59
+ name: "tel",
60
+ label: "Enter your telephone number",
61
+ placeholder: "###-###-####",
62
+ required: false,
63
+ type: "tel",
64
+ pattern: "[0-9]{3}-[0-9]{3}-[0-9]{4}",
65
+ };
66
+
67
+ export const url: LabelledTextInputProps = {
68
+ ...basic,
69
+ label: "Enter website address",
70
+ id: "url-input",
71
+ name: "url",
72
+ placeholder: "https://www.example.com",
73
+ required: false,
74
+ type: "url",
75
+ };
@@ -0,0 +1,20 @@
1
+ import { FormFieldProps, TextInputTypes } from "../../types";
2
+ import { LabelledFormFieldProps } from "../../types";
3
+ export interface TextInputProps extends FormFieldProps<HTMLInputElement> {
4
+ /**
5
+ * Optional pattern attribute for phone numbers, zip codes, etc.
6
+ */
7
+ pattern?: string;
8
+
9
+ /**
10
+ * Specify an optional className to be added to your Input component.
11
+ */
12
+ placeholder?: string;
13
+
14
+ /**
15
+ * The input's type.
16
+ */
17
+ type: TextInputTypes;
18
+ }
19
+
20
+ export type LabelledTextInputProps = LabelledFormFieldProps<TextInputProps>;
@@ -0,0 +1,71 @@
1
+ import React from "react";
2
+ import classNames from "classnames";
3
+ import useGlobalSettings from "../../hooks/useGlobalSettings";
4
+ import { TextInputProps, LabelledTextInputProps } from "./TextInput.props";
5
+ import FormControl, { useFormControl } from "../FormControl/FormControl";
6
+
7
+ const TextInput = React.forwardRef<HTMLInputElement, TextInputProps>(
8
+ (
9
+ {
10
+ onChange,
11
+ onBlur,
12
+ error,
13
+ id,
14
+ name,
15
+ placeholder,
16
+ required,
17
+ pattern,
18
+ disabled = false,
19
+ type = "text",
20
+ },
21
+ ref
22
+ ) => {
23
+ const { prefix } = useGlobalSettings();
24
+ const formControlCtx = useFormControl();
25
+ const { ariaDescribedBy } = formControlCtx;
26
+
27
+ const baseClass = `${prefix}--text-input`;
28
+
29
+ const inputClass = classNames(baseClass, {
30
+ [`${baseClass}__error`]: error,
31
+ });
32
+
33
+ return (
34
+ <input
35
+ ref={ref}
36
+ id={id ? id : name}
37
+ name={name}
38
+ onChange={onChange}
39
+ onBlur={onBlur}
40
+ disabled={disabled}
41
+ placeholder={placeholder}
42
+ required={required}
43
+ type={type}
44
+ className={inputClass}
45
+ pattern={pattern}
46
+ aria-describedby={ariaDescribedBy}
47
+ />
48
+ );
49
+ }
50
+ );
51
+
52
+ const LabelledTextInput = React.forwardRef<
53
+ HTMLInputElement,
54
+ LabelledTextInputProps
55
+ >((props, ref) => {
56
+ const { style, inputStyle, className, ...rest } = props;
57
+ const fieldId = props.id ? props.id : props.name;
58
+
59
+ return (
60
+ <FormControl
61
+ fieldId={fieldId}
62
+ style={style}
63
+ className={className}
64
+ {...rest}
65
+ >
66
+ <TextInput ref={ref} style={inputStyle} {...rest} />
67
+ </FormControl>
68
+ );
69
+ });
70
+
71
+ export default LabelledTextInput;
@@ -0,0 +1,2 @@
1
+ export { default as TextInput } from "./TextInput";
2
+ export * as TextInputArgs from "./TextInput.args";
@@ -1,52 +1,34 @@
1
- import { TextareaProps } from "./Textarea.props";
1
+ import { LabelledTextareaProps, TextareaProps } from "./Textarea.props";
2
2
 
3
- const basic: TextareaProps = {
4
- disabled: false,
5
- label: "Textarea",
6
- name: "textarea",
7
- placeholder: "Textarea",
8
- required: false,
9
- spellcheck: false,
10
- };
3
+ const placeholder =
4
+ "It was a cold day in April and the clocks were striking thirteen....";
11
5
 
12
- const hashelper: TextareaProps = {
6
+ export const basic: LabelledTextareaProps = {
7
+ id: "textarea",
13
8
  disabled: false,
14
- helper: "This one has helper text",
15
- label: "Textarea",
16
9
  name: "textarea",
17
- placeholder: "Textarea",
10
+ placeholder,
18
11
  required: false,
19
12
  spellcheck: false,
13
+ label: "Insert your life story here",
14
+ labelPlacement: "top" as const,
15
+ labelSize: "medium" as const,
16
+ style: { width: "100%" },
17
+ errorMessage: "This is an error message",
20
18
  };
21
19
 
22
- const haserror: TextareaProps = {
23
- disabled: false,
24
- error: "This one has an error",
25
- label: "Textarea",
26
- name: "textarea",
27
- placeholder: "Textarea",
28
- required: false,
29
- spellcheck: false,
20
+ export const haserror: TextareaProps = {
21
+ ...basic,
22
+ error: true,
30
23
  };
31
24
 
32
- const hastooltip: TextareaProps = {
33
- disabled: false,
34
- label: "Textarea",
35
- name: "textarea",
36
- placeholder: "Textarea",
37
- required: false,
38
- spellcheck: false,
39
- tooltip: "This is the tooltip",
25
+ export const disabled: TextareaProps = {
26
+ ...basic,
27
+ disabled: true,
40
28
  };
41
29
 
42
- /**
43
- * Sample prop definitions Textarea's enumerable properties (imported in stories and test)
44
- */
45
- const TextareaArgs = {
30
+ export default {
46
31
  basic,
47
- hashelper,
48
32
  haserror,
49
- hastooltip,
33
+ disabled,
50
34
  };
51
-
52
- export default TextareaArgs;
@@ -1,38 +1,20 @@
1
- export interface TextareaProps {
1
+ import { FormFieldProps } from "../../types";
2
+ import { LabelledFormFieldProps } from "../../types";
3
+ export interface TextareaProps extends FormFieldProps<HTMLTextAreaElement> {
2
4
  /**
3
5
  * The Textarea's onChange callback.
4
6
  */
5
- callback?: (e: React.ChangeEvent<HTMLTextAreaElement>) => any;
7
+ onChange?: (e: React.ChangeEvent<HTMLTextAreaElement>) => any;
6
8
 
7
9
  /**
8
- * Specify an optional className to be added to your Textarea.
9
- */
10
- className?: string;
11
-
12
- /**
13
- * Is the Textarea disabled?
14
- */
15
- disabled?: boolean;
16
-
17
- /**
18
- * Does the Textarea have an error?
19
- */
20
- error?: string;
21
-
22
- /**
23
- * The Textarea's helper text
24
- */
25
- helper?: string;
26
-
27
- /**
28
- * The Textarea's id attribute
29
- */
30
- id?: string;
10
+ * Activate automatic spelling correction and processing of text substitutions
11
+ **/
12
+ autocorrect?: "on" | "off";
31
13
 
32
14
  /**
33
- * Does this Textarea have a label?
34
- */
35
- label: string;
15
+ * The id of the form element the Textarea belongs to if it's not nested inside the form.
16
+ **/
17
+ form?: string;
36
18
 
37
19
  /**
38
20
  * The Textarea's maxlength
@@ -44,30 +26,20 @@ export interface TextareaProps {
44
26
  */
45
27
  minlength?: number;
46
28
 
47
- /**
48
- * The Textarea's name attribute
49
- */
50
- name?: Required<string>;
51
-
52
29
  /**
53
30
  * Specify an optional className to be added to your Textarea component.
54
31
  */
55
32
  placeholder?: string;
56
33
 
57
34
  /**
58
- * Specify whether this Textarea is required
59
- */
60
- required?: boolean;
61
-
62
- /**
63
- * Specify whether this Textarea employs browser-based spellcheck
64
- */
65
- spellcheck?: boolean;
35
+ * Specifies whether the textarea is subject to spellchecking by the underlying browser/OS
36
+ **/
37
+ spellcheck?: boolean | "default";
66
38
 
67
39
  /**
68
- * Does this Textarea have a tooltip?
69
- */
70
- tooltip?: string;
71
-
72
- type?: never;
40
+ * How the control should wrap the value for submission.
41
+ **/
42
+ wrap?: "hard" | "soft" | "off";
73
43
  }
44
+
45
+ export type LabelledTextareaProps = LabelledFormFieldProps<TextareaProps>;