corestack-ui 0.2.0 → 0.2.2

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 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 react = require('react');
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 = react.useCallback(
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 = react.useCallback(
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] = react.useState(() => {
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] = react.useState(false);
124
- const [inputValue, setInputValue] = react.useState(() => {
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] = react.useState(-1);
129
- const rootRef = react.useRef(null);
130
- const inputRef = react.useRef(null);
131
- const listboxRef = react.useRef(null);
132
- const isFocusedRef = react.useRef(false);
133
- const blurTimeoutRef = react.useRef(null);
134
- const filteredOptions = react.useMemo(() => {
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 = react.useMemo(() => {
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
- react.useEffect(() => {
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 = react.useCallback(
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 = react.useCallback(
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 = react.useCallback(
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 setInputFocused = react.useCallback((focused) => {
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
- react.useEffect(() => {
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
- react.useEffect(() => {
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 = react.useCallback(
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 = react.useCallback(
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 = react.useCallback(
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 = react.useCallback(
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 = react.useCallback(
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] = react.useState(null);
361
- react.useLayoutEffect(() => {
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,23 +498,43 @@ function Autocomplete(props) {
485
498
  handleInputBlur,
486
499
  handleKeyDown
487
500
  } = useAutocomplete(props);
488
- const listboxId = react.useMemo(
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 = react.useMemo(() => {
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.jsx(
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: getLabel(option)
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(
523
+ Button,
524
+ {
525
+ type: "button",
526
+ className: "w-4",
527
+ onClick: (event) => onRemove(event, index),
528
+ 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" }) })
529
+ }
530
+ )
531
+ ]
499
532
  },
500
533
  `${getLabel(option)}-${index}`
501
534
  )) });
502
- }, [multiple, selectedValues, getLabel]);
503
- const endAdornment = react.useMemo(() => {
504
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center absolute right-3", children: [
535
+ }, [getLabel, multiple, onRemove, selectedValues]);
536
+ const endAdornment = React2.useMemo(() => {
537
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center absolute rtl:left-3 ltr:right-3", children: [
505
538
  inputValue ? /* @__PURE__ */ jsxRuntime.jsx(
506
539
  Button,
507
540
  {
@@ -564,7 +597,7 @@ function Autocomplete(props) {
564
597
  )
565
598
  ] });
566
599
  }, [clearValue, handleToggleClick, inputValue, isDisabled, loading, open]);
567
- const inputParams = react.useMemo(
600
+ const inputParams = React2.useMemo(
568
601
  () => ({
569
602
  ...props,
570
603
  options: void 0,
@@ -584,7 +617,6 @@ function Autocomplete(props) {
584
617
  onBlur: handleInputBlur,
585
618
  disabled: isDisabled,
586
619
  InputProps: {
587
- startAdornment,
588
620
  endAdornment,
589
621
  className: "min-h-[40px]"
590
622
  }
@@ -607,7 +639,7 @@ function Autocomplete(props) {
607
639
  if (!renderInput) {
608
640
  return /* @__PURE__ */ jsxRuntime.jsx("p", { children: "Render Input Prop Must be pass " });
609
641
  }
610
- const wrapperRef = react.useRef(null);
642
+ const wrapperRef = React2.useRef(null);
611
643
  const { position } = useDropdownPosition(() => rootRef.current, listboxRef);
612
644
  return /* @__PURE__ */ jsxRuntime.jsxs(
613
645
  "div",
@@ -618,9 +650,12 @@ function Autocomplete(props) {
618
650
  setOpen(true);
619
651
  }
620
652
  },
621
- className: `${className} [&_.input-container]:pe-[54px] [&_.input-container]:gap-0`,
653
+ className: `${className != null ? className : ""} [&_.input-container]:pe-[54px] [&_.input-container]:gap-0`,
622
654
  children: [
623
- renderInput(inputParams),
655
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-2", children: [
656
+ startAdornment,
657
+ renderInput(inputParams)
658
+ ] }),
624
659
  open || open && loading ? (() => {
625
660
  const portalNode = document.body;
626
661
  const dropdown = /* @__PURE__ */ jsxRuntime.jsx(
@@ -643,7 +678,7 @@ function Autocomplete(props) {
643
678
  id: listboxId,
644
679
  ref: listboxRef,
645
680
  role: "listbox",
646
- className: "max-h-60 sm:max-h-[530px] w-full overflow-auto ",
681
+ className: "max-h-60 sm:max-h-[325px] w-full overflow-auto ",
647
682
  children: loading ? /* @__PURE__ */ jsxRuntime.jsxs(
648
683
  "svg",
649
684
  {
@@ -677,7 +712,7 @@ function Autocomplete(props) {
677
712
  id: `autocomplete-option-${index}`,
678
713
  role: "option",
679
714
  "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" : ""),
715
+ className: "cursor-pointer px-3 py-2 text-sm text-slate-700 hover:bg-slate-100 " + (index === activeIndex ? "bg-slate-100 " : "") + (selected ? "bg-slate-100 font-medium text-slate-900" : ""),
681
716
  onMouseDown: (event) => event.preventDefault(),
682
717
  onClick: (event) => selectOption(event, option)
683
718
  };
@@ -700,7 +735,7 @@ function Autocomplete(props) {
700
735
  }
701
736
  );
702
737
  }
703
- var TextField = react.forwardRef(
738
+ var TextField = React2.forwardRef(
704
739
  ({
705
740
  value,
706
741
  defaultValue,
@@ -727,10 +762,10 @@ var TextField = react.forwardRef(
727
762
  }, ref) => {
728
763
  var _a;
729
764
  const InputComponent = (_a = InputProps == null ? void 0 : InputProps.inputComponent) != null ? _a : multiline ? "textarea" : "input";
730
- const reactId = react.useId();
765
+ const reactId = React2.useId();
731
766
  const inputId = id != null ? id : `textfield-${reactId}`;
732
767
  const isControlled = value !== void 0;
733
- const [focused, setFocused] = react.useState(false);
768
+ const [focused, setFocused] = React2.useState(false);
734
769
  const handleChange = (event) => {
735
770
  onChange == null ? void 0 : onChange(event);
736
771
  };
@@ -742,7 +777,7 @@ var TextField = react.forwardRef(
742
777
  setFocused(false);
743
778
  onBlur == null ? void 0 : onBlur(event);
744
779
  };
745
- const sizeClasses = react.useMemo(() => {
780
+ const sizeClasses = React2.useMemo(() => {
746
781
  if (size === "small") {
747
782
  return {
748
783
  container: `${multiline ? "min-h-10" : "h-[45px]"} text-sm`,
@@ -899,7 +934,7 @@ var tokens = {
899
934
  };
900
935
  var styles_default = tokens;
901
936
  var defaultTheme = styles_default;
902
- var ThemeContext = react.createContext(defaultTheme);
937
+ var ThemeContext = React2.createContext(defaultTheme);
903
938
  var ThemeProvider = ({
904
939
  theme,
905
940
  children
@@ -918,7 +953,7 @@ var ThemeProvider = ({
918
953
  };
919
954
  return /* @__PURE__ */ jsxRuntime.jsx(ThemeContext.Provider, { value: mergedTheme, children });
920
955
  };
921
- var useTheme = () => react.useContext(ThemeContext);
956
+ var useTheme = () => React2.useContext(ThemeContext);
922
957
 
923
958
  // src/index.ts
924
959
  var cssFile = "./styles.css";