@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,67 +1,52 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import React from "react";
|
|
2
|
+
import classnames from "classnames";
|
|
3
3
|
import useGlobalSettings from "../../hooks/useGlobalSettings";
|
|
4
|
-
import { TextareaProps } from "./Textarea.props";
|
|
5
|
-
import {
|
|
6
|
-
import { FormElement } from "../FormElement";
|
|
4
|
+
import { TextareaProps, LabelledTextareaProps } from "./Textarea.props";
|
|
5
|
+
import FormControl, { useFormControl } from "../FormControl/FormControl";
|
|
7
6
|
|
|
8
|
-
const Textarea
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
id,
|
|
14
|
-
label,
|
|
15
|
-
maxlength,
|
|
16
|
-
minlength,
|
|
17
|
-
name,
|
|
18
|
-
placeholder,
|
|
19
|
-
required,
|
|
20
|
-
spellcheck,
|
|
21
|
-
tooltip,
|
|
22
|
-
}) => {
|
|
23
|
-
const { prefix } = useGlobalSettings();
|
|
24
|
-
const baseClass = `${prefix}--textarea`;
|
|
7
|
+
const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
|
|
8
|
+
({ error, className, name, id, ...props }, ref) => {
|
|
9
|
+
const { prefix } = useGlobalSettings();
|
|
10
|
+
const formControlCtx = useFormControl();
|
|
11
|
+
const { ariaDescribedBy } = formControlCtx;
|
|
25
12
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
[`error`]: error,
|
|
29
|
-
});
|
|
13
|
+
const baseClass = `${prefix}--textarea`;
|
|
14
|
+
const errorClass = `${baseClass}__error`;
|
|
30
15
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
16
|
+
const textAreaClass = classnames(baseClass, className, {
|
|
17
|
+
[errorClass]: error,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<textarea
|
|
22
|
+
ref={ref}
|
|
23
|
+
className={textAreaClass}
|
|
24
|
+
name={name}
|
|
25
|
+
id={id ? id : name}
|
|
26
|
+
aria-describedby={ariaDescribedBy}
|
|
27
|
+
{...props}
|
|
28
|
+
/>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
const LabelledTextarea = React.forwardRef<
|
|
34
|
+
HTMLTextAreaElement,
|
|
35
|
+
LabelledTextareaProps
|
|
36
|
+
>((props, ref) => {
|
|
37
|
+
const { style, inputStyle, className, ...rest } = props;
|
|
38
|
+
const fieldId = props.id ? props.id : props.name;
|
|
39
39
|
|
|
40
40
|
return (
|
|
41
|
-
<
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
>
|
|
50
|
-
<textarea
|
|
51
|
-
id={id}
|
|
52
|
-
name={name}
|
|
53
|
-
onChange={handleChange}
|
|
54
|
-
disabled={disabled}
|
|
55
|
-
placeholder={placeholder}
|
|
56
|
-
required={required as any}
|
|
57
|
-
className={TextareaClasses}
|
|
58
|
-
maxLength={maxlength}
|
|
59
|
-
minLength={minlength}
|
|
60
|
-
spellCheck={spellcheck}
|
|
61
|
-
/>
|
|
62
|
-
</FormElement>
|
|
63
|
-
</Fieldset>
|
|
41
|
+
<FormControl
|
|
42
|
+
fieldId={fieldId}
|
|
43
|
+
style={style}
|
|
44
|
+
className={className}
|
|
45
|
+
{...rest}
|
|
46
|
+
>
|
|
47
|
+
<Textarea ref={ref} style={inputStyle} {...rest} />
|
|
48
|
+
</FormControl>
|
|
64
49
|
);
|
|
65
|
-
};
|
|
50
|
+
});
|
|
66
51
|
|
|
67
|
-
export default
|
|
52
|
+
export default LabelledTextarea;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { LabelledToggleProps } from "./Toggle.props";
|
|
2
|
+
|
|
3
|
+
export const Default: LabelledToggleProps = {
|
|
4
|
+
defaultChecked: false,
|
|
5
|
+
errorMessage: "Invalid option",
|
|
6
|
+
name: "my-toggle",
|
|
7
|
+
size: "medium",
|
|
8
|
+
label: "Show details",
|
|
9
|
+
labelPlacement: "end",
|
|
10
|
+
labelSize: "small",
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const Checked: LabelledToggleProps = {
|
|
14
|
+
...Default,
|
|
15
|
+
defaultChecked: true,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const Disabled: LabelledToggleProps = {
|
|
19
|
+
...Default,
|
|
20
|
+
disabled: true,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const Helper: LabelledToggleProps = {
|
|
24
|
+
...Default,
|
|
25
|
+
helper: "This is a helper text",
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const Tooltip: LabelledToggleProps = {
|
|
29
|
+
...Helper,
|
|
30
|
+
tooltip: "This is a tooltip",
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const Error: LabelledToggleProps = {
|
|
34
|
+
...Default,
|
|
35
|
+
error: true,
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export const DefaultChecked: LabelledToggleProps = {
|
|
39
|
+
...Default,
|
|
40
|
+
defaultChecked: true,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const Controlled: LabelledToggleProps = {
|
|
44
|
+
...Default,
|
|
45
|
+
onClick: () => console.log("clicked"),
|
|
46
|
+
checked: true,
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const Large: LabelledToggleProps = {
|
|
50
|
+
...Default,
|
|
51
|
+
size: "large",
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export const Medium: LabelledToggleProps = {
|
|
55
|
+
...Default,
|
|
56
|
+
size: "medium",
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export const Small: LabelledToggleProps = {
|
|
60
|
+
...Default,
|
|
61
|
+
size: "small",
|
|
62
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { FormFieldProps } from "../../types";
|
|
2
|
+
import { LabelledFormFieldProps } from "../../types";
|
|
3
|
+
|
|
4
|
+
export interface ToggleProps extends FormFieldProps<HTMLInputElement> {
|
|
5
|
+
/**
|
|
6
|
+
* Specify the size of your Toggle. Defaults to "medium".
|
|
7
|
+
*/
|
|
8
|
+
size?: "large" | "medium" | "small";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Specify whether your Toggle is checked by default. Defaults to false.
|
|
12
|
+
*
|
|
13
|
+
*/
|
|
14
|
+
defaultChecked?: boolean;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Specify whether your Toggle is checked. Defaults to undefined.
|
|
18
|
+
*/
|
|
19
|
+
checked?: boolean;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* OnClick handler for the input element.
|
|
23
|
+
*/
|
|
24
|
+
onClick?: (event: React.MouseEvent<HTMLInputElement>) => any;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type LabelledToggleProps = LabelledFormFieldProps<ToggleProps>;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { Ref, forwardRef } from "react";
|
|
2
|
+
import { ToggleProps } from "./Toggle.props";
|
|
3
|
+
import { LabelledToggleProps } from "./Toggle.props";
|
|
4
|
+
import { useGlobalSettings } from "../../hooks";
|
|
5
|
+
import classnames from "classnames";
|
|
6
|
+
import FormControl, { useFormControl } from "../FormControl/FormControl";
|
|
7
|
+
|
|
8
|
+
const Toggle = forwardRef<HTMLInputElement, ToggleProps>(
|
|
9
|
+
(
|
|
10
|
+
{
|
|
11
|
+
size = "medium",
|
|
12
|
+
error = false,
|
|
13
|
+
disabled = false,
|
|
14
|
+
defaultChecked = false,
|
|
15
|
+
required = false,
|
|
16
|
+
id,
|
|
17
|
+
name,
|
|
18
|
+
onChange,
|
|
19
|
+
onBlur,
|
|
20
|
+
onClick,
|
|
21
|
+
checked,
|
|
22
|
+
className,
|
|
23
|
+
},
|
|
24
|
+
ref
|
|
25
|
+
) => {
|
|
26
|
+
const { prefix } = useGlobalSettings();
|
|
27
|
+
const formControlCtx = useFormControl();
|
|
28
|
+
const { ariaDescribedBy } = formControlCtx;
|
|
29
|
+
|
|
30
|
+
const hasError = !disabled && !!error;
|
|
31
|
+
|
|
32
|
+
const baseClass = `${prefix}--input--toggle`;
|
|
33
|
+
const sliderClass = `${baseClass}--slider`;
|
|
34
|
+
|
|
35
|
+
const toggleClass = classnames(
|
|
36
|
+
baseClass,
|
|
37
|
+
className,
|
|
38
|
+
`${baseClass}__size__${size}`,
|
|
39
|
+
[
|
|
40
|
+
{ [`${baseClass}__error`]: hasError },
|
|
41
|
+
{ [`${baseClass}__disabled`]: disabled },
|
|
42
|
+
]
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<div className={toggleClass}>
|
|
47
|
+
<input
|
|
48
|
+
ref={ref} // Forwarded ref applied here
|
|
49
|
+
checked={checked}
|
|
50
|
+
disabled={disabled}
|
|
51
|
+
defaultChecked={defaultChecked}
|
|
52
|
+
name={name}
|
|
53
|
+
id={id ? id : name}
|
|
54
|
+
type="checkbox"
|
|
55
|
+
role="switch"
|
|
56
|
+
required={required}
|
|
57
|
+
onChange={onChange}
|
|
58
|
+
onBlur={onBlur}
|
|
59
|
+
onClick={onClick}
|
|
60
|
+
aria-describedby={ariaDescribedBy}
|
|
61
|
+
/>
|
|
62
|
+
<span className={sliderClass} />
|
|
63
|
+
</div>
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
const LabelledToggle = forwardRef(
|
|
69
|
+
(props: LabelledToggleProps, ref: Ref<HTMLInputElement>) => {
|
|
70
|
+
const fieldId = props.id ? props.id : props.name;
|
|
71
|
+
const { style, inputStyle, className, ...rest } = props;
|
|
72
|
+
return (
|
|
73
|
+
<FormControl
|
|
74
|
+
fieldId={fieldId}
|
|
75
|
+
style={style}
|
|
76
|
+
className={className}
|
|
77
|
+
{...rest}
|
|
78
|
+
>
|
|
79
|
+
<Toggle ref={ref} style={inputStyle} {...rest} />
|
|
80
|
+
</FormControl>
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
export default LabelledToggle;
|
|
@@ -10,6 +10,7 @@ const Tooltip: FC<TooltipProps> = ({
|
|
|
10
10
|
icon,
|
|
11
11
|
label,
|
|
12
12
|
theme,
|
|
13
|
+
id,
|
|
13
14
|
}) => {
|
|
14
15
|
const { prefix } = useGlobalSettings();
|
|
15
16
|
const baseClass = `${prefix}--tooltip`;
|
|
@@ -127,6 +128,7 @@ const Tooltip: FC<TooltipProps> = ({
|
|
|
127
128
|
onFocus={handleOnMouseOver}
|
|
128
129
|
onMouseOut={handleOnMouseOut}
|
|
129
130
|
onBlur={handleOnMouseOut}
|
|
131
|
+
id={id}
|
|
130
132
|
>
|
|
131
133
|
{!icon && <>{children}</>}
|
|
132
134
|
<span className={tooltipClasses} style={style} ref={tooltipRef}>
|
package/src/components/index.ts
CHANGED
|
@@ -4,9 +4,9 @@ export {
|
|
|
4
4
|
AccordionItem,
|
|
5
5
|
AccordionPanel,
|
|
6
6
|
} from "./Accordion";
|
|
7
|
+
export { Form } from "./Form";
|
|
7
8
|
export { Collapse } from "./Collapse";
|
|
8
9
|
export { Empty } from "./Empty";
|
|
9
|
-
export { FormGroup } from "./FormGroup";
|
|
10
10
|
export { Image } from "./Image";
|
|
11
11
|
export { Loading } from "./Loading";
|
|
12
12
|
export { Radio } from "./Radio";
|
|
@@ -15,7 +15,6 @@ export { Button } from "./Button";
|
|
|
15
15
|
export { ContextMenu } from "./ContextMenu";
|
|
16
16
|
export { Fieldset } from "./Fieldset";
|
|
17
17
|
export { GlobalProvider } from "./GlobalProvider";
|
|
18
|
-
export { Input } from "./Input";
|
|
19
18
|
export { Notification } from "./Notification";
|
|
20
19
|
export { ReadMore } from "./ReadMore";
|
|
21
20
|
export { Textarea } from "./Textarea";
|
|
@@ -29,15 +28,12 @@ export { RichText } from "./RichText";
|
|
|
29
28
|
export { Tooltip } from "./Tooltip";
|
|
30
29
|
export { Checkbox } from "./Checkbox";
|
|
31
30
|
export { DatePicker } from "./DatePicker";
|
|
32
|
-
export { Form } from "./Form";
|
|
33
31
|
export { Hero } from "./Hero";
|
|
34
32
|
export { LinkList } from "./LinkList";
|
|
35
33
|
export { Pagination } from "./Pagination";
|
|
36
34
|
export { SearchField } from "./SearchField";
|
|
37
35
|
export { Video } from "./Video";
|
|
38
|
-
export { ChoiceGroup } from "./ChoiceGroup";
|
|
39
36
|
export { Dropdown } from "./Dropdown";
|
|
40
|
-
export { FormElement } from "./FormElement";
|
|
41
37
|
export { Icon } from "./Icon";
|
|
42
38
|
export { List } from "./List";
|
|
43
39
|
export { Profile } from "./Profile";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
2
|
+
|
|
3
|
+
// This code was shamelessly borrowed from the blog post
|
|
4
|
+
// "How to access previous props or state with React Hooks" by
|
|
5
|
+
// Ohans Emmanuel, published on LogRocket May 11, 2023
|
|
6
|
+
// https://blog.logrocket.com/accessing-previous-props-state-react-hooks/
|
|
7
|
+
|
|
8
|
+
export function usePrevious<T>(value: T) {
|
|
9
|
+
const ref = useRef<T>();
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
ref.current = value; //assign the value of ref to the argument
|
|
12
|
+
}, [value]); //this code will run when the value of 'value' changes
|
|
13
|
+
return ref.current; //in the end, return the current ref value.
|
|
14
|
+
}
|
|
15
|
+
export default usePrevious;
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
// This annoying file has to exist because at the present time, react-docgen-typescript can't generate argTypes for
|
|
2
|
+
// components that use forwardRef. So we have to create the argTypes manually. This only regards Form elements for the time being.
|
|
3
|
+
|
|
4
|
+
export const formFieldArgTypes = (element: string) => ({
|
|
5
|
+
className: {
|
|
6
|
+
description:
|
|
7
|
+
"The className of the Component. Passed to the outermost element.",
|
|
8
|
+
control: {
|
|
9
|
+
type: "text",
|
|
10
|
+
},
|
|
11
|
+
table: {
|
|
12
|
+
type: {
|
|
13
|
+
summary: "string | undefined",
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
disabled: {
|
|
18
|
+
description: "Whether the Component is disabled",
|
|
19
|
+
control: {
|
|
20
|
+
type: "boolean",
|
|
21
|
+
},
|
|
22
|
+
table: {
|
|
23
|
+
defaultValue: { summary: "false" },
|
|
24
|
+
type: {
|
|
25
|
+
summary: "boolean | undefined",
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
error: {
|
|
30
|
+
description: "Whether the Component has an error",
|
|
31
|
+
control: {
|
|
32
|
+
type: "boolean",
|
|
33
|
+
},
|
|
34
|
+
table: {
|
|
35
|
+
defaultValue: { summary: "false" },
|
|
36
|
+
type: {
|
|
37
|
+
summary: "boolean | undefined",
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
id: {
|
|
42
|
+
description:
|
|
43
|
+
"The id attribute of the underlying form element. This will be the same as `name` if not set",
|
|
44
|
+
control: {
|
|
45
|
+
type: "text",
|
|
46
|
+
},
|
|
47
|
+
table: {
|
|
48
|
+
type: {
|
|
49
|
+
summary: "string | undefined",
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
inputStyle: {
|
|
54
|
+
description: "Inline styles for the input",
|
|
55
|
+
control: {
|
|
56
|
+
type: "object",
|
|
57
|
+
},
|
|
58
|
+
table: {
|
|
59
|
+
type: {
|
|
60
|
+
summary: "React.CSSProperties | undefined",
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
name: {
|
|
65
|
+
description:
|
|
66
|
+
"The name of the Component. This is required and should be unique",
|
|
67
|
+
control: {
|
|
68
|
+
type: "text",
|
|
69
|
+
},
|
|
70
|
+
type: {
|
|
71
|
+
required: true,
|
|
72
|
+
name: "other" as const,
|
|
73
|
+
value: "string",
|
|
74
|
+
},
|
|
75
|
+
table: {
|
|
76
|
+
type: {
|
|
77
|
+
summary: "string",
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
onBlur: {
|
|
82
|
+
description: "The onBlur handler of the Component",
|
|
83
|
+
control: {
|
|
84
|
+
type: "function",
|
|
85
|
+
},
|
|
86
|
+
table: {
|
|
87
|
+
type: {
|
|
88
|
+
summary: `(event: React.FocusEvent<${element}>) => any`,
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
onChange: {
|
|
93
|
+
description: "The onChange handler of the Component",
|
|
94
|
+
control: {
|
|
95
|
+
type: "function",
|
|
96
|
+
},
|
|
97
|
+
table: {
|
|
98
|
+
type: {
|
|
99
|
+
summary: `(event: React.ChangeEvent<${element}>) => any`,
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
required: {
|
|
104
|
+
description: "Whether the Component is required",
|
|
105
|
+
control: {
|
|
106
|
+
type: "boolean",
|
|
107
|
+
},
|
|
108
|
+
table: {
|
|
109
|
+
type: {
|
|
110
|
+
summary: "boolean | undefined",
|
|
111
|
+
},
|
|
112
|
+
defaultValue: { summary: false },
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
export const choiceFieldArgTypes = (element: string) => ({
|
|
118
|
+
...formFieldArgTypes(element),
|
|
119
|
+
defaultChecked: {
|
|
120
|
+
description: "Whether the Component is checked by default when it loads",
|
|
121
|
+
control: {
|
|
122
|
+
type: "boolean",
|
|
123
|
+
},
|
|
124
|
+
table: {
|
|
125
|
+
type: {
|
|
126
|
+
summary: "boolean | undefined",
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
checked: {
|
|
131
|
+
description: "Whether the Component is checked",
|
|
132
|
+
control: {
|
|
133
|
+
type: "boolean",
|
|
134
|
+
},
|
|
135
|
+
table: {
|
|
136
|
+
defaultValue: { summary: "false" },
|
|
137
|
+
type: {
|
|
138
|
+
summary: "boolean | undefined",
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
value: {
|
|
143
|
+
description: "The value of the Component",
|
|
144
|
+
control: {
|
|
145
|
+
type: "text",
|
|
146
|
+
},
|
|
147
|
+
table: {
|
|
148
|
+
type: {
|
|
149
|
+
summary: "string | undefined",
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
export const formControlArgTypes = {
|
|
156
|
+
className: {
|
|
157
|
+
description:
|
|
158
|
+
"The className of the Component. Passed to the outermost element.",
|
|
159
|
+
control: {
|
|
160
|
+
type: "text",
|
|
161
|
+
},
|
|
162
|
+
table: {
|
|
163
|
+
type: {
|
|
164
|
+
summary: "string | undefined",
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
disabled: {
|
|
169
|
+
description: "Whether the Component is disabled",
|
|
170
|
+
control: {
|
|
171
|
+
type: "boolean",
|
|
172
|
+
},
|
|
173
|
+
table: {
|
|
174
|
+
defaultValue: { summary: "false" },
|
|
175
|
+
type: {
|
|
176
|
+
summary: "boolean | undefined",
|
|
177
|
+
},
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
error: {
|
|
181
|
+
description: "Whether the Component has an error",
|
|
182
|
+
control: {
|
|
183
|
+
type: "boolean",
|
|
184
|
+
},
|
|
185
|
+
table: {
|
|
186
|
+
defaultValue: { summary: "false" },
|
|
187
|
+
type: {
|
|
188
|
+
summary: "boolean | undefined",
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
errorMessage: {
|
|
193
|
+
description: "The error message to display in case of an error",
|
|
194
|
+
control: {
|
|
195
|
+
type: "text",
|
|
196
|
+
},
|
|
197
|
+
table: {
|
|
198
|
+
type: {
|
|
199
|
+
summary: "string | undefined",
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
},
|
|
203
|
+
label: {
|
|
204
|
+
description: "The label of the Component. This is required.",
|
|
205
|
+
control: {
|
|
206
|
+
type: "text",
|
|
207
|
+
},
|
|
208
|
+
type: {
|
|
209
|
+
required: true,
|
|
210
|
+
name: "other" as const,
|
|
211
|
+
value: "string",
|
|
212
|
+
},
|
|
213
|
+
table: {
|
|
214
|
+
type: {
|
|
215
|
+
summary: "string | undefined",
|
|
216
|
+
},
|
|
217
|
+
},
|
|
218
|
+
},
|
|
219
|
+
labelSize: {
|
|
220
|
+
description: "The size of the label",
|
|
221
|
+
defaultValue: "medium",
|
|
222
|
+
control: "select",
|
|
223
|
+
options: ["small", "medium", "large"],
|
|
224
|
+
table: {
|
|
225
|
+
defaultValue: { summary: "medium" },
|
|
226
|
+
type: {
|
|
227
|
+
name: "enum",
|
|
228
|
+
summary: "small | medium | large",
|
|
229
|
+
},
|
|
230
|
+
},
|
|
231
|
+
},
|
|
232
|
+
labelPlacement: {
|
|
233
|
+
description: "The placement of the label",
|
|
234
|
+
defaultValue: "start",
|
|
235
|
+
control: "select",
|
|
236
|
+
options: ["top", "start", "bottom", "end"],
|
|
237
|
+
table: {
|
|
238
|
+
defaultValue: { summary: "start" },
|
|
239
|
+
type: {
|
|
240
|
+
name: "enum",
|
|
241
|
+
summary: "top | start | bottom | end",
|
|
242
|
+
},
|
|
243
|
+
},
|
|
244
|
+
},
|
|
245
|
+
helper: {
|
|
246
|
+
description: "Helper text to display with the label",
|
|
247
|
+
control: {
|
|
248
|
+
type: "text",
|
|
249
|
+
},
|
|
250
|
+
table: {
|
|
251
|
+
type: {
|
|
252
|
+
summary: "string | undefined",
|
|
253
|
+
},
|
|
254
|
+
},
|
|
255
|
+
},
|
|
256
|
+
style: {
|
|
257
|
+
description: "Inline styles for the outermost element of the Component",
|
|
258
|
+
control: {
|
|
259
|
+
type: "object",
|
|
260
|
+
},
|
|
261
|
+
table: {
|
|
262
|
+
type: {
|
|
263
|
+
summary: "React.CSSProperties | undefined",
|
|
264
|
+
},
|
|
265
|
+
},
|
|
266
|
+
},
|
|
267
|
+
tooltip: {
|
|
268
|
+
description: "Optional text to render in a tooltip",
|
|
269
|
+
control: {
|
|
270
|
+
type: "text",
|
|
271
|
+
},
|
|
272
|
+
table: {
|
|
273
|
+
type: {
|
|
274
|
+
summary: "string | undefined",
|
|
275
|
+
},
|
|
276
|
+
},
|
|
277
|
+
},
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
export const labelledFormFieldArgTypes = (element: string) => ({
|
|
281
|
+
...formControlArgTypes,
|
|
282
|
+
...formFieldArgTypes(element),
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
export const labelledChoiceFieldArgTypes = (element: string) => ({
|
|
286
|
+
...formControlArgTypes,
|
|
287
|
+
...choiceFieldArgTypes(element),
|
|
288
|
+
});
|