// // Copyright 2023 DXOS.org // import { CaretDown, CaretUp } from '@phosphor-icons/react'; import * as SelectPrimitive from '@radix-ui/react-select'; import React, { forwardRef } from 'react'; import { useElevationContext, useThemeContext } from '../../hooks'; import { useSafeCollisionPadding } from '../../hooks/useSafeCollisionPadding'; import { type ThemedClassName } from '../../util'; import { Button, type ButtonProps } from '../Buttons'; import { Icon } from '../Icon'; type SelectRootProps = SelectPrimitive.SelectProps; const SelectRoot = SelectPrimitive.Root; type SelectTriggerProps = SelectPrimitive.SelectTriggerProps; const SelectTrigger = SelectPrimitive.Trigger; type SelectValueProps = SelectPrimitive.SelectValueProps; const SelectValue = SelectPrimitive.Value; type SelectIconProps = SelectPrimitive.SelectIconProps; const SelectIcon = SelectPrimitive.Icon; type SelectPortalProps = SelectPrimitive.SelectPortalProps; const SelectPortal = SelectPrimitive.Portal; type SelectTriggerButtonProps = Omit & Pick; const SelectTriggerButton = forwardRef( ({ children, placeholder, ...props }, forwardedRef) => { const { tx } = useThemeContext(); return ( ); }, ); type SelectContentProps = ThemedClassName; const SelectContent = forwardRef( ({ classNames, children, collisionPadding = 8, ...props }, forwardedRef) => { const { tx } = useThemeContext(); const elevation = useElevationContext(); const safeCollisionPadding = useSafeCollisionPadding(collisionPadding); return ( {children} ); }, ); type SelectScrollUpButtonProps = ThemedClassName; const SelectScrollUpButton = forwardRef( ({ classNames, children, ...props }, forwardedRef) => { const { tx } = useThemeContext(); return ( {children ?? } ); }, ); type SelectScrollDownButtonProps = ThemedClassName; const SelectScrollDownButton = forwardRef( ({ classNames, children, ...props }, forwardedRef) => { const { tx } = useThemeContext(); return ( {children ?? } ); }, ); type SelectViewportProps = ThemedClassName; const SelectViewport = forwardRef( ({ classNames, asChild, children, ...props }, forwardedRef) => { const { tx } = useThemeContext(); return ( {children} ); }, ); type SelectItemProps = ThemedClassName; const SelectItem = forwardRef(({ classNames, ...props }, forwardedRef) => { const { tx } = useThemeContext(); return ; }); type SelectItemTextProps = SelectPrimitive.SelectItemTextProps; const SelectItemText = SelectPrimitive.ItemText; type SelectItemIndicatorProps = ThemedClassName; const SelectItemIndicator = forwardRef( ({ classNames, children, ...props }, forwardedRef) => { const { tx } = useThemeContext(); return ( {children} ); }, ); type SelectOptionProps = SelectItemProps; const SelectOption = forwardRef(({ children, classNames, ...props }, forwardedRef) => { const { tx } = useThemeContext(); return ( {children} {/* */} {/* */} ); }); type SelectGroupProps = SelectPrimitive.SelectGroupProps; const SelectGroup = SelectPrimitive.Group; type SelectLabelProps = SelectPrimitive.SelectLabelProps; const SelectLabel = SelectPrimitive.Label; type SelectSeparatorProps = ThemedClassName; const SelectSeparator = forwardRef(({ classNames, ...props }, forwardedRef) => { const { tx } = useThemeContext(); return ( ); }); type SelectArrowProps = ThemedClassName; const SelectArrow = forwardRef(({ classNames, ...props }, forwardedRef) => { const { tx } = useThemeContext(); return ( ); }); export const Select = { Root: SelectRoot, Trigger: SelectTrigger, TriggerButton: SelectTriggerButton, Value: SelectValue, Icon: SelectIcon, Portal: SelectPortal, Content: SelectContent, ScrollUpButton: SelectScrollUpButton, ScrollDownButton: SelectScrollDownButton, Viewport: SelectViewport, Item: SelectItem, ItemText: SelectItemText, ItemIndicator: SelectItemIndicator, Option: SelectOption, Group: SelectGroup, Label: SelectLabel, Separator: SelectSeparator, Arrow: SelectArrow, }; export type { SelectRootProps, SelectTriggerProps, SelectTriggerButtonProps, SelectValueProps, SelectIconProps, SelectPortalProps, SelectContentProps, SelectScrollUpButtonProps, SelectScrollDownButtonProps, SelectViewportProps, SelectItemProps, SelectItemTextProps, SelectItemIndicatorProps, SelectOptionProps, SelectGroupProps, SelectLabelProps, SelectSeparatorProps, SelectArrowProps, };