@ilo-org/react 0.7.8 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -0
- package/lib/cjs/components/Checkbox/Checkbox.js +28 -16
- package/lib/cjs/components/Checkbox/index.js +25 -3
- package/lib/cjs/components/DatePicker/DatePicker.js +21 -16
- package/lib/cjs/components/DatePicker/index.js +4 -4
- package/lib/cjs/components/Dropdown/Dropdown.js +19 -15
- package/lib/cjs/components/Dropdown/index.js +3 -3
- package/lib/cjs/components/Fieldset/Fieldset.js +33 -9
- package/lib/cjs/components/Fieldset/index.js +2 -2
- package/lib/cjs/components/FileUpload/FileUpload.js +29 -15
- package/lib/cjs/components/FileUpload/index.js +3 -3
- package/lib/cjs/components/Form/Form.js +8 -55
- package/lib/cjs/components/Form/index.js +10 -20
- package/lib/cjs/components/FormControl/FormControl.js +79 -0
- package/lib/cjs/components/FormControl/index.js +16 -0
- package/lib/cjs/components/Input/Input.js +1 -1
- package/lib/cjs/components/NumberPicker/NumberPicker.js +21 -16
- package/lib/cjs/components/NumberPicker/index.js +4 -4
- package/lib/cjs/components/Radio/Radio.js +34 -17
- package/lib/cjs/components/Radio/index.js +19 -4
- package/lib/cjs/components/TextInput/TextInput.js +30 -0
- package/lib/cjs/components/TextInput/index.js +52 -0
- package/lib/cjs/components/Textarea/Textarea.js +19 -19
- package/lib/cjs/components/Textarea/index.js +26 -5
- package/lib/cjs/components/Toggle/Toggle.js +33 -0
- package/lib/cjs/components/Toggle/index.js +51 -0
- package/lib/cjs/components/Tooltip/Tooltip.js +2 -2
- package/lib/cjs/components/index.js +10 -11
- package/lib/cjs/hooks/usePrevious.js +20 -0
- package/lib/cjs/index.js +10 -11
- package/lib/esm/components/Checkbox/Checkbox.js +31 -19
- package/lib/esm/components/Checkbox/index.js +27 -2
- package/lib/esm/components/DatePicker/DatePicker.js +22 -17
- package/lib/esm/components/DatePicker/index.js +4 -4
- package/lib/esm/components/Dropdown/Dropdown.js +20 -16
- package/lib/esm/components/Dropdown/index.js +3 -3
- package/lib/esm/components/Fieldset/Fieldset.js +31 -11
- package/lib/esm/components/Fieldset/index.js +1 -1
- package/lib/esm/components/FileUpload/FileUpload.js +31 -17
- package/lib/esm/components/FileUpload/index.js +3 -3
- package/lib/esm/components/Form/Form.js +10 -57
- package/lib/esm/components/Form/index.js +13 -20
- package/lib/esm/components/FormControl/FormControl.js +73 -0
- package/lib/esm/components/{ChoiceGroup → FormControl}/index.js +3 -6
- package/lib/esm/components/NumberPicker/NumberPicker.js +21 -16
- package/lib/esm/components/NumberPicker/index.js +4 -4
- package/lib/esm/components/Radio/Radio.js +34 -17
- package/lib/esm/components/Radio/index.js +21 -3
- package/lib/esm/components/TextInput/TextInput.js +28 -0
- package/lib/esm/components/TextInput/index.js +49 -0
- package/lib/esm/components/Textarea/Textarea.js +19 -19
- package/lib/esm/components/Textarea/index.js +28 -4
- package/lib/esm/components/Toggle/Toggle.js +31 -0
- package/lib/esm/components/Toggle/index.js +48 -0
- package/lib/esm/components/Tooltip/Tooltip.js +2 -2
- package/lib/esm/components/index.js +8 -5
- package/lib/esm/hooks/usePrevious.js +15 -0
- package/lib/esm/index.js +8 -5
- package/lib/types/react/src/components/Checkbox/Checkbox.args.d.ts +52 -0
- package/lib/types/react/src/components/Checkbox/Checkbox.d.ts +5 -3
- package/lib/types/react/src/components/Checkbox/Checkbox.props.d.ts +4 -13
- package/lib/types/react/src/components/Checkbox/index.d.ts +1 -0
- package/lib/types/react/src/components/DatePicker/DatePicker.d.ts +4 -3
- package/lib/types/react/src/components/DatePicker/DatePicker.props.d.ts +10 -43
- package/lib/types/react/src/components/Dropdown/Dropdown.d.ts +5 -3
- package/lib/types/react/src/components/Dropdown/Dropdown.props.d.ts +16 -42
- package/lib/types/react/src/components/Fieldset/Fieldset.d.ts +6 -0
- package/lib/types/react/src/components/Fieldset/Fieldset.props.d.ts +14 -21
- package/lib/types/react/src/components/FileUpload/FileUpload.d.ts +5 -3
- package/lib/types/react/src/components/FileUpload/FileUpload.props.d.ts +7 -44
- package/lib/types/react/src/components/Form/Form.args.d.ts +2 -0
- package/lib/types/react/src/components/Form/Form.d.ts +1 -2
- package/lib/types/react/src/components/Form/Form.props.d.ts +4 -111
- package/lib/types/react/src/components/Form/index.d.ts +1 -0
- package/lib/types/react/src/components/FormControl/FormControl.d.ts +9 -0
- package/lib/types/react/src/components/FormControl/FormControl.props.d.ts +55 -0
- package/lib/types/react/src/components/FormControl/index.d.ts +2 -0
- package/lib/types/react/src/components/FormElement/FormElement.props.d.ts +2 -2
- package/lib/types/react/src/components/Input/Input.props.d.ts +2 -2
- package/lib/types/react/src/components/NumberPicker/NumberPicker.d.ts +5 -3
- package/lib/types/react/src/components/NumberPicker/NumberPicker.props.d.ts +5 -42
- package/lib/types/react/src/components/Radio/Radio.args.d.ts +8 -0
- package/lib/types/react/src/components/Radio/Radio.d.ts +5 -3
- package/lib/types/react/src/components/Radio/Radio.props.d.ts +4 -14
- package/lib/types/react/src/components/Radio/index.d.ts +1 -0
- package/lib/types/react/src/components/TextInput/TextInput.args.d.ts +10 -0
- package/lib/types/react/src/components/TextInput/TextInput.d.ts +6 -0
- package/lib/types/react/src/components/TextInput/TextInput.props.d.ts +17 -0
- package/lib/types/react/src/components/TextInput/index.d.ts +2 -0
- package/lib/types/react/src/components/Textarea/Textarea.args.d.ts +10 -0
- package/lib/types/react/src/components/Textarea/Textarea.d.ts +5 -3
- package/lib/types/react/src/components/Textarea/Textarea.props.d.ts +17 -39
- package/lib/types/react/src/components/Textarea/index.d.ts +2 -0
- package/lib/types/react/src/components/Toggle/Toggle.args.d.ts +12 -0
- package/lib/types/react/src/components/Toggle/Toggle.d.ts +5 -0
- package/lib/types/react/src/components/Toggle/Toggle.props.d.ts +22 -0
- package/lib/types/react/src/components/Toggle/index.d.ts +3 -0
- package/lib/types/react/src/components/Tooltip/Tooltip.props.d.ts +4 -0
- package/lib/types/react/src/components/index.d.ts +1 -5
- package/lib/types/react/src/hooks/usePrevious.d.ts +2 -0
- package/lib/types/react/src/types/index.d.ts +57 -1
- package/package.json +20 -19
- package/src/components/Checkbox/Checkbox.args.ts +31 -9
- package/src/components/Checkbox/Checkbox.props.ts +5 -13
- package/src/components/Checkbox/Checkbox.tsx +78 -76
- package/src/components/Checkbox/index.ts +1 -0
- package/src/components/DatePicker/DatePicker.args.ts +6 -32
- package/src/components/DatePicker/DatePicker.props.ts +11 -51
- package/src/components/DatePicker/DatePicker.tsx +71 -110
- package/src/components/Dropdown/Dropdown.args.ts +42 -192
- package/src/components/Dropdown/Dropdown.props.ts +18 -49
- package/src/components/Dropdown/Dropdown.tsx +73 -62
- package/src/components/Fieldset/Fieldset.props.ts +14 -23
- package/src/components/Fieldset/Fieldset.tsx +75 -69
- package/src/components/FileUpload/FileUpload.args.ts +25 -27
- package/src/components/FileUpload/FileUpload.props.ts +8 -53
- package/src/components/FileUpload/FileUpload.tsx +103 -72
- package/src/components/Form/Form.args.ts +2 -184
- package/src/components/Form/Form.props.ts +4 -133
- package/src/components/Form/Form.tsx +17 -77
- package/src/components/Form/index.ts +1 -0
- package/src/components/FormControl/FormControl.props.ts +72 -0
- package/src/components/FormControl/FormControl.tsx +169 -0
- package/src/components/FormControl/index.ts +2 -0
- package/src/components/FormElement/FormElement.props.ts +2 -2
- package/src/components/Input/Input.props.ts +2 -2
- package/src/components/Navigation/Navigation.args.ts +2 -1
- package/src/components/NumberPicker/NumberPicker.args.ts +18 -26
- package/src/components/NumberPicker/NumberPicker.props.ts +7 -52
- package/src/components/NumberPicker/NumberPicker.tsx +73 -56
- package/src/components/Radio/Radio.args.ts +1 -7
- package/src/components/Radio/Radio.props.ts +6 -14
- package/src/components/Radio/Radio.tsx +90 -52
- package/src/components/Radio/index.ts +1 -0
- package/src/components/TextInput/TextInput.args.ts +75 -0
- package/src/components/TextInput/TextInput.props.ts +20 -0
- package/src/components/TextInput/TextInput.tsx +71 -0
- package/src/components/TextInput/index.ts +2 -0
- package/src/components/Textarea/Textarea.args.ts +19 -37
- package/src/components/Textarea/Textarea.props.ts +18 -46
- package/src/components/Textarea/Textarea.tsx +44 -59
- package/src/components/Textarea/index.ts +2 -0
- package/src/components/Toggle/Toggle.args.ts +62 -0
- package/src/components/Toggle/Toggle.props.ts +27 -0
- package/src/components/Toggle/Toggle.tsx +85 -0
- package/src/components/Toggle/index.ts +3 -0
- package/src/components/Tooltip/Tooltip.props.ts +5 -0
- package/src/components/Tooltip/Tooltip.tsx +2 -0
- package/src/components/index.ts +1 -5
- package/src/hooks/usePrevious.ts +15 -0
- package/src/types/forms.args.ts +288 -0
- package/src/types/index.ts +69 -1
- package/tsconfig.json +2 -1
- package/lib/cjs/components/ChoiceGroup/ChoiceGroup.js +0 -34
- package/lib/cjs/components/ChoiceGroup/index.js +0 -19
- package/lib/cjs/components/FormGroup/FormGroup.js +0 -58
- package/lib/cjs/components/FormGroup/index.js +0 -26
- package/lib/esm/components/ChoiceGroup/ChoiceGroup.js +0 -32
- package/lib/esm/components/FormGroup/FormGroup.js +0 -56
- package/lib/esm/components/FormGroup/index.js +0 -20
- package/lib/types/react/src/components/ChoiceGroup/ChoiceGroup.d.ts +0 -4
- package/lib/types/react/src/components/ChoiceGroup/ChoiceGroup.props.d.ts +0 -20
- package/lib/types/react/src/components/ChoiceGroup/index.d.ts +0 -1
- package/lib/types/react/src/components/FormGroup/FormGroup.d.ts +0 -4
- package/lib/types/react/src/components/FormGroup/FormGroup.props.d.ts +0 -81
- package/lib/types/react/src/components/FormGroup/index.d.ts +0 -1
- package/src/components/ChoiceGroup/ChoiceGroup.args.ts +0 -95
- package/src/components/ChoiceGroup/ChoiceGroup.props.ts +0 -25
- package/src/components/ChoiceGroup/ChoiceGroup.tsx +0 -54
- package/src/components/ChoiceGroup/index.ts +0 -1
- package/src/components/FormGroup/FormGroup.args.ts +0 -85
- package/src/components/FormGroup/FormGroup.props.ts +0 -102
- package/src/components/FormGroup/FormGroup.tsx +0 -73
- package/src/components/FormGroup/index.ts +0 -1
|
@@ -1,65 +1,82 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React from "react";
|
|
2
2
|
import classNames from "classnames";
|
|
3
3
|
import useGlobalSettings from "../../hooks/useGlobalSettings";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
4
|
+
import FormControl, { useFormControl } from "../FormControl/FormControl";
|
|
5
|
+
import {
|
|
6
|
+
NumberPickerProps,
|
|
7
|
+
LabelledNumberPickerProps,
|
|
8
|
+
} from "./NumberPicker.props";
|
|
7
9
|
|
|
8
|
-
const NumberPicker
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
[`error`]: error,
|
|
26
|
-
});
|
|
28
|
+
const inputClass = `${prefix}--input`;
|
|
29
|
+
const baseClass = `${prefix}--numberpicker`;
|
|
27
30
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
<
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
|
82
|
+
export default LabelledNumberPicker;
|
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
import { RadioProps } from "./Radio.props";
|
|
2
2
|
|
|
3
3
|
const basic: RadioProps = {
|
|
4
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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 {
|
|
1
|
+
import React, { useEffect } from "react";
|
|
2
2
|
import classNames from "classnames";
|
|
3
|
-
import useGlobalSettings from "../../hooks
|
|
4
|
-
import { RadioProps } from "./Radio.props";
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
<
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
|
|
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
|
|
52
|
-
type=
|
|
60
|
+
required={required}
|
|
61
|
+
type="radio"
|
|
53
62
|
className={RadioClasses}
|
|
54
|
-
|
|
63
|
+
defaultChecked={defaultChecked}
|
|
64
|
+
aria-describedby={ariaDescribedBy}
|
|
65
|
+
checked={checked}
|
|
55
66
|
value={value}
|
|
56
67
|
/>
|
|
57
|
-
|
|
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
|
|
99
|
+
export default LabelledRadio;
|
|
@@ -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;
|
|
@@ -1,52 +1,34 @@
|
|
|
1
|
-
import { TextareaProps } from "./Textarea.props";
|
|
1
|
+
import { LabelledTextareaProps, TextareaProps } from "./Textarea.props";
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
24
|
-
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
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
33
|
+
disabled,
|
|
50
34
|
};
|
|
51
|
-
|
|
52
|
-
export default TextareaArgs;
|
|
@@ -1,38 +1,20 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
7
|
+
onChange?: (e: React.ChangeEvent<HTMLTextAreaElement>) => any;
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
|
-
*
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
*
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
*
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
*
|
|
69
|
-
|
|
70
|
-
|
|
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>;
|