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