@onewelcome/react-lib-components 1.2.0 → 1.4.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/dist/Button/IconButton.d.ts +2 -1
- package/dist/DataGrid/DataGrid.d.ts +1 -0
- package/dist/DataGrid/DataGridActions/DataGridActions.d.ts +2 -1
- package/dist/Form/Form.d.ts +3 -3
- package/dist/Notifications/SlideInModal/SlideInModal.d.ts +1 -1
- package/dist/Tabs/Tab.d.ts +5 -9
- package/dist/Tabs/TabButton.d.ts +3 -6
- package/dist/Tabs/Tabs.d.ts +1 -2
- package/dist/hooks/useDebouncedCallback.d.ts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/react-lib-components.cjs.development.js +472 -395
- package/dist/react-lib-components.cjs.development.js.map +1 -1
- package/dist/react-lib-components.cjs.production.min.js +1 -1
- package/dist/react-lib-components.cjs.production.min.js.map +1 -1
- package/dist/react-lib-components.esm.js +473 -397
- package/dist/react-lib-components.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/Breadcrumbs/Breadcrumbs.tsx +46 -38
- package/src/Button/BaseButton.tsx +23 -20
- package/src/Button/Button.module.scss +9 -0
- package/src/Button/Button.tsx +40 -40
- package/src/Button/IconButton.tsx +28 -28
- package/src/ContextMenu/ContextMenu.tsx +161 -160
- package/src/ContextMenu/ContextMenuItem.tsx +55 -49
- package/src/DataGrid/DataGrid.tsx +1 -0
- package/src/DataGrid/DataGridActions/DataGridActions.module.scss +1 -1
- package/src/DataGrid/DataGridActions/DataGridActions.test.tsx +4 -2
- package/src/DataGrid/DataGridActions/DataGridActions.tsx +95 -87
- package/src/DataGrid/DataGridActions/DataGridColumnsToggle.tsx +64 -64
- package/src/DataGrid/DataGridBody/DataGridCell.tsx +42 -44
- package/src/DataGrid/DataGridBody/DataGridRow.tsx +29 -29
- package/src/DataGrid/DataGridHeader/DataGridHeader.tsx +78 -78
- package/src/DataGrid/DataGridHeader/DataGridHeaderCell.tsx +48 -48
- package/src/Form/Checkbox/Checkbox.tsx +134 -130
- package/src/Form/Fieldset/Fieldset.tsx +81 -78
- package/src/Form/Form.tsx +9 -4
- package/src/Form/FormControl/FormControl.module.scss +1 -20
- package/src/Form/FormControl/FormControl.tsx +36 -35
- package/src/Form/FormGroup/FormGroup.tsx +62 -62
- package/src/Form/FormHelperText/FormHelperText.tsx +19 -18
- package/src/Form/FormSelectorWrapper/FormSelectorWrapper.tsx +58 -53
- package/src/Form/Input/Input.tsx +90 -87
- package/src/Form/Label/Label.tsx +17 -16
- package/src/Form/Radio/Radio.tsx +91 -91
- package/src/Form/Select/Option.tsx +66 -60
- package/src/Form/Select/Select.tsx +207 -209
- package/src/Form/Textarea/Textarea.tsx +51 -53
- package/src/Form/Toggle/Toggle.tsx +26 -23
- package/src/Form/Wrapper/CheckboxWrapper/CheckboxWrapper.tsx +51 -43
- package/src/Form/Wrapper/InputWrapper/InputWrapper.tsx +112 -106
- package/src/Form/Wrapper/RadioWrapper/RadioWrapper.tsx +67 -62
- package/src/Form/Wrapper/SelectWrapper/SelectWrapper.tsx +42 -37
- package/src/Form/Wrapper/TextareaWrapper/TextareaWrapper.tsx +94 -94
- package/src/Form/Wrapper/Wrapper/Wrapper.tsx +73 -73
- package/src/Icon/Icon.module.scss +1 -0
- package/src/Icon/Icon.tsx +19 -16
- package/src/Link/Link.tsx +68 -63
- package/src/Notifications/BaseModal/BaseModal.tsx +68 -68
- package/src/Notifications/BaseModal/BaseModalActions/BaseModalActions.tsx +13 -10
- package/src/Notifications/BaseModal/BaseModalContent/BaseModalContent.tsx +33 -25
- package/src/Notifications/BaseModal/BaseModalHeader/BaseModalHeader.tsx +20 -17
- package/src/Notifications/Dialog/Dialog.tsx +83 -83
- package/src/Notifications/Dialog/DialogActions/DialogActions.tsx +17 -14
- package/src/Notifications/Dialog/DialogTitle/DialogTitle.tsx +15 -12
- package/src/Notifications/DiscardChangesModal/DiscardChangesDialog/DiscardChangesDialog.tsx +40 -40
- package/src/Notifications/SlideInModal/SlideInModal.module.scss +5 -5
- package/src/Notifications/SlideInModal/SlideInModal.test.tsx +7 -2
- package/src/Notifications/SlideInModal/SlideInModal.tsx +47 -27
- package/src/Pagination/Pagination.tsx +169 -169
- package/src/Popover/Popover.module.scss +1 -0
- package/src/Popover/Popover.tsx +43 -33
- package/src/ProgressBar/ProgressBar.tsx +17 -14
- package/src/Skeleton/Skeleton.tsx +23 -20
- package/src/StatusIndicator/StatusIndicator.tsx +18 -15
- package/src/Tabs/{TabPanel.module.scss → Tab.module.scss} +1 -1
- package/src/Tabs/Tab.test.tsx +1 -39
- package/src/Tabs/Tab.tsx +16 -10
- package/src/Tabs/TabButton.module.scss +0 -4
- package/src/Tabs/TabButton.test.tsx +3 -31
- package/src/Tabs/TabButton.tsx +35 -49
- package/src/Tabs/Tabs.test.tsx +40 -33
- package/src/Tabs/Tabs.tsx +107 -101
- package/src/TextEllipsis/TextEllipsis.tsx +50 -41
- package/src/Tiles/Tile.tsx +58 -56
- package/src/Tiles/Tiles.tsx +44 -41
- package/src/Tooltip/Tooltip.tsx +101 -100
- package/src/Typography/Typography.tsx +47 -44
- package/src/Wizard/BaseWizardSteps/BaseWizardSteps.tsx +55 -52
- package/src/Wizard/WizardSteps/WizardSteps.tsx +25 -22
- package/src/hooks/useDebouncedCallback.test.ts +140 -0
- package/src/hooks/useDebouncedCallback.tsx +32 -0
- package/src/index.ts +1 -0
- package/src/mixins.module.scss +2 -2
- package/src/util/helper.test.tsx +0 -28
- package/dist/Tabs/TabPanel.d.ts +0 -8
- package/src/Tabs/TabPanel.test.tsx +0 -92
- package/src/Tabs/TabPanel.tsx +0 -43
package/src/Form/Input/Input.tsx
CHANGED
|
@@ -14,7 +14,14 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import React, {
|
|
17
|
+
import React, {
|
|
18
|
+
ForwardRefRenderFunction,
|
|
19
|
+
ComponentPropsWithRef,
|
|
20
|
+
Ref,
|
|
21
|
+
useEffect,
|
|
22
|
+
useRef,
|
|
23
|
+
useState
|
|
24
|
+
} from "react";
|
|
18
25
|
import classes from "./Input.module.scss";
|
|
19
26
|
import readyclasses from "../../readyclasses.module.scss";
|
|
20
27
|
import { Icon, Icons } from "../../Icon/Icon";
|
|
@@ -42,95 +49,91 @@ export interface Props extends ComponentPropsWithRef<"input">, FormElement {
|
|
|
42
49
|
prefix?: string;
|
|
43
50
|
}
|
|
44
51
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const suffixRef = useRef<HTMLDivElement>(null);
|
|
52
|
+
const InputComponent: ForwardRefRenderFunction<HTMLInputElement, Props> = (
|
|
53
|
+
{
|
|
54
|
+
error = false,
|
|
55
|
+
className,
|
|
56
|
+
name,
|
|
57
|
+
style,
|
|
58
|
+
wrapperProps,
|
|
59
|
+
type,
|
|
60
|
+
labeledBy,
|
|
61
|
+
prefix,
|
|
62
|
+
suffix,
|
|
63
|
+
disabled,
|
|
64
|
+
onFocus,
|
|
65
|
+
onBlur,
|
|
66
|
+
...rest
|
|
67
|
+
}: Props,
|
|
68
|
+
ref: Ref<HTMLInputElement>
|
|
69
|
+
) => {
|
|
70
|
+
const [focus, setFocus] = useState(false);
|
|
71
|
+
const inputWrapperRef = useRef<HTMLDivElement>(null);
|
|
72
|
+
const errorIconRef = useRef<HTMLDivElement>(null);
|
|
73
|
+
const suffixRef = useRef<HTMLDivElement>(null);
|
|
68
74
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
if (name === undefined) {
|
|
77
|
+
throw new Error("Please give your <Input /> component a 'name' attribute");
|
|
78
|
+
}
|
|
79
|
+
}, []);
|
|
74
80
|
|
|
75
|
-
|
|
81
|
+
const inputClassNames = [classes["input"]];
|
|
76
82
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
83
|
+
(dateTypes as ReadonlyArray<string>).includes(type) &&
|
|
84
|
+
inputClassNames.push(classes["shrink-width-for-date-icon"]);
|
|
85
|
+
className && inputClassNames.push(className);
|
|
80
86
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
87
|
+
const iconClassNames = [classes["warning"]];
|
|
88
|
+
const wrapperClasses = [classes["input-wrapper"]];
|
|
89
|
+
const outlineClasses = [classes["outline"]];
|
|
84
90
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
error && wrapperClasses.push(classes["error"]) && outlineClasses.push(classes["error"]);
|
|
93
|
-
focus && wrapperClasses.push(classes["focus"]) && outlineClasses.push(classes["focus"]);
|
|
91
|
+
wrapperProps?.className && wrapperClasses.push(wrapperProps.className);
|
|
92
|
+
type === "hidden" && wrapperClasses.push(readyclasses["hidden"]);
|
|
93
|
+
prefix && wrapperClasses.push(classes["prefix"]);
|
|
94
|
+
suffix && wrapperClasses.push(classes["suffix"]);
|
|
95
|
+
disabled && wrapperClasses.push(classes["disabled"]) && outlineClasses.push(classes["disabled"]);
|
|
96
|
+
error && wrapperClasses.push(classes["error"]) && outlineClasses.push(classes["error"]);
|
|
97
|
+
focus && wrapperClasses.push(classes["focus"]) && outlineClasses.push(classes["focus"]);
|
|
94
98
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
);
|
|
99
|
+
return (
|
|
100
|
+
<div
|
|
101
|
+
ref={inputWrapperRef}
|
|
102
|
+
{...wrapperProps}
|
|
103
|
+
style={{ ...style }}
|
|
104
|
+
className={`${classes["input-wrapper"]} ${wrapperClasses.join(" ")}`}
|
|
105
|
+
>
|
|
106
|
+
{prefix && (
|
|
107
|
+
<div data-prefix className={classes["prefix"]}>
|
|
108
|
+
<span>{prefix}</span>
|
|
109
|
+
</div>
|
|
110
|
+
)}
|
|
111
|
+
<input
|
|
112
|
+
{...rest}
|
|
113
|
+
ref={ref}
|
|
114
|
+
onFocus={event => {
|
|
115
|
+
setFocus(true);
|
|
116
|
+
onFocus && onFocus(event);
|
|
117
|
+
}}
|
|
118
|
+
onBlur={event => {
|
|
119
|
+
setFocus(false);
|
|
120
|
+
onBlur && onBlur(event);
|
|
121
|
+
}}
|
|
122
|
+
aria-labelledby={labeledBy}
|
|
123
|
+
type={type}
|
|
124
|
+
name={name}
|
|
125
|
+
disabled={disabled}
|
|
126
|
+
className={inputClassNames.join(" ")}
|
|
127
|
+
/>
|
|
128
|
+
{suffix && (
|
|
129
|
+
<div ref={suffixRef} data-suffix className={classes["suffix"]}>
|
|
130
|
+
<span>{suffix}</span>
|
|
131
|
+
</div>
|
|
132
|
+
)}
|
|
133
|
+
{error && <Icon ref={errorIconRef} className={iconClassNames.join(" ")} icon={Icons.Error} />}
|
|
134
|
+
<span className={outlineClasses.join(" ")}></span>
|
|
135
|
+
</div>
|
|
136
|
+
);
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
export const Input = React.forwardRef(InputComponent);
|
package/src/Form/Label/Label.tsx
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import React, { ComponentPropsWithRef, ReactNode } from "react";
|
|
17
|
+
import React, { ForwardRefRenderFunction, ComponentPropsWithRef, ReactNode } from "react";
|
|
18
18
|
import classes from "./Label.module.scss";
|
|
19
19
|
import readyclasses from "../../readyclasses.module.scss";
|
|
20
20
|
|
|
@@ -22,18 +22,19 @@ export interface Props extends ComponentPropsWithRef<"label"> {
|
|
|
22
22
|
children?: ReactNode;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
25
|
+
const LabelComponent: ForwardRefRenderFunction<HTMLLabelElement, Props> = (
|
|
26
|
+
{ children, className, hidden = false, ...rest }: Props,
|
|
27
|
+
ref
|
|
28
|
+
) => {
|
|
29
|
+
return (
|
|
30
|
+
<label
|
|
31
|
+
{...rest}
|
|
32
|
+
ref={ref}
|
|
33
|
+
className={`${hidden ? readyclasses["sr-only"] : ""} ${classes["label"]} ${className ?? ""}`}
|
|
34
|
+
>
|
|
35
|
+
{children}
|
|
36
|
+
</label>
|
|
37
|
+
);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export const Label = React.forwardRef(LabelComponent);
|
package/src/Form/Radio/Radio.tsx
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import React, { ComponentPropsWithRef } from "react";
|
|
17
|
+
import React, { ForwardRefRenderFunction, ComponentPropsWithRef } from "react";
|
|
18
18
|
import { Icon, Icons } from "../../Icon/Icon";
|
|
19
19
|
import { Props as HelperProps } from "../FormHelperText/FormHelperText";
|
|
20
20
|
import classes from "./Radio.module.scss";
|
|
@@ -32,101 +32,101 @@ export interface Props extends ComponentPropsWithRef<"input">, FormSelector {
|
|
|
32
32
|
helperProps?: HelperProps;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
});
|
|
35
|
+
const RadioComponent: ForwardRefRenderFunction<HTMLInputElement, Props> = (
|
|
36
|
+
{
|
|
37
|
+
children,
|
|
38
|
+
disabled,
|
|
39
|
+
className,
|
|
40
|
+
value,
|
|
41
|
+
name,
|
|
42
|
+
helperText,
|
|
43
|
+
parentErrorId,
|
|
44
|
+
parentHelperId,
|
|
45
|
+
error,
|
|
46
|
+
errorMessage,
|
|
47
|
+
checked = false,
|
|
48
|
+
formSelectorWrapperProps,
|
|
49
|
+
helperProps,
|
|
50
|
+
onChange,
|
|
51
|
+
...rest
|
|
52
|
+
}: Props,
|
|
53
|
+
ref
|
|
54
|
+
) => {
|
|
55
|
+
const { errorId, identifier, describedBy } = useFormSelector({
|
|
56
|
+
name,
|
|
57
|
+
helperText,
|
|
58
|
+
parentErrorId,
|
|
59
|
+
errorMessage,
|
|
60
|
+
error,
|
|
61
|
+
parentHelperId
|
|
62
|
+
});
|
|
64
63
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
64
|
+
const onChangeHandler = (event: React.ChangeEvent<HTMLInputElement> | React.MouseEvent) => {
|
|
65
|
+
if (disabled) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
/** We have to clone the native event we got here and change the "target" property to the value. Otherwise, this regular event has "on" as it's event.target.value, which is useless. */
|
|
69
|
+
const nativeEvent: any = event.nativeEvent || event;
|
|
70
|
+
const clonedEvent = new nativeEvent.constructor(nativeEvent.type, nativeEvent);
|
|
72
71
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
72
|
+
Object.defineProperty(clonedEvent, "target", {
|
|
73
|
+
writable: true,
|
|
74
|
+
value: { value: value }
|
|
75
|
+
});
|
|
77
76
|
|
|
78
|
-
|
|
79
|
-
|
|
77
|
+
onChange && onChange(clonedEvent);
|
|
78
|
+
};
|
|
80
79
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
80
|
+
/** Default return value is the default radio */
|
|
81
|
+
return (
|
|
82
|
+
<FormSelectorWrapper
|
|
83
|
+
{...formSelectorWrapperProps}
|
|
84
|
+
className={`${classes["radio-wrapper"]} ${className ?? ""}`}
|
|
85
|
+
containerProps={{ className: classes["radio-container"] }}
|
|
86
|
+
helperText={helperText}
|
|
87
|
+
helperProps={helperProps}
|
|
88
|
+
parentErrorId={parentErrorId}
|
|
89
|
+
errorId={errorId}
|
|
90
|
+
errorMessage={errorMessage}
|
|
91
|
+
error={error}
|
|
92
|
+
disabled={disabled}
|
|
93
|
+
identifier={identifier}
|
|
94
|
+
>
|
|
95
|
+
<input
|
|
96
|
+
{...rest}
|
|
97
|
+
ref={ref}
|
|
93
98
|
disabled={disabled}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
99
|
+
tabIndex={0}
|
|
100
|
+
className={`${classes["native-input"]} ${error ? classes["error"] : ""}`}
|
|
101
|
+
onChange={onChangeHandler}
|
|
102
|
+
checked={checked}
|
|
103
|
+
aria-invalid={error ? true : false}
|
|
104
|
+
aria-checked={checked}
|
|
105
|
+
aria-describedby={describedBy}
|
|
106
|
+
name={name}
|
|
107
|
+
value={value}
|
|
108
|
+
id={`${identifier}-radio`}
|
|
109
|
+
type="radio"
|
|
110
|
+
/>
|
|
111
|
+
|
|
112
|
+
{checked && (
|
|
113
|
+
<Icon
|
|
114
|
+
className={`${classes["input"]} ${disabled ? classes["disabled"] : ""}`}
|
|
115
|
+
icon={Icons.Radio}
|
|
116
|
+
/>
|
|
117
|
+
)}
|
|
118
|
+
{!checked && (
|
|
119
|
+
<Icon
|
|
120
|
+
className={`${classes["input"]} ${disabled ? classes["disabled"] : ""}`}
|
|
121
|
+
icon={Icons.Circle}
|
|
111
122
|
/>
|
|
123
|
+
)}
|
|
112
124
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
{!checked && (
|
|
120
|
-
<Icon
|
|
121
|
-
className={`${classes["input"]} ${disabled ? classes["disabled"] : ""}`}
|
|
122
|
-
icon={Icons.Circle}
|
|
123
|
-
/>
|
|
124
|
-
)}
|
|
125
|
+
<label onClick={onChangeHandler} htmlFor={`${identifier}-radio`}>
|
|
126
|
+
{children}
|
|
127
|
+
</label>
|
|
128
|
+
</FormSelectorWrapper>
|
|
129
|
+
);
|
|
130
|
+
};
|
|
125
131
|
|
|
126
|
-
|
|
127
|
-
{children}
|
|
128
|
-
</label>
|
|
129
|
-
</FormSelectorWrapper>
|
|
130
|
-
);
|
|
131
|
-
}
|
|
132
|
-
);
|
|
132
|
+
export const Radio = React.forwardRef(RadioComponent);
|
|
@@ -14,7 +14,13 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import React, {
|
|
17
|
+
import React, {
|
|
18
|
+
ForwardRefRenderFunction,
|
|
19
|
+
ComponentPropsWithRef,
|
|
20
|
+
createRef,
|
|
21
|
+
RefObject,
|
|
22
|
+
useEffect
|
|
23
|
+
} from "react";
|
|
18
24
|
import classes from "./Select.module.scss";
|
|
19
25
|
|
|
20
26
|
export interface Props extends ComponentPropsWithRef<"li"> {
|
|
@@ -32,67 +38,67 @@ export interface Props extends ComponentPropsWithRef<"li"> {
|
|
|
32
38
|
onFocusChange?: (childIndex: number) => void;
|
|
33
39
|
}
|
|
34
40
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
)
|
|
54
|
-
let innerOptionRef = (ref as RefObject<HTMLLIElement>) || createRef<HTMLLIElement>();
|
|
41
|
+
const OptionComponent: ForwardRefRenderFunction<HTMLLIElement, Props> = (
|
|
42
|
+
{
|
|
43
|
+
children,
|
|
44
|
+
className,
|
|
45
|
+
isSelected = false,
|
|
46
|
+
shouldClick,
|
|
47
|
+
hasFocus,
|
|
48
|
+
selectOpened,
|
|
49
|
+
isSearching,
|
|
50
|
+
childIndex,
|
|
51
|
+
onOptionSelect,
|
|
52
|
+
onFocusChange,
|
|
53
|
+
disabled,
|
|
54
|
+
value,
|
|
55
|
+
...rest
|
|
56
|
+
}: Props,
|
|
57
|
+
ref
|
|
58
|
+
) => {
|
|
59
|
+
let innerOptionRef = (ref as RefObject<HTMLLIElement>) || createRef<HTMLLIElement>();
|
|
55
60
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
if (isSelected && innerOptionRef.current && shouldClick) {
|
|
63
|
+
innerOptionRef.current.click();
|
|
64
|
+
}
|
|
65
|
+
}, [isSelected, shouldClick]);
|
|
61
66
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
if (innerOptionRef.current && hasFocus && selectOpened && !isSearching) {
|
|
69
|
+
onFocusChange && childIndex && onFocusChange(childIndex);
|
|
70
|
+
innerOptionRef.current.focus();
|
|
71
|
+
}
|
|
72
|
+
}, [hasFocus, innerOptionRef, selectOpened, isSearching]);
|
|
68
73
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
74
|
+
const onSelectHandler = () => {
|
|
75
|
+
if (onOptionSelect) onOptionSelect(innerOptionRef);
|
|
76
|
+
};
|
|
72
77
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
78
|
+
return (
|
|
79
|
+
<li
|
|
80
|
+
{...rest}
|
|
81
|
+
ref={innerOptionRef}
|
|
82
|
+
data-value={value}
|
|
83
|
+
className={`${isSelected ? classes["selected-option"] : ""} ${
|
|
84
|
+
disabled ? classes.disabled : ""
|
|
85
|
+
} ${className ?? ""}`}
|
|
86
|
+
onClick={onSelectHandler}
|
|
87
|
+
onKeyDownCapture={event => {
|
|
88
|
+
if (event.code === "Enter") {
|
|
89
|
+
event.stopPropagation();
|
|
90
|
+
event.preventDefault();
|
|
86
91
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
92
|
+
onSelectHandler();
|
|
93
|
+
}
|
|
94
|
+
}}
|
|
95
|
+
aria-selected={isSelected}
|
|
96
|
+
role="option"
|
|
97
|
+
tabIndex={disabled ? -1 : 0}
|
|
98
|
+
>
|
|
99
|
+
{children}
|
|
100
|
+
</li>
|
|
101
|
+
);
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
export const Option = React.forwardRef(OptionComponent);
|