corestack-ui 0.2.0 → 0.2.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/dist/index.d.mts +49 -17
- package/dist/index.d.ts +49 -17
- package/dist/index.js +74 -47
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +35 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import * as React from 'react';
|
|
2
|
+
import * as React$1 from 'react';
|
|
3
3
|
import React__default from 'react';
|
|
4
4
|
|
|
5
5
|
type AutocompleteChangeReason = "selectOption" | "removeOption" | "clear" | "blur";
|
|
@@ -8,14 +8,14 @@ interface AutocompleteRenderOptionState {
|
|
|
8
8
|
index: number;
|
|
9
9
|
}
|
|
10
10
|
interface RenderInputParams {
|
|
11
|
-
ref: React.Ref<HTMLInputElement>;
|
|
11
|
+
ref: React$1.Ref<HTMLInputElement>;
|
|
12
12
|
value: string;
|
|
13
13
|
placeholder?: string;
|
|
14
14
|
disabled?: boolean;
|
|
15
|
-
onChange: React.ChangeEventHandler<HTMLInputElement | HTMLTextAreaElement>;
|
|
16
|
-
onKeyDown: React.KeyboardEventHandler<HTMLInputElement | HTMLTextAreaElement>;
|
|
17
|
-
onFocus: React.FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>;
|
|
18
|
-
onBlur: React.FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>;
|
|
15
|
+
onChange: React$1.ChangeEventHandler<HTMLInputElement | HTMLTextAreaElement>;
|
|
16
|
+
onKeyDown: React$1.KeyboardEventHandler<HTMLInputElement | HTMLTextAreaElement>;
|
|
17
|
+
onFocus: React$1.FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>;
|
|
18
|
+
onBlur: React$1.FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>;
|
|
19
19
|
role: string;
|
|
20
20
|
"aria-autocomplete": "list";
|
|
21
21
|
"aria-controls"?: string;
|
|
@@ -23,8 +23,8 @@ interface RenderInputParams {
|
|
|
23
23
|
"aria-activedescendant"?: string;
|
|
24
24
|
autoComplete?: string;
|
|
25
25
|
InputProps: {
|
|
26
|
-
startAdornment?: React.ReactNode;
|
|
27
|
-
endAdornment?: React.ReactNode;
|
|
26
|
+
startAdornment?: React$1.ReactNode;
|
|
27
|
+
endAdornment?: React$1.ReactNode;
|
|
28
28
|
className?: string;
|
|
29
29
|
};
|
|
30
30
|
}
|
|
@@ -32,8 +32,8 @@ interface BaseAutocompleteProps<T> {
|
|
|
32
32
|
options: T[];
|
|
33
33
|
getOptionLabel: (option: T) => string;
|
|
34
34
|
isOptionEqualToValue?: (option: T, value: T) => boolean;
|
|
35
|
-
renderInput: (params: RenderInputParams) => React.ReactNode;
|
|
36
|
-
renderOption?: (props: React.HTMLAttributes<HTMLLIElement>, option: T, state: AutocompleteRenderOptionState) => React.ReactNode;
|
|
35
|
+
renderInput: (params: RenderInputParams) => React$1.ReactNode;
|
|
36
|
+
renderOption?: (props: React$1.HTMLAttributes<HTMLLIElement>, option: T, state: AutocompleteRenderOptionState) => React$1.ReactNode;
|
|
37
37
|
loading?: boolean;
|
|
38
38
|
disabled?: boolean;
|
|
39
39
|
placeholder?: string;
|
|
@@ -41,20 +41,20 @@ interface BaseAutocompleteProps<T> {
|
|
|
41
41
|
/** Text to show when there are no options and not loading */
|
|
42
42
|
emptyText?: string;
|
|
43
43
|
}
|
|
44
|
-
type NativeInputProps = Omit<React.InputHTMLAttributes<HTMLInputElement>, "onChange" | "value" | "defaultValue">;
|
|
44
|
+
type NativeInputProps = Omit<React$1.InputHTMLAttributes<HTMLInputElement>, "onChange" | "value" | "defaultValue">;
|
|
45
45
|
interface SingleAutocompleteProps<T> extends BaseAutocompleteProps<T>, NativeInputProps {
|
|
46
46
|
multiple?: false;
|
|
47
47
|
value?: T | null;
|
|
48
48
|
defaultValue?: T | null;
|
|
49
49
|
disableCloseOnSelect?: boolean;
|
|
50
|
-
onChange?: (event: React.SyntheticEvent, value: T | null, reason: AutocompleteChangeReason) => void;
|
|
50
|
+
onChange?: (event: React$1.SyntheticEvent, value: T | null, reason: AutocompleteChangeReason) => void;
|
|
51
51
|
}
|
|
52
52
|
interface MultipleAutocompleteProps<T> extends BaseAutocompleteProps<T>, NativeInputProps {
|
|
53
53
|
multiple: true;
|
|
54
54
|
value?: T[];
|
|
55
55
|
defaultValue?: T[];
|
|
56
56
|
disableCloseOnSelect?: boolean;
|
|
57
|
-
onChange?: (event: React.SyntheticEvent, value: T[], reason: AutocompleteChangeReason) => void;
|
|
57
|
+
onChange?: (event: React$1.SyntheticEvent, value: T[], reason: AutocompleteChangeReason) => void;
|
|
58
58
|
}
|
|
59
59
|
type AutocompleteProps<T> = SingleAutocompleteProps<T> | MultipleAutocompleteProps<T>;
|
|
60
60
|
|
|
@@ -62,7 +62,7 @@ declare function Autocomplete<T>(props: AutocompleteProps<T>): react_jsx_runtime
|
|
|
62
62
|
|
|
63
63
|
type ButtonVariant = "primary" | "secondary" | "ghost";
|
|
64
64
|
type ButtonSize = "sm" | "md" | "lg";
|
|
65
|
-
interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
65
|
+
interface ButtonProps extends React$1.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
66
66
|
variant?: ButtonVariant;
|
|
67
67
|
size?: ButtonSize;
|
|
68
68
|
disableRipple?: boolean;
|
|
@@ -72,13 +72,13 @@ interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
|
72
72
|
declare function Button({ children, disableRipple, isLoading, className, onClick, ...props }: ButtonProps): react_jsx_runtime.JSX.Element;
|
|
73
73
|
|
|
74
74
|
declare const TextField: React__default.ForwardRefExoticComponent<{
|
|
75
|
-
value?: string | number | readonly string[];
|
|
75
|
+
value?: string | number | null | readonly string[];
|
|
76
76
|
defaultValue?: string | number | readonly string[];
|
|
77
77
|
onChange?: React__default.ChangeEventHandler<HTMLInputElement | HTMLTextAreaElement>;
|
|
78
78
|
onBlur?: React__default.FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>;
|
|
79
79
|
onFocus?: React__default.FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>;
|
|
80
80
|
placeholder?: string;
|
|
81
|
-
label?: string;
|
|
81
|
+
label?: string | React__default.ReactNode;
|
|
82
82
|
helperText?: string | false | undefined;
|
|
83
83
|
error?: boolean;
|
|
84
84
|
disabled?: boolean;
|
|
@@ -217,9 +217,41 @@ declare const tokens: {
|
|
|
217
217
|
};
|
|
218
218
|
};
|
|
219
219
|
|
|
220
|
+
type TextFieldSize = "small" | "medium";
|
|
221
|
+
type TextFieldVariant = "outlined" | "filled" | "standard";
|
|
222
|
+
type TextFieldInputProps = {
|
|
223
|
+
startAdornment?: React.ReactNode;
|
|
224
|
+
endAdornment?: React.ReactNode;
|
|
225
|
+
inputComponent?: React.ElementType;
|
|
226
|
+
className?: string;
|
|
227
|
+
};
|
|
228
|
+
type TextFieldProps = {
|
|
229
|
+
value?: string | number | null | readonly string[];
|
|
230
|
+
defaultValue?: string | number | readonly string[];
|
|
231
|
+
onChange?: React.ChangeEventHandler<HTMLInputElement | HTMLTextAreaElement>;
|
|
232
|
+
onBlur?: React.FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>;
|
|
233
|
+
onFocus?: React.FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>;
|
|
234
|
+
placeholder?: string;
|
|
235
|
+
label?: string | React.ReactNode;
|
|
236
|
+
helperText?: string | false | undefined;
|
|
237
|
+
error?: boolean;
|
|
238
|
+
disabled?: boolean;
|
|
239
|
+
required?: boolean;
|
|
240
|
+
multiline?: boolean;
|
|
241
|
+
rows?: number;
|
|
242
|
+
type?: string;
|
|
243
|
+
name?: string;
|
|
244
|
+
id?: string;
|
|
245
|
+
fullWidth?: boolean;
|
|
246
|
+
size?: TextFieldSize;
|
|
247
|
+
variant?: TextFieldVariant;
|
|
248
|
+
InputProps?: TextFieldInputProps;
|
|
249
|
+
className?: string;
|
|
250
|
+
} & Omit<React.InputHTMLAttributes<HTMLInputElement> & React.TextareaHTMLAttributes<HTMLTextAreaElement>, "size" | "type" | "onChange" | "value" | "defaultValue" | "disabled" | "required" | "name" | "id" | "placeholder" | "onBlur" | "onFocus">;
|
|
251
|
+
|
|
220
252
|
type ClassValue = string | false | null | undefined;
|
|
221
253
|
declare const cn: (...parts: ClassValue[]) => string;
|
|
222
254
|
|
|
223
255
|
declare const cssFile = "./styles.css";
|
|
224
256
|
|
|
225
|
-
export { Autocomplete, Button, type ButtonProps, type ClassValue, TextField, ThemeProvider, cn, cssFile, tokens, useTheme };
|
|
257
|
+
export { Autocomplete, type AutocompleteProps, Button, type ButtonProps, type ClassValue, TextField, type TextFieldProps, ThemeProvider, cn, cssFile, tokens, useTheme };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import * as React from 'react';
|
|
2
|
+
import * as React$1 from 'react';
|
|
3
3
|
import React__default from 'react';
|
|
4
4
|
|
|
5
5
|
type AutocompleteChangeReason = "selectOption" | "removeOption" | "clear" | "blur";
|
|
@@ -8,14 +8,14 @@ interface AutocompleteRenderOptionState {
|
|
|
8
8
|
index: number;
|
|
9
9
|
}
|
|
10
10
|
interface RenderInputParams {
|
|
11
|
-
ref: React.Ref<HTMLInputElement>;
|
|
11
|
+
ref: React$1.Ref<HTMLInputElement>;
|
|
12
12
|
value: string;
|
|
13
13
|
placeholder?: string;
|
|
14
14
|
disabled?: boolean;
|
|
15
|
-
onChange: React.ChangeEventHandler<HTMLInputElement | HTMLTextAreaElement>;
|
|
16
|
-
onKeyDown: React.KeyboardEventHandler<HTMLInputElement | HTMLTextAreaElement>;
|
|
17
|
-
onFocus: React.FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>;
|
|
18
|
-
onBlur: React.FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>;
|
|
15
|
+
onChange: React$1.ChangeEventHandler<HTMLInputElement | HTMLTextAreaElement>;
|
|
16
|
+
onKeyDown: React$1.KeyboardEventHandler<HTMLInputElement | HTMLTextAreaElement>;
|
|
17
|
+
onFocus: React$1.FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>;
|
|
18
|
+
onBlur: React$1.FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>;
|
|
19
19
|
role: string;
|
|
20
20
|
"aria-autocomplete": "list";
|
|
21
21
|
"aria-controls"?: string;
|
|
@@ -23,8 +23,8 @@ interface RenderInputParams {
|
|
|
23
23
|
"aria-activedescendant"?: string;
|
|
24
24
|
autoComplete?: string;
|
|
25
25
|
InputProps: {
|
|
26
|
-
startAdornment?: React.ReactNode;
|
|
27
|
-
endAdornment?: React.ReactNode;
|
|
26
|
+
startAdornment?: React$1.ReactNode;
|
|
27
|
+
endAdornment?: React$1.ReactNode;
|
|
28
28
|
className?: string;
|
|
29
29
|
};
|
|
30
30
|
}
|
|
@@ -32,8 +32,8 @@ interface BaseAutocompleteProps<T> {
|
|
|
32
32
|
options: T[];
|
|
33
33
|
getOptionLabel: (option: T) => string;
|
|
34
34
|
isOptionEqualToValue?: (option: T, value: T) => boolean;
|
|
35
|
-
renderInput: (params: RenderInputParams) => React.ReactNode;
|
|
36
|
-
renderOption?: (props: React.HTMLAttributes<HTMLLIElement>, option: T, state: AutocompleteRenderOptionState) => React.ReactNode;
|
|
35
|
+
renderInput: (params: RenderInputParams) => React$1.ReactNode;
|
|
36
|
+
renderOption?: (props: React$1.HTMLAttributes<HTMLLIElement>, option: T, state: AutocompleteRenderOptionState) => React$1.ReactNode;
|
|
37
37
|
loading?: boolean;
|
|
38
38
|
disabled?: boolean;
|
|
39
39
|
placeholder?: string;
|
|
@@ -41,20 +41,20 @@ interface BaseAutocompleteProps<T> {
|
|
|
41
41
|
/** Text to show when there are no options and not loading */
|
|
42
42
|
emptyText?: string;
|
|
43
43
|
}
|
|
44
|
-
type NativeInputProps = Omit<React.InputHTMLAttributes<HTMLInputElement>, "onChange" | "value" | "defaultValue">;
|
|
44
|
+
type NativeInputProps = Omit<React$1.InputHTMLAttributes<HTMLInputElement>, "onChange" | "value" | "defaultValue">;
|
|
45
45
|
interface SingleAutocompleteProps<T> extends BaseAutocompleteProps<T>, NativeInputProps {
|
|
46
46
|
multiple?: false;
|
|
47
47
|
value?: T | null;
|
|
48
48
|
defaultValue?: T | null;
|
|
49
49
|
disableCloseOnSelect?: boolean;
|
|
50
|
-
onChange?: (event: React.SyntheticEvent, value: T | null, reason: AutocompleteChangeReason) => void;
|
|
50
|
+
onChange?: (event: React$1.SyntheticEvent, value: T | null, reason: AutocompleteChangeReason) => void;
|
|
51
51
|
}
|
|
52
52
|
interface MultipleAutocompleteProps<T> extends BaseAutocompleteProps<T>, NativeInputProps {
|
|
53
53
|
multiple: true;
|
|
54
54
|
value?: T[];
|
|
55
55
|
defaultValue?: T[];
|
|
56
56
|
disableCloseOnSelect?: boolean;
|
|
57
|
-
onChange?: (event: React.SyntheticEvent, value: T[], reason: AutocompleteChangeReason) => void;
|
|
57
|
+
onChange?: (event: React$1.SyntheticEvent, value: T[], reason: AutocompleteChangeReason) => void;
|
|
58
58
|
}
|
|
59
59
|
type AutocompleteProps<T> = SingleAutocompleteProps<T> | MultipleAutocompleteProps<T>;
|
|
60
60
|
|
|
@@ -62,7 +62,7 @@ declare function Autocomplete<T>(props: AutocompleteProps<T>): react_jsx_runtime
|
|
|
62
62
|
|
|
63
63
|
type ButtonVariant = "primary" | "secondary" | "ghost";
|
|
64
64
|
type ButtonSize = "sm" | "md" | "lg";
|
|
65
|
-
interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
65
|
+
interface ButtonProps extends React$1.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
66
66
|
variant?: ButtonVariant;
|
|
67
67
|
size?: ButtonSize;
|
|
68
68
|
disableRipple?: boolean;
|
|
@@ -72,13 +72,13 @@ interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
|
72
72
|
declare function Button({ children, disableRipple, isLoading, className, onClick, ...props }: ButtonProps): react_jsx_runtime.JSX.Element;
|
|
73
73
|
|
|
74
74
|
declare const TextField: React__default.ForwardRefExoticComponent<{
|
|
75
|
-
value?: string | number | readonly string[];
|
|
75
|
+
value?: string | number | null | readonly string[];
|
|
76
76
|
defaultValue?: string | number | readonly string[];
|
|
77
77
|
onChange?: React__default.ChangeEventHandler<HTMLInputElement | HTMLTextAreaElement>;
|
|
78
78
|
onBlur?: React__default.FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>;
|
|
79
79
|
onFocus?: React__default.FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>;
|
|
80
80
|
placeholder?: string;
|
|
81
|
-
label?: string;
|
|
81
|
+
label?: string | React__default.ReactNode;
|
|
82
82
|
helperText?: string | false | undefined;
|
|
83
83
|
error?: boolean;
|
|
84
84
|
disabled?: boolean;
|
|
@@ -217,9 +217,41 @@ declare const tokens: {
|
|
|
217
217
|
};
|
|
218
218
|
};
|
|
219
219
|
|
|
220
|
+
type TextFieldSize = "small" | "medium";
|
|
221
|
+
type TextFieldVariant = "outlined" | "filled" | "standard";
|
|
222
|
+
type TextFieldInputProps = {
|
|
223
|
+
startAdornment?: React.ReactNode;
|
|
224
|
+
endAdornment?: React.ReactNode;
|
|
225
|
+
inputComponent?: React.ElementType;
|
|
226
|
+
className?: string;
|
|
227
|
+
};
|
|
228
|
+
type TextFieldProps = {
|
|
229
|
+
value?: string | number | null | readonly string[];
|
|
230
|
+
defaultValue?: string | number | readonly string[];
|
|
231
|
+
onChange?: React.ChangeEventHandler<HTMLInputElement | HTMLTextAreaElement>;
|
|
232
|
+
onBlur?: React.FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>;
|
|
233
|
+
onFocus?: React.FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>;
|
|
234
|
+
placeholder?: string;
|
|
235
|
+
label?: string | React.ReactNode;
|
|
236
|
+
helperText?: string | false | undefined;
|
|
237
|
+
error?: boolean;
|
|
238
|
+
disabled?: boolean;
|
|
239
|
+
required?: boolean;
|
|
240
|
+
multiline?: boolean;
|
|
241
|
+
rows?: number;
|
|
242
|
+
type?: string;
|
|
243
|
+
name?: string;
|
|
244
|
+
id?: string;
|
|
245
|
+
fullWidth?: boolean;
|
|
246
|
+
size?: TextFieldSize;
|
|
247
|
+
variant?: TextFieldVariant;
|
|
248
|
+
InputProps?: TextFieldInputProps;
|
|
249
|
+
className?: string;
|
|
250
|
+
} & Omit<React.InputHTMLAttributes<HTMLInputElement> & React.TextareaHTMLAttributes<HTMLTextAreaElement>, "size" | "type" | "onChange" | "value" | "defaultValue" | "disabled" | "required" | "name" | "id" | "placeholder" | "onBlur" | "onFocus">;
|
|
251
|
+
|
|
220
252
|
type ClassValue = string | false | null | undefined;
|
|
221
253
|
declare const cn: (...parts: ClassValue[]) => string;
|
|
222
254
|
|
|
223
255
|
declare const cssFile = "./styles.css";
|
|
224
256
|
|
|
225
|
-
export { Autocomplete, Button, type ButtonProps, type ClassValue, TextField, ThemeProvider, cn, cssFile, tokens, useTheme };
|
|
257
|
+
export { Autocomplete, type AutocompleteProps, Button, type ButtonProps, type ClassValue, TextField, type TextFieldProps, ThemeProvider, cn, cssFile, tokens, useTheme };
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var React2 = require('react');
|
|
4
4
|
var ReactDOM = require('react-dom');
|
|
5
5
|
var jsxRuntime = require('react/jsx-runtime');
|
|
6
6
|
|
|
7
7
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
8
|
|
|
9
|
+
var React2__default = /*#__PURE__*/_interopDefault(React2);
|
|
9
10
|
var ReactDOM__default = /*#__PURE__*/_interopDefault(ReactDOM);
|
|
10
11
|
|
|
11
12
|
/* Corestack UI - built with tsup */
|
|
@@ -103,54 +104,54 @@ function useAutocomplete(props) {
|
|
|
103
104
|
disabled,
|
|
104
105
|
disableCloseOnSelect
|
|
105
106
|
} = props;
|
|
106
|
-
const getLabel =
|
|
107
|
+
const getLabel = React2.useCallback(
|
|
107
108
|
(option) => {
|
|
108
109
|
if (getOptionLabel) return getOptionLabel(option);
|
|
109
110
|
return String(option);
|
|
110
111
|
},
|
|
111
112
|
[getOptionLabel]
|
|
112
113
|
);
|
|
113
|
-
const isEqual =
|
|
114
|
+
const isEqual = React2.useCallback(
|
|
114
115
|
(option, v) => isOptionEqualToValue ? isOptionEqualToValue(option, v) : getLabel(option) === getLabel(v),
|
|
115
116
|
[isOptionEqualToValue, getLabel]
|
|
116
117
|
);
|
|
117
118
|
const isControlled = value !== void 0;
|
|
118
|
-
const [internalValue, setInternalValue] =
|
|
119
|
+
const [internalValue, setInternalValue] = React2.useState(() => {
|
|
119
120
|
if (defaultValue !== void 0) return defaultValue;
|
|
120
121
|
return multiple ? [] : null;
|
|
121
122
|
});
|
|
122
123
|
const currentValue = isControlled ? value : internalValue;
|
|
123
|
-
const [open, setOpen] =
|
|
124
|
-
const [inputValue, setInputValue] =
|
|
124
|
+
const [open, setOpen] = React2.useState(false);
|
|
125
|
+
const [inputValue, setInputValue] = React2.useState(() => {
|
|
125
126
|
if (multiple) return "";
|
|
126
127
|
return currentValue && !Array.isArray(currentValue) ? getLabel(currentValue) : "";
|
|
127
128
|
});
|
|
128
|
-
const [activeIndex, setActiveIndex] =
|
|
129
|
-
const rootRef =
|
|
130
|
-
const inputRef =
|
|
131
|
-
const listboxRef =
|
|
132
|
-
const isFocusedRef =
|
|
133
|
-
const blurTimeoutRef =
|
|
134
|
-
const filteredOptions =
|
|
129
|
+
const [activeIndex, setActiveIndex] = React2.useState(-1);
|
|
130
|
+
const rootRef = React2.useRef(null);
|
|
131
|
+
const inputRef = React2.useRef(null);
|
|
132
|
+
const listboxRef = React2.useRef(null);
|
|
133
|
+
const isFocusedRef = React2.useRef(false);
|
|
134
|
+
const blurTimeoutRef = React2.useRef(null);
|
|
135
|
+
const filteredOptions = React2.useMemo(() => {
|
|
135
136
|
const query = inputValue.trim().toLowerCase();
|
|
136
137
|
if (!query) return options;
|
|
137
138
|
return options.filter(
|
|
138
139
|
(option) => getLabel(option).toLowerCase().includes(query)
|
|
139
140
|
);
|
|
140
141
|
}, [options, inputValue, getLabel]);
|
|
141
|
-
const selectedValues =
|
|
142
|
+
const selectedValues = React2.useMemo(() => {
|
|
142
143
|
if (multiple)
|
|
143
144
|
return Array.isArray(currentValue) ? currentValue : [];
|
|
144
145
|
return currentValue && !Array.isArray(currentValue) ? [currentValue] : [];
|
|
145
146
|
}, [currentValue, multiple]);
|
|
146
|
-
|
|
147
|
+
React2.useEffect(() => {
|
|
147
148
|
if (multiple) return;
|
|
148
149
|
if (!isFocusedRef.current) {
|
|
149
150
|
const next = currentValue && !Array.isArray(currentValue) ? getLabel(currentValue) : "";
|
|
150
151
|
setInputValue(next);
|
|
151
152
|
}
|
|
152
153
|
}, [currentValue, getLabel, multiple]);
|
|
153
|
-
const updateValue =
|
|
154
|
+
const updateValue = React2.useCallback(
|
|
154
155
|
(event, nextValue, reason) => {
|
|
155
156
|
if (!isControlled) {
|
|
156
157
|
setInternalValue(nextValue);
|
|
@@ -165,7 +166,7 @@ function useAutocomplete(props) {
|
|
|
165
166
|
},
|
|
166
167
|
[isControlled, onChange, multiple]
|
|
167
168
|
);
|
|
168
|
-
const selectOption =
|
|
169
|
+
const selectOption = React2.useCallback(
|
|
169
170
|
(event, option) => {
|
|
170
171
|
if (blurTimeoutRef.current) {
|
|
171
172
|
clearTimeout(blurTimeoutRef.current);
|
|
@@ -191,7 +192,7 @@ function useAutocomplete(props) {
|
|
|
191
192
|
},
|
|
192
193
|
[currentValue, getLabel, isEqual, multiple, updateValue]
|
|
193
194
|
);
|
|
194
|
-
const clearValue =
|
|
195
|
+
const clearValue = React2.useCallback(
|
|
195
196
|
(event) => {
|
|
196
197
|
updateValue(event, multiple ? [] : null, "clear");
|
|
197
198
|
setInputValue("");
|
|
@@ -199,10 +200,20 @@ function useAutocomplete(props) {
|
|
|
199
200
|
},
|
|
200
201
|
[multiple, updateValue]
|
|
201
202
|
);
|
|
202
|
-
const
|
|
203
|
+
const removeOption = React2.useCallback(
|
|
204
|
+
(event, option) => {
|
|
205
|
+
if (!multiple) return;
|
|
206
|
+
const existing = Array.isArray(currentValue) ? currentValue : [];
|
|
207
|
+
const next = existing.filter((item) => !isEqual(item, option));
|
|
208
|
+
updateValue(event, next, "removeOption");
|
|
209
|
+
setActiveIndex(-1);
|
|
210
|
+
},
|
|
211
|
+
[currentValue, isEqual, multiple, updateValue]
|
|
212
|
+
);
|
|
213
|
+
const setInputFocused = React2.useCallback((focused) => {
|
|
203
214
|
isFocusedRef.current = focused;
|
|
204
215
|
}, []);
|
|
205
|
-
|
|
216
|
+
React2.useEffect(() => {
|
|
206
217
|
if (!open || activeIndex < 0 || !listboxRef.current) return;
|
|
207
218
|
const activeId = `autocomplete-option-${activeIndex}`;
|
|
208
219
|
const el = listboxRef.current.querySelector(`#${activeId}`);
|
|
@@ -210,7 +221,7 @@ function useAutocomplete(props) {
|
|
|
210
221
|
el.scrollIntoView({ block: "nearest" });
|
|
211
222
|
}
|
|
212
223
|
}, [open, activeIndex]);
|
|
213
|
-
|
|
224
|
+
React2.useEffect(() => {
|
|
214
225
|
const handleClickOutside = (event) => {
|
|
215
226
|
const root = rootRef.current;
|
|
216
227
|
const list = listboxRef.current;
|
|
@@ -222,7 +233,7 @@ function useAutocomplete(props) {
|
|
|
222
233
|
document.addEventListener("mousedown", handleClickOutside);
|
|
223
234
|
return () => document.removeEventListener("mousedown", handleClickOutside);
|
|
224
235
|
}, []);
|
|
225
|
-
const handleInputChange =
|
|
236
|
+
const handleInputChange = React2.useCallback(
|
|
226
237
|
(event) => {
|
|
227
238
|
var _a;
|
|
228
239
|
setInputValue(event.target.value);
|
|
@@ -232,7 +243,7 @@ function useAutocomplete(props) {
|
|
|
232
243
|
},
|
|
233
244
|
[setInputValue, setOpen, setActiveIndex]
|
|
234
245
|
);
|
|
235
|
-
const handleInputFocus =
|
|
246
|
+
const handleInputFocus = React2.useCallback(
|
|
236
247
|
(event) => {
|
|
237
248
|
var _a;
|
|
238
249
|
if (!!disabled) return;
|
|
@@ -255,7 +266,7 @@ function useAutocomplete(props) {
|
|
|
255
266
|
setActiveIndex
|
|
256
267
|
]
|
|
257
268
|
);
|
|
258
|
-
const handleInputBlur =
|
|
269
|
+
const handleInputBlur = React2.useCallback(
|
|
259
270
|
(event) => {
|
|
260
271
|
var _a;
|
|
261
272
|
setInputFocused(false);
|
|
@@ -274,7 +285,7 @@ function useAutocomplete(props) {
|
|
|
274
285
|
},
|
|
275
286
|
[setInputFocused, setOpen, setActiveIndex]
|
|
276
287
|
);
|
|
277
|
-
const handleToggleClick =
|
|
288
|
+
const handleToggleClick = React2.useCallback(
|
|
278
289
|
(event) => {
|
|
279
290
|
var _a;
|
|
280
291
|
if (!!disabled) return;
|
|
@@ -290,7 +301,7 @@ function useAutocomplete(props) {
|
|
|
290
301
|
},
|
|
291
302
|
[!!disabled, open, setActiveIndex, setOpen, inputRef]
|
|
292
303
|
);
|
|
293
|
-
const handleKeyDown =
|
|
304
|
+
const handleKeyDown = React2.useCallback(
|
|
294
305
|
(event) => {
|
|
295
306
|
if (!!disabled) return;
|
|
296
307
|
if (event.key === "ArrowDown") {
|
|
@@ -346,6 +357,7 @@ function useAutocomplete(props) {
|
|
|
346
357
|
isEqual,
|
|
347
358
|
selectOption,
|
|
348
359
|
clearValue,
|
|
360
|
+
removeOption,
|
|
349
361
|
disabled: !!disabled,
|
|
350
362
|
handleToggleClick,
|
|
351
363
|
handleInputChange,
|
|
@@ -357,8 +369,8 @@ function useAutocomplete(props) {
|
|
|
357
369
|
}
|
|
358
370
|
var MARGIN = 16;
|
|
359
371
|
function useDropdownPosition(anchor, menuRef) {
|
|
360
|
-
const [position, setPosition] =
|
|
361
|
-
|
|
372
|
+
const [position, setPosition] = React2.useState(null);
|
|
373
|
+
React2.useLayoutEffect(() => {
|
|
362
374
|
let mounted = true;
|
|
363
375
|
let ro = null;
|
|
364
376
|
let rafId = null;
|
|
@@ -478,6 +490,7 @@ function Autocomplete(props) {
|
|
|
478
490
|
isEqual,
|
|
479
491
|
selectOption,
|
|
480
492
|
clearValue,
|
|
493
|
+
removeOption,
|
|
481
494
|
disabled: isDisabled,
|
|
482
495
|
handleToggleClick,
|
|
483
496
|
handleInputChange,
|
|
@@ -485,22 +498,34 @@ function Autocomplete(props) {
|
|
|
485
498
|
handleInputBlur,
|
|
486
499
|
handleKeyDown
|
|
487
500
|
} = useAutocomplete(props);
|
|
488
|
-
const
|
|
501
|
+
const onRemove = React2__default.default.useCallback(
|
|
502
|
+
(event, index) => {
|
|
503
|
+
event.stopPropagation();
|
|
504
|
+
const option = selectedValues[index];
|
|
505
|
+
if (!option || !removeOption) return;
|
|
506
|
+
removeOption(event, option);
|
|
507
|
+
},
|
|
508
|
+
[removeOption, selectedValues]
|
|
509
|
+
);
|
|
510
|
+
const listboxId = React2.useMemo(
|
|
489
511
|
() => `autocomplete-listbox-${Math.random().toString(36).slice(2, 9)}`,
|
|
490
512
|
[]
|
|
491
513
|
);
|
|
492
|
-
const startAdornment =
|
|
514
|
+
const startAdornment = React2.useMemo(() => {
|
|
493
515
|
if (!multiple || selectedValues.length === 0) return void 0;
|
|
494
|
-
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-wrap gap-1", children: selectedValues.map((option, index) => /* @__PURE__ */ jsxRuntime.
|
|
516
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-wrap gap-1", children: selectedValues.map((option, index) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
495
517
|
"span",
|
|
496
518
|
{
|
|
497
|
-
className: "inline-flex items-center rounded-full bg-slate-100 px-2 py-0.5 text-xs text-slate-700",
|
|
498
|
-
children:
|
|
519
|
+
className: "inline-flex gap-2 items-center rounded-full bg-slate-100 px-2 py-0.5 text-xs text-slate-700",
|
|
520
|
+
children: [
|
|
521
|
+
getLabel(option),
|
|
522
|
+
/* @__PURE__ */ jsxRuntime.jsx(Button, { type: "button", className: "w-4", onClick: (event) => onRemove(event, index), children: /* @__PURE__ */ jsxRuntime.jsx("svg", { focusable: "false", "aria-hidden": "true", viewBox: "0 0 24 24", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M12 2C6.47 2 2 6.47 2 12s4.47 10 10 10 10-4.47 10-10S17.53 2 12 2zm5 13.59L15.59 17 12 13.41 8.41 17 7 15.59 10.59 12 7 8.41 8.41 7 12 10.59 15.59 7 17 8.41 13.41 12 17 15.59z" }) }) })
|
|
523
|
+
]
|
|
499
524
|
},
|
|
500
525
|
`${getLabel(option)}-${index}`
|
|
501
526
|
)) });
|
|
502
|
-
}, [multiple,
|
|
503
|
-
const endAdornment =
|
|
527
|
+
}, [getLabel, multiple, onRemove, selectedValues]);
|
|
528
|
+
const endAdornment = React2.useMemo(() => {
|
|
504
529
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center absolute right-3", children: [
|
|
505
530
|
inputValue ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
506
531
|
Button,
|
|
@@ -564,7 +589,7 @@ function Autocomplete(props) {
|
|
|
564
589
|
)
|
|
565
590
|
] });
|
|
566
591
|
}, [clearValue, handleToggleClick, inputValue, isDisabled, loading, open]);
|
|
567
|
-
const inputParams =
|
|
592
|
+
const inputParams = React2.useMemo(
|
|
568
593
|
() => ({
|
|
569
594
|
...props,
|
|
570
595
|
options: void 0,
|
|
@@ -584,7 +609,6 @@ function Autocomplete(props) {
|
|
|
584
609
|
onBlur: handleInputBlur,
|
|
585
610
|
disabled: isDisabled,
|
|
586
611
|
InputProps: {
|
|
587
|
-
startAdornment,
|
|
588
612
|
endAdornment,
|
|
589
613
|
className: "min-h-[40px]"
|
|
590
614
|
}
|
|
@@ -607,7 +631,7 @@ function Autocomplete(props) {
|
|
|
607
631
|
if (!renderInput) {
|
|
608
632
|
return /* @__PURE__ */ jsxRuntime.jsx("p", { children: "Render Input Prop Must be pass " });
|
|
609
633
|
}
|
|
610
|
-
const wrapperRef =
|
|
634
|
+
const wrapperRef = React2.useRef(null);
|
|
611
635
|
const { position } = useDropdownPosition(() => rootRef.current, listboxRef);
|
|
612
636
|
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
613
637
|
"div",
|
|
@@ -620,7 +644,10 @@ function Autocomplete(props) {
|
|
|
620
644
|
},
|
|
621
645
|
className: `${className} [&_.input-container]:pe-[54px] [&_.input-container]:gap-0`,
|
|
622
646
|
children: [
|
|
623
|
-
|
|
647
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-2", children: [
|
|
648
|
+
startAdornment,
|
|
649
|
+
renderInput(inputParams)
|
|
650
|
+
] }),
|
|
624
651
|
open || open && loading ? (() => {
|
|
625
652
|
const portalNode = document.body;
|
|
626
653
|
const dropdown = /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -643,7 +670,7 @@ function Autocomplete(props) {
|
|
|
643
670
|
id: listboxId,
|
|
644
671
|
ref: listboxRef,
|
|
645
672
|
role: "listbox",
|
|
646
|
-
className: "max-h-60
|
|
673
|
+
className: "max-h-60 sm:max-h-[325px] w-full overflow-auto ",
|
|
647
674
|
children: loading ? /* @__PURE__ */ jsxRuntime.jsxs(
|
|
648
675
|
"svg",
|
|
649
676
|
{
|
|
@@ -677,7 +704,7 @@ function Autocomplete(props) {
|
|
|
677
704
|
id: `autocomplete-option-${index}`,
|
|
678
705
|
role: "option",
|
|
679
706
|
"aria-selected": selected,
|
|
680
|
-
className: "cursor-pointer px-3 py-2 text-sm text-slate-700 hover:bg-slate-100 " + (index === activeIndex ? "bg-slate-100" : ""),
|
|
707
|
+
className: "cursor-pointer px-3 py-2 text-sm text-slate-700 hover:bg-slate-100 " + (index === activeIndex ? "bg-slate-100 " : "") + (selected ? "bg-slate-50 font-medium text-slate-900" : ""),
|
|
681
708
|
onMouseDown: (event) => event.preventDefault(),
|
|
682
709
|
onClick: (event) => selectOption(event, option)
|
|
683
710
|
};
|
|
@@ -700,7 +727,7 @@ function Autocomplete(props) {
|
|
|
700
727
|
}
|
|
701
728
|
);
|
|
702
729
|
}
|
|
703
|
-
var TextField =
|
|
730
|
+
var TextField = React2.forwardRef(
|
|
704
731
|
({
|
|
705
732
|
value,
|
|
706
733
|
defaultValue,
|
|
@@ -727,10 +754,10 @@ var TextField = react.forwardRef(
|
|
|
727
754
|
}, ref) => {
|
|
728
755
|
var _a;
|
|
729
756
|
const InputComponent = (_a = InputProps == null ? void 0 : InputProps.inputComponent) != null ? _a : multiline ? "textarea" : "input";
|
|
730
|
-
const reactId =
|
|
757
|
+
const reactId = React2.useId();
|
|
731
758
|
const inputId = id != null ? id : `textfield-${reactId}`;
|
|
732
759
|
const isControlled = value !== void 0;
|
|
733
|
-
const [focused, setFocused] =
|
|
760
|
+
const [focused, setFocused] = React2.useState(false);
|
|
734
761
|
const handleChange = (event) => {
|
|
735
762
|
onChange == null ? void 0 : onChange(event);
|
|
736
763
|
};
|
|
@@ -742,7 +769,7 @@ var TextField = react.forwardRef(
|
|
|
742
769
|
setFocused(false);
|
|
743
770
|
onBlur == null ? void 0 : onBlur(event);
|
|
744
771
|
};
|
|
745
|
-
const sizeClasses =
|
|
772
|
+
const sizeClasses = React2.useMemo(() => {
|
|
746
773
|
if (size === "small") {
|
|
747
774
|
return {
|
|
748
775
|
container: `${multiline ? "min-h-10" : "h-[45px]"} text-sm`,
|
|
@@ -899,7 +926,7 @@ var tokens = {
|
|
|
899
926
|
};
|
|
900
927
|
var styles_default = tokens;
|
|
901
928
|
var defaultTheme = styles_default;
|
|
902
|
-
var ThemeContext =
|
|
929
|
+
var ThemeContext = React2.createContext(defaultTheme);
|
|
903
930
|
var ThemeProvider = ({
|
|
904
931
|
theme,
|
|
905
932
|
children
|
|
@@ -918,7 +945,7 @@ var ThemeProvider = ({
|
|
|
918
945
|
};
|
|
919
946
|
return /* @__PURE__ */ jsxRuntime.jsx(ThemeContext.Provider, { value: mergedTheme, children });
|
|
920
947
|
};
|
|
921
|
-
var useTheme = () =>
|
|
948
|
+
var useTheme = () => React2.useContext(ThemeContext);
|
|
922
949
|
|
|
923
950
|
// src/index.ts
|
|
924
951
|
var cssFile = "./styles.css";
|