@yamada-ui/autocomplete 1.6.5-next-20241118220617 → 1.6.5-next-20241119123334

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. package/dist/autocomplete-create.js.map +1 -1
  2. package/dist/autocomplete-create.mjs +2 -2
  3. package/dist/autocomplete-empty.js.map +1 -1
  4. package/dist/autocomplete-empty.mjs +2 -2
  5. package/dist/autocomplete-option.js +10 -6
  6. package/dist/autocomplete-option.js.map +1 -1
  7. package/dist/autocomplete-option.mjs +2 -2
  8. package/dist/autocomplete.js +12 -8
  9. package/dist/autocomplete.js.map +1 -1
  10. package/dist/autocomplete.mjs +6 -6
  11. package/dist/{chunk-6II6KCIJ.mjs → chunk-6QAH2ARG.mjs} +2 -2
  12. package/dist/{chunk-2UKLSSUA.mjs → chunk-7GVG5MVF.mjs} +2 -2
  13. package/dist/{chunk-JYPMXZG4.mjs → chunk-7YDPBPBY.mjs} +4 -4
  14. package/dist/{chunk-NOSATNDY.mjs → chunk-J3GHHVSC.mjs} +7 -5
  15. package/dist/chunk-J3GHHVSC.mjs.map +1 -0
  16. package/dist/{chunk-3A2HEULI.mjs → chunk-LCC3VNZV.mjs} +11 -7
  17. package/dist/chunk-LCC3VNZV.mjs.map +1 -0
  18. package/dist/{chunk-75VF5Q5W.mjs → chunk-YWUT56L3.mjs} +4 -4
  19. package/dist/chunk-YWUT56L3.mjs.map +1 -0
  20. package/dist/{chunk-G6SC44LI.mjs → chunk-ZFWB5LCD.mjs} +2 -2
  21. package/dist/index.js +15 -9
  22. package/dist/index.js.map +1 -1
  23. package/dist/index.mjs +7 -7
  24. package/dist/multi-autocomplete.d.mts +8 -0
  25. package/dist/multi-autocomplete.d.ts +8 -0
  26. package/dist/multi-autocomplete.js +15 -9
  27. package/dist/multi-autocomplete.js.map +1 -1
  28. package/dist/multi-autocomplete.mjs +6 -6
  29. package/dist/use-autocomplete-option.d.mts +16 -0
  30. package/dist/use-autocomplete-option.d.ts +16 -0
  31. package/dist/use-autocomplete-option.js +10 -6
  32. package/dist/use-autocomplete-option.js.map +1 -1
  33. package/dist/use-autocomplete-option.mjs +1 -1
  34. package/dist/use-autocomplete.d.mts +1 -1
  35. package/dist/use-autocomplete.d.ts +1 -1
  36. package/dist/use-autocomplete.js +12 -8
  37. package/dist/use-autocomplete.js.map +1 -1
  38. package/dist/use-autocomplete.mjs +3 -3
  39. package/package.json +4 -4
  40. package/dist/chunk-3A2HEULI.mjs.map +0 -1
  41. package/dist/chunk-75VF5Q5W.mjs.map +0 -1
  42. package/dist/chunk-NOSATNDY.mjs.map +0 -1
  43. /package/dist/{chunk-6II6KCIJ.mjs.map → chunk-6QAH2ARG.mjs.map} +0 -0
  44. /package/dist/{chunk-2UKLSSUA.mjs.map → chunk-7GVG5MVF.mjs.map} +0 -0
  45. /package/dist/{chunk-JYPMXZG4.mjs.map → chunk-7YDPBPBY.mjs.map} +0 -0
  46. /package/dist/{chunk-G6SC44LI.mjs.map → chunk-ZFWB5LCD.mjs.map} +0 -0
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/multi-autocomplete.tsx"],"sourcesContent":["import type { CSSUIObject, HTMLUIProps, ThemeProps } from \"@yamada-ui/core\"\nimport type { MotionProps } from \"@yamada-ui/motion\"\nimport type { PortalProps } from \"@yamada-ui/portal\"\nimport type {\n CSSProperties,\n FC,\n MouseEventHandler,\n ReactElement,\n ReactNode,\n} from \"react\"\nimport type { AutocompleteCreateProps } from \"./autocomplete-create\"\nimport type { AutocompleteEmptyProps } from \"./autocomplete-empty\"\nimport type { AutocompleteIconProps } from \"./autocomplete-icon\"\nimport type { AutocompleteListProps } from \"./autocomplete-list\"\nimport type { UseAutocompleteProps } from \"./use-autocomplete\"\nimport {\n forwardRef,\n omitThemeProps,\n ui,\n useComponentMultiStyle,\n} from \"@yamada-ui/core\"\nimport { Popover, PopoverTrigger } from \"@yamada-ui/popover\"\nimport { Portal } from \"@yamada-ui/portal\"\nimport { cx, handlerAll, runIfFunc } from \"@yamada-ui/utils\"\nimport { cloneElement, useMemo } from \"react\"\nimport {\n AutocompleteDescendantsContextProvider,\n AutocompleteProvider,\n useAutocompleteContext,\n} from \"./autocomplete-context\"\nimport { AutocompleteCreate } from \"./autocomplete-create\"\nimport { AutocompleteEmpty } from \"./autocomplete-empty\"\nimport { AutocompleteClearIcon, AutocompleteIcon } from \"./autocomplete-icon\"\nimport { AutocompleteList } from \"./autocomplete-list\"\nimport { useAutocomplete, useAutocompleteInput } from \"./use-autocomplete\"\n\ninterface MultiAutocompleteOptions {\n /**\n * If `true`, the list element will be closed when value is selected.\n *\n * @default false\n */\n closeOnSelect?: boolean\n /**\n * The custom display value to use.\n */\n component?: FC<{\n index: number\n label: string\n value: number | string\n onRemove: MouseEventHandler<HTMLElement>\n }>\n /**\n * The border color when the input is invalid.\n */\n errorBorderColor?: string\n /**\n * The border color when the input is focused.\n */\n focusBorderColor?: string\n /**\n * The footer of the autocomplete content element.\n */\n footer?: FC<{ value: string[] | undefined; onClose: () => void }> | ReactNode\n /**\n * The header of the autocomplete content element.\n */\n header?: FC<{ value: string[] | undefined; onClose: () => void }> | ReactNode\n /**\n * If `true`, display the select clear icon.\n *\n * @default true\n */\n isClearable?: boolean\n /**\n * If `true`, keep the placeholder.\n *\n * @default false\n */\n keepPlaceholder?: boolean\n /**\n * The visual separator between each value.\n *\n * @default ','\n */\n separator?: string\n /**\n * Props for multi autocomplete clear icon element.\n */\n clearIconProps?: AutocompleteIconProps\n /**\n * Props for multi autocomplete container element.\n */\n containerProps?: Omit<HTMLUIProps, \"children\">\n /**\n * Props for multi autocomplete content element.\n */\n contentProps?: Omit<MotionProps, \"children\">\n /**\n * Props for autocomplete create element.\n */\n createProps?: Omit<AutocompleteCreateProps, \"children\">\n /**\n * Props for autocomplete empty element.\n */\n emptyProps?: Omit<AutocompleteEmptyProps, \"children\">\n /**\n * Props for multi autocomplete field element.\n */\n fieldProps?: Omit<\n MultiAutocompleteFieldProps,\n \"children\" | \"component\" | \"inputProps\" | \"keepPlaceholder\" | \"separator\"\n >\n /**\n * Props for multi autocomplete icon element.\n */\n iconProps?: AutocompleteIconProps\n /**\n * Props for multi autocomplete input element.\n */\n inputProps?: HTMLUIProps<\"input\">\n /**\n * Props for multi autocomplete list element.\n */\n listProps?: Omit<AutocompleteListProps, \"children\">\n /**\n * Props to be forwarded to the portal component.\n *\n * @default '{ isDisabled: true }'\n *\n */\n portalProps?: Omit<PortalProps, \"children\">\n}\n\nexport interface MultiAutocompleteProps\n extends ThemeProps<\"MultiAutocomplete\">,\n Omit<UseAutocompleteProps<string[]>, \"closeOnSelect\">,\n MultiAutocompleteOptions {}\n\n/**\n * `MultiAutocomplete` is a component used to display suggestions based on user text input and to obtain multiple values.\n *\n * @see Docs https://yamada-ui.com/components/forms/multi-autocomplete\n */\nexport const MultiAutocomplete = forwardRef<MultiAutocompleteProps, \"input\">(\n (props, ref) => {\n const [styles, mergedProps] = useComponentMultiStyle(\n \"MultiAutocomplete\",\n props,\n )\n let {\n className,\n closeOnSelect = false,\n color,\n component,\n defaultValue = [],\n footer,\n h,\n header,\n height,\n isClearable = true,\n keepPlaceholder = false,\n minH,\n minHeight,\n separator,\n clearIconProps,\n containerProps,\n contentProps,\n createProps,\n emptyProps,\n fieldProps,\n iconProps,\n inputProps,\n listProps,\n portalProps = { isDisabled: true },\n ...computedProps\n } = omitThemeProps(mergedProps)\n\n const {\n allowCreate,\n children,\n descendants,\n inputValue,\n isEmpty,\n value,\n formControlProps,\n getContainerProps,\n getFieldProps,\n getPopoverProps,\n onClear,\n onClose,\n ...rest\n } = useAutocomplete<string[]>({\n ...computedProps,\n closeOnSelect,\n defaultValue,\n })\n\n h ??= height\n minH ??= minHeight\n\n const css: CSSUIObject = {\n color,\n h: \"fit-content\",\n w: \"100%\",\n ...styles.container,\n }\n\n return (\n <AutocompleteDescendantsContextProvider value={descendants}>\n <AutocompleteProvider\n value={{\n ...rest,\n allowCreate,\n inputValue,\n isEmpty,\n styles,\n value,\n formControlProps,\n onClose,\n }}\n >\n <Popover {...getPopoverProps()}>\n <ui.div\n className={cx(\"ui-multi-autocomplete\", className)}\n __css={css}\n {...getContainerProps(containerProps)}\n >\n <ui.div\n className=\"ui-multi-autocomplete__inner\"\n __css={{ position: \"relative\", ...styles.inner }}\n >\n <MultiAutocompleteField\n component={component}\n h={h}\n keepPlaceholder={keepPlaceholder}\n minH={minH}\n separator={separator}\n inputProps={inputProps}\n {...getFieldProps(fieldProps, ref)}\n />\n\n {isClearable && value.length ? (\n <AutocompleteClearIcon\n {...clearIconProps}\n onClick={handlerAll(clearIconProps?.onClick, onClear)}\n {...formControlProps}\n />\n ) : (\n <AutocompleteIcon {...iconProps} {...formControlProps} />\n )}\n </ui.div>\n\n <Portal {...portalProps}>\n <AutocompleteList\n footer={runIfFunc(footer, { value, onClose })}\n header={runIfFunc(header, { value, onClose })}\n contentProps={contentProps}\n {...listProps}\n >\n {!isEmpty ? (\n <>\n {allowCreate ? (\n <AutocompleteCreate {...createProps} />\n ) : (\n <AutocompleteEmpty {...emptyProps} />\n )}\n\n {children}\n </>\n ) : allowCreate && inputValue ? (\n <AutocompleteCreate {...createProps} />\n ) : (\n <AutocompleteEmpty {...emptyProps} />\n )}\n </AutocompleteList>\n </Portal>\n </ui.div>\n </Popover>\n </AutocompleteProvider>\n </AutocompleteDescendantsContextProvider>\n )\n },\n)\n\nMultiAutocomplete.displayName = \"MultiAutocomplete\"\nMultiAutocomplete.__ui__ = \"MultiAutocomplete\"\n\ninterface MultiAutocompleteFieldProps\n extends HTMLUIProps,\n Pick<\n MultiAutocompleteProps,\n \"component\" | \"inputProps\" | \"keepPlaceholder\" | \"separator\"\n > {}\n\nconst MultiAutocompleteField = forwardRef<MultiAutocompleteFieldProps, \"input\">(\n (\n {\n className,\n component,\n h,\n keepPlaceholder,\n minH,\n placeholder,\n separator = \",\",\n inputProps,\n ...rest\n },\n ref,\n ) => {\n const { inputRef, inputValue, isOpen, label, styles, value, onChange } =\n useAutocompleteContext()\n const { getInputProps } = useAutocompleteInput()\n\n const cloneChildren = useMemo(() => {\n if (!label?.length) return null\n\n if (component) {\n return (label as string[]).map((label, index) => {\n if (!value[index]) return null\n\n const onRemove: MouseEventHandler<HTMLElement> = (ev) => {\n if (!value[index]) return\n\n ev.stopPropagation()\n\n onChange(value[index])\n\n if (inputRef.current) inputRef.current.focus()\n }\n\n const el = component({\n index,\n label,\n value: value[index],\n onRemove,\n })\n\n const style: CSSProperties = {\n marginBlockEnd: \"0.125rem\",\n marginBlockStart: \"0.125rem\",\n marginInlineEnd: \"0.25rem\",\n }\n\n return el\n ? cloneElement(el as ReactElement, { key: index, style })\n : null\n })\n } else {\n return (label as string[]).map((value, index) => {\n const isLast = label.length === index + 1\n\n return (\n <ui.span key={index} display=\"inline-block\" me=\"0.25rem\">\n {value}\n {!isLast || isOpen ? separator : null}\n </ui.span>\n )\n })\n }\n }, [label, component, value, onChange, isOpen, inputRef, separator])\n\n const css: CSSUIObject = {\n alignItems: \"center\",\n display: \"flex\",\n flexWrap: \"wrap\",\n h,\n minH,\n pe: \"2rem\",\n ...styles.field,\n cursor: \"text\",\n }\n\n if (label?.length && component) css.py = \"0.125rem\"\n\n return (\n <PopoverTrigger>\n <ui.div\n className={cx(\"ui-multi-autocomplete__field\", className)}\n __css={css}\n {...rest}\n >\n {cloneChildren}\n\n <ui.input\n className=\"ui-multi-autocomplete__field__input\"\n display=\"inline-block\"\n flex=\"1\"\n marginBlockEnd=\"0.125rem\"\n marginBlockStart=\"0.125rem\"\n minW=\"0px\"\n overflow=\"hidden\"\n placeholder={\n !label?.length || (keepPlaceholder && isOpen)\n ? placeholder\n : undefined\n }\n {...getInputProps({ ...inputProps, value: inputValue }, ref)}\n />\n </ui.div>\n </PopoverTrigger>\n )\n },\n)\n\nMultiAutocompleteField.displayName = \"MultiAutocompleteField\"\nMultiAutocompleteField.__ui__ = \"MultiAutocompleteField\"\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAeA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,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