{"version":3,"sources":["../src/select.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 { FC, ReactNode } from \"react\"\nimport type { SelectIconProps } from \"./select-icon\"\nimport type { SelectListProps } from \"./select-list\"\nimport type { UseSelectProps } from \"./use-select\"\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, runIfFunc } from \"@yamada-ui/utils\"\nimport { Option } from \"./option\"\nimport { SelectIcon } from \"./select-icon\"\nimport { SelectList } from \"./select-list\"\nimport {\n  SelectDescendantsContextProvider,\n  SelectProvider,\n  useSelect,\n  useSelectContext,\n} from \"./use-select\"\n\ninterface SelectOptions {\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 select content element.\n   */\n  footer?: FC<{ value: string | undefined; onClose: () => void }> | ReactNode\n  /**\n   * The header of the select content element.\n   */\n  header?: FC<{ value: string | undefined; onClose: () => void }> | ReactNode\n  /**\n   * Props for select container element.\n   */\n  containerProps?: Omit<HTMLUIProps, \"children\">\n  /**\n   * Props for select content element.\n   */\n  contentProps?: Omit<MotionProps, \"children\">\n  /**\n   * Props for select field element.\n   */\n  fieldProps?: Omit<SelectFieldProps, \"children\">\n  /**\n   * Props for select icon element.\n   */\n  iconProps?: SelectIconProps\n  /**\n   * Props for select list element.\n   */\n  listProps?: Omit<SelectListProps, \"children\">\n  /**\n   * Props to be forwarded to the portal component.\n   *\n   * @default '{ disabled: true }'\n   */\n  portalProps?: Omit<PortalProps, \"children\">\n}\n\nexport type SelectProps = Omit<\n  UseSelectProps,\n  \"maxSelectValues\" | \"omitSelectedValues\"\n> &\n  SelectOptions &\n  ThemeProps<\"Select\">\n\n/**\n * `Select` is a component used for allowing a user to choose one option from a list.\n *\n * @see Docs https://yamada-ui.com/components/forms/select\n */\nexport const Select = forwardRef<SelectProps, \"div\">((props, ref) => {\n  const [styles, mergedProps] = useComponentMultiStyle(\"Select\", props)\n  const {\n    className,\n    color,\n    defaultValue = \"\",\n    footer,\n    h,\n    header,\n    height = h,\n    minH,\n    minHeight = minH,\n    placeholder,\n    placeholderInOptions = true,\n    containerProps,\n    contentProps,\n    fieldProps,\n    iconProps,\n    listProps,\n    portalProps = { disabled: true },\n    ...computedProps\n  } = omitThemeProps(mergedProps)\n\n  const {\n    children,\n    descendants,\n    empty,\n    value,\n    formControlProps,\n    getContainerProps,\n    getFieldProps,\n    getPopoverProps,\n    onClose,\n    ...rest\n  } = useSelect({\n    ...computedProps,\n    defaultValue,\n    placeholder,\n    placeholderInOptions,\n  })\n  const css: CSSUIObject = {\n    color,\n    h: \"fit-content\",\n    w: \"100%\",\n    ...styles.container,\n  }\n\n  return (\n    <SelectDescendantsContextProvider value={descendants}>\n      <SelectProvider\n        value={{\n          ...rest,\n          placeholder,\n          placeholderInOptions,\n          styles,\n          value,\n          onClose,\n        }}\n      >\n        <Popover {...getPopoverProps()}>\n          <ui.div\n            className={cx(\"ui-select\", className)}\n            __css={css}\n            {...getContainerProps(containerProps)}\n          >\n            <ui.div\n              className=\"ui-select__inner\"\n              __css={{ position: \"relative\", ...styles.inner }}\n            >\n              <PopoverTrigger>\n                <SelectField\n                  height={height}\n                  minHeight={minHeight}\n                  {...getFieldProps(fieldProps, ref)}\n                />\n              </PopoverTrigger>\n\n              <SelectIcon {...iconProps} {...formControlProps} />\n            </ui.div>\n\n            {!empty ? (\n              <Portal {...portalProps}>\n                <SelectList\n                  footer={runIfFunc(footer, { value, onClose })}\n                  header={runIfFunc(header, { value, onClose })}\n                  contentProps={contentProps}\n                  {...listProps}\n                >\n                  {!!placeholder && placeholderInOptions ? (\n                    <Option>{placeholder}</Option>\n                  ) : null}\n\n                  {children}\n                </SelectList>\n              </Portal>\n            ) : null}\n          </ui.div>\n        </Popover>\n      </SelectProvider>\n    </SelectDescendantsContextProvider>\n  )\n})\n\nSelect.displayName = \"Select\"\nSelect.__ui__ = \"Select\"\n\ninterface SelectFieldProps extends HTMLUIProps {}\n\nconst SelectField = forwardRef<SelectFieldProps, \"div\">(\n  ({ className, isTruncated = true, lineClamp, ...rest }, ref) => {\n    const { label, placeholder, styles } = useSelectContext()\n\n    const css: CSSUIObject = {\n      alignItems: \"center\",\n      display: \"flex\",\n      pe: \"2rem\",\n      ...styles.field,\n    }\n\n    return (\n      <ui.div\n        ref={ref}\n        className={cx(\"ui-select__field\", className)}\n        __css={css}\n        {...rest}\n      >\n        <ui.span\n          dangerouslySetInnerHTML={{\n            __html: label ?? placeholder ?? \"\",\n          }}\n          isTruncated={isTruncated}\n          lineClamp={lineClamp}\n        />\n      </ui.div>\n    )\n  },\n)\n\nSelectField.displayName = \"SelectField\"\nSelectField.__ui__ = \"SelectField\"\n"],"mappings":";;;;;;;;;;;;;;;;AAOA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,SAAS,sBAAsB;AACxC,SAAS,cAAc;AACvB,SAAS,IAAI,iBAAiB;AAqIlB,SAKI,KALJ;AAjEL,IAAM,SAAS,WAA+B,CAAC,OAAO,QAAQ;AACnE,QAAM,CAAC,QAAQ,WAAW,IAAI,uBAAuB,UAAU,KAAK;AACpE,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA,eAAe;AAAA,IACf;AAAA,IACA;AAAA,IACA;AAAA,IACA,SAAS;AAAA,IACT;AAAA,IACA,YAAY;AAAA,IACZ;AAAA,IACA,uBAAuB;AAAA,IACvB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,cAAc,EAAE,UAAU,KAAK;AAAA,IAC/B,GAAG;AAAA,EACL,IAAI,eAAe,WAAW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