@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.
- package/CHANGELOG.md +22 -0
- package/lib/cjs/components/Checkbox/Checkbox.js +28 -16
- package/lib/cjs/components/Checkbox/index.js +25 -3
- package/lib/cjs/components/DatePicker/DatePicker.js +21 -16
- package/lib/cjs/components/DatePicker/index.js +4 -4
- package/lib/cjs/components/Dropdown/Dropdown.js +19 -15
- package/lib/cjs/components/Dropdown/index.js +3 -3
- package/lib/cjs/components/Fieldset/Fieldset.js +33 -9
- package/lib/cjs/components/Fieldset/index.js +2 -2
- package/lib/cjs/components/FileUpload/FileUpload.js +29 -15
- package/lib/cjs/components/FileUpload/index.js +3 -3
- package/lib/cjs/components/Form/Form.js +8 -55
- package/lib/cjs/components/Form/index.js +10 -20
- package/lib/cjs/components/FormControl/FormControl.js +79 -0
- package/lib/cjs/components/FormControl/index.js +16 -0
- package/lib/cjs/components/Input/Input.js +1 -1
- package/lib/cjs/components/NumberPicker/NumberPicker.js +21 -16
- package/lib/cjs/components/NumberPicker/index.js +4 -4
- package/lib/cjs/components/Radio/Radio.js +34 -17
- package/lib/cjs/components/Radio/index.js +19 -4
- package/lib/cjs/components/TextInput/TextInput.js +30 -0
- package/lib/cjs/components/TextInput/index.js +52 -0
- package/lib/cjs/components/Textarea/Textarea.js +19 -19
- package/lib/cjs/components/Textarea/index.js +26 -5
- package/lib/cjs/components/Toggle/Toggle.js +33 -0
- package/lib/cjs/components/Toggle/index.js +51 -0
- package/lib/cjs/components/Tooltip/Tooltip.js +2 -2
- package/lib/cjs/components/index.js +10 -11
- package/lib/cjs/hooks/usePrevious.js +20 -0
- package/lib/cjs/index.js +10 -11
- package/lib/esm/components/Checkbox/Checkbox.js +31 -19
- package/lib/esm/components/Checkbox/index.js +27 -2
- package/lib/esm/components/DatePicker/DatePicker.js +22 -17
- package/lib/esm/components/DatePicker/index.js +4 -4
- package/lib/esm/components/Dropdown/Dropdown.js +20 -16
- package/lib/esm/components/Dropdown/index.js +3 -3
- package/lib/esm/components/Fieldset/Fieldset.js +31 -11
- package/lib/esm/components/Fieldset/index.js +1 -1
- package/lib/esm/components/FileUpload/FileUpload.js +31 -17
- package/lib/esm/components/FileUpload/index.js +3 -3
- package/lib/esm/components/Form/Form.js +10 -57
- package/lib/esm/components/Form/index.js +13 -20
- package/lib/esm/components/FormControl/FormControl.js +73 -0
- package/lib/esm/components/{ChoiceGroup → FormControl}/index.js +3 -6
- package/lib/esm/components/NumberPicker/NumberPicker.js +21 -16
- package/lib/esm/components/NumberPicker/index.js +4 -4
- package/lib/esm/components/Radio/Radio.js +34 -17
- package/lib/esm/components/Radio/index.js +21 -3
- package/lib/esm/components/TextInput/TextInput.js +28 -0
- package/lib/esm/components/TextInput/index.js +49 -0
- package/lib/esm/components/Textarea/Textarea.js +19 -19
- package/lib/esm/components/Textarea/index.js +28 -4
- package/lib/esm/components/Toggle/Toggle.js +31 -0
- package/lib/esm/components/Toggle/index.js +48 -0
- package/lib/esm/components/Tooltip/Tooltip.js +2 -2
- package/lib/esm/components/index.js +8 -5
- package/lib/esm/hooks/usePrevious.js +15 -0
- package/lib/esm/index.js +8 -5
- package/lib/types/react/src/components/Checkbox/Checkbox.args.d.ts +52 -0
- package/lib/types/react/src/components/Checkbox/Checkbox.d.ts +5 -3
- package/lib/types/react/src/components/Checkbox/Checkbox.props.d.ts +4 -13
- package/lib/types/react/src/components/Checkbox/index.d.ts +1 -0
- package/lib/types/react/src/components/DatePicker/DatePicker.d.ts +4 -3
- package/lib/types/react/src/components/DatePicker/DatePicker.props.d.ts +10 -43
- package/lib/types/react/src/components/Dropdown/Dropdown.d.ts +5 -3
- package/lib/types/react/src/components/Dropdown/Dropdown.props.d.ts +16 -42
- package/lib/types/react/src/components/Fieldset/Fieldset.d.ts +6 -0
- package/lib/types/react/src/components/Fieldset/Fieldset.props.d.ts +14 -21
- package/lib/types/react/src/components/FileUpload/FileUpload.d.ts +5 -3
- package/lib/types/react/src/components/FileUpload/FileUpload.props.d.ts +7 -44
- package/lib/types/react/src/components/Form/Form.args.d.ts +2 -0
- package/lib/types/react/src/components/Form/Form.d.ts +1 -2
- package/lib/types/react/src/components/Form/Form.props.d.ts +4 -111
- package/lib/types/react/src/components/Form/index.d.ts +1 -0
- package/lib/types/react/src/components/FormControl/FormControl.d.ts +9 -0
- package/lib/types/react/src/components/FormControl/FormControl.props.d.ts +55 -0
- package/lib/types/react/src/components/FormControl/index.d.ts +2 -0
- package/lib/types/react/src/components/FormElement/FormElement.props.d.ts +2 -2
- package/lib/types/react/src/components/Input/Input.props.d.ts +2 -2
- package/lib/types/react/src/components/NumberPicker/NumberPicker.d.ts +5 -3
- package/lib/types/react/src/components/NumberPicker/NumberPicker.props.d.ts +5 -42
- package/lib/types/react/src/components/Radio/Radio.args.d.ts +8 -0
- package/lib/types/react/src/components/Radio/Radio.d.ts +5 -3
- package/lib/types/react/src/components/Radio/Radio.props.d.ts +4 -14
- package/lib/types/react/src/components/Radio/index.d.ts +1 -0
- package/lib/types/react/src/components/TextInput/TextInput.args.d.ts +10 -0
- package/lib/types/react/src/components/TextInput/TextInput.d.ts +6 -0
- package/lib/types/react/src/components/TextInput/TextInput.props.d.ts +17 -0
- package/lib/types/react/src/components/TextInput/index.d.ts +2 -0
- package/lib/types/react/src/components/Textarea/Textarea.args.d.ts +10 -0
- package/lib/types/react/src/components/Textarea/Textarea.d.ts +5 -3
- package/lib/types/react/src/components/Textarea/Textarea.props.d.ts +17 -39
- package/lib/types/react/src/components/Textarea/index.d.ts +2 -0
- package/lib/types/react/src/components/Toggle/Toggle.args.d.ts +12 -0
- package/lib/types/react/src/components/Toggle/Toggle.d.ts +5 -0
- package/lib/types/react/src/components/Toggle/Toggle.props.d.ts +22 -0
- package/lib/types/react/src/components/Toggle/index.d.ts +3 -0
- package/lib/types/react/src/components/Tooltip/Tooltip.props.d.ts +4 -0
- package/lib/types/react/src/components/index.d.ts +1 -5
- package/lib/types/react/src/hooks/usePrevious.d.ts +2 -0
- package/lib/types/react/src/types/index.d.ts +57 -1
- package/package.json +19 -18
- package/src/components/Checkbox/Checkbox.args.ts +31 -9
- package/src/components/Checkbox/Checkbox.props.ts +5 -13
- package/src/components/Checkbox/Checkbox.tsx +78 -76
- package/src/components/Checkbox/index.ts +1 -0
- package/src/components/DatePicker/DatePicker.args.ts +6 -32
- package/src/components/DatePicker/DatePicker.props.ts +11 -51
- package/src/components/DatePicker/DatePicker.tsx +71 -110
- package/src/components/Dropdown/Dropdown.args.ts +42 -192
- package/src/components/Dropdown/Dropdown.props.ts +18 -49
- package/src/components/Dropdown/Dropdown.tsx +73 -62
- package/src/components/Fieldset/Fieldset.props.ts +14 -23
- package/src/components/Fieldset/Fieldset.tsx +75 -69
- package/src/components/FileUpload/FileUpload.args.ts +25 -27
- package/src/components/FileUpload/FileUpload.props.ts +8 -53
- package/src/components/FileUpload/FileUpload.tsx +103 -72
- package/src/components/Form/Form.args.ts +2 -184
- package/src/components/Form/Form.props.ts +4 -133
- package/src/components/Form/Form.tsx +17 -77
- package/src/components/Form/index.ts +1 -0
- package/src/components/FormControl/FormControl.props.ts +72 -0
- package/src/components/FormControl/FormControl.tsx +169 -0
- package/src/components/FormControl/index.ts +2 -0
- package/src/components/FormElement/FormElement.props.ts +2 -2
- package/src/components/Input/Input.props.ts +2 -2
- package/src/components/Navigation/Navigation.args.ts +2 -1
- package/src/components/NumberPicker/NumberPicker.args.ts +18 -26
- package/src/components/NumberPicker/NumberPicker.props.ts +7 -52
- package/src/components/NumberPicker/NumberPicker.tsx +73 -56
- package/src/components/Radio/Radio.args.ts +1 -7
- package/src/components/Radio/Radio.props.ts +6 -14
- package/src/components/Radio/Radio.tsx +90 -52
- package/src/components/Radio/index.ts +1 -0
- package/src/components/TextInput/TextInput.args.ts +75 -0
- package/src/components/TextInput/TextInput.props.ts +20 -0
- package/src/components/TextInput/TextInput.tsx +71 -0
- package/src/components/TextInput/index.ts +2 -0
- package/src/components/Textarea/Textarea.args.ts +19 -37
- package/src/components/Textarea/Textarea.props.ts +18 -46
- package/src/components/Textarea/Textarea.tsx +44 -59
- package/src/components/Textarea/index.ts +2 -0
- package/src/components/Toggle/Toggle.args.ts +62 -0
- package/src/components/Toggle/Toggle.props.ts +27 -0
- package/src/components/Toggle/Toggle.tsx +85 -0
- package/src/components/Toggle/index.ts +3 -0
- package/src/components/Tooltip/Tooltip.props.ts +5 -0
- package/src/components/Tooltip/Tooltip.tsx +2 -0
- package/src/components/index.ts +1 -5
- package/src/hooks/usePrevious.ts +15 -0
- package/src/types/forms.args.ts +288 -0
- package/src/types/index.ts +69 -1
- package/tsconfig.json +2 -1
- package/lib/cjs/components/ChoiceGroup/ChoiceGroup.js +0 -34
- package/lib/cjs/components/ChoiceGroup/index.js +0 -19
- package/lib/cjs/components/FormGroup/FormGroup.js +0 -58
- package/lib/cjs/components/FormGroup/index.js +0 -26
- package/lib/esm/components/ChoiceGroup/ChoiceGroup.js +0 -32
- package/lib/esm/components/FormGroup/FormGroup.js +0 -56
- package/lib/esm/components/FormGroup/index.js +0 -20
- package/lib/types/react/src/components/ChoiceGroup/ChoiceGroup.d.ts +0 -4
- package/lib/types/react/src/components/ChoiceGroup/ChoiceGroup.props.d.ts +0 -20
- package/lib/types/react/src/components/ChoiceGroup/index.d.ts +0 -1
- package/lib/types/react/src/components/FormGroup/FormGroup.d.ts +0 -4
- package/lib/types/react/src/components/FormGroup/FormGroup.props.d.ts +0 -81
- package/lib/types/react/src/components/FormGroup/index.d.ts +0 -1
- package/src/components/ChoiceGroup/ChoiceGroup.args.ts +0 -95
- package/src/components/ChoiceGroup/ChoiceGroup.props.ts +0 -25
- package/src/components/ChoiceGroup/ChoiceGroup.tsx +0 -54
- package/src/components/ChoiceGroup/index.ts +0 -1
- package/src/components/FormGroup/FormGroup.args.ts +0 -85
- package/src/components/FormGroup/FormGroup.props.ts +0 -102
- package/src/components/FormGroup/FormGroup.tsx +0 -73
- package/src/components/FormGroup/index.ts +0 -1
|
@@ -1,13 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
grouped?: boolean;
|
|
7
|
-
helper?: string;
|
|
8
|
-
id?: string;
|
|
9
|
-
label?: string;
|
|
10
|
-
name: string;
|
|
11
|
-
required?: boolean;
|
|
12
|
-
tooltip?: string;
|
|
13
|
-
}
|
|
1
|
+
import { ChoiceFieldProps } from "../../types";
|
|
2
|
+
import { LabelledFormFieldProps } from "../../types";
|
|
3
|
+
export type CheckboxProps = ChoiceFieldProps<HTMLInputElement>;
|
|
4
|
+
|
|
5
|
+
export type LabelledCheckboxProps = LabelledFormFieldProps<CheckboxProps>;
|
|
@@ -1,92 +1,94 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import React, { useEffect, forwardRef } from "react";
|
|
2
2
|
import classNames from "classnames";
|
|
3
3
|
import useGlobalSettings from "../../hooks/useGlobalSettings";
|
|
4
|
-
import { CheckboxProps } from "./Checkbox.props";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import { CheckboxProps, LabelledCheckboxProps } from "./Checkbox.props";
|
|
5
|
+
import { useFieldsetError } from "../Fieldset/Fieldset";
|
|
6
|
+
import FormControl, { useFormControl } from "../FormControl/FormControl";
|
|
7
|
+
import usePrevious from "../../hooks/usePrevious";
|
|
8
|
+
|
|
9
|
+
const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>((props, ref) => {
|
|
10
|
+
const {
|
|
11
|
+
onChange,
|
|
12
|
+
onBlur,
|
|
13
|
+
disabled = false,
|
|
14
|
+
error,
|
|
15
|
+
id,
|
|
16
|
+
name,
|
|
17
|
+
required,
|
|
18
|
+
defaultChecked = false,
|
|
19
|
+
checked,
|
|
20
|
+
value,
|
|
21
|
+
} = props;
|
|
7
22
|
|
|
8
|
-
const Checkbox: FC<CheckboxProps> = ({
|
|
9
|
-
callback,
|
|
10
|
-
disabled = false,
|
|
11
|
-
error,
|
|
12
|
-
grouped,
|
|
13
|
-
helper,
|
|
14
|
-
id,
|
|
15
|
-
label,
|
|
16
|
-
name,
|
|
17
|
-
required,
|
|
18
|
-
tooltip,
|
|
19
|
-
}) => {
|
|
20
23
|
const { prefix } = useGlobalSettings();
|
|
24
|
+
const { setHasError } = useFieldsetError();
|
|
25
|
+
const formControlCtx = useFormControl();
|
|
26
|
+
const { ariaDescribedBy } = formControlCtx;
|
|
27
|
+
|
|
21
28
|
const baseClass = `${prefix}--checkbox`;
|
|
29
|
+
const errorClass = `${baseClass}__error`;
|
|
22
30
|
|
|
23
|
-
const CheckboxClasses = classNames(
|
|
24
|
-
[
|
|
25
|
-
[`error`]: error,
|
|
31
|
+
const CheckboxClasses = classNames(baseClass, {
|
|
32
|
+
[errorClass]: error,
|
|
26
33
|
});
|
|
27
34
|
|
|
28
|
-
const
|
|
35
|
+
const prevError = usePrevious(error);
|
|
29
36
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
if (error !== prevError) {
|
|
39
|
+
setHasError(!!error);
|
|
40
|
+
}
|
|
41
|
+
}, [error, prevError, setHasError]);
|
|
35
42
|
|
|
36
|
-
|
|
37
|
-
|
|
43
|
+
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
44
|
+
if (onChange) {
|
|
45
|
+
onChange(e);
|
|
38
46
|
}
|
|
39
47
|
};
|
|
40
48
|
|
|
41
49
|
return (
|
|
42
|
-
|
|
43
|
-
{
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
required={required as any}
|
|
58
|
-
type={"checkbox"}
|
|
59
|
-
className={CheckboxClasses}
|
|
60
|
-
checked={checked}
|
|
61
|
-
/>
|
|
62
|
-
</FormElement>
|
|
63
|
-
)}
|
|
64
|
-
{!grouped && (
|
|
65
|
-
<Fieldset>
|
|
66
|
-
<FormElement
|
|
67
|
-
elemid={id as any}
|
|
68
|
-
label={label}
|
|
69
|
-
helper={helper as any}
|
|
70
|
-
error={error as any}
|
|
71
|
-
required={required as any}
|
|
72
|
-
tooltip={tooltip}
|
|
73
|
-
type={"checkbox"}
|
|
74
|
-
>
|
|
75
|
-
<input
|
|
76
|
-
id={id}
|
|
77
|
-
name={name}
|
|
78
|
-
onChange={handleChange}
|
|
79
|
-
disabled={disabled}
|
|
80
|
-
required={required as any}
|
|
81
|
-
type={"checkbox"}
|
|
82
|
-
className={CheckboxClasses}
|
|
83
|
-
checked={checked}
|
|
84
|
-
/>
|
|
85
|
-
</FormElement>
|
|
86
|
-
</Fieldset>
|
|
87
|
-
)}
|
|
88
|
-
</>
|
|
50
|
+
<input
|
|
51
|
+
ref={ref}
|
|
52
|
+
id={id ? id : name}
|
|
53
|
+
name={name}
|
|
54
|
+
onChange={handleChange}
|
|
55
|
+
onBlur={onBlur}
|
|
56
|
+
disabled={disabled}
|
|
57
|
+
required={required}
|
|
58
|
+
type="checkbox"
|
|
59
|
+
className={CheckboxClasses}
|
|
60
|
+
defaultChecked={defaultChecked}
|
|
61
|
+
aria-describedby={ariaDescribedBy}
|
|
62
|
+
checked={checked}
|
|
63
|
+
value={value}
|
|
64
|
+
/>
|
|
89
65
|
);
|
|
90
|
-
};
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const LabelledCheckbox = forwardRef<HTMLInputElement, LabelledCheckboxProps>(
|
|
69
|
+
(props, ref) => {
|
|
70
|
+
const fieldId = props.id ? props.id : props.name;
|
|
71
|
+
const {
|
|
72
|
+
style,
|
|
73
|
+
inputStyle,
|
|
74
|
+
className,
|
|
75
|
+
labelPlacement = "end",
|
|
76
|
+
labelSize = "small",
|
|
77
|
+
...rest
|
|
78
|
+
} = props;
|
|
79
|
+
return (
|
|
80
|
+
<FormControl
|
|
81
|
+
fieldId={fieldId}
|
|
82
|
+
style={style}
|
|
83
|
+
className={className}
|
|
84
|
+
labelPlacement={labelPlacement}
|
|
85
|
+
labelSize={labelSize}
|
|
86
|
+
{...rest}
|
|
87
|
+
>
|
|
88
|
+
<Checkbox ref={ref} style={inputStyle} {...rest} />
|
|
89
|
+
</FormControl>
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
);
|
|
91
93
|
|
|
92
|
-
export default
|
|
94
|
+
export default LabelledCheckbox;
|
|
@@ -1,76 +1,50 @@
|
|
|
1
1
|
import { DatePickerProps } from "./DatePicker.props";
|
|
2
2
|
|
|
3
3
|
const basic: DatePickerProps = {
|
|
4
|
-
|
|
4
|
+
id: "datepicker",
|
|
5
5
|
disabled: false,
|
|
6
6
|
error: false,
|
|
7
|
-
helper: false,
|
|
8
|
-
label: "Date Picker Field Label",
|
|
9
7
|
name: "datepicker",
|
|
10
8
|
placeholder: "MM/DD/YYYY",
|
|
11
9
|
required: false,
|
|
12
10
|
};
|
|
13
11
|
|
|
14
12
|
const hashelper: DatePickerProps = {
|
|
15
|
-
|
|
13
|
+
id: "datepicker",
|
|
16
14
|
disabled: false,
|
|
17
15
|
error: false,
|
|
18
|
-
helper: "here is helper text",
|
|
19
|
-
label: "Date Picker Field Label",
|
|
20
16
|
name: "datepicker",
|
|
21
17
|
placeholder: "MM/DD/YYYY",
|
|
22
18
|
required: false,
|
|
23
19
|
};
|
|
24
20
|
|
|
25
21
|
const haserror: DatePickerProps = {
|
|
26
|
-
|
|
22
|
+
id: "datepicker",
|
|
27
23
|
disabled: false,
|
|
28
|
-
error:
|
|
29
|
-
helper: false,
|
|
30
|
-
label: "Date Picker Field Label",
|
|
24
|
+
error: true,
|
|
31
25
|
name: "datepicker",
|
|
32
26
|
placeholder: "MM/DD/YYYY",
|
|
33
27
|
required: false,
|
|
34
28
|
};
|
|
35
29
|
|
|
36
30
|
const hastooltip: DatePickerProps = {
|
|
37
|
-
|
|
31
|
+
id: "datepicker",
|
|
38
32
|
disabled: false,
|
|
39
33
|
error: false,
|
|
40
|
-
helper: false,
|
|
41
|
-
label: "Date Picker Field Label",
|
|
42
34
|
name: "datepicker",
|
|
43
35
|
placeholder: "MM/DD/YYYY",
|
|
44
36
|
required: false,
|
|
45
|
-
tooltip: "This is the tooltip",
|
|
46
37
|
};
|
|
47
38
|
|
|
48
39
|
const hasrange: DatePickerProps = {
|
|
49
|
-
|
|
40
|
+
id: "datepicker",
|
|
50
41
|
disabled: false,
|
|
51
|
-
enddata: {
|
|
52
|
-
callback: () => {},
|
|
53
|
-
disabled: false,
|
|
54
|
-
error: false,
|
|
55
|
-
helper: "this is an end date range",
|
|
56
|
-
label: "Date Picker End Field Label",
|
|
57
|
-
name: "datepickerend",
|
|
58
|
-
placeholder: "MM/DD/YYYY",
|
|
59
|
-
range: false,
|
|
60
|
-
required: false,
|
|
61
|
-
},
|
|
62
42
|
error: false,
|
|
63
|
-
helper: false,
|
|
64
|
-
label: "Date Picker Field Label",
|
|
65
43
|
name: "datepicker",
|
|
66
44
|
placeholder: "MM/DD/YYYY",
|
|
67
|
-
range: true,
|
|
68
45
|
required: false,
|
|
69
46
|
};
|
|
70
47
|
|
|
71
|
-
/**
|
|
72
|
-
* Sample prop definitions DatePicker's enumerable properties (imported in stories and test)
|
|
73
|
-
*/
|
|
74
48
|
const DatePickerArgs = {
|
|
75
49
|
basic,
|
|
76
50
|
hasrange,
|
|
@@ -1,66 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* The input's onChange callback.
|
|
4
|
-
*/
|
|
5
|
-
callback?: (e: React.ChangeEvent<HTMLInputElement>, picker?: string) => any;
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Specify an optional className to be added to your input.
|
|
9
|
-
*/
|
|
10
|
-
className?: string;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Is the input disabled?
|
|
14
|
-
*/
|
|
15
|
-
disabled?: boolean;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* If this is a range, the data for the second field
|
|
19
|
-
*/
|
|
20
|
-
enddata?: DatePickerProps;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Does the input have an error?
|
|
24
|
-
*/
|
|
25
|
-
error?: string | false;
|
|
1
|
+
import { FormFieldProps } from "../../types";
|
|
2
|
+
import { LabelledFormFieldProps } from "../../types";
|
|
26
3
|
|
|
4
|
+
export interface DatePickerProps extends FormFieldProps<HTMLInputElement> {
|
|
27
5
|
/**
|
|
28
|
-
* The
|
|
6
|
+
* The latest date to accept
|
|
29
7
|
*/
|
|
30
|
-
|
|
8
|
+
max?: string | number;
|
|
31
9
|
|
|
32
10
|
/**
|
|
33
|
-
* The
|
|
11
|
+
* The earliest date to accept.
|
|
34
12
|
*/
|
|
35
|
-
|
|
13
|
+
min?: string | number;
|
|
36
14
|
|
|
37
15
|
/**
|
|
38
|
-
*
|
|
16
|
+
* The granularity of the date picker
|
|
39
17
|
*/
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* The input's name attribute
|
|
44
|
-
*/
|
|
45
|
-
name?: Required<string>;
|
|
18
|
+
step?: number;
|
|
46
19
|
|
|
47
20
|
/**
|
|
48
21
|
* Specify an optional className to be added to your DatePicker component.
|
|
49
22
|
*/
|
|
50
23
|
placeholder?: string;
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Specify whether this is a date range
|
|
54
|
-
*/
|
|
55
|
-
range?: boolean;
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Specify whether this input is required
|
|
59
|
-
*/
|
|
60
|
-
required?: boolean;
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Does this DatePicker have a tooltip?
|
|
64
|
-
*/
|
|
65
|
-
tooltip?: string;
|
|
66
24
|
}
|
|
25
|
+
|
|
26
|
+
export type LabelledDatePickerProps = LabelledFormFieldProps<DatePickerProps>;
|
|
@@ -1,119 +1,80 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { forwardRef } from "react";
|
|
2
2
|
import classNames from "classnames";
|
|
3
3
|
import useGlobalSettings from "../../hooks/useGlobalSettings";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { FormElement } from "../FormElement";
|
|
4
|
+
import FormControl, { useFormControl } from "../FormControl/FormControl";
|
|
5
|
+
import { DatePickerProps, LabelledDatePickerProps } from "./DatePicker.props";
|
|
7
6
|
|
|
8
|
-
const DatePicker
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const baseClass = `${prefix}--datepicker`;
|
|
7
|
+
const DatePicker = forwardRef<HTMLInputElement, DatePickerProps>(
|
|
8
|
+
(props, ref) => {
|
|
9
|
+
const {
|
|
10
|
+
onChange,
|
|
11
|
+
onBlur,
|
|
12
|
+
disabled = false,
|
|
13
|
+
error,
|
|
14
|
+
id,
|
|
15
|
+
name,
|
|
16
|
+
placeholder,
|
|
17
|
+
required,
|
|
18
|
+
max,
|
|
19
|
+
min,
|
|
20
|
+
step,
|
|
21
|
+
} = props;
|
|
24
22
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
});
|
|
23
|
+
const { prefix } = useGlobalSettings();
|
|
24
|
+
const formControlCtx = useFormControl();
|
|
25
|
+
const { ariaDescribedBy } = formControlCtx;
|
|
29
26
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
27
|
+
const inputClass = `${prefix}--input`;
|
|
28
|
+
const baseClass = `${prefix}--datepicker`;
|
|
29
|
+
|
|
30
|
+
const datePickerClasses = classNames(inputClass, baseClass, {
|
|
31
|
+
[`error`]: error,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
35
|
+
if (onChange) {
|
|
36
|
+
onChange(e);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<input
|
|
42
|
+
ref={ref}
|
|
43
|
+
type="date"
|
|
44
|
+
id={id ? id : name}
|
|
45
|
+
name={name}
|
|
46
|
+
onChange={handleChange}
|
|
47
|
+
onBlur={onBlur}
|
|
48
|
+
disabled={disabled}
|
|
49
|
+
placeholder={placeholder}
|
|
50
|
+
required={required}
|
|
51
|
+
className={datePickerClasses}
|
|
52
|
+
max={max}
|
|
53
|
+
min={min}
|
|
54
|
+
step={step}
|
|
55
|
+
aria-describedby={ariaDescribedBy}
|
|
56
|
+
/>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
const LabelledDatePicker = forwardRef<
|
|
62
|
+
HTMLInputElement,
|
|
63
|
+
LabelledDatePickerProps
|
|
64
|
+
>((props, ref) => {
|
|
65
|
+
const { style, inputStyle, className, ...rest } = props;
|
|
66
|
+
const fieldId = props.id ? props.id : props.name;
|
|
41
67
|
|
|
42
68
|
return (
|
|
43
|
-
|
|
44
|
-
{
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
required={required as any}
|
|
52
|
-
tooltip={tooltip}
|
|
53
|
-
>
|
|
54
|
-
<input
|
|
55
|
-
id={`${id ? id : name}`}
|
|
56
|
-
name={`${name}`}
|
|
57
|
-
onChange={handleChange}
|
|
58
|
-
disabled={disabled}
|
|
59
|
-
placeholder={placeholder}
|
|
60
|
-
required={required as any}
|
|
61
|
-
type={"date"}
|
|
62
|
-
className={`${DatePickerClasses} ${prefix}--input`}
|
|
63
|
-
/>
|
|
64
|
-
</FormElement>
|
|
65
|
-
</Fieldset>
|
|
66
|
-
)}
|
|
67
|
-
{range && (
|
|
68
|
-
<div className={`${baseClass}--range`}>
|
|
69
|
-
<Fieldset>
|
|
70
|
-
<FormElement
|
|
71
|
-
elemid={name as any}
|
|
72
|
-
label={label}
|
|
73
|
-
helper={helper as any}
|
|
74
|
-
error={error as any}
|
|
75
|
-
required={required as any}
|
|
76
|
-
tooltip={tooltip}
|
|
77
|
-
type={"date"}
|
|
78
|
-
>
|
|
79
|
-
<input
|
|
80
|
-
id={`${id ? id : name}`}
|
|
81
|
-
name={`${name}`}
|
|
82
|
-
onChange={handleChange}
|
|
83
|
-
disabled={disabled}
|
|
84
|
-
placeholder={placeholder}
|
|
85
|
-
required={required as any}
|
|
86
|
-
type={"date"}
|
|
87
|
-
className={`${DatePickerClasses} ${prefix}--input`}
|
|
88
|
-
/>
|
|
89
|
-
</FormElement>
|
|
90
|
-
</Fieldset>
|
|
91
|
-
<Fieldset>
|
|
92
|
-
<FormElement
|
|
93
|
-
elemid={enddata?.name as any}
|
|
94
|
-
label={enddata?.label as any}
|
|
95
|
-
helper={enddata?.helper as any}
|
|
96
|
-
error={enddata?.error as any}
|
|
97
|
-
required={enddata?.required as any}
|
|
98
|
-
tooltip={enddata?.tooltip as any}
|
|
99
|
-
type={"date"}
|
|
100
|
-
>
|
|
101
|
-
<input
|
|
102
|
-
id={enddata?.id ? enddata?.id : enddata?.name}
|
|
103
|
-
name={enddata?.name}
|
|
104
|
-
onChange={(e) => handleChange(e, "end")}
|
|
105
|
-
disabled={enddata?.disabled}
|
|
106
|
-
placeholder={enddata?.placeholder}
|
|
107
|
-
required={enddata?.required as any}
|
|
108
|
-
type={"date"}
|
|
109
|
-
className={`${DatePickerClasses} ${prefix}--input`}
|
|
110
|
-
/>
|
|
111
|
-
</FormElement>
|
|
112
|
-
</Fieldset>
|
|
113
|
-
</div>
|
|
114
|
-
)}
|
|
115
|
-
</>
|
|
69
|
+
<FormControl
|
|
70
|
+
fieldId={fieldId}
|
|
71
|
+
style={style}
|
|
72
|
+
className={className}
|
|
73
|
+
{...rest}
|
|
74
|
+
>
|
|
75
|
+
<DatePicker ref={ref} style={inputStyle} {...rest} />
|
|
76
|
+
</FormControl>
|
|
116
77
|
);
|
|
117
|
-
};
|
|
78
|
+
});
|
|
118
79
|
|
|
119
|
-
export default
|
|
80
|
+
export default LabelledDatePicker;
|