@yamada-ui/react 2.1.1 → 2.1.2-dev-20260304113314
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/cjs/components/autocomplete/use-autocomplete.cjs +9 -7
- package/dist/cjs/components/autocomplete/use-autocomplete.cjs.map +1 -1
- package/dist/esm/components/autocomplete/use-autocomplete.js +9 -7
- package/dist/esm/components/autocomplete/use-autocomplete.js.map +1 -1
- package/dist/types/components/accordion/accordion.d.ts +2 -2
- package/dist/types/components/accordion/accordion.style.d.ts +1 -1
- package/dist/types/components/accordion/use-accordion.d.ts +11 -11
- package/dist/types/components/airy/airy.d.ts +2 -2
- package/dist/types/components/alert/alert.d.ts +2 -2
- package/dist/types/components/alpha-slider/alpha-slider.d.ts +2 -2
- package/dist/types/components/aspect-ratio/aspect-ratio.d.ts +2 -2
- package/dist/types/components/autocomplete/autocomplete.d.ts +2 -2
- package/dist/types/components/autocomplete/use-autocomplete.d.ts +5 -5
- package/dist/types/components/avatar/avatar.d.ts +5 -5
- package/dist/types/components/avatar/avatar.style.d.ts +1 -1
- package/dist/types/components/avatar/use-avatar-group.d.ts +2 -2
- package/dist/types/components/badge/badge.d.ts +2 -2
- package/dist/types/components/bleed/bleed.d.ts +2 -2
- package/dist/types/components/blockquote/blockquote.d.ts +2 -2
- package/dist/types/components/breadcrumb/breadcrumb.d.ts +2 -2
- package/dist/types/components/breadcrumb/breadcrumb.style.d.ts +1 -1
- package/dist/types/components/breadcrumb/use-breadcrumb.d.ts +2 -2
- package/dist/types/components/button/button.d.ts +2 -2
- package/dist/types/components/button/icon-button.d.ts +2 -2
- package/dist/types/components/calendar/calendar.d.ts +2 -2
- package/dist/types/components/calendar/calendar.style.d.ts +2 -2
- package/dist/types/components/calendar/use-calendar.d.ts +8 -8
- package/dist/types/components/card/card.d.ts +2 -2
- package/dist/types/components/carousel/carousel.d.ts +2 -2
- package/dist/types/components/carousel/carousel.style.d.ts +2 -2
- package/dist/types/components/carousel/use-carousel.d.ts +3 -3
- package/dist/types/components/center/center.d.ts +2 -2
- package/dist/types/components/chart/chart.d.ts +2 -2
- package/dist/types/components/chart/use-chart.d.ts +2 -2
- package/dist/types/components/checkbox/checkbox.d.ts +4 -4
- package/dist/types/components/checkbox/use-checkbox-group.d.ts +2 -2
- package/dist/types/components/checkbox-card/checkbox-card.d.ts +4 -4
- package/dist/types/components/circle-progress/circle-progress.d.ts +2 -2
- package/dist/types/components/close-button/close-button.d.ts +2 -2
- package/dist/types/components/code/code.d.ts +2 -2
- package/dist/types/components/collapse/collapse.d.ts +2 -2
- package/dist/types/components/color-picker/color-picker.d.ts +2 -2
- package/dist/types/components/color-picker/use-color-picker.d.ts +2 -2
- package/dist/types/components/color-selector/color-selector.d.ts +2 -2
- package/dist/types/components/color-selector/use-color-selector.d.ts +3 -3
- package/dist/types/components/color-swatch/color-swatch.d.ts +2 -2
- package/dist/types/components/container/container.d.ts +2 -2
- package/dist/types/components/data-list/data-list.d.ts +2 -2
- package/dist/types/components/data-list/data-list.style.d.ts +1 -1
- package/dist/types/components/date-picker/date-picker.d.ts +2 -2
- package/dist/types/components/date-picker/use-date-picker.d.ts +4 -4
- package/dist/types/components/drawer/drawer.d.ts +2 -2
- package/dist/types/components/dropzone/dropzone.d.ts +2 -2
- package/dist/types/components/editable/editable.d.ts +4 -4
- package/dist/types/components/editable/use-editable.d.ts +2 -2
- package/dist/types/components/em/em.d.ts +2 -2
- package/dist/types/components/empty-state/empty-state.d.ts +2 -2
- package/dist/types/components/fade/fade.d.ts +2 -2
- package/dist/types/components/field/field.d.ts +3 -3
- package/dist/types/components/field/use-field-props.d.ts +3 -3
- package/dist/types/components/fieldset/fieldset.d.ts +3 -3
- package/dist/types/components/file-button/file-button.d.ts +2 -2
- package/dist/types/components/file-button/use-file-button.d.ts +18 -18
- package/dist/types/components/file-input/file-input.d.ts +2 -2
- package/dist/types/components/file-input/use-file-input.d.ts +15 -15
- package/dist/types/components/flex/flex.d.ts +2 -2
- package/dist/types/components/flip/flip.d.ts +3 -3
- package/dist/types/components/flip/flip.style.d.ts +1 -1
- package/dist/types/components/float/float.d.ts +2 -2
- package/dist/types/components/form/form.d.ts +3 -3
- package/dist/types/components/format/format-byte.d.ts +4 -4
- package/dist/types/components/format/format-date-time.d.ts +4 -4
- package/dist/types/components/format/format-number.d.ts +2 -2
- package/dist/types/components/grid/grid-item.d.ts +2 -2
- package/dist/types/components/grid/grid.d.ts +2 -2
- package/dist/types/components/group/group.d.ts +2 -2
- package/dist/types/components/group/use-group.d.ts +2 -2
- package/dist/types/components/heading/heading.d.ts +2 -2
- package/dist/types/components/hue-slider/hue-slider.d.ts +3 -3
- package/dist/types/components/icon/icon.d.ts +5 -5
- package/dist/types/components/image/image.d.ts +2 -2
- package/dist/types/components/indicator/indicator.d.ts +4 -4
- package/dist/types/components/infinite-scroll-area/infinite-scroll-area.d.ts +2 -2
- package/dist/types/components/infinite-scroll-area/infinite-scroll-area.style.d.ts +2 -2
- package/dist/types/components/input/input-addon.d.ts +2 -2
- package/dist/types/components/input/input-element.d.ts +2 -2
- package/dist/types/components/input/input.d.ts +2 -2
- package/dist/types/components/kbd/kbd.d.ts +2 -2
- package/dist/types/components/link/link.d.ts +2 -2
- package/dist/types/components/link-box/link-box.d.ts +2 -2
- package/dist/types/components/list/list.d.ts +2 -2
- package/dist/types/components/list/list.style.d.ts +2 -2
- package/dist/types/components/loading/loading-provider.d.ts +2 -2
- package/dist/types/components/loading/loading.d.ts +3 -3
- package/dist/types/components/mark/mark.d.ts +2 -2
- package/dist/types/components/menu/menu.d.ts +2 -2
- package/dist/types/components/menu/menu.style.d.ts +2 -2
- package/dist/types/components/menu/use-menu.d.ts +11 -11
- package/dist/types/components/modal/modal.d.ts +2 -2
- package/dist/types/components/native-accordion/native-accordion.d.ts +2 -2
- package/dist/types/components/native-accordion/native-accordion.style.d.ts +2 -2
- package/dist/types/components/native-accordion/use-native-accordion.d.ts +2 -2
- package/dist/types/components/native-popover/native-popover.d.ts +2 -2
- package/dist/types/components/native-select/native-select.d.ts +2 -2
- package/dist/types/components/native-table/native-table.d.ts +4 -4
- package/dist/types/components/notice/notice.style.d.ts +1 -1
- package/dist/types/components/number-input/number-input.d.ts +2 -2
- package/dist/types/components/number-input/number-input.style.d.ts +1 -1
- package/dist/types/components/pagination/pagination.d.ts +2 -2
- package/dist/types/components/pagination/pagination.style.d.ts +1 -1
- package/dist/types/components/pagination/use-pagination.d.ts +2 -2
- package/dist/types/components/password-input/password-input.d.ts +2 -2
- package/dist/types/components/password-input/strength-meter.d.ts +2 -2
- package/dist/types/components/password-input/use-password-input.d.ts +2 -2
- package/dist/types/components/pin-input/pin-input.d.ts +2 -2
- package/dist/types/components/pin-input/use-pin-input.d.ts +7 -7
- package/dist/types/components/popover/popover.d.ts +2 -2
- package/dist/types/components/progress/progress.d.ts +2 -2
- package/dist/types/components/progress/use-progress.d.ts +706 -706
- package/dist/types/components/qr-code/qr-code.d.ts +2 -2
- package/dist/types/components/radio/radio.d.ts +4 -4
- package/dist/types/components/radio/use-radio-group.d.ts +2 -2
- package/dist/types/components/radio-card/radio-card.d.ts +4 -4
- package/dist/types/components/rating/rating.style.d.ts +2 -2
- package/dist/types/components/rating/use-rating.d.ts +7 -7
- package/dist/types/components/reorder/reorder.d.ts +2 -2
- package/dist/types/components/reorder/reorder.style.d.ts +1 -1
- package/dist/types/components/reorder/use-reorder.d.ts +3 -3
- package/dist/types/components/resizable/resizable.d.ts +2 -2
- package/dist/types/components/resizable/resizable.style.d.ts +2 -2
- package/dist/types/components/resizable/use-resizable.d.ts +2 -2
- package/dist/types/components/ripple/ripple.d.ts +2 -2
- package/dist/types/components/ripple/use-ripple.d.ts +2 -2
- package/dist/types/components/rotate/rotate.d.ts +2 -2
- package/dist/types/components/saturation-slider/saturation-slider.d.ts +2 -2
- package/dist/types/components/saturation-slider/use-saturation-slider.d.ts +2 -2
- package/dist/types/components/scroll-area/scroll-area.d.ts +2 -2
- package/dist/types/components/segmented-control/segmented-control.d.ts +2 -2
- package/dist/types/components/segmented-control/segmented-control.style.d.ts +2 -2
- package/dist/types/components/segmented-control/use-segmented-control.d.ts +9 -9
- package/dist/types/components/select/select.d.ts +2 -2
- package/dist/types/components/select/use-select.d.ts +4 -4
- package/dist/types/components/separator/separator.d.ts +2 -2
- package/dist/types/components/simple-grid/simple-grid.d.ts +2 -2
- package/dist/types/components/skeleton/skeleton.d.ts +2 -2
- package/dist/types/components/slide/slide.d.ts +2 -2
- package/dist/types/components/slide-fade/slide-fade.d.ts +2 -2
- package/dist/types/components/slider/slider.d.ts +2 -2
- package/dist/types/components/slider/use-slider.d.ts +2 -2
- package/dist/types/components/stack/h-stack.d.ts +2 -2
- package/dist/types/components/stack/stack.d.ts +2 -2
- package/dist/types/components/stack/v-stack.d.ts +2 -2
- package/dist/types/components/stack/z-stack.d.ts +2 -2
- package/dist/types/components/stat/stat.d.ts +2 -2
- package/dist/types/components/status/status.d.ts +2 -2
- package/dist/types/components/steps/steps.d.ts +2 -2
- package/dist/types/components/steps/steps.style.d.ts +1 -1
- package/dist/types/components/steps/use-steps.d.ts +10 -10
- package/dist/types/components/switch/switch.d.ts +2 -2
- package/dist/types/components/table/table.d.ts +2 -2
- package/dist/types/components/tabs/tabs.d.ts +2 -2
- package/dist/types/components/tabs/use-tabs.d.ts +16 -16
- package/dist/types/components/tag/tag.d.ts +2 -2
- package/dist/types/components/tag/tag.style.d.ts +1 -1
- package/dist/types/components/text/text.d.ts +2 -2
- package/dist/types/components/textarea/textarea.d.ts +2 -2
- package/dist/types/components/textarea/use-autosize.d.ts +2 -2
- package/dist/types/components/timeline/timeline.d.ts +5 -5
- package/dist/types/components/timeline/timeline.style.d.ts +2 -2
- package/dist/types/components/toggle/toggle.d.ts +5 -5
- package/dist/types/components/toggle/use-toggle-group.d.ts +2 -2
- package/dist/types/components/toggle/use-toggle.d.ts +2 -2
- package/dist/types/components/tooltip/tooltip.d.ts +2 -2
- package/dist/types/components/visually-hidden/visually-hidden.d.ts +2 -2
- package/dist/types/components/wrap/wrap.d.ts +2 -2
- package/dist/types/core/components/create-component.d.ts +7 -7
- package/dist/types/core/system/color-mode-provider.d.ts +2 -2
- package/dist/types/core/system/styled.d.ts +2 -2
- package/dist/types/core/system/system-provider.d.ts +2 -2
- package/dist/types/hooks/use-breakpoint/use-breakpoint-state.d.ts +2 -2
- package/dist/types/hooks/use-counter/index.d.ts +2 -2
- package/dist/types/hooks/use-descendants/index.d.ts +2 -2
- package/dist/types/providers/i18n-provider/i18n-provider.d.ts +3 -3
- package/dist/types/providers/ui-provider/ui-provider.d.ts +2 -2
- package/dist/types/utils/children.d.ts +2 -2
- package/package.json +1 -1
|
@@ -248,14 +248,16 @@ const useAutocomplete = (props = {}) => {
|
|
|
248
248
|
descendants.enabledFirstValue
|
|
249
249
|
]);
|
|
250
250
|
const onBlur = (0, react.useCallback)((ev) => {
|
|
251
|
-
setFocused(false);
|
|
252
251
|
if ((0, require_utils_index.utils_exports.contains)(fieldRef.current, ev.relatedTarget) || (0, require_utils_index.utils_exports.contains)(contentRef.current, ev.relatedTarget)) ev.preventDefault();
|
|
253
|
-
else
|
|
254
|
-
|
|
255
|
-
if (
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
252
|
+
else {
|
|
253
|
+
setFocused(false);
|
|
254
|
+
if ((0, require_utils_index.utils_exports.isArray)(value)) setInputValue("");
|
|
255
|
+
else if (allowCustomValue) {
|
|
256
|
+
if (inputValue) setValue(inputValue);
|
|
257
|
+
} else {
|
|
258
|
+
const item = valueMap[value];
|
|
259
|
+
setInputValue(getInputValue(item));
|
|
260
|
+
}
|
|
259
261
|
}
|
|
260
262
|
}, [
|
|
261
263
|
allowCustomValue,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-autocomplete.cjs","names":["defaultRender: AutocompleteItemRender","defaultFilter: AutocompleteFilter","items","item","defaultMatcher: AutocompleteMatcher","createContext","useI18n","useFieldProps","valueMap: { [key: string]: ComboboxItemWithValue }","valueMap","useControllableState","useCombobox","value","onClear","inputValue","isComposing","getRootProps: PropGetter","props","getFieldProps: PropGetter","mergeRefs","ref","getInputProps: PropGetter<\"input\">","visuallyHiddenAttributes","getContentProps: PropGetter","getIconProps: PropGetter","runKeyAction","useComboboxItem"],"sources":["../../../../src/components/autocomplete/use-autocomplete.tsx"],"sourcesContent":["\"use client\"\n\nimport type {\n ChangeEvent,\n FocusEvent,\n KeyboardEvent,\n MouseEvent,\n ReactNode,\n} from \"react\"\nimport type { HTMLProps, HTMLRefAttributes, PropGetter } from \"../../core\"\nimport type {\n ComboboxItem,\n ComboboxItemWithValue,\n UseComboboxItemProps,\n UseComboboxProps,\n} from \"../../hooks/use-combobox\"\nimport type { Dict } from \"../../utils\"\nimport type { FieldProps } from \"../field\"\nimport {\n cloneElement,\n isValidElement,\n useCallback,\n useMemo,\n useRef,\n useState,\n} from \"react\"\nimport { useCombobox, useComboboxItem } from \"../../hooks/use-combobox\"\nimport { useControllableState } from \"../../hooks/use-controllable-state\"\nimport { useI18n } from \"../../providers/i18n-provider\"\nimport {\n ariaAttr,\n cast,\n contains,\n createContext,\n dataAttr,\n handlerAll,\n isArray,\n isComposing,\n isNumber,\n isString,\n isUndefined,\n mergeRefs,\n runIfFn,\n runKeyAction,\n useUpdateEffect,\n visuallyHiddenAttributes,\n} from \"../../utils\"\nimport { useFieldProps } from \"../field\"\n\ninterface AutocompleteRenderProps extends ComboboxItemWithValue {\n count: number\n focused: boolean\n index: number\n separator: string\n onClear: () => void\n max?: number\n}\n\nexport interface AutocompleteItemRender {\n (props: AutocompleteRenderProps): ReactNode\n}\n\nconst defaultRender: AutocompleteItemRender = ({\n count,\n focused,\n index,\n label,\n max,\n separator,\n}) => {\n const last = count - 1 === index\n\n return (\n <span style={{ marginInlineEnd: \"var(--gap)\" }}>\n {label}\n {((!isNumber(max) || count < max) && focused) || !last ? separator : null}\n </span>\n )\n}\n\nconst getInputValue = (item?: ComboboxItemWithValue) =>\n isString(item?.label) ? item.label : (item?.query ?? \"\")\n\nexport interface AutocompleteFilter {\n (\n inputValue: string,\n items: ComboboxItem[],\n matcher: AutocompleteMatcher,\n ): ComboboxItem[]\n}\n\nconst defaultFilter: AutocompleteFilter = (inputValue, items, matcher) => {\n if (!inputValue.length) return items\n\n return items\n .map((item) => {\n if (\"items\" in item) {\n const items = item.items.filter((item) => {\n if (\"query\" in item) {\n return matcher(inputValue, item.query)\n } else if (isString(item.label)) {\n return matcher(inputValue, item.label)\n }\n })\n\n if (items.length) return { ...item, items }\n } else if (\"query\" in item) {\n if (matcher(inputValue, item.query)) return item\n } else if (isString(item.label)) {\n if (matcher(inputValue, item.label)) return item\n }\n })\n .filter(Boolean) as ComboboxItem[]\n}\n\nexport interface AutocompleteMatcher {\n (input: string, target?: string): boolean\n}\n\nconst defaultMatcher: AutocompleteMatcher = (input, target) =>\n target?.toLowerCase().includes(input.toLowerCase()) ?? false\n\ninterface AutocompleteContext extends Pick<\n UseAutocompleteReturn,\n \"max\" | \"value\"\n> {}\n\nconst [AutocompleteContext, useAutocompleteContext] =\n createContext<AutocompleteContext>({\n name: \"AutocompleteContext\",\n })\n\nexport { AutocompleteContext, useAutocompleteContext }\n\nexport interface UseAutocompleteProps<Multiple extends boolean = false>\n extends\n Omit<HTMLProps, \"defaultValue\" | \"onChange\" | \"ref\" | \"value\">,\n Omit<\n UseComboboxProps,\n \"defaultValue\" | \"initialFocusValue\" | \"onChange\" | \"ref\" | \"value\"\n >,\n HTMLRefAttributes<\"input\">,\n FieldProps {\n /**\n * If `true`, the autocomplete will allow custom value.\n *\n * @default false\n */\n allowCustomValue?: boolean\n /**\n * If `true`, the autocomplete will be closed when the input value changes.\n *\n * @default false\n */\n closeOnChange?: ((ev: ChangeEvent<HTMLInputElement>) => boolean) | boolean\n /**\n * The initial value of the input.\n */\n defaultInputValue?: string\n /**\n * The initial value of the autocomplete.\n */\n defaultValue?: Multiple extends true ? string[] : string\n /**\n * The message displayed when the search yields no hits.\n *\n * @default 'No results found'\n */\n emptyMessage?: ReactNode\n /**\n * The function to filter the items.\n */\n filter?: AutocompleteFilter\n /**\n * If `true`, the input will be focused when the clear icon is clicked.\n *\n * @default true\n */\n focusOnClear?: boolean\n /**\n * The `id` attribute of the input element.\n */\n id?: string\n /**\n * The value of the input.\n */\n inputValue?: string\n /**\n * If provided, generate options based on items.\n *\n * @default []\n */\n items?: ComboboxItem[]\n /**\n * The function to match the items.\n */\n matcher?: AutocompleteMatcher\n /**\n * The maximum selectable value.\n */\n max?: number\n /**\n * If `true`, the autocomplete will be multiple.\n *\n * @default false\n */\n multiple?: Multiple\n /**\n * The `name` attribute of the input element.\n */\n name?: string\n /**\n * If `true`, the autocomplete will be opened when the input value changes.\n *\n * @default true\n */\n openOnChange?: ((ev: ChangeEvent<HTMLInputElement>) => boolean) | boolean\n /**\n * If `true`, the autocomplete will be opened when the input is focused.\n *\n * @default true\n */\n openOnFocus?: boolean\n /**\n * The placeholder for autocomplete.\n */\n placeholder?: string\n /**\n * The visual separator between each value.\n *\n * @default ','\n */\n separator?: string\n /**\n * The value of the autocomplete.\n */\n value?: Multiple extends true ? string[] : string\n /**\n * The callback invoked when value state changes.\n */\n onChange?: (value: Multiple extends true ? string[] : string) => void\n /**\n * The callback invoked when input value state changes.\n */\n onInputChange?: (value: string) => void\n /**\n * The function to render the selected items.\n */\n render?: (props: AutocompleteRenderProps) => ReactNode\n}\n\nexport const useAutocomplete = <Multiple extends boolean = false>(\n props: UseAutocompleteProps<Multiple> = {},\n) => {\n type MaybeValue = Multiple extends true ? string[] : string\n\n const { t } = useI18n(\"autocomplete\")\n const {\n props: {\n id,\n ref,\n name,\n allowCustomValue = false,\n closeOnChange = false,\n multiple = false,\n closeOnSelect = !multiple,\n defaultInputValue,\n defaultValue = (multiple ? [] : \"\") as MaybeValue,\n disabled,\n emptyMessage = t(\"No results found\"),\n filter = defaultFilter,\n focusOnClear = true,\n inputValue: inputValueProp,\n items = [],\n matcher = defaultMatcher,\n max,\n openOnChange = true,\n openOnClick = true,\n openOnFocus = true,\n placeholder,\n readOnly,\n render = defaultRender,\n required,\n separator = \",\",\n value: valueProp,\n onChange: onChangeProp,\n onInputChange: onInputChangeProp,\n ...rest\n },\n ariaProps,\n dataProps,\n eventProps,\n } = useFieldProps(props)\n const fieldRef = useRef<HTMLDivElement>(null)\n const contentRef = useRef<HTMLDivElement>(null)\n const inputRef = useRef<HTMLInputElement>(null)\n const focusByClickRef = useRef<boolean>(false)\n const valueMap = useMemo<{ [key: string]: ComboboxItemWithValue }>(() => {\n const valueMap: { [key: string]: ComboboxItemWithValue } = {}\n\n items.forEach((item) => {\n if (\"items\" in item) {\n item.items.forEach((item) => {\n item.value ??= isString(item.label) ? item.label : undefined\n\n if (!isUndefined(item.value)) valueMap[item.value] = item\n })\n } else {\n item.value ??= isString(item.label) ? item.label : undefined\n\n if (!isUndefined(item.value)) valueMap[item.value] = item\n }\n })\n\n return valueMap\n }, [items])\n const [focused, setFocused] = useState(false)\n const [value, setValue] = useControllableState({\n defaultValue,\n value: valueProp,\n onChange: onChangeProp,\n })\n const [inputValue, setInputValue] = useControllableState({\n defaultValue:\n defaultInputValue ??\n getInputValue(isArray(value) ? undefined : valueMap[value as string]),\n value: inputValueProp,\n onChange: onInputChangeProp,\n })\n const onChange = useCallback(\n (selectedValue: string) => {\n setValue((prev) => {\n if (isArray(prev)) {\n if (prev.includes(selectedValue)) {\n return prev.filter(\n (prevValue) => prevValue !== selectedValue,\n ) as MaybeValue\n } else if (!isNumber(max) || prev.length < max) {\n return [...prev, selectedValue] as MaybeValue\n } else {\n return prev\n }\n } else {\n return selectedValue as MaybeValue\n }\n })\n\n if (isArray(value)) {\n setInputValue(\"\")\n } else {\n const item = valueMap[selectedValue]\n\n setInputValue(getInputValue(item))\n }\n },\n [max, setInputValue, setValue, value, valueMap],\n )\n const {\n activeDescendant,\n descendants,\n interactive,\n open,\n getContentProps: getComboboxContentProps,\n getSeparatorProps,\n getTriggerProps,\n popoverProps,\n onActiveDescendant,\n onClose,\n onOpen,\n onOpenWithActiveDescendant,\n onSelect,\n } = useCombobox({\n closeOnSelect,\n disabled,\n initialFocusValue: isArray(value) ? value[0] : value,\n openOnClick: false,\n openOnEnter: false,\n openOnSpace: false,\n readOnly,\n selectFocusRef: inputRef,\n selectOnSpace: false,\n onChange,\n ...ariaProps,\n ...dataProps,\n ...eventProps,\n ...rest,\n })\n const filteredItems = useMemo<ComboboxItem[]>(() => {\n if (!items.length) return []\n\n return filter(inputValue, items, matcher)\n }, [filter, inputValue, items, matcher])\n const resolvedItems = useMemo<ComboboxItem[]>(() => {\n return filteredItems.length\n ? filteredItems\n : [{ \"data-empty\": \"\", label: emptyMessage }]\n }, [filteredItems, emptyMessage])\n const empty = useMemo(\n () => !resolvedItems.filter(({ hidden }) => !hidden).length,\n [resolvedItems],\n )\n const children = useMemo<ReactNode>(() => {\n if (!isArray(value)) return null\n\n const count = value.length\n\n return value.map((value, index) => {\n const item = valueMap[value] ?? { label: value, value }\n\n const onClear = (ev?: MouseEvent<HTMLElement>) => {\n ev?.preventDefault()\n ev?.stopPropagation()\n\n if (item.value) onChange(item.value)\n }\n\n const component = render({\n count,\n focused,\n index,\n max,\n separator,\n onClear,\n ...item,\n })\n\n if (isValidElement<Dict>(component)) {\n return cloneElement(component, { ...component.props, key: index })\n } else {\n return component\n }\n })\n }, [focused, max, onChange, render, separator, value, valueMap])\n const hasValues = isArray(value) && !!value.length\n\n const onInputChange = useCallback(\n (ev: ChangeEvent<HTMLInputElement>) => {\n if (isArray(value) && value.length === max) return\n\n if (runIfFn(closeOnChange, ev)) {\n onClose()\n } else if (runIfFn(openOnChange, ev)) {\n onOpen()\n }\n\n activeDescendant.current = null\n\n const inputValue = ev.target.value\n\n setInputValue(inputValue)\n\n if (inputValue.length || isArray(value)) return\n\n setValue(\"\" as MaybeValue)\n },\n [\n activeDescendant,\n closeOnChange,\n max,\n onClose,\n onOpen,\n openOnChange,\n setInputValue,\n setValue,\n value,\n ],\n )\n\n const onKeyDown = useCallback(\n (ev: KeyboardEvent<HTMLInputElement>) => {\n if (disabled || isComposing(ev)) return\n\n const inputValue = cast<HTMLInputElement>(ev.target).value\n\n runKeyAction(\n ev,\n {\n Backspace: (ev) => {\n if (!isArray(value)) return\n if (!!inputValue.length) return\n\n ev.preventDefault()\n\n setValue((prev) => prev.slice(0, -1) as MaybeValue)\n },\n Enter: (ev) => {\n if (!open || !inputValue.length || activeDescendant.current) return\n\n const item = filteredItems[0]\n\n if (!item) {\n if (!allowCustomValue || !isArray(value)) return\n\n ev.preventDefault()\n\n onSelect(inputValue)\n } else {\n ev.preventDefault()\n\n if (\"items\" in item) {\n onSelect(item.items[0]?.value)\n } else {\n onSelect(item.value)\n }\n }\n },\n },\n { preventDefault: false },\n )\n },\n [\n activeDescendant,\n allowCustomValue,\n disabled,\n filteredItems,\n onSelect,\n open,\n setValue,\n value,\n ],\n )\n\n const onClick = useCallback(() => {\n if (!interactive) return\n\n focusByClickRef.current = true\n\n inputRef.current?.focus()\n\n if (openOnClick) onOpenWithActiveDescendant(descendants.enabledFirstValue)\n }, [descendants, interactive, onOpenWithActiveDescendant, openOnClick])\n\n const onMouseDown = useCallback(\n (ev: MouseEvent<HTMLInputElement>) => {\n if (!openOnFocus) return\n\n ev.preventDefault()\n ev.stopPropagation()\n },\n [openOnFocus],\n )\n\n const onFocus = useCallback(\n (ev: FocusEvent<HTMLInputElement>) => {\n ev.preventDefault()\n ev.stopPropagation()\n\n setFocused(true)\n\n if (openOnFocus && !focusByClickRef.current)\n onOpenWithActiveDescendant(descendants.enabledFirstValue)\n\n focusByClickRef.current = false\n },\n [openOnFocus, onOpenWithActiveDescendant, descendants.enabledFirstValue],\n )\n\n const onBlur = useCallback(\n (ev: FocusEvent<HTMLInputElement>) => {\n setFocused(false)\n\n if (\n contains(fieldRef.current, ev.relatedTarget) ||\n contains(contentRef.current, ev.relatedTarget)\n ) {\n ev.preventDefault()\n } else {\n if (isArray(value)) {\n setInputValue(\"\")\n } else {\n if (allowCustomValue) {\n if (inputValue) setValue(inputValue as MaybeValue)\n } else {\n const item = valueMap[value as string]\n\n setInputValue(getInputValue(item))\n }\n }\n }\n },\n [allowCustomValue, inputValue, setInputValue, setValue, value, valueMap],\n )\n\n const onClear = useCallback(() => {\n if (!interactive) return\n\n setValue((prev) => (isArray(prev) ? [] : \"\") as MaybeValue)\n setInputValue(\"\")\n\n if (focusOnClear) inputRef.current?.focus()\n }, [focusOnClear, interactive, setInputValue, setValue])\n\n useUpdateEffect(() => {\n if (isArray(valueProp)) return\n\n setInputValue(\n getInputValue(valueProp ? valueMap[valueProp as string] : undefined),\n )\n }, [valueProp])\n\n const getRootProps: PropGetter = useCallback(\n (props) => ({\n ...dataProps,\n ...props,\n }),\n [dataProps],\n )\n\n const getFieldProps: PropGetter = useCallback(\n ({ ref, ...props } = {}) =>\n getTriggerProps({\n ref: mergeRefs(ref, fieldRef),\n tabIndex: -1,\n ...props,\n onClick: handlerAll(props.onClick, onClick),\n }),\n\n [getTriggerProps, onClick],\n )\n\n const getInputProps: PropGetter<\"input\"> = useCallback(\n (props = {}) => ({\n id,\n ref: mergeRefs(props.ref, ref, inputRef),\n name,\n style: {\n ...(!focused && isArray(value) && !!value.length\n ? visuallyHiddenAttributes.style\n : {}),\n ...props.style,\n },\n \"data-max\": dataAttr(\n isArray(value) && isNumber(max) && value.length >= max,\n ),\n autoCapitalize: \"off\",\n autoComplete: \"off\",\n autoCorrect: \"off\",\n disabled,\n placeholder: hasValues ? undefined : placeholder,\n readOnly,\n required,\n spellCheck: false,\n value: inputValue,\n ...dataProps,\n ...props,\n onBlur: handlerAll(props.onBlur, onBlur),\n onChange: handlerAll(props.onChange, onInputChange),\n onFocus: handlerAll(props.onFocus, onFocus),\n onKeyDown: handlerAll(props.onKeyDown, onKeyDown),\n onMouseDown: handlerAll(props.onMouseDown, onMouseDown),\n }),\n [\n dataProps,\n disabled,\n focused,\n hasValues,\n id,\n inputValue,\n max,\n name,\n onBlur,\n onFocus,\n onInputChange,\n onKeyDown,\n onMouseDown,\n placeholder,\n readOnly,\n ref,\n required,\n value,\n ],\n )\n\n const getContentProps: PropGetter = useCallback(\n ({ ref, ...props } = {}) =>\n getComboboxContentProps({\n ref: mergeRefs(ref, contentRef),\n hidden: empty,\n ...props,\n }),\n [empty, getComboboxContentProps],\n )\n\n const getIconProps: PropGetter = useCallback(\n (props) => ({ ...dataProps, ...props }),\n [dataProps],\n )\n\n const getClearIconProps: PropGetter = useCallback(\n (props = {}) =>\n getIconProps({\n \"aria-disabled\": ariaAttr(!interactive),\n \"aria-label\": t(\"Clear value\"),\n role: \"button\",\n tabIndex: interactive ? 0 : -1,\n ...props,\n onClick: handlerAll(props.onClick, onClear),\n onKeyDown: handlerAll(props.onKeyDown, (ev) =>\n runKeyAction(ev, { Enter: onClear, Space: onClear }),\n ),\n }),\n [getIconProps, interactive, onClear, t],\n )\n\n return {\n children,\n descendants,\n inputValue,\n interactive,\n items: resolvedItems,\n max,\n open,\n setInputValue,\n setValue,\n value,\n valueMap,\n getClearIconProps,\n getContentProps,\n getFieldProps,\n getIconProps,\n getInputProps,\n getRootProps,\n getSeparatorProps,\n popoverProps,\n onActiveDescendant,\n onChange,\n onClose,\n onInputChange,\n onOpen,\n onSelect,\n }\n}\n\nexport type UseAutocompleteReturn = ReturnType<typeof useAutocomplete>\n\nexport interface UseAutocompleteOptionProps extends UseComboboxItemProps {}\n\nexport const useAutocompleteOption = ({\n children,\n closeOnSelect,\n disabled,\n hidden,\n value,\n ...rest\n}: UseAutocompleteOptionProps = {}) => {\n const { max, value: selectedValue } = useAutocompleteContext()\n\n value ??= isString(children) ? children : undefined\n\n const selected = isArray(selectedValue)\n ? !isUndefined(value) && selectedValue.includes(value)\n : selectedValue === value\n const completed =\n isNumber(max) && isArray(selectedValue) && selectedValue.length >= max\n const { getIndicatorProps, getItemProps } = useComboboxItem({\n children,\n closeOnSelect,\n disabled: disabled || hidden || (completed && !selected),\n hidden,\n selected,\n value,\n ...rest,\n })\n\n const getOptionProps: PropGetter = useCallback(\n (props = {}) => getItemProps(props),\n [getItemProps],\n )\n\n return { getIndicatorProps, getOptionProps }\n}\n\nexport type UseAutocompleteOptionReturn = ReturnType<\n typeof useAutocompleteOption\n>\n"],"mappings":";;;;;;;;;;;;;;;;;;AA8DA,MAAMA,iBAAyC,EAC7C,OACA,SACA,OACA,OACA,KACA,gBACI;CACJ,MAAM,OAAO,QAAQ,MAAM;AAE3B,QACE,4CAAC;EAAK,OAAO,EAAE,iBAAiB,cAAc;aAC3C,QACE,iDAAU,IAAI,IAAI,QAAQ,QAAQ,WAAY,CAAC,OAAO,YAAY;GAChE;;AAIX,MAAM,iBAAiB,yDACZ,MAAM,MAAM,GAAG,KAAK,QAAS,MAAM,SAAS;AAUvD,MAAMC,iBAAqC,YAAY,OAAO,YAAY;AACxE,KAAI,CAAC,WAAW,OAAQ,QAAO;AAE/B,QAAO,MACJ,KAAK,SAAS;AACb,MAAI,WAAW,MAAM;GACnB,MAAMC,UAAQ,KAAK,MAAM,QAAQ,WAAS;AACxC,QAAI,WAAWC,OACb,QAAO,QAAQ,YAAYA,OAAK,MAAM;6DACpBA,OAAK,MAAM,CAC7B,QAAO,QAAQ,YAAYA,OAAK,MAAM;KAExC;AAEF,OAAID,QAAM,OAAQ,QAAO;IAAE,GAAG;IAAM;IAAO;aAClC,WAAW,MACpB;OAAI,QAAQ,YAAY,KAAK,MAAM,CAAE,QAAO;6DAC1B,KAAK,MAAM,EAC7B;OAAI,QAAQ,YAAY,KAAK,MAAM,CAAE,QAAO;;GAE9C,CACD,OAAO,QAAQ;;AAOpB,MAAME,kBAAuC,OAAO,WAClD,QAAQ,aAAa,CAAC,SAAS,MAAM,aAAa,CAAC,IAAI;AAOzD,MAAM,CAAC,qBAAqB,0BAC1BC,8BAAmC,EACjC,MAAM,uBACP,CAAC;AAyHJ,MAAa,mBACX,QAAwC,EAAE,KACvC;CAGH,MAAM,EAAE,MAAMC,8BAAQ,eAAe;CACrC,MAAM,EACJ,OAAO,EACL,IACA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ACT,aAAa;GACX,iEAA0B,CAAC,YAAY;GACvC,cAAc,EAAE,cAAc;GAC9B,MAAM;GACN,UAAU,cAAc,IAAI;GAC5B,GAAGA;GACH,2DAAoBA,QAAM,SAAS,QAAQ;GAC3C,6DAAsBA,QAAM,YAAY,OACtCQ,yBAAa,IAAI;IAAE,OAAO;IAAS,OAAO;IAAS,CAAC,CACrD;GACF,CAAC,EACJ;GAAC;GAAc;GAAa;GAAS;GAAE,CACxC;EAeC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACD;;AAOH,MAAa,yBAAyB,EACpC,UACA,eACA,UACA,QACA,OACA,GAAG,SAC2B,EAAE,KAAK;CACrC,MAAM,EAAE,KAAK,OAAO,kBAAkB,wBAAwB;AAE9D,2DAAmB,SAAS,GAAG,WAAW;CAE1C,MAAM,0DAAmB,cAAc,GACnC,oDAAa,MAAM,IAAI,cAAc,SAAS,MAAM,GACpD,kBAAkB;CACtB,MAAM,4DACK,IAAI,mDAAY,cAAc,IAAI,cAAc,UAAU;CACrE,MAAM,EAAE,mBAAmB,iBAAiBC,iDAAgB;EAC1D;EACA;EACA,UAAU,YAAY,UAAW,aAAa,CAAC;EAC/C;EACA;EACA;EACA,GAAG;EACJ,CAAC;AAOF,QAAO;EAAE;EAAmB,wCAJzB,QAAQ,EAAE,KAAK,aAAa,MAAM,EACnC,CAAC,aAAa,CACf;EAE2C"}
|
|
1
|
+
{"version":3,"file":"use-autocomplete.cjs","names":["defaultRender: AutocompleteItemRender","defaultFilter: AutocompleteFilter","items","item","defaultMatcher: AutocompleteMatcher","createContext","useI18n","useFieldProps","valueMap: { [key: string]: ComboboxItemWithValue }","valueMap","useControllableState","useCombobox","value","onClear","inputValue","isComposing","getRootProps: PropGetter","props","getFieldProps: PropGetter","mergeRefs","ref","getInputProps: PropGetter<\"input\">","visuallyHiddenAttributes","getContentProps: PropGetter","getIconProps: PropGetter","runKeyAction","useComboboxItem"],"sources":["../../../../src/components/autocomplete/use-autocomplete.tsx"],"sourcesContent":["\"use client\"\n\nimport type {\n ChangeEvent,\n FocusEvent,\n KeyboardEvent,\n MouseEvent,\n ReactNode,\n} from \"react\"\nimport type { HTMLProps, HTMLRefAttributes, PropGetter } from \"../../core\"\nimport type {\n ComboboxItem,\n ComboboxItemWithValue,\n UseComboboxItemProps,\n UseComboboxProps,\n} from \"../../hooks/use-combobox\"\nimport type { Dict } from \"../../utils\"\nimport type { FieldProps } from \"../field\"\nimport {\n cloneElement,\n isValidElement,\n useCallback,\n useMemo,\n useRef,\n useState,\n} from \"react\"\nimport { useCombobox, useComboboxItem } from \"../../hooks/use-combobox\"\nimport { useControllableState } from \"../../hooks/use-controllable-state\"\nimport { useI18n } from \"../../providers/i18n-provider\"\nimport {\n ariaAttr,\n cast,\n contains,\n createContext,\n dataAttr,\n handlerAll,\n isArray,\n isComposing,\n isNumber,\n isString,\n isUndefined,\n mergeRefs,\n runIfFn,\n runKeyAction,\n useUpdateEffect,\n visuallyHiddenAttributes,\n} from \"../../utils\"\nimport { useFieldProps } from \"../field\"\n\ninterface AutocompleteRenderProps extends ComboboxItemWithValue {\n count: number\n focused: boolean\n index: number\n separator: string\n onClear: () => void\n max?: number\n}\n\nexport interface AutocompleteItemRender {\n (props: AutocompleteRenderProps): ReactNode\n}\n\nconst defaultRender: AutocompleteItemRender = ({\n count,\n focused,\n index,\n label,\n max,\n separator,\n}) => {\n const last = count - 1 === index\n\n return (\n <span style={{ marginInlineEnd: \"var(--gap)\" }}>\n {label}\n {((!isNumber(max) || count < max) && focused) || !last ? separator : null}\n </span>\n )\n}\n\nconst getInputValue = (item?: ComboboxItemWithValue) =>\n isString(item?.label) ? item.label : (item?.query ?? \"\")\n\nexport interface AutocompleteFilter {\n (\n inputValue: string,\n items: ComboboxItem[],\n matcher: AutocompleteMatcher,\n ): ComboboxItem[]\n}\n\nconst defaultFilter: AutocompleteFilter = (inputValue, items, matcher) => {\n if (!inputValue.length) return items\n\n return items\n .map((item) => {\n if (\"items\" in item) {\n const items = item.items.filter((item) => {\n if (\"query\" in item) {\n return matcher(inputValue, item.query)\n } else if (isString(item.label)) {\n return matcher(inputValue, item.label)\n }\n })\n\n if (items.length) return { ...item, items }\n } else if (\"query\" in item) {\n if (matcher(inputValue, item.query)) return item\n } else if (isString(item.label)) {\n if (matcher(inputValue, item.label)) return item\n }\n })\n .filter(Boolean) as ComboboxItem[]\n}\n\nexport interface AutocompleteMatcher {\n (input: string, target?: string): boolean\n}\n\nconst defaultMatcher: AutocompleteMatcher = (input, target) =>\n target?.toLowerCase().includes(input.toLowerCase()) ?? false\n\ninterface AutocompleteContext extends Pick<\n UseAutocompleteReturn,\n \"max\" | \"value\"\n> {}\n\nconst [AutocompleteContext, useAutocompleteContext] =\n createContext<AutocompleteContext>({\n name: \"AutocompleteContext\",\n })\n\nexport { AutocompleteContext, useAutocompleteContext }\n\nexport interface UseAutocompleteProps<Multiple extends boolean = false>\n extends\n Omit<HTMLProps, \"defaultValue\" | \"onChange\" | \"ref\" | \"value\">,\n Omit<\n UseComboboxProps,\n \"defaultValue\" | \"initialFocusValue\" | \"onChange\" | \"ref\" | \"value\"\n >,\n HTMLRefAttributes<\"input\">,\n FieldProps {\n /**\n * If `true`, the autocomplete will allow custom value.\n *\n * @default false\n */\n allowCustomValue?: boolean\n /**\n * If `true`, the autocomplete will be closed when the input value changes.\n *\n * @default false\n */\n closeOnChange?: ((ev: ChangeEvent<HTMLInputElement>) => boolean) | boolean\n /**\n * The initial value of the input.\n */\n defaultInputValue?: string\n /**\n * The initial value of the autocomplete.\n */\n defaultValue?: Multiple extends true ? string[] : string\n /**\n * The message displayed when the search yields no hits.\n *\n * @default 'No results found'\n */\n emptyMessage?: ReactNode\n /**\n * The function to filter the items.\n */\n filter?: AutocompleteFilter\n /**\n * If `true`, the input will be focused when the clear icon is clicked.\n *\n * @default true\n */\n focusOnClear?: boolean\n /**\n * The `id` attribute of the input element.\n */\n id?: string\n /**\n * The value of the input.\n */\n inputValue?: string\n /**\n * If provided, generate options based on items.\n *\n * @default []\n */\n items?: ComboboxItem[]\n /**\n * The function to match the items.\n */\n matcher?: AutocompleteMatcher\n /**\n * The maximum selectable value.\n */\n max?: number\n /**\n * If `true`, the autocomplete will be multiple.\n *\n * @default false\n */\n multiple?: Multiple\n /**\n * The `name` attribute of the input element.\n */\n name?: string\n /**\n * If `true`, the autocomplete will be opened when the input value changes.\n *\n * @default true\n */\n openOnChange?: ((ev: ChangeEvent<HTMLInputElement>) => boolean) | boolean\n /**\n * If `true`, the autocomplete will be opened when the input is focused.\n *\n * @default true\n */\n openOnFocus?: boolean\n /**\n * The placeholder for autocomplete.\n */\n placeholder?: string\n /**\n * The visual separator between each value.\n *\n * @default ','\n */\n separator?: string\n /**\n * The value of the autocomplete.\n */\n value?: Multiple extends true ? string[] : string\n /**\n * The callback invoked when value state changes.\n */\n onChange?: (value: Multiple extends true ? string[] : string) => void\n /**\n * The callback invoked when input value state changes.\n */\n onInputChange?: (value: string) => void\n /**\n * The function to render the selected items.\n */\n render?: (props: AutocompleteRenderProps) => ReactNode\n}\n\nexport const useAutocomplete = <Multiple extends boolean = false>(\n props: UseAutocompleteProps<Multiple> = {},\n) => {\n type MaybeValue = Multiple extends true ? string[] : string\n\n const { t } = useI18n(\"autocomplete\")\n const {\n props: {\n id,\n ref,\n name,\n allowCustomValue = false,\n closeOnChange = false,\n multiple = false,\n closeOnSelect = !multiple,\n defaultInputValue,\n defaultValue = (multiple ? [] : \"\") as MaybeValue,\n disabled,\n emptyMessage = t(\"No results found\"),\n filter = defaultFilter,\n focusOnClear = true,\n inputValue: inputValueProp,\n items = [],\n matcher = defaultMatcher,\n max,\n openOnChange = true,\n openOnClick = true,\n openOnFocus = true,\n placeholder,\n readOnly,\n render = defaultRender,\n required,\n separator = \",\",\n value: valueProp,\n onChange: onChangeProp,\n onInputChange: onInputChangeProp,\n ...rest\n },\n ariaProps,\n dataProps,\n eventProps,\n } = useFieldProps(props)\n const fieldRef = useRef<HTMLDivElement>(null)\n const contentRef = useRef<HTMLDivElement>(null)\n const inputRef = useRef<HTMLInputElement>(null)\n const focusByClickRef = useRef<boolean>(false)\n const valueMap = useMemo<{ [key: string]: ComboboxItemWithValue }>(() => {\n const valueMap: { [key: string]: ComboboxItemWithValue } = {}\n\n items.forEach((item) => {\n if (\"items\" in item) {\n item.items.forEach((item) => {\n item.value ??= isString(item.label) ? item.label : undefined\n\n if (!isUndefined(item.value)) valueMap[item.value] = item\n })\n } else {\n item.value ??= isString(item.label) ? item.label : undefined\n\n if (!isUndefined(item.value)) valueMap[item.value] = item\n }\n })\n\n return valueMap\n }, [items])\n const [focused, setFocused] = useState(false)\n const [value, setValue] = useControllableState({\n defaultValue,\n value: valueProp,\n onChange: onChangeProp,\n })\n const [inputValue, setInputValue] = useControllableState({\n defaultValue:\n defaultInputValue ??\n getInputValue(isArray(value) ? undefined : valueMap[value as string]),\n value: inputValueProp,\n onChange: onInputChangeProp,\n })\n const onChange = useCallback(\n (selectedValue: string) => {\n setValue((prev) => {\n if (isArray(prev)) {\n if (prev.includes(selectedValue)) {\n return prev.filter(\n (prevValue) => prevValue !== selectedValue,\n ) as MaybeValue\n } else if (!isNumber(max) || prev.length < max) {\n return [...prev, selectedValue] as MaybeValue\n } else {\n return prev\n }\n } else {\n return selectedValue as MaybeValue\n }\n })\n\n if (isArray(value)) {\n setInputValue(\"\")\n } else {\n const item = valueMap[selectedValue]\n\n setInputValue(getInputValue(item))\n }\n },\n [max, setInputValue, setValue, value, valueMap],\n )\n const {\n activeDescendant,\n descendants,\n interactive,\n open,\n getContentProps: getComboboxContentProps,\n getSeparatorProps,\n getTriggerProps,\n popoverProps,\n onActiveDescendant,\n onClose,\n onOpen,\n onOpenWithActiveDescendant,\n onSelect,\n } = useCombobox({\n closeOnSelect,\n disabled,\n initialFocusValue: isArray(value) ? value[0] : value,\n openOnClick: false,\n openOnEnter: false,\n openOnSpace: false,\n readOnly,\n selectFocusRef: inputRef,\n selectOnSpace: false,\n onChange,\n ...ariaProps,\n ...dataProps,\n ...eventProps,\n ...rest,\n })\n const filteredItems = useMemo<ComboboxItem[]>(() => {\n if (!items.length) return []\n\n return filter(inputValue, items, matcher)\n }, [filter, inputValue, items, matcher])\n const resolvedItems = useMemo<ComboboxItem[]>(() => {\n return filteredItems.length\n ? filteredItems\n : [{ \"data-empty\": \"\", label: emptyMessage }]\n }, [filteredItems, emptyMessage])\n const empty = useMemo(\n () => !resolvedItems.filter(({ hidden }) => !hidden).length,\n [resolvedItems],\n )\n const children = useMemo<ReactNode>(() => {\n if (!isArray(value)) return null\n\n const count = value.length\n\n return value.map((value, index) => {\n const item = valueMap[value] ?? { label: value, value }\n\n const onClear = (ev?: MouseEvent<HTMLElement>) => {\n ev?.preventDefault()\n ev?.stopPropagation()\n\n if (item.value) onChange(item.value)\n }\n\n const component = render({\n count,\n focused,\n index,\n max,\n separator,\n onClear,\n ...item,\n })\n\n if (isValidElement<Dict>(component)) {\n return cloneElement(component, { ...component.props, key: index })\n } else {\n return component\n }\n })\n }, [focused, max, onChange, render, separator, value, valueMap])\n const hasValues = isArray(value) && !!value.length\n\n const onInputChange = useCallback(\n (ev: ChangeEvent<HTMLInputElement>) => {\n if (isArray(value) && value.length === max) return\n\n if (runIfFn(closeOnChange, ev)) {\n onClose()\n } else if (runIfFn(openOnChange, ev)) {\n onOpen()\n }\n\n activeDescendant.current = null\n\n const inputValue = ev.target.value\n\n setInputValue(inputValue)\n\n if (inputValue.length || isArray(value)) return\n\n setValue(\"\" as MaybeValue)\n },\n [\n activeDescendant,\n closeOnChange,\n max,\n onClose,\n onOpen,\n openOnChange,\n setInputValue,\n setValue,\n value,\n ],\n )\n\n const onKeyDown = useCallback(\n (ev: KeyboardEvent<HTMLInputElement>) => {\n if (disabled || isComposing(ev)) return\n\n const inputValue = cast<HTMLInputElement>(ev.target).value\n\n runKeyAction(\n ev,\n {\n Backspace: (ev) => {\n if (!isArray(value)) return\n if (!!inputValue.length) return\n\n ev.preventDefault()\n\n setValue((prev) => prev.slice(0, -1) as MaybeValue)\n },\n Enter: (ev) => {\n if (!open || !inputValue.length || activeDescendant.current) return\n\n const item = filteredItems[0]\n\n if (!item) {\n if (!allowCustomValue || !isArray(value)) return\n\n ev.preventDefault()\n\n onSelect(inputValue)\n } else {\n ev.preventDefault()\n\n if (\"items\" in item) {\n onSelect(item.items[0]?.value)\n } else {\n onSelect(item.value)\n }\n }\n },\n },\n { preventDefault: false },\n )\n },\n [\n activeDescendant,\n allowCustomValue,\n disabled,\n filteredItems,\n onSelect,\n open,\n setValue,\n value,\n ],\n )\n\n const onClick = useCallback(() => {\n if (!interactive) return\n\n focusByClickRef.current = true\n\n inputRef.current?.focus()\n\n if (openOnClick) onOpenWithActiveDescendant(descendants.enabledFirstValue)\n }, [descendants, interactive, onOpenWithActiveDescendant, openOnClick])\n\n const onMouseDown = useCallback(\n (ev: MouseEvent<HTMLInputElement>) => {\n if (!openOnFocus) return\n\n ev.preventDefault()\n ev.stopPropagation()\n },\n [openOnFocus],\n )\n\n const onFocus = useCallback(\n (ev: FocusEvent<HTMLInputElement>) => {\n ev.preventDefault()\n ev.stopPropagation()\n\n setFocused(true)\n\n if (openOnFocus && !focusByClickRef.current)\n onOpenWithActiveDescendant(descendants.enabledFirstValue)\n\n focusByClickRef.current = false\n },\n [openOnFocus, onOpenWithActiveDescendant, descendants.enabledFirstValue],\n )\n\n const onBlur = useCallback(\n (ev: FocusEvent<HTMLInputElement>) => {\n if (\n contains(fieldRef.current, ev.relatedTarget) ||\n contains(contentRef.current, ev.relatedTarget)\n ) {\n ev.preventDefault()\n } else {\n setFocused(false)\n\n if (isArray(value)) {\n setInputValue(\"\")\n } else {\n if (allowCustomValue) {\n if (inputValue) setValue(inputValue as MaybeValue)\n } else {\n const item = valueMap[value as string]\n\n setInputValue(getInputValue(item))\n }\n }\n }\n },\n [allowCustomValue, inputValue, setInputValue, setValue, value, valueMap],\n )\n\n const onClear = useCallback(() => {\n if (!interactive) return\n\n setValue((prev) => (isArray(prev) ? [] : \"\") as MaybeValue)\n setInputValue(\"\")\n\n if (focusOnClear) inputRef.current?.focus()\n }, [focusOnClear, interactive, setInputValue, setValue])\n\n useUpdateEffect(() => {\n if (isArray(valueProp)) return\n\n setInputValue(\n getInputValue(valueProp ? valueMap[valueProp as string] : undefined),\n )\n }, [valueProp])\n\n const getRootProps: PropGetter = useCallback(\n (props) => ({\n ...dataProps,\n ...props,\n }),\n [dataProps],\n )\n\n const getFieldProps: PropGetter = useCallback(\n ({ ref, ...props } = {}) =>\n getTriggerProps({\n ref: mergeRefs(ref, fieldRef),\n tabIndex: -1,\n ...props,\n onClick: handlerAll(props.onClick, onClick),\n }),\n\n [getTriggerProps, onClick],\n )\n\n const getInputProps: PropGetter<\"input\"> = useCallback(\n (props = {}) => ({\n id,\n ref: mergeRefs(props.ref, ref, inputRef),\n name,\n style: {\n ...(!focused && isArray(value) && !!value.length\n ? visuallyHiddenAttributes.style\n : {}),\n ...props.style,\n },\n \"data-max\": dataAttr(\n isArray(value) && isNumber(max) && value.length >= max,\n ),\n autoCapitalize: \"off\",\n autoComplete: \"off\",\n autoCorrect: \"off\",\n disabled,\n placeholder: hasValues ? undefined : placeholder,\n readOnly,\n required,\n spellCheck: false,\n value: inputValue,\n ...dataProps,\n ...props,\n onBlur: handlerAll(props.onBlur, onBlur),\n onChange: handlerAll(props.onChange, onInputChange),\n onFocus: handlerAll(props.onFocus, onFocus),\n onKeyDown: handlerAll(props.onKeyDown, onKeyDown),\n onMouseDown: handlerAll(props.onMouseDown, onMouseDown),\n }),\n [\n dataProps,\n disabled,\n focused,\n hasValues,\n id,\n inputValue,\n max,\n name,\n onBlur,\n onFocus,\n onInputChange,\n onKeyDown,\n onMouseDown,\n placeholder,\n readOnly,\n ref,\n required,\n value,\n ],\n )\n\n const getContentProps: PropGetter = useCallback(\n ({ ref, ...props } = {}) =>\n getComboboxContentProps({\n ref: mergeRefs(ref, contentRef),\n hidden: empty,\n ...props,\n }),\n [empty, getComboboxContentProps],\n )\n\n const getIconProps: PropGetter = useCallback(\n (props) => ({ ...dataProps, ...props }),\n [dataProps],\n )\n\n const getClearIconProps: PropGetter = useCallback(\n (props = {}) =>\n getIconProps({\n \"aria-disabled\": ariaAttr(!interactive),\n \"aria-label\": t(\"Clear value\"),\n role: \"button\",\n tabIndex: interactive ? 0 : -1,\n ...props,\n onClick: handlerAll(props.onClick, onClear),\n onKeyDown: handlerAll(props.onKeyDown, (ev) =>\n runKeyAction(ev, { Enter: onClear, Space: onClear }),\n ),\n }),\n [getIconProps, interactive, onClear, t],\n )\n\n return {\n children,\n descendants,\n inputValue,\n interactive,\n items: resolvedItems,\n max,\n open,\n setInputValue,\n setValue,\n value,\n valueMap,\n getClearIconProps,\n getContentProps,\n getFieldProps,\n getIconProps,\n getInputProps,\n getRootProps,\n getSeparatorProps,\n popoverProps,\n onActiveDescendant,\n onChange,\n onClose,\n onInputChange,\n onOpen,\n onSelect,\n }\n}\n\nexport type UseAutocompleteReturn = ReturnType<typeof useAutocomplete>\n\nexport interface UseAutocompleteOptionProps extends UseComboboxItemProps {}\n\nexport const useAutocompleteOption = ({\n children,\n closeOnSelect,\n disabled,\n hidden,\n value,\n ...rest\n}: UseAutocompleteOptionProps = {}) => {\n const { max, value: selectedValue } = useAutocompleteContext()\n\n value ??= isString(children) ? children : undefined\n\n const selected = isArray(selectedValue)\n ? !isUndefined(value) && selectedValue.includes(value)\n : selectedValue === value\n const completed =\n isNumber(max) && isArray(selectedValue) && selectedValue.length >= max\n const { getIndicatorProps, getItemProps } = useComboboxItem({\n children,\n closeOnSelect,\n disabled: disabled || hidden || (completed && !selected),\n hidden,\n selected,\n value,\n ...rest,\n })\n\n const getOptionProps: PropGetter = useCallback(\n (props = {}) => getItemProps(props),\n [getItemProps],\n )\n\n return { getIndicatorProps, getOptionProps }\n}\n\nexport type UseAutocompleteOptionReturn = ReturnType<\n typeof useAutocompleteOption\n>\n"],"mappings":";;;;;;;;;;;;;;;;;;AA8DA,MAAMA,iBAAyC,EAC7C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,yBAAa,IAAI;IAAE,OAAO;IAAS,OAAO;IAAS,CAAC,CACrD;GACF,CAAC,EACJ;GAAC;GAAc;GAAa;GAAS;GAAE,CACxC;EAeC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACD;;AAOH,MAAa,yBAAyB,EACpC,UACA,eACA,UACA,QACA,OACA,GAAG,SAC2B,EAAE,KAAK;CACrC,MAAM,EAAE,KAAK,OAAO,kBAAkB,wBAAwB;AAE9D,2DAAmB,SAAS,GAAG,WAAW;CAE1C,MAAM,0DAAmB,cAAc,GACnC,oDAAa,MAAM,IAAI,cAAc,SAAS,MAAM,GACpD,kBAAkB;CACtB,MAAM,4DACK,IAAI,mDAAY,cAAc,IAAI,cAAc,UAAU;CACrE,MAAM,EAAE,mBAAmB,iBAAiBC,iDAAgB;EAC1D;EACA;EACA,UAAU,YAAY,UAAW,aAAa,CAAC;EAC/C;EACA;EACA;EACA,GAAG;EACJ,CAAC;AAOF,QAAO;EAAE;EAAmB,wCAJzB,QAAQ,EAAE,KAAK,aAAa,MAAM,EACnC,CAAC,aAAa,CACf;EAE2C"}
|
|
@@ -247,14 +247,16 @@ const useAutocomplete = (props = {}) => {
|
|
|
247
247
|
descendants.enabledFirstValue
|
|
248
248
|
]);
|
|
249
249
|
const onBlur = useCallback((ev) => {
|
|
250
|
-
setFocused(false);
|
|
251
250
|
if ((0, utils_exports.contains)(fieldRef.current, ev.relatedTarget) || (0, utils_exports.contains)(contentRef.current, ev.relatedTarget)) ev.preventDefault();
|
|
252
|
-
else
|
|
253
|
-
|
|
254
|
-
if (
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
251
|
+
else {
|
|
252
|
+
setFocused(false);
|
|
253
|
+
if ((0, utils_exports.isArray)(value)) setInputValue("");
|
|
254
|
+
else if (allowCustomValue) {
|
|
255
|
+
if (inputValue) setValue(inputValue);
|
|
256
|
+
} else {
|
|
257
|
+
const item = valueMap[value];
|
|
258
|
+
setInputValue(getInputValue(item));
|
|
259
|
+
}
|
|
258
260
|
}
|
|
259
261
|
}, [
|
|
260
262
|
allowCustomValue,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-autocomplete.js","names":["defaultRender: AutocompleteItemRender","defaultFilter: AutocompleteFilter","items","item","defaultMatcher: AutocompleteMatcher","createContext","valueMap: { [key: string]: ComboboxItemWithValue }","valueMap","value","onClear","inputValue","getRootProps: PropGetter","props","getFieldProps: PropGetter","ref","getInputProps: PropGetter<\"input\">","getContentProps: PropGetter","getIconProps: PropGetter"],"sources":["../../../../src/components/autocomplete/use-autocomplete.tsx"],"sourcesContent":["\"use client\"\n\nimport type {\n ChangeEvent,\n FocusEvent,\n KeyboardEvent,\n MouseEvent,\n ReactNode,\n} from \"react\"\nimport type { HTMLProps, HTMLRefAttributes, PropGetter } from \"../../core\"\nimport type {\n ComboboxItem,\n ComboboxItemWithValue,\n UseComboboxItemProps,\n UseComboboxProps,\n} from \"../../hooks/use-combobox\"\nimport type { Dict } from \"../../utils\"\nimport type { FieldProps } from \"../field\"\nimport {\n cloneElement,\n isValidElement,\n useCallback,\n useMemo,\n useRef,\n useState,\n} from \"react\"\nimport { useCombobox, useComboboxItem } from \"../../hooks/use-combobox\"\nimport { useControllableState } from \"../../hooks/use-controllable-state\"\nimport { useI18n } from \"../../providers/i18n-provider\"\nimport {\n ariaAttr,\n cast,\n contains,\n createContext,\n dataAttr,\n handlerAll,\n isArray,\n isComposing,\n isNumber,\n isString,\n isUndefined,\n mergeRefs,\n runIfFn,\n runKeyAction,\n useUpdateEffect,\n visuallyHiddenAttributes,\n} from \"../../utils\"\nimport { useFieldProps } from \"../field\"\n\ninterface AutocompleteRenderProps extends ComboboxItemWithValue {\n count: number\n focused: boolean\n index: number\n separator: string\n onClear: () => void\n max?: number\n}\n\nexport interface AutocompleteItemRender {\n (props: AutocompleteRenderProps): ReactNode\n}\n\nconst defaultRender: AutocompleteItemRender = ({\n count,\n focused,\n index,\n label,\n max,\n separator,\n}) => {\n const last = count - 1 === index\n\n return (\n <span style={{ marginInlineEnd: \"var(--gap)\" }}>\n {label}\n {((!isNumber(max) || count < max) && focused) || !last ? separator : null}\n </span>\n )\n}\n\nconst getInputValue = (item?: ComboboxItemWithValue) =>\n isString(item?.label) ? item.label : (item?.query ?? \"\")\n\nexport interface AutocompleteFilter {\n (\n inputValue: string,\n items: ComboboxItem[],\n matcher: AutocompleteMatcher,\n ): ComboboxItem[]\n}\n\nconst defaultFilter: AutocompleteFilter = (inputValue, items, matcher) => {\n if (!inputValue.length) return items\n\n return items\n .map((item) => {\n if (\"items\" in item) {\n const items = item.items.filter((item) => {\n if (\"query\" in item) {\n return matcher(inputValue, item.query)\n } else if (isString(item.label)) {\n return matcher(inputValue, item.label)\n }\n })\n\n if (items.length) return { ...item, items }\n } else if (\"query\" in item) {\n if (matcher(inputValue, item.query)) return item\n } else if (isString(item.label)) {\n if (matcher(inputValue, item.label)) return item\n }\n })\n .filter(Boolean) as ComboboxItem[]\n}\n\nexport interface AutocompleteMatcher {\n (input: string, target?: string): boolean\n}\n\nconst defaultMatcher: AutocompleteMatcher = (input, target) =>\n target?.toLowerCase().includes(input.toLowerCase()) ?? false\n\ninterface AutocompleteContext extends Pick<\n UseAutocompleteReturn,\n \"max\" | \"value\"\n> {}\n\nconst [AutocompleteContext, useAutocompleteContext] =\n createContext<AutocompleteContext>({\n name: \"AutocompleteContext\",\n })\n\nexport { AutocompleteContext, useAutocompleteContext }\n\nexport interface UseAutocompleteProps<Multiple extends boolean = false>\n extends\n Omit<HTMLProps, \"defaultValue\" | \"onChange\" | \"ref\" | \"value\">,\n Omit<\n UseComboboxProps,\n \"defaultValue\" | \"initialFocusValue\" | \"onChange\" | \"ref\" | \"value\"\n >,\n HTMLRefAttributes<\"input\">,\n FieldProps {\n /**\n * If `true`, the autocomplete will allow custom value.\n *\n * @default false\n */\n allowCustomValue?: boolean\n /**\n * If `true`, the autocomplete will be closed when the input value changes.\n *\n * @default false\n */\n closeOnChange?: ((ev: ChangeEvent<HTMLInputElement>) => boolean) | boolean\n /**\n * The initial value of the input.\n */\n defaultInputValue?: string\n /**\n * The initial value of the autocomplete.\n */\n defaultValue?: Multiple extends true ? string[] : string\n /**\n * The message displayed when the search yields no hits.\n *\n * @default 'No results found'\n */\n emptyMessage?: ReactNode\n /**\n * The function to filter the items.\n */\n filter?: AutocompleteFilter\n /**\n * If `true`, the input will be focused when the clear icon is clicked.\n *\n * @default true\n */\n focusOnClear?: boolean\n /**\n * The `id` attribute of the input element.\n */\n id?: string\n /**\n * The value of the input.\n */\n inputValue?: string\n /**\n * If provided, generate options based on items.\n *\n * @default []\n */\n items?: ComboboxItem[]\n /**\n * The function to match the items.\n */\n matcher?: AutocompleteMatcher\n /**\n * The maximum selectable value.\n */\n max?: number\n /**\n * If `true`, the autocomplete will be multiple.\n *\n * @default false\n */\n multiple?: Multiple\n /**\n * The `name` attribute of the input element.\n */\n name?: string\n /**\n * If `true`, the autocomplete will be opened when the input value changes.\n *\n * @default true\n */\n openOnChange?: ((ev: ChangeEvent<HTMLInputElement>) => boolean) | boolean\n /**\n * If `true`, the autocomplete will be opened when the input is focused.\n *\n * @default true\n */\n openOnFocus?: boolean\n /**\n * The placeholder for autocomplete.\n */\n placeholder?: string\n /**\n * The visual separator between each value.\n *\n * @default ','\n */\n separator?: string\n /**\n * The value of the autocomplete.\n */\n value?: Multiple extends true ? string[] : string\n /**\n * The callback invoked when value state changes.\n */\n onChange?: (value: Multiple extends true ? string[] : string) => void\n /**\n * The callback invoked when input value state changes.\n */\n onInputChange?: (value: string) => void\n /**\n * The function to render the selected items.\n */\n render?: (props: AutocompleteRenderProps) => ReactNode\n}\n\nexport const useAutocomplete = <Multiple extends boolean = false>(\n props: UseAutocompleteProps<Multiple> = {},\n) => {\n type MaybeValue = Multiple extends true ? string[] : string\n\n const { t } = useI18n(\"autocomplete\")\n const {\n props: {\n id,\n ref,\n name,\n allowCustomValue = false,\n closeOnChange = false,\n multiple = false,\n closeOnSelect = !multiple,\n defaultInputValue,\n defaultValue = (multiple ? [] : \"\") as MaybeValue,\n disabled,\n emptyMessage = t(\"No results found\"),\n filter = defaultFilter,\n focusOnClear = true,\n inputValue: inputValueProp,\n items = [],\n matcher = defaultMatcher,\n max,\n openOnChange = true,\n openOnClick = true,\n openOnFocus = true,\n placeholder,\n readOnly,\n render = defaultRender,\n required,\n separator = \",\",\n value: valueProp,\n onChange: onChangeProp,\n onInputChange: onInputChangeProp,\n ...rest\n },\n ariaProps,\n dataProps,\n eventProps,\n } = useFieldProps(props)\n const fieldRef = useRef<HTMLDivElement>(null)\n const contentRef = useRef<HTMLDivElement>(null)\n const inputRef = useRef<HTMLInputElement>(null)\n const focusByClickRef = useRef<boolean>(false)\n const valueMap = useMemo<{ [key: string]: ComboboxItemWithValue }>(() => {\n const valueMap: { [key: string]: ComboboxItemWithValue } = {}\n\n items.forEach((item) => {\n if (\"items\" in item) {\n item.items.forEach((item) => {\n item.value ??= isString(item.label) ? item.label : undefined\n\n if (!isUndefined(item.value)) valueMap[item.value] = item\n })\n } else {\n item.value ??= isString(item.label) ? item.label : undefined\n\n if (!isUndefined(item.value)) valueMap[item.value] = item\n }\n })\n\n return valueMap\n }, [items])\n const [focused, setFocused] = useState(false)\n const [value, setValue] = useControllableState({\n defaultValue,\n value: valueProp,\n onChange: onChangeProp,\n })\n const [inputValue, setInputValue] = useControllableState({\n defaultValue:\n defaultInputValue ??\n getInputValue(isArray(value) ? undefined : valueMap[value as string]),\n value: inputValueProp,\n onChange: onInputChangeProp,\n })\n const onChange = useCallback(\n (selectedValue: string) => {\n setValue((prev) => {\n if (isArray(prev)) {\n if (prev.includes(selectedValue)) {\n return prev.filter(\n (prevValue) => prevValue !== selectedValue,\n ) as MaybeValue\n } else if (!isNumber(max) || prev.length < max) {\n return [...prev, selectedValue] as MaybeValue\n } else {\n return prev\n }\n } else {\n return selectedValue as MaybeValue\n }\n })\n\n if (isArray(value)) {\n setInputValue(\"\")\n } else {\n const item = valueMap[selectedValue]\n\n setInputValue(getInputValue(item))\n }\n },\n [max, setInputValue, setValue, value, valueMap],\n )\n const {\n activeDescendant,\n descendants,\n interactive,\n open,\n getContentProps: getComboboxContentProps,\n getSeparatorProps,\n getTriggerProps,\n popoverProps,\n onActiveDescendant,\n onClose,\n onOpen,\n onOpenWithActiveDescendant,\n onSelect,\n } = useCombobox({\n closeOnSelect,\n disabled,\n initialFocusValue: isArray(value) ? value[0] : value,\n openOnClick: false,\n openOnEnter: false,\n openOnSpace: false,\n readOnly,\n selectFocusRef: inputRef,\n selectOnSpace: false,\n onChange,\n ...ariaProps,\n ...dataProps,\n ...eventProps,\n ...rest,\n })\n const filteredItems = useMemo<ComboboxItem[]>(() => {\n if (!items.length) return []\n\n return filter(inputValue, items, matcher)\n }, [filter, inputValue, items, matcher])\n const resolvedItems = useMemo<ComboboxItem[]>(() => {\n return filteredItems.length\n ? filteredItems\n : [{ \"data-empty\": \"\", label: emptyMessage }]\n }, [filteredItems, emptyMessage])\n const empty = useMemo(\n () => !resolvedItems.filter(({ hidden }) => !hidden).length,\n [resolvedItems],\n )\n const children = useMemo<ReactNode>(() => {\n if (!isArray(value)) return null\n\n const count = value.length\n\n return value.map((value, index) => {\n const item = valueMap[value] ?? { label: value, value }\n\n const onClear = (ev?: MouseEvent<HTMLElement>) => {\n ev?.preventDefault()\n ev?.stopPropagation()\n\n if (item.value) onChange(item.value)\n }\n\n const component = render({\n count,\n focused,\n index,\n max,\n separator,\n onClear,\n ...item,\n })\n\n if (isValidElement<Dict>(component)) {\n return cloneElement(component, { ...component.props, key: index })\n } else {\n return component\n }\n })\n }, [focused, max, onChange, render, separator, value, valueMap])\n const hasValues = isArray(value) && !!value.length\n\n const onInputChange = useCallback(\n (ev: ChangeEvent<HTMLInputElement>) => {\n if (isArray(value) && value.length === max) return\n\n if (runIfFn(closeOnChange, ev)) {\n onClose()\n } else if (runIfFn(openOnChange, ev)) {\n onOpen()\n }\n\n activeDescendant.current = null\n\n const inputValue = ev.target.value\n\n setInputValue(inputValue)\n\n if (inputValue.length || isArray(value)) return\n\n setValue(\"\" as MaybeValue)\n },\n [\n activeDescendant,\n closeOnChange,\n max,\n onClose,\n onOpen,\n openOnChange,\n setInputValue,\n setValue,\n value,\n ],\n )\n\n const onKeyDown = useCallback(\n (ev: KeyboardEvent<HTMLInputElement>) => {\n if (disabled || isComposing(ev)) return\n\n const inputValue = cast<HTMLInputElement>(ev.target).value\n\n runKeyAction(\n ev,\n {\n Backspace: (ev) => {\n if (!isArray(value)) return\n if (!!inputValue.length) return\n\n ev.preventDefault()\n\n setValue((prev) => prev.slice(0, -1) as MaybeValue)\n },\n Enter: (ev) => {\n if (!open || !inputValue.length || activeDescendant.current) return\n\n const item = filteredItems[0]\n\n if (!item) {\n if (!allowCustomValue || !isArray(value)) return\n\n ev.preventDefault()\n\n onSelect(inputValue)\n } else {\n ev.preventDefault()\n\n if (\"items\" in item) {\n onSelect(item.items[0]?.value)\n } else {\n onSelect(item.value)\n }\n }\n },\n },\n { preventDefault: false },\n )\n },\n [\n activeDescendant,\n allowCustomValue,\n disabled,\n filteredItems,\n onSelect,\n open,\n setValue,\n value,\n ],\n )\n\n const onClick = useCallback(() => {\n if (!interactive) return\n\n focusByClickRef.current = true\n\n inputRef.current?.focus()\n\n if (openOnClick) onOpenWithActiveDescendant(descendants.enabledFirstValue)\n }, [descendants, interactive, onOpenWithActiveDescendant, openOnClick])\n\n const onMouseDown = useCallback(\n (ev: MouseEvent<HTMLInputElement>) => {\n if (!openOnFocus) return\n\n ev.preventDefault()\n ev.stopPropagation()\n },\n [openOnFocus],\n )\n\n const onFocus = useCallback(\n (ev: FocusEvent<HTMLInputElement>) => {\n ev.preventDefault()\n ev.stopPropagation()\n\n setFocused(true)\n\n if (openOnFocus && !focusByClickRef.current)\n onOpenWithActiveDescendant(descendants.enabledFirstValue)\n\n focusByClickRef.current = false\n },\n [openOnFocus, onOpenWithActiveDescendant, descendants.enabledFirstValue],\n )\n\n const onBlur = useCallback(\n (ev: FocusEvent<HTMLInputElement>) => {\n setFocused(false)\n\n if (\n contains(fieldRef.current, ev.relatedTarget) ||\n contains(contentRef.current, ev.relatedTarget)\n ) {\n ev.preventDefault()\n } else {\n if (isArray(value)) {\n setInputValue(\"\")\n } else {\n if (allowCustomValue) {\n if (inputValue) setValue(inputValue as MaybeValue)\n } else {\n const item = valueMap[value as string]\n\n setInputValue(getInputValue(item))\n }\n }\n }\n },\n [allowCustomValue, inputValue, setInputValue, setValue, value, valueMap],\n )\n\n const onClear = useCallback(() => {\n if (!interactive) return\n\n setValue((prev) => (isArray(prev) ? [] : \"\") as MaybeValue)\n setInputValue(\"\")\n\n if (focusOnClear) inputRef.current?.focus()\n }, [focusOnClear, interactive, setInputValue, setValue])\n\n useUpdateEffect(() => {\n if (isArray(valueProp)) return\n\n setInputValue(\n getInputValue(valueProp ? valueMap[valueProp as string] : undefined),\n )\n }, [valueProp])\n\n const getRootProps: PropGetter = useCallback(\n (props) => ({\n ...dataProps,\n ...props,\n }),\n [dataProps],\n )\n\n const getFieldProps: PropGetter = useCallback(\n ({ ref, ...props } = {}) =>\n getTriggerProps({\n ref: mergeRefs(ref, fieldRef),\n tabIndex: -1,\n ...props,\n onClick: handlerAll(props.onClick, onClick),\n }),\n\n [getTriggerProps, onClick],\n )\n\n const getInputProps: PropGetter<\"input\"> = useCallback(\n (props = {}) => ({\n id,\n ref: mergeRefs(props.ref, ref, inputRef),\n name,\n style: {\n ...(!focused && isArray(value) && !!value.length\n ? visuallyHiddenAttributes.style\n : {}),\n ...props.style,\n },\n \"data-max\": dataAttr(\n isArray(value) && isNumber(max) && value.length >= max,\n ),\n autoCapitalize: \"off\",\n autoComplete: \"off\",\n autoCorrect: \"off\",\n disabled,\n placeholder: hasValues ? undefined : placeholder,\n readOnly,\n required,\n spellCheck: false,\n value: inputValue,\n ...dataProps,\n ...props,\n onBlur: handlerAll(props.onBlur, onBlur),\n onChange: handlerAll(props.onChange, onInputChange),\n onFocus: handlerAll(props.onFocus, onFocus),\n onKeyDown: handlerAll(props.onKeyDown, onKeyDown),\n onMouseDown: handlerAll(props.onMouseDown, onMouseDown),\n }),\n [\n dataProps,\n disabled,\n focused,\n hasValues,\n id,\n inputValue,\n max,\n name,\n onBlur,\n onFocus,\n onInputChange,\n onKeyDown,\n onMouseDown,\n placeholder,\n readOnly,\n ref,\n required,\n value,\n ],\n )\n\n const getContentProps: PropGetter = useCallback(\n ({ ref, ...props } = {}) =>\n getComboboxContentProps({\n ref: mergeRefs(ref, contentRef),\n hidden: empty,\n ...props,\n }),\n [empty, getComboboxContentProps],\n )\n\n const getIconProps: PropGetter = useCallback(\n (props) => ({ ...dataProps, ...props }),\n [dataProps],\n )\n\n const getClearIconProps: PropGetter = useCallback(\n (props = {}) =>\n getIconProps({\n \"aria-disabled\": ariaAttr(!interactive),\n \"aria-label\": t(\"Clear value\"),\n role: \"button\",\n tabIndex: interactive ? 0 : -1,\n ...props,\n onClick: handlerAll(props.onClick, onClear),\n onKeyDown: handlerAll(props.onKeyDown, (ev) =>\n runKeyAction(ev, { Enter: onClear, Space: onClear }),\n ),\n }),\n [getIconProps, interactive, onClear, t],\n )\n\n return {\n children,\n descendants,\n inputValue,\n interactive,\n items: resolvedItems,\n max,\n open,\n setInputValue,\n setValue,\n value,\n valueMap,\n getClearIconProps,\n getContentProps,\n getFieldProps,\n getIconProps,\n getInputProps,\n getRootProps,\n getSeparatorProps,\n popoverProps,\n onActiveDescendant,\n onChange,\n onClose,\n onInputChange,\n onOpen,\n onSelect,\n }\n}\n\nexport type UseAutocompleteReturn = ReturnType<typeof useAutocomplete>\n\nexport interface UseAutocompleteOptionProps extends UseComboboxItemProps {}\n\nexport const useAutocompleteOption = ({\n children,\n closeOnSelect,\n disabled,\n hidden,\n value,\n ...rest\n}: UseAutocompleteOptionProps = {}) => {\n const { max, value: selectedValue } = useAutocompleteContext()\n\n value ??= isString(children) ? children : undefined\n\n const selected = isArray(selectedValue)\n ? !isUndefined(value) && selectedValue.includes(value)\n : selectedValue === value\n const completed =\n isNumber(max) && isArray(selectedValue) && selectedValue.length >= max\n const { getIndicatorProps, getItemProps } = useComboboxItem({\n children,\n closeOnSelect,\n disabled: disabled || hidden || (completed && !selected),\n hidden,\n selected,\n value,\n ...rest,\n })\n\n const getOptionProps: PropGetter = useCallback(\n (props = {}) => getItemProps(props),\n [getItemProps],\n )\n\n return { getIndicatorProps, getOptionProps }\n}\n\nexport type UseAutocompleteOptionReturn = ReturnType<\n typeof useAutocompleteOption\n>\n"],"mappings":";;;;;;;;;;;;;;;;;AA8DA,MAAMA,iBAAyC,EAC7C,OACA,SACA,OACA,OACA,KACA,gBACI;CACJ,MAAM,OAAO,QAAQ,MAAM;AAE3B,QACE,qBAAC;EAAK,OAAO,EAAE,iBAAiB,cAAc;aAC3C,QACE,6BAAU,IAAI,IAAI,QAAQ,QAAQ,WAAY,CAAC,OAAO,YAAY;GAChE;;AAIX,MAAM,iBAAiB,qCACZ,MAAM,MAAM,GAAG,KAAK,QAAS,MAAM,SAAS;AAUvD,MAAMC,iBAAqC,YAAY,OAAO,YAAY;AACxE,KAAI,CAAC,WAAW,OAAQ,QAAO;AAE/B,QAAO,MACJ,KAAK,SAAS;AACb,MAAI,WAAW,MAAM;GACnB,MAAMC,UAAQ,KAAK,MAAM,QAAQ,WAAS;AACxC,QAAI,WAAWC,OACb,QAAO,QAAQ,YAAYA,OAAK,MAAM;yCACpBA,OAAK,MAAM,CAC7B,QAAO,QAAQ,YAAYA,OAAK,MAAM;KAExC;AAEF,OAAID,QAAM,OAAQ,QAAO;IAAE,GAAG;IAAM;IAAO;aAClC,WAAW,MACpB;OAAI,QAAQ,YAAY,KAAK,MAAM,CAAE,QAAO;yCAC1B,KAAK,MAAM,EAC7B;OAAI,QAAQ,YAAY,KAAK,MAAM,CAAE,QAAO;;GAE9C,CACD,OAAO,QAAQ;;AAOpB,MAAME,kBAAuC,OAAO,WAClD,QAAQ,aAAa,CAAC,SAAS,MAAM,aAAa,CAAC,IAAI;A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autocomplete.js","names":["defaultRender: AutocompleteItemRender","defaultFilter: AutocompleteFilter","items","item","defaultMatcher: AutocompleteMatcher","createContext","valueMap: { [key: string]: ComboboxItemWithValue }","valueMap","value","onClear","inputValue","getRootProps: PropGetter","props","getFieldProps: PropGetter","ref","getInputProps: PropGetter<\"input\">","getContentProps: PropGetter","getIconProps: PropGetter"],"sources":["../../../../src/components/autocomplete/use-autocomplete.tsx"],"sourcesContent":["\"use client\"\n\nimport type {\n ChangeEvent,\n FocusEvent,\n KeyboardEvent,\n MouseEvent,\n ReactNode,\n} from \"react\"\nimport type { HTMLProps, HTMLRefAttributes, PropGetter } from \"../../core\"\nimport type {\n ComboboxItem,\n ComboboxItemWithValue,\n UseComboboxItemProps,\n UseComboboxProps,\n} from \"../../hooks/use-combobox\"\nimport type { Dict } from \"../../utils\"\nimport type { FieldProps } from \"../field\"\nimport {\n cloneElement,\n isValidElement,\n useCallback,\n useMemo,\n useRef,\n useState,\n} from \"react\"\nimport { useCombobox, useComboboxItem } from \"../../hooks/use-combobox\"\nimport { useControllableState } from \"../../hooks/use-controllable-state\"\nimport { useI18n } from \"../../providers/i18n-provider\"\nimport {\n ariaAttr,\n cast,\n contains,\n createContext,\n dataAttr,\n handlerAll,\n isArray,\n isComposing,\n isNumber,\n isString,\n isUndefined,\n mergeRefs,\n runIfFn,\n runKeyAction,\n useUpdateEffect,\n visuallyHiddenAttributes,\n} from \"../../utils\"\nimport { useFieldProps } from \"../field\"\n\ninterface AutocompleteRenderProps extends ComboboxItemWithValue {\n count: number\n focused: boolean\n index: number\n separator: string\n onClear: () => void\n max?: number\n}\n\nexport interface AutocompleteItemRender {\n (props: AutocompleteRenderProps): ReactNode\n}\n\nconst defaultRender: AutocompleteItemRender = ({\n count,\n focused,\n index,\n label,\n max,\n separator,\n}) => {\n const last = count - 1 === index\n\n return (\n <span style={{ marginInlineEnd: \"var(--gap)\" }}>\n {label}\n {((!isNumber(max) || count < max) && focused) || !last ? separator : null}\n </span>\n )\n}\n\nconst getInputValue = (item?: ComboboxItemWithValue) =>\n isString(item?.label) ? item.label : (item?.query ?? \"\")\n\nexport interface AutocompleteFilter {\n (\n inputValue: string,\n items: ComboboxItem[],\n matcher: AutocompleteMatcher,\n ): ComboboxItem[]\n}\n\nconst defaultFilter: AutocompleteFilter = (inputValue, items, matcher) => {\n if (!inputValue.length) return items\n\n return items\n .map((item) => {\n if (\"items\" in item) {\n const items = item.items.filter((item) => {\n if (\"query\" in item) {\n return matcher(inputValue, item.query)\n } else if (isString(item.label)) {\n return matcher(inputValue, item.label)\n }\n })\n\n if (items.length) return { ...item, items }\n } else if (\"query\" in item) {\n if (matcher(inputValue, item.query)) return item\n } else if (isString(item.label)) {\n if (matcher(inputValue, item.label)) return item\n }\n })\n .filter(Boolean) as ComboboxItem[]\n}\n\nexport interface AutocompleteMatcher {\n (input: string, target?: string): boolean\n}\n\nconst defaultMatcher: AutocompleteMatcher = (input, target) =>\n target?.toLowerCase().includes(input.toLowerCase()) ?? false\n\ninterface AutocompleteContext extends Pick<\n UseAutocompleteReturn,\n \"max\" | \"value\"\n> {}\n\nconst [AutocompleteContext, useAutocompleteContext] =\n createContext<AutocompleteContext>({\n name: \"AutocompleteContext\",\n })\n\nexport { AutocompleteContext, useAutocompleteContext }\n\nexport interface UseAutocompleteProps<Multiple extends boolean = false>\n extends\n Omit<HTMLProps, \"defaultValue\" | \"onChange\" | \"ref\" | \"value\">,\n Omit<\n UseComboboxProps,\n \"defaultValue\" | \"initialFocusValue\" | \"onChange\" | \"ref\" | \"value\"\n >,\n HTMLRefAttributes<\"input\">,\n FieldProps {\n /**\n * If `true`, the autocomplete will allow custom value.\n *\n * @default false\n */\n allowCustomValue?: boolean\n /**\n * If `true`, the autocomplete will be closed when the input value changes.\n *\n * @default false\n */\n closeOnChange?: ((ev: ChangeEvent<HTMLInputElement>) => boolean) | boolean\n /**\n * The initial value of the input.\n */\n defaultInputValue?: string\n /**\n * The initial value of the autocomplete.\n */\n defaultValue?: Multiple extends true ? string[] : string\n /**\n * The message displayed when the search yields no hits.\n *\n * @default 'No results found'\n */\n emptyMessage?: ReactNode\n /**\n * The function to filter the items.\n */\n filter?: AutocompleteFilter\n /**\n * If `true`, the input will be focused when the clear icon is clicked.\n *\n * @default true\n */\n focusOnClear?: boolean\n /**\n * The `id` attribute of the input element.\n */\n id?: string\n /**\n * The value of the input.\n */\n inputValue?: string\n /**\n * If provided, generate options based on items.\n *\n * @default []\n */\n items?: ComboboxItem[]\n /**\n * The function to match the items.\n */\n matcher?: AutocompleteMatcher\n /**\n * The maximum selectable value.\n */\n max?: number\n /**\n * If `true`, the autocomplete will be multiple.\n *\n * @default false\n */\n multiple?: Multiple\n /**\n * The `name` attribute of the input element.\n */\n name?: string\n /**\n * If `true`, the autocomplete will be opened when the input value changes.\n *\n * @default true\n */\n openOnChange?: ((ev: ChangeEvent<HTMLInputElement>) => boolean) | boolean\n /**\n * If `true`, the autocomplete will be opened when the input is focused.\n *\n * @default true\n */\n openOnFocus?: boolean\n /**\n * The placeholder for autocomplete.\n */\n placeholder?: string\n /**\n * The visual separator between each value.\n *\n * @default ','\n */\n separator?: string\n /**\n * The value of the autocomplete.\n */\n value?: Multiple extends true ? string[] : string\n /**\n * The callback invoked when value state changes.\n */\n onChange?: (value: Multiple extends true ? string[] : string) => void\n /**\n * The callback invoked when input value state changes.\n */\n onInputChange?: (value: string) => void\n /**\n * The function to render the selected items.\n */\n render?: (props: AutocompleteRenderProps) => ReactNode\n}\n\nexport const useAutocomplete = <Multiple extends boolean = false>(\n props: UseAutocompleteProps<Multiple> = {},\n) => {\n type MaybeValue = Multiple extends true ? string[] : string\n\n const { t } = useI18n(\"autocomplete\")\n const {\n props: {\n id,\n ref,\n name,\n allowCustomValue = false,\n closeOnChange = false,\n multiple = false,\n closeOnSelect = !multiple,\n defaultInputValue,\n defaultValue = (multiple ? [] : \"\") as MaybeValue,\n disabled,\n emptyMessage = t(\"No results found\"),\n filter = defaultFilter,\n focusOnClear = true,\n inputValue: inputValueProp,\n items = [],\n matcher = defaultMatcher,\n max,\n openOnChange = true,\n openOnClick = true,\n openOnFocus = true,\n placeholder,\n readOnly,\n render = defaultRender,\n required,\n separator = \",\",\n value: valueProp,\n onChange: onChangeProp,\n onInputChange: onInputChangeProp,\n ...rest\n },\n ariaProps,\n dataProps,\n eventProps,\n } = useFieldProps(props)\n const fieldRef = useRef<HTMLDivElement>(null)\n const contentRef = useRef<HTMLDivElement>(null)\n const inputRef = useRef<HTMLInputElement>(null)\n const focusByClickRef = useRef<boolean>(false)\n const valueMap = useMemo<{ [key: string]: ComboboxItemWithValue }>(() => {\n const valueMap: { [key: string]: ComboboxItemWithValue } = {}\n\n items.forEach((item) => {\n if (\"items\" in item) {\n item.items.forEach((item) => {\n item.value ??= isString(item.label) ? item.label : undefined\n\n if (!isUndefined(item.value)) valueMap[item.value] = item\n })\n } else {\n item.value ??= isString(item.label) ? item.label : undefined\n\n if (!isUndefined(item.value)) valueMap[item.value] = item\n }\n })\n\n return valueMap\n }, [items])\n const [focused, setFocused] = useState(false)\n const [value, setValue] = useControllableState({\n defaultValue,\n value: valueProp,\n onChange: onChangeProp,\n })\n const [inputValue, setInputValue] = useControllableState({\n defaultValue:\n defaultInputValue ??\n getInputValue(isArray(value) ? undefined : valueMap[value as string]),\n value: inputValueProp,\n onChange: onInputChangeProp,\n })\n const onChange = useCallback(\n (selectedValue: string) => {\n setValue((prev) => {\n if (isArray(prev)) {\n if (prev.includes(selectedValue)) {\n return prev.filter(\n (prevValue) => prevValue !== selectedValue,\n ) as MaybeValue\n } else if (!isNumber(max) || prev.length < max) {\n return [...prev, selectedValue] as MaybeValue\n } else {\n return prev\n }\n } else {\n return selectedValue as MaybeValue\n }\n })\n\n if (isArray(value)) {\n setInputValue(\"\")\n } else {\n const item = valueMap[selectedValue]\n\n setInputValue(getInputValue(item))\n }\n },\n [max, setInputValue, setValue, value, valueMap],\n )\n const {\n activeDescendant,\n descendants,\n interactive,\n open,\n getContentProps: getComboboxContentProps,\n getSeparatorProps,\n getTriggerProps,\n popoverProps,\n onActiveDescendant,\n onClose,\n onOpen,\n onOpenWithActiveDescendant,\n onSelect,\n } = useCombobox({\n closeOnSelect,\n disabled,\n initialFocusValue: isArray(value) ? value[0] : value,\n openOnClick: false,\n openOnEnter: false,\n openOnSpace: false,\n readOnly,\n selectFocusRef: inputRef,\n selectOnSpace: false,\n onChange,\n ...ariaProps,\n ...dataProps,\n ...eventProps,\n ...rest,\n })\n const filteredItems = useMemo<ComboboxItem[]>(() => {\n if (!items.length) return []\n\n return filter(inputValue, items, matcher)\n }, [filter, inputValue, items, matcher])\n const resolvedItems = useMemo<ComboboxItem[]>(() => {\n return filteredItems.length\n ? filteredItems\n : [{ \"data-empty\": \"\", label: emptyMessage }]\n }, [filteredItems, emptyMessage])\n const empty = useMemo(\n () => !resolvedItems.filter(({ hidden }) => !hidden).length,\n [resolvedItems],\n )\n const children = useMemo<ReactNode>(() => {\n if (!isArray(value)) return null\n\n const count = value.length\n\n return value.map((value, index) => {\n const item = valueMap[value] ?? { label: value, value }\n\n const onClear = (ev?: MouseEvent<HTMLElement>) => {\n ev?.preventDefault()\n ev?.stopPropagation()\n\n if (item.value) onChange(item.value)\n }\n\n const component = render({\n count,\n focused,\n index,\n max,\n separator,\n onClear,\n ...item,\n })\n\n if (isValidElement<Dict>(component)) {\n return cloneElement(component, { ...component.props, key: index })\n } else {\n return component\n }\n })\n }, [focused, max, onChange, render, separator, value, valueMap])\n const hasValues = isArray(value) && !!value.length\n\n const onInputChange = useCallback(\n (ev: ChangeEvent<HTMLInputElement>) => {\n if (isArray(value) && value.length === max) return\n\n if (runIfFn(closeOnChange, ev)) {\n onClose()\n } else if (runIfFn(openOnChange, ev)) {\n onOpen()\n }\n\n activeDescendant.current = null\n\n const inputValue = ev.target.value\n\n setInputValue(inputValue)\n\n if (inputValue.length || isArray(value)) return\n\n setValue(\"\" as MaybeValue)\n },\n [\n activeDescendant,\n closeOnChange,\n max,\n onClose,\n onOpen,\n openOnChange,\n setInputValue,\n setValue,\n value,\n ],\n )\n\n const onKeyDown = useCallback(\n (ev: KeyboardEvent<HTMLInputElement>) => {\n if (disabled || isComposing(ev)) return\n\n const inputValue = cast<HTMLInputElement>(ev.target).value\n\n runKeyAction(\n ev,\n {\n Backspace: (ev) => {\n if (!isArray(value)) return\n if (!!inputValue.length) return\n\n ev.preventDefault()\n\n setValue((prev) => prev.slice(0, -1) as MaybeValue)\n },\n Enter: (ev) => {\n if (!open || !inputValue.length || activeDescendant.current) return\n\n const item = filteredItems[0]\n\n if (!item) {\n if (!allowCustomValue || !isArray(value)) return\n\n ev.preventDefault()\n\n onSelect(inputValue)\n } else {\n ev.preventDefault()\n\n if (\"items\" in item) {\n onSelect(item.items[0]?.value)\n } else {\n onSelect(item.value)\n }\n }\n },\n },\n { preventDefault: false },\n )\n },\n [\n activeDescendant,\n allowCustomValue,\n disabled,\n filteredItems,\n onSelect,\n open,\n setValue,\n value,\n ],\n )\n\n const onClick = useCallback(() => {\n if (!interactive) return\n\n focusByClickRef.current = true\n\n inputRef.current?.focus()\n\n if (openOnClick) onOpenWithActiveDescendant(descendants.enabledFirstValue)\n }, [descendants, interactive, onOpenWithActiveDescendant, openOnClick])\n\n const onMouseDown = useCallback(\n (ev: MouseEvent<HTMLInputElement>) => {\n if (!openOnFocus) return\n\n ev.preventDefault()\n ev.stopPropagation()\n },\n [openOnFocus],\n )\n\n const onFocus = useCallback(\n (ev: FocusEvent<HTMLInputElement>) => {\n ev.preventDefault()\n ev.stopPropagation()\n\n setFocused(true)\n\n if (openOnFocus && !focusByClickRef.current)\n onOpenWithActiveDescendant(descendants.enabledFirstValue)\n\n focusByClickRef.current = false\n },\n [openOnFocus, onOpenWithActiveDescendant, descendants.enabledFirstValue],\n )\n\n const onBlur = useCallback(\n (ev: FocusEvent<HTMLInputElement>) => {\n if (\n contains(fieldRef.current, ev.relatedTarget) ||\n contains(contentRef.current, ev.relatedTarget)\n ) {\n ev.preventDefault()\n } else {\n setFocused(false)\n\n if (isArray(value)) {\n setInputValue(\"\")\n } else {\n if (allowCustomValue) {\n if (inputValue) setValue(inputValue as MaybeValue)\n } else {\n const item = valueMap[value as string]\n\n setInputValue(getInputValue(item))\n }\n }\n }\n },\n [allowCustomValue, inputValue, setInputValue, setValue, value, valueMap],\n )\n\n const onClear = useCallback(() => {\n if (!interactive) return\n\n setValue((prev) => (isArray(prev) ? [] : \"\") as MaybeValue)\n setInputValue(\"\")\n\n if (focusOnClear) inputRef.current?.focus()\n }, [focusOnClear, interactive, setInputValue, setValue])\n\n useUpdateEffect(() => {\n if (isArray(valueProp)) return\n\n setInputValue(\n getInputValue(valueProp ? valueMap[valueProp as string] : undefined),\n )\n }, [valueProp])\n\n const getRootProps: PropGetter = useCallback(\n (props) => ({\n ...dataProps,\n ...props,\n }),\n [dataProps],\n )\n\n const getFieldProps: PropGetter = useCallback(\n ({ ref, ...props } = {}) =>\n getTriggerProps({\n ref: mergeRefs(ref, fieldRef),\n tabIndex: -1,\n ...props,\n onClick: handlerAll(props.onClick, onClick),\n }),\n\n [getTriggerProps, onClick],\n )\n\n const getInputProps: PropGetter<\"input\"> = useCallback(\n (props = {}) => ({\n id,\n ref: mergeRefs(props.ref, ref, inputRef),\n name,\n style: {\n ...(!focused && isArray(value) && !!value.length\n ? visuallyHiddenAttributes.style\n : {}),\n ...props.style,\n },\n \"data-max\": dataAttr(\n isArray(value) && isNumber(max) && value.length >= max,\n ),\n autoCapitalize: \"off\",\n autoComplete: \"off\",\n autoCorrect: \"off\",\n disabled,\n placeholder: hasValues ? undefined : placeholder,\n readOnly,\n required,\n spellCheck: false,\n value: inputValue,\n ...dataProps,\n ...props,\n onBlur: handlerAll(props.onBlur, onBlur),\n onChange: handlerAll(props.onChange, onInputChange),\n onFocus: handlerAll(props.onFocus, onFocus),\n onKeyDown: handlerAll(props.onKeyDown, onKeyDown),\n onMouseDown: handlerAll(props.onMouseDown, onMouseDown),\n }),\n [\n dataProps,\n disabled,\n focused,\n hasValues,\n id,\n inputValue,\n max,\n name,\n onBlur,\n onFocus,\n onInputChange,\n onKeyDown,\n onMouseDown,\n placeholder,\n readOnly,\n ref,\n required,\n value,\n ],\n )\n\n const getContentProps: PropGetter = useCallback(\n ({ ref, ...props } = {}) =>\n getComboboxContentProps({\n ref: mergeRefs(ref, contentRef),\n hidden: empty,\n ...props,\n }),\n [empty, getComboboxContentProps],\n )\n\n const getIconProps: PropGetter = useCallback(\n (props) => ({ ...dataProps, ...props }),\n [dataProps],\n )\n\n const getClearIconProps: PropGetter = useCallback(\n (props = {}) =>\n getIconProps({\n \"aria-disabled\": ariaAttr(!interactive),\n \"aria-label\": t(\"Clear value\"),\n role: \"button\",\n tabIndex: interactive ? 0 : -1,\n ...props,\n onClick: handlerAll(props.onClick, onClear),\n onKeyDown: handlerAll(props.onKeyDown, (ev) =>\n runKeyAction(ev, { Enter: onClear, Space: onClear }),\n ),\n }),\n [getIconProps, interactive, onClear, t],\n )\n\n return {\n children,\n descendants,\n inputValue,\n interactive,\n items: resolvedItems,\n max,\n open,\n setInputValue,\n setValue,\n value,\n valueMap,\n getClearIconProps,\n getContentProps,\n getFieldProps,\n getIconProps,\n getInputProps,\n getRootProps,\n getSeparatorProps,\n popoverProps,\n onActiveDescendant,\n onChange,\n onClose,\n onInputChange,\n onOpen,\n onSelect,\n }\n}\n\nexport type UseAutocompleteReturn = ReturnType<typeof useAutocomplete>\n\nexport interface UseAutocompleteOptionProps extends UseComboboxItemProps {}\n\nexport const useAutocompleteOption = ({\n children,\n closeOnSelect,\n disabled,\n hidden,\n value,\n ...rest\n}: UseAutocompleteOptionProps = {}) => {\n const { max, value: selectedValue } = useAutocompleteContext()\n\n value ??= isString(children) ? children : undefined\n\n const selected = isArray(selectedValue)\n ? !isUndefined(value) && selectedValue.includes(value)\n : selectedValue === value\n const completed =\n isNumber(max) && isArray(selectedValue) && selectedValue.length >= max\n const { getIndicatorProps, getItemProps } = useComboboxItem({\n children,\n closeOnSelect,\n disabled: disabled || hidden || (completed && !selected),\n hidden,\n selected,\n value,\n ...rest,\n })\n\n const getOptionProps: PropGetter = useCallback(\n (props = {}) => getItemProps(props),\n [getItemProps],\n )\n\n return { getIndicatorProps, getOptionProps }\n}\n\nexport type UseAutocompleteOptionReturn = ReturnType<\n typeof useAutocompleteOption\n>\n"],"mappings":";;;;;;;;;;;;;;;;;AA8DA,MAAMA,iBAAyC,EAC7C,OACA,SACA,OACA,OACA,KACA,gBACI;CACJ,MAAM,OAAO,QAAQ,MAAM;AAE3B,QACE,qBAAC;EAAK,OAAO,EAAE,iBAAiB,cAAc;aAC3C,QACE,6BAAU,IAAI,IAAI,QAAQ,QAAQ,WAAY,CAAC,OAAO,YAAY;GAChE;;AAIX,MAAM,iBAAiB,qCACZ,MAAM,MAAM,GAAG,KAAK,QAAS,MAAM,SAAS;AAUvD,MAAMC,iBAAqC,YAAY,OAAO,YAAY;AACxE,KAAI,CAAC,WAAW,OAAQ,QAAO;AAE/B,QAAO,MACJ,KAAK,SAAS;AACb,MAAI,WAAW,MAAM;GACnB,MAAMC,UAAQ,KAAK,MAAM,QAAQ,WAAS;AACxC,QAAI,WAAWC,OACb,QAAO,QAAQ,YAAYA,OAAK,MAAM;yCACpBA,OAAK,MAAM,CAC7B,QAAO,QAAQ,YAAYA,OAAK,MAAM;KAExC;AAEF,OAAID,QAAM,OAAQ,QAAO;IAAE,GAAG;IAAM;IAAO;aAClC,WAAW,MACpB;OAAI,QAAQ,YAAY,KAAK,MAAM,CAAE,QAAO;yCAC1B,KAAK,MAAM,EAC7B;OAAI,QAAQ,YAAY,KAAK,MAAM,CAAE,QAAO;;GAE9C,CACD,OAAO,QAAQ;;AAOpB,MAAME,kBAAuC,OAAO,WAClD,QAAQ,aAAa,CAAC,SAAS,MAAM,aAAa,CAAC,IAAI;AAOzD,MAAM,CAAC,qBAAqB,0BAC1BC,gBAAmC,EACjC,MAAM,uBACP,CAAC;AAyHJ,MAAa,mBACX,QAAwC,EAAE,KACvC;CAGH,MAAM,EAAE,MAA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B,CACjC;CAED,MAAMK,eAA2B,aAC9B,aAAW;EAAE,GAAG;EAAW,GAAGL;EAAO,GACtC,CAAC,UAAU,CACZ;AAkBD,QAAO;EACL;EACA;EACA;EACA;EACA,OAAO;EACP;EACA;EACA;EACA;EACA;EACA;EACA,mBA5BoC,aACnC,UAAQ,EAAE,KACT,aAAa;GACX,6CAA0B,CAAC,YAAY;GACvC,cAAc,EAAE,cAAc;GAC9B,MAAM;GACN,UAAU,cAAc,IAAI;GAC5B,GAAGA;GACH,uCAAoBA,QAAM,SAAS,QAAQ;GAC3C,yCAAsBA,QAAM,YAAY,OACtC,aAAa,IAAI;IAAE,OAAO;IAAS,OAAO;IAAS,CAAC,CACrD;GACF,CAAC,EACJ;GAAC;GAAc;GAAa;GAAS;GAAE,CACxC;EAeC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACD;;AAOH,MAAa,yBAAyB,EACpC,UACA,eACA,UACA,QACA,OACA,GAAG,SAC2B,EAAE,KAAK;CACrC,MAAM,EAAE,KAAK,OAAO,kBAAkB,wBAAwB;AAE9D,uCAAmB,SAAS,GAAG,WAAW;CAE1C,MAAM,sCAAmB,cAAc,GACnC,gCAAa,MAAM,IAAI,cAAc,SAAS,MAAM,GACpD,kBAAkB;CACtB,MAAM,wCACK,IAAI,+BAAY,cAAc,IAAI,cAAc,UAAU;CACrE,MAAM,EAAE,mBAAmB,iBAAiB,gBAAgB;EAC1D;EACA;EACA,UAAU,YAAY,UAAW,aAAa,CAAC;EAC/C;EACA;EACA;EACA,GAAG;EACJ,CAAC;AAOF,QAAO;EAAE;EAAmB,gBALO,aAChC,QAAQ,EAAE,KAAK,aAAa,MAAM,EACnC,CAAC,aAAa,CACf;EAE2C"}
|
|
@@ -9,7 +9,7 @@ import "../collapse/index.js";
|
|
|
9
9
|
import "../../index.js";
|
|
10
10
|
import { AccordionStyle } from "./accordion.style.js";
|
|
11
11
|
import { UseAccordionItemProps, UseAccordionProps } from "./use-accordion.js";
|
|
12
|
-
import * as
|
|
12
|
+
import * as react968 from "react";
|
|
13
13
|
|
|
14
14
|
//#region src/components/accordion/accordion.d.ts
|
|
15
15
|
interface AccordionCallBackProps {
|
|
@@ -33,7 +33,7 @@ interface AccordionRootProps extends Omit<HTMLStyledProps, "onChange">, ThemePro
|
|
|
33
33
|
*/
|
|
34
34
|
items?: AccordionItem[];
|
|
35
35
|
}
|
|
36
|
-
declare const AccordionPropsContext:
|
|
36
|
+
declare const AccordionPropsContext: react968.Context<Partial<AccordionRootProps> | undefined>, useAccordionPropsContext: () => Partial<AccordionRootProps> | undefined;
|
|
37
37
|
/**
|
|
38
38
|
* `Accordion` is a component for a list that displays information in an expandable or collapsible manner.
|
|
39
39
|
*
|
|
@@ -3,7 +3,7 @@ import { CSSModifierObject, CSSPropObject, CSSSlotObject } from "../../core/css/
|
|
|
3
3
|
import "../../index.js";
|
|
4
4
|
|
|
5
5
|
//#region src/components/accordion/accordion.style.d.ts
|
|
6
|
-
declare const accordionStyle: ComponentSlotStyle<"button" | "panel" | "icon" | "
|
|
6
|
+
declare const accordionStyle: ComponentSlotStyle<"button" | "panel" | "icon" | "root" | "item", CSSPropObject<CSSSlotObject<"button" | "panel" | "icon" | "root" | "item">>, CSSModifierObject<CSSSlotObject<"button" | "panel" | "icon" | "root" | "item">>, {
|
|
7
7
|
panel: {
|
|
8
8
|
button: {
|
|
9
9
|
rounded: "l2";
|
|
@@ -2,10 +2,10 @@ import { HTMLProps, PropGetter } from "../../core/components/index.types.js";
|
|
|
2
2
|
import "../../core/index.js";
|
|
3
3
|
import { Descendant } from "../../hooks/use-descendants/index.js";
|
|
4
4
|
import "../../index.js";
|
|
5
|
-
import * as
|
|
5
|
+
import * as react956 from "react";
|
|
6
6
|
|
|
7
7
|
//#region src/components/accordion/use-accordion.d.ts
|
|
8
|
-
declare const AccordionDescendantsContext:
|
|
8
|
+
declare const AccordionDescendantsContext: react956.Context<{
|
|
9
9
|
active: (target?: HTMLButtonElement | Descendant<HTMLButtonElement, {}> | null | undefined, options?: FocusOptions) => void;
|
|
10
10
|
count: () => number;
|
|
11
11
|
destroy: () => void;
|
|
@@ -24,7 +24,7 @@ declare const AccordionDescendantsContext: react147.Context<{
|
|
|
24
24
|
prevValue: (indexOrNode: number | HTMLButtonElement | Descendant<HTMLButtonElement, {}> | null, loop?: boolean) => Descendant<HTMLButtonElement, {}> | undefined;
|
|
25
25
|
register: (props?: {
|
|
26
26
|
disabled?: boolean | ((node: HTMLButtonElement) => boolean) | undefined;
|
|
27
|
-
} | undefined) =>
|
|
27
|
+
} | undefined) => react956.RefCallback<HTMLButtonElement>;
|
|
28
28
|
unregister: (node?: HTMLButtonElement | null | undefined) => void;
|
|
29
29
|
value: (indexOrNode: number | HTMLButtonElement | null) => Descendant<HTMLButtonElement, {}> | undefined;
|
|
30
30
|
values: () => Descendant<HTMLButtonElement, {}>[];
|
|
@@ -50,12 +50,12 @@ declare const AccordionDescendantsContext: react147.Context<{
|
|
|
50
50
|
prevValue: (indexOrNode: number | HTMLButtonElement | Descendant<HTMLButtonElement, {}> | null, loop?: boolean) => Descendant<HTMLButtonElement, {}> | undefined;
|
|
51
51
|
register: (props?: {
|
|
52
52
|
disabled?: boolean | ((node: HTMLButtonElement) => boolean) | undefined;
|
|
53
|
-
} | undefined) =>
|
|
53
|
+
} | undefined) => react956.RefCallback<HTMLButtonElement>;
|
|
54
54
|
unregister: (node?: HTMLButtonElement | null | undefined) => void;
|
|
55
55
|
value: (indexOrNode: number | HTMLButtonElement | null) => Descendant<HTMLButtonElement, {}> | undefined;
|
|
56
56
|
values: () => Descendant<HTMLButtonElement, {}>[];
|
|
57
57
|
};
|
|
58
|
-
register:
|
|
58
|
+
register: react956.RefCallback<HTMLButtonElement>;
|
|
59
59
|
}, useAccordionDescendants: () => {
|
|
60
60
|
active: (target?: HTMLButtonElement | Descendant<HTMLButtonElement, {}> | null | undefined, options?: FocusOptions) => void;
|
|
61
61
|
count: () => number;
|
|
@@ -75,15 +75,15 @@ declare const AccordionDescendantsContext: react147.Context<{
|
|
|
75
75
|
prevValue: (indexOrNode: number | HTMLButtonElement | Descendant<HTMLButtonElement, {}> | null, loop?: boolean) => Descendant<HTMLButtonElement, {}> | undefined;
|
|
76
76
|
register: (props?: {
|
|
77
77
|
disabled?: boolean | ((node: HTMLButtonElement) => boolean) | undefined;
|
|
78
|
-
} | undefined) =>
|
|
78
|
+
} | undefined) => react956.RefCallback<HTMLButtonElement>;
|
|
79
79
|
unregister: (node?: HTMLButtonElement | null | undefined) => void;
|
|
80
80
|
value: (indexOrNode: number | HTMLButtonElement | null) => Descendant<HTMLButtonElement, {}> | undefined;
|
|
81
81
|
values: () => Descendant<HTMLButtonElement, {}>[];
|
|
82
82
|
};
|
|
83
83
|
interface AccordionContext extends Omit<UseAccordionReturn, "descendants" | "getRootProps"> {}
|
|
84
|
-
declare const AccordionContext:
|
|
84
|
+
declare const AccordionContext: react956.Context<AccordionContext>, useAccordionContext: () => AccordionContext;
|
|
85
85
|
interface AccordionItemContext extends Omit<UseAccordionItemReturn, "getItemProps"> {}
|
|
86
|
-
declare const AccordionItemContext:
|
|
86
|
+
declare const AccordionItemContext: react956.Context<AccordionItemContext>, useAccordionItemContext: () => AccordionItemContext;
|
|
87
87
|
interface UseAccordionProps extends Omit<HTMLProps, "onChange"> {
|
|
88
88
|
/**
|
|
89
89
|
* The initial index(es) of the accordion item to expand.
|
|
@@ -137,7 +137,7 @@ declare const useAccordion: ({
|
|
|
137
137
|
prevValue: (indexOrNode: number | HTMLButtonElement | Descendant<HTMLButtonElement, {}> | null, loop?: boolean) => Descendant<HTMLButtonElement, {}> | undefined;
|
|
138
138
|
register: (props?: {
|
|
139
139
|
disabled?: boolean | ((node: HTMLButtonElement) => boolean) | undefined;
|
|
140
|
-
} | undefined) =>
|
|
140
|
+
} | undefined) => react956.RefCallback<HTMLButtonElement>;
|
|
141
141
|
unregister: (node?: HTMLButtonElement | null | undefined) => void;
|
|
142
142
|
value: (indexOrNode: number | HTMLButtonElement | null) => Descendant<HTMLButtonElement, {}> | undefined;
|
|
143
143
|
values: () => Descendant<HTMLButtonElement, {}>[];
|
|
@@ -145,8 +145,8 @@ declare const useAccordion: ({
|
|
|
145
145
|
focusedIndex: number;
|
|
146
146
|
index: number | number[];
|
|
147
147
|
multiple: boolean | undefined;
|
|
148
|
-
setFocusedIndex:
|
|
149
|
-
setIndex:
|
|
148
|
+
setFocusedIndex: react956.Dispatch<react956.SetStateAction<number>>;
|
|
149
|
+
setIndex: react956.Dispatch<react956.SetStateAction<number | number[]>>;
|
|
150
150
|
toggle: boolean | undefined;
|
|
151
151
|
getRootProps: PropGetter<"div", undefined, undefined>;
|
|
152
152
|
};
|
|
@@ -5,7 +5,7 @@ import { AiryStyle } from "./airy.style.js";
|
|
|
5
5
|
import { HTMLMotionProps } from "../motion/index.types.js";
|
|
6
6
|
import "../motion/index.js";
|
|
7
7
|
import "../../index.js";
|
|
8
|
-
import * as
|
|
8
|
+
import * as react955 from "react";
|
|
9
9
|
import { ReactNode } from "react";
|
|
10
10
|
|
|
11
11
|
//#region src/components/airy/airy.d.ts
|
|
@@ -57,7 +57,7 @@ interface AiryProps extends Omit<HTMLMotionProps<"button">, "onChange">, ThemePr
|
|
|
57
57
|
*/
|
|
58
58
|
onChange?: (value: KeyframeIdent) => void;
|
|
59
59
|
}
|
|
60
|
-
declare const AiryPropsContext:
|
|
60
|
+
declare const AiryPropsContext: react955.Context<Partial<AiryProps> | undefined>, useAiryPropsContext: () => Partial<AiryProps> | undefined;
|
|
61
61
|
/**
|
|
62
62
|
* `Airy` is a component that creates an airy animation, switching between two elements when one is clicked.
|
|
63
63
|
*
|
|
@@ -9,7 +9,7 @@ import "../loading/index.js";
|
|
|
9
9
|
import { StatusScheme } from "../status/status.js";
|
|
10
10
|
import "../status/index.js";
|
|
11
11
|
import "../../index.js";
|
|
12
|
-
import * as
|
|
12
|
+
import * as react954 from "react";
|
|
13
13
|
|
|
14
14
|
//#region src/components/alert/alert.d.ts
|
|
15
15
|
interface AlertRootProps extends HTMLStyledProps, ThemeProps<AlertStyle> {
|
|
@@ -20,7 +20,7 @@ interface AlertRootProps extends HTMLStyledProps, ThemeProps<AlertStyle> {
|
|
|
20
20
|
*/
|
|
21
21
|
status?: StatusScheme;
|
|
22
22
|
}
|
|
23
|
-
declare const AlertPropsContext:
|
|
23
|
+
declare const AlertPropsContext: react954.Context<Partial<AlertRootProps> | undefined>, useAlertPropsContext: () => Partial<AlertRootProps> | undefined;
|
|
24
24
|
/**
|
|
25
25
|
* `Alert` is a component that conveys information to the user.
|
|
26
26
|
*
|
|
@@ -5,7 +5,7 @@ import { AlphaSliderStyle } from "./alpha-slider.style.js";
|
|
|
5
5
|
import { HueSliderOverlayProps, HueSliderRootProps, HueSliderThumbProps, HueSliderTrackProps } from "../hue-slider/hue-slider.js";
|
|
6
6
|
import "../hue-slider/index.js";
|
|
7
7
|
import "../../index.js";
|
|
8
|
-
import * as
|
|
8
|
+
import * as react953 from "react";
|
|
9
9
|
|
|
10
10
|
//#region src/components/alpha-slider/alpha-slider.d.ts
|
|
11
11
|
interface AlphaSliderRootProps extends WithoutThemeProps<Omit<HueSliderRootProps, "color" | "max" | "step" | "thumbProps" | "trackProps">, AlphaSliderStyle> {
|
|
@@ -38,7 +38,7 @@ interface AlphaSliderRootProps extends WithoutThemeProps<Omit<HueSliderRootProps
|
|
|
38
38
|
*/
|
|
39
39
|
trackProps?: AlphaSliderTrackProps;
|
|
40
40
|
}
|
|
41
|
-
declare const AlphaSliderPropsContext:
|
|
41
|
+
declare const AlphaSliderPropsContext: react953.Context<Partial<AlphaSliderRootProps> | undefined>, useAlphaSliderPropsContext: () => Partial<AlphaSliderRootProps> | undefined;
|
|
42
42
|
/**
|
|
43
43
|
* `AlphaSlider` is a component used to allow the user to select color transparency.
|
|
44
44
|
*
|
|
@@ -2,7 +2,7 @@ import { StyleValue } from "../../core/css/index.types.js";
|
|
|
2
2
|
import { Component, HTMLStyledProps } from "../../core/components/index.types.js";
|
|
3
3
|
import "../../core/index.js";
|
|
4
4
|
import "../../index.js";
|
|
5
|
-
import * as
|
|
5
|
+
import * as react952 from "react";
|
|
6
6
|
|
|
7
7
|
//#region src/components/aspect-ratio/aspect-ratio.d.ts
|
|
8
8
|
interface AspectRatioProps extends HTMLStyledProps {
|
|
@@ -13,7 +13,7 @@ interface AspectRatioProps extends HTMLStyledProps {
|
|
|
13
13
|
*/
|
|
14
14
|
ratio?: StyleValue<number>;
|
|
15
15
|
}
|
|
16
|
-
declare const AspectRatioPropsContext:
|
|
16
|
+
declare const AspectRatioPropsContext: react952.Context<Partial<AspectRatioProps> | undefined>, useAspectRatioPropsContext: () => Partial<AspectRatioProps> | undefined;
|
|
17
17
|
/**
|
|
18
18
|
* `AspectRatio` is a component for embedding things like videos and maps while maintaining the aspect ratio.
|
|
19
19
|
*
|
|
@@ -11,7 +11,7 @@ import { InputGroupRootProps } from "../input/input-group.js";
|
|
|
11
11
|
import "../input/index.js";
|
|
12
12
|
import { UseAutocompleteOptionProps, UseAutocompleteProps } from "./use-autocomplete.js";
|
|
13
13
|
import "../../index.js";
|
|
14
|
-
import * as
|
|
14
|
+
import * as react940 from "react";
|
|
15
15
|
import { ReactElement, ReactNode } from "react";
|
|
16
16
|
|
|
17
17
|
//#region src/components/autocomplete/autocomplete.d.ts
|
|
@@ -67,7 +67,7 @@ interface AutocompleteRootProps<Multiple extends boolean = false> extends Omit<H
|
|
|
67
67
|
*/
|
|
68
68
|
rootProps?: InputGroupRootProps;
|
|
69
69
|
}
|
|
70
|
-
declare const AutocompletePropsContext:
|
|
70
|
+
declare const AutocompletePropsContext: react940.Context<Partial<AutocompleteRootProps<false>> | undefined>, useAutocompletePropsContext: () => Partial<AutocompleteRootProps<false>> | undefined;
|
|
71
71
|
/**
|
|
72
72
|
* `Autocomplete` is a component used to display suggestions in response to user text input.
|
|
73
73
|
*
|
|
@@ -7,7 +7,7 @@ import { UsePopoverProps } from "../popover/use-popover.js";
|
|
|
7
7
|
import "../popover/index.js";
|
|
8
8
|
import { ComboboxDescendant, ComboboxDescendantProps, ComboboxItem, ComboboxItemWithValue, UseComboboxItemProps, UseComboboxProps } from "../../hooks/use-combobox/index.js";
|
|
9
9
|
import "../../index.js";
|
|
10
|
-
import * as
|
|
10
|
+
import * as react941 from "react";
|
|
11
11
|
import { ChangeEvent, ReactNode } from "react";
|
|
12
12
|
|
|
13
13
|
//#region src/components/autocomplete/use-autocomplete.d.ts
|
|
@@ -29,7 +29,7 @@ interface AutocompleteMatcher {
|
|
|
29
29
|
(input: string, target?: string): boolean;
|
|
30
30
|
}
|
|
31
31
|
interface AutocompleteContext extends Pick<UseAutocompleteReturn, "max" | "value"> {}
|
|
32
|
-
declare const AutocompleteContext:
|
|
32
|
+
declare const AutocompleteContext: react941.Context<AutocompleteContext>, useAutocompleteContext: () => AutocompleteContext;
|
|
33
33
|
interface UseAutocompleteProps<Multiple extends boolean = false> extends Omit<HTMLProps, "defaultValue" | "onChange" | "ref" | "value">, Omit<UseComboboxProps, "defaultValue" | "initialFocusValue" | "onChange" | "ref" | "value">, HTMLRefAttributes<"input">, FieldProps {
|
|
34
34
|
/**
|
|
35
35
|
* If `true`, the autocomplete will allow custom value.
|
|
@@ -157,7 +157,7 @@ declare const useAutocomplete: <Multiple extends boolean = false>(props?: UseAut
|
|
|
157
157
|
lastValue: () => Descendant<HTMLDivElement, ComboboxDescendantProps> | undefined;
|
|
158
158
|
nextValue: (indexOrNode: number | HTMLDivElement | Descendant<HTMLDivElement, ComboboxDescendantProps> | null, loop?: boolean) => Descendant<HTMLDivElement, ComboboxDescendantProps> | undefined;
|
|
159
159
|
prevValue: (indexOrNode: number | HTMLDivElement | Descendant<HTMLDivElement, ComboboxDescendantProps> | null, loop?: boolean) => Descendant<HTMLDivElement, ComboboxDescendantProps> | undefined;
|
|
160
|
-
register: (props?: DescendantProps<HTMLDivElement, ComboboxDescendantProps> | undefined) =>
|
|
160
|
+
register: (props?: DescendantProps<HTMLDivElement, ComboboxDescendantProps> | undefined) => react941.RefCallback<HTMLDivElement>;
|
|
161
161
|
unregister: (node?: HTMLDivElement | null | undefined) => void;
|
|
162
162
|
value: (indexOrNode: number | HTMLDivElement | null) => Descendant<HTMLDivElement, ComboboxDescendantProps> | undefined;
|
|
163
163
|
values: () => Descendant<HTMLDivElement, ComboboxDescendantProps>[];
|
|
@@ -167,8 +167,8 @@ declare const useAutocomplete: <Multiple extends boolean = false>(props?: UseAut
|
|
|
167
167
|
items: ComboboxItem[];
|
|
168
168
|
max: number | undefined;
|
|
169
169
|
open: boolean;
|
|
170
|
-
setInputValue:
|
|
171
|
-
setValue:
|
|
170
|
+
setInputValue: react941.Dispatch<react941.SetStateAction<string>>;
|
|
171
|
+
setValue: react941.Dispatch<react941.SetStateAction<Multiple extends true ? string[] : string>>;
|
|
172
172
|
value: Multiple extends true ? string[] : string;
|
|
173
173
|
valueMap: {
|
|
174
174
|
[key: string]: ComboboxItemWithValue;
|
|
@@ -6,9 +6,9 @@ import "../../core/index.js";
|
|
|
6
6
|
import { AvatarStyle } from "./avatar.style.js";
|
|
7
7
|
import { UseAvatarProps } from "./use-avatar.js";
|
|
8
8
|
import "../../index.js";
|
|
9
|
-
import * as
|
|
9
|
+
import * as react949 from "react";
|
|
10
10
|
import { ReactElement } from "react";
|
|
11
|
-
import * as
|
|
11
|
+
import * as _yamada_ui_utils14 from "@yamada-ui/utils";
|
|
12
12
|
|
|
13
13
|
//#region src/components/avatar/avatar.d.ts
|
|
14
14
|
interface AvatarProps extends HTMLStyledProps, ThemeProps<AvatarStyle>, UseAvatarProps {
|
|
@@ -25,7 +25,7 @@ interface AvatarProps extends HTMLStyledProps, ThemeProps<AvatarStyle>, UseAvata
|
|
|
25
25
|
*/
|
|
26
26
|
imageProps?: AvatarImageProps;
|
|
27
27
|
}
|
|
28
|
-
declare const component: <H extends "fragment" | As = "div", R extends
|
|
28
|
+
declare const component: <H extends "fragment" | As = "div", R extends _yamada_ui_utils14.Dict = _yamada_ui_utils14.Dict<any>>(el: H | react949.FC<R>, slot?: ComponentSlot<ComponentSlotName<ComponentSlotStyle<"image" | "group" | "fallback" | "root", {
|
|
29
29
|
shape: {
|
|
30
30
|
circle: {
|
|
31
31
|
root: {
|
|
@@ -148,7 +148,7 @@ declare const component: <H extends "fragment" | As = "div", R extends _yamada_u
|
|
|
148
148
|
name,
|
|
149
149
|
className,
|
|
150
150
|
...options
|
|
151
|
-
}?: ComponentOptions) => (initialProps?: InitialProps<R>, ...superProps: SuperProps<R>[]) => H extends "fragment" ?
|
|
151
|
+
}?: ComponentOptions) => (initialProps?: InitialProps<R>, ...superProps: SuperProps<R>[]) => H extends "fragment" ? react949.FunctionComponent<R> : Component<Exclude<H, "fragment">, R>, AvatarPropsContext: react949.Context<Partial<AvatarProps> | undefined>, useAvatarPropsContext: () => Partial<AvatarProps> | undefined, useRootComponentProps: <Y extends _yamada_ui_utils14.Dict = _yamada_ui_utils14.Dict<any>, R extends keyof Y = keyof Y>(props: Y, slot?: ComponentSlot<ComponentSlotName<ComponentSlotStyle<"image" | "group" | "fallback" | "root", {
|
|
152
152
|
shape: {
|
|
153
153
|
circle: {
|
|
154
154
|
root: {
|
|
@@ -271,7 +271,7 @@ declare const component: <H extends "fragment" | As = "div", R extends _yamada_u
|
|
|
271
271
|
className,
|
|
272
272
|
withContext,
|
|
273
273
|
transferProps
|
|
274
|
-
}?: UseComponentPropsOptions<R>) => [CSSSlotObject,
|
|
274
|
+
}?: UseComponentPropsOptions<R>) => [CSSSlotObject, _yamada_ui_utils14.Merge<WithoutThemeProps<Y, ComponentSlotStyle<"image" | "group" | "fallback" | "root", {
|
|
275
275
|
shape: {
|
|
276
276
|
circle: {
|
|
277
277
|
root: {
|