@lobehub/ui
Version:
Lobe UI is an open-source UI component library for building AIGC web apps
1 lines • 12.3 kB
Source Map (JSON)
{"version":3,"file":"atoms.mjs","names":["styles","menuStyles"],"sources":["../../src/LobeSelect/atoms.tsx"],"sourcesContent":["'use client';\n\nimport { mergeProps } from '@base-ui/react/merge-props';\nimport { Select } from '@base-ui/react/select';\nimport { cx, useThemeMode } from 'antd-style';\nimport {\n type ComponentProps,\n type ComponentPropsWithRef,\n cloneElement,\n isValidElement,\n} from 'react';\nimport { mergeRefs } from 'react-merge-refs';\n\nimport { styles as menuStyles } from '@/Menu/sharedStyle';\nimport { useNativeButton } from '@/hooks/useNativeButton';\nimport { usePortalContainer } from '@/hooks/usePortalContainer';\n\nimport { LOBE_SELECT_CONTAINER_ATTR } from './constants';\nimport { styles, triggerVariants } from './style';\nimport type { LobeSelectSize, LobeSelectVariant } from './type';\n\nconst mergeStateClassName = <TState,>(\n base: string,\n className: string | ((state: TState) => string | undefined) | undefined,\n) => {\n if (typeof className === 'function') return (state: TState) => cx(base, className(state));\n return cx(base, className);\n};\n\nexport const LobeSelectRoot = Select.Root;\nexport const LobeSelectBackdrop = Select.Backdrop;\nexport const LobeSelectSeparator = Select.Separator;\n\nexport type LobeSelectTriggerProps = Omit<\n ComponentPropsWithRef<typeof Select.Trigger>,\n 'children' | 'render'\n> & {\n children: ComponentProps<typeof Select.Trigger>['children'];\n shadow?: boolean;\n size?: LobeSelectSize;\n variant?: LobeSelectVariant;\n};\n\nexport const LobeSelectTrigger = ({\n children,\n className,\n nativeButton,\n shadow,\n size = 'middle',\n variant,\n ref: refProp,\n ...rest\n}: LobeSelectTriggerProps) => {\n const { isDarkMode } = useThemeMode();\n const resolvedVariant = variant ?? (isDarkMode ? 'filled' : 'outlined');\n const baseClassName = triggerVariants({ shadow, size, variant: resolvedVariant });\n\n const { isNativeButtonTriggerElement, resolvedNativeButton } = useNativeButton({\n children,\n nativeButton,\n });\n\n if (isValidElement(children)) {\n return (\n <Select.Trigger\n {...rest}\n nativeButton={resolvedNativeButton}\n render={(props, state) => {\n // Base UI's trigger props include `type=\"button\"` by default.\n // If we render into a non-<button> element, that prop is invalid and can warn.\n const resolvedProps = (() => {\n if (isNativeButtonTriggerElement) return props as any;\n // eslint-disable-next-line unused-imports/no-unused-vars, @typescript-eslint/no-unused-vars\n const { type, ref: triggerRef, ...restProps } = props as any;\n return restProps;\n })();\n\n const mergedProps = mergeProps((children as any).props, resolvedProps);\n const childClassName =\n typeof (mergedProps as any).className === 'function'\n ? (mergedProps as any).className(state)\n : (mergedProps as any).className;\n const extraClassName = typeof className === 'function' ? className(state) : className;\n\n return cloneElement(children as any, {\n ...mergedProps,\n className: cx(baseClassName, childClassName, extraClassName),\n ref: mergeRefs([(children as any).ref, (props as any).ref, refProp]),\n });\n }}\n />\n );\n }\n\n return (\n <Select.Trigger\n {...rest}\n className={mergeStateClassName(baseClassName, className) as any}\n nativeButton={resolvedNativeButton}\n ref={refProp as any}\n >\n {children}\n </Select.Trigger>\n );\n};\n\nLobeSelectTrigger.displayName = 'LobeSelectTrigger';\n\nexport type LobeSelectIconProps = ComponentProps<typeof Select.Icon>;\n\nexport const LobeSelectIcon = ({ className, ...rest }: LobeSelectIconProps) => {\n return <Select.Icon className={mergeStateClassName(styles.icon, className) as any} {...rest} />;\n};\n\nLobeSelectIcon.displayName = 'LobeSelectIcon';\n\nexport type LobeSelectValueProps = ComponentProps<typeof Select.Value>;\n\nexport const LobeSelectValue = ({ className, ...rest }: LobeSelectValueProps) => {\n return <Select.Value className={mergeStateClassName(styles.value, className) as any} {...rest} />;\n};\n\nLobeSelectValue.displayName = 'LobeSelectValue';\n\nexport type LobeSelectPortalProps = ComponentProps<typeof Select.Portal> & {\n /**\n * When `container` is not provided, it uses a shared container created by `usePortalContainer`.\n */\n container?: HTMLElement | null;\n};\n\nexport const LobeSelectPortal = ({ container, ...rest }: LobeSelectPortalProps) => {\n const defaultContainer = usePortalContainer(LOBE_SELECT_CONTAINER_ATTR);\n return <Select.Portal container={container ?? defaultContainer} {...rest} />;\n};\n\nLobeSelectPortal.displayName = 'LobeSelectPortal';\n\nexport type LobeSelectPositionerProps = ComponentProps<typeof Select.Positioner>;\n\nexport const LobeSelectPositioner = ({\n align,\n alignItemWithTrigger,\n className,\n side,\n sideOffset,\n ...rest\n}: LobeSelectPositionerProps) => {\n return (\n <Select.Positioner\n align={align ?? 'start'}\n alignItemWithTrigger={alignItemWithTrigger ?? false}\n className={mergeStateClassName(styles.positioner, className) as any}\n side={side ?? 'bottom'}\n sideOffset={sideOffset ?? 6}\n {...rest}\n />\n );\n};\n\nLobeSelectPositioner.displayName = 'LobeSelectPositioner';\n\nexport type LobeSelectPopupProps = ComponentProps<typeof Select.Popup>;\n\nexport const LobeSelectPopup = ({ className, ...rest }: LobeSelectPopupProps) => {\n return (\n <Select.Popup\n className={mergeStateClassName(cx(menuStyles.popup, styles.popup), className) as any}\n {...rest}\n />\n );\n};\n\nLobeSelectPopup.displayName = 'LobeSelectPopup';\n\nexport type LobeSelectListProps = ComponentProps<typeof Select.List>;\n\nexport const LobeSelectList = ({ className, ...rest }: LobeSelectListProps) => {\n return <Select.List className={mergeStateClassName(styles.list, className) as any} {...rest} />;\n};\n\nLobeSelectList.displayName = 'LobeSelectList';\n\nexport type LobeSelectItemProps = ComponentProps<typeof Select.Item>;\n\nexport const LobeSelectItem = ({ className, ...rest }: LobeSelectItemProps) => {\n return (\n <Select.Item\n className={mergeStateClassName(cx(menuStyles.item, styles.item), className) as any}\n {...rest}\n />\n );\n};\n\nLobeSelectItem.displayName = 'LobeSelectItem';\n\nexport type LobeSelectItemTextProps = ComponentProps<typeof Select.ItemText>;\n\nexport const LobeSelectItemText = ({ className, ...rest }: LobeSelectItemTextProps) => {\n return (\n <Select.ItemText\n className={mergeStateClassName(cx(menuStyles.label, styles.itemText), className) as any}\n {...rest}\n />\n );\n};\n\nLobeSelectItemText.displayName = 'LobeSelectItemText';\n\nexport type LobeSelectItemIndicatorProps = ComponentProps<typeof Select.ItemIndicator>;\n\nexport const LobeSelectItemIndicator = ({ className, ...rest }: LobeSelectItemIndicatorProps) => {\n return (\n <Select.ItemIndicator\n className={mergeStateClassName(styles.itemIndicator, className) as any}\n {...rest}\n />\n );\n};\n\nLobeSelectItemIndicator.displayName = 'LobeSelectItemIndicator';\n\nexport type LobeSelectGroupProps = ComponentProps<typeof Select.Group>;\n\nexport const LobeSelectGroup = ({ className, ...rest }: LobeSelectGroupProps) => {\n return <Select.Group className={mergeStateClassName(styles.group, className) as any} {...rest} />;\n};\n\nLobeSelectGroup.displayName = 'LobeSelectGroup';\n\nexport type LobeSelectGroupLabelProps = ComponentProps<typeof Select.GroupLabel>;\n\nexport const LobeSelectGroupLabel = ({ className, ...rest }: LobeSelectGroupLabelProps) => {\n return (\n <Select.GroupLabel\n className={\n mergeStateClassName(cx(menuStyles.groupLabel, styles.groupLabel), className) as any\n }\n {...rest}\n />\n );\n};\n\nLobeSelectGroupLabel.displayName = 'LobeSelectGroupLabel';\n\nexport type LobeSelectScrollUpArrowProps = ComponentProps<typeof Select.ScrollUpArrow>;\n\nexport const LobeSelectScrollUpArrow = ({ className, ...rest }: LobeSelectScrollUpArrowProps) => {\n return (\n <Select.ScrollUpArrow\n className={mergeStateClassName(styles.scrollArrow, className) as any}\n {...rest}\n />\n );\n};\n\nLobeSelectScrollUpArrow.displayName = 'LobeSelectScrollUpArrow';\n\nexport type LobeSelectScrollDownArrowProps = ComponentProps<typeof Select.ScrollDownArrow>;\n\nexport const LobeSelectScrollDownArrow = ({\n className,\n ...rest\n}: LobeSelectScrollDownArrowProps) => {\n return (\n <Select.ScrollDownArrow\n className={mergeStateClassName(styles.scrollArrow, className) as any}\n {...rest}\n />\n );\n};\n\nLobeSelectScrollDownArrow.displayName = 'LobeSelectScrollDownArrow';\n\nexport type LobeSelectArrowProps = ComponentProps<typeof Select.Arrow>;\n\nexport const LobeSelectArrow = ({ className, ...rest }: LobeSelectArrowProps) => {\n return <Select.Arrow className={mergeStateClassName(styles.arrow, className) as any} {...rest} />;\n};\n\nLobeSelectArrow.displayName = 'LobeSelectArrow';\n\nexport { LOBE_SELECT_CONTAINER_ATTR } from './constants';\n"],"mappings":";;;;;;;;;;;;;;;AAqBA,MAAM,uBACJ,MACA,cACG;AACH,KAAI,OAAO,cAAc,WAAY,SAAQ,UAAkB,GAAG,MAAM,UAAU,MAAM,CAAC;AACzF,QAAO,GAAG,MAAM,UAAU;;AAG5B,MAAa,iBAAiB,OAAO;AACrC,MAAa,qBAAqB,OAAO;AACzC,MAAa,sBAAsB,OAAO;AAY1C,MAAa,qBAAqB,EAChC,UACA,WACA,cACA,QACA,OAAO,UACP,SACA,KAAK,SACL,GAAG,WACyB;CAC5B,MAAM,EAAE,eAAe,cAAc;CAErC,MAAM,gBAAgB,gBAAgB;EAAE;EAAQ;EAAM,SAD9B,YAAY,aAAa,WAAW;EACoB,CAAC;CAEjF,MAAM,EAAE,8BAA8B,yBAAyB,gBAAgB;EAC7E;EACA;EACD,CAAC;AAEF,KAAI,eAAe,SAAS,CAC1B,QACE,oBAAC,OAAO;EACN,GAAI;EACJ,cAAc;EACd,SAAS,OAAO,UAAU;GAGxB,MAAM,uBAAuB;AAC3B,QAAI,6BAA8B,QAAO;IAEzC,MAAM,EAAE,MAAM,KAAK,YAAY,GAAG,cAAc;AAChD,WAAO;OACL;GAEJ,MAAM,cAAc,WAAY,SAAiB,OAAO,cAAc;GACtE,MAAM,iBACJ,OAAQ,YAAoB,cAAc,aACrC,YAAoB,UAAU,MAAM,GACpC,YAAoB;GAC3B,MAAM,iBAAiB,OAAO,cAAc,aAAa,UAAU,MAAM,GAAG;AAE5E,UAAO,aAAa,UAAiB;IACnC,GAAG;IACH,WAAW,GAAG,eAAe,gBAAgB,eAAe;IAC5D,KAAK,UAAU;KAAE,SAAiB;KAAM,MAAc;KAAK;KAAQ,CAAC;IACrE,CAAC;;GAEJ;AAIN,QACE,oBAAC,OAAO;EACN,GAAI;EACJ,WAAW,oBAAoB,eAAe,UAAU;EACx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