// // Copyright 2023 DXOS.org // import * as SelectPrimitive from '@radix-ui/react-select'; import React, { forwardRef } from 'react'; import { useElevationContext, useSafeCollisionPadding, useThemeContext } from '../../hooks'; import { type ThemedClassName } from '../../util'; import { Button, type ButtonProps } from '../Button'; 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, classNames, ...props }, forwardedRef) => { const { tx } = useThemeContext(); return ( ); }, ); SelectTriggerButton.displayName = 'Select.TriggerButton'; type SelectContentProps = ThemedClassName; const SelectContent = forwardRef( ({ classNames, children, collisionPadding = 8, ...props }, forwardedRef) => { const { tx } = useThemeContext(); const elevation = useElevationContext(); const safeCollisionPadding = useSafeCollisionPadding(collisionPadding); return ( {children} ); }, ); SelectContent.displayName = 'Select.Content'; type SelectScrollUpButtonProps = ThemedClassName; const SelectScrollUpButton = forwardRef( ({ classNames, children, ...props }, forwardedRef) => { const { tx } = useThemeContext(); return ( {children ?? } ); }, ); SelectScrollUpButton.displayName = 'Select.ScrollUpButton'; type SelectScrollDownButtonProps = ThemedClassName; const SelectScrollDownButton = forwardRef( ({ classNames, children, ...props }, forwardedRef) => { const { tx } = useThemeContext(); return ( {children ?? } ); }, ); SelectScrollDownButton.displayName = 'Select.ScrollDownButton'; type SelectViewportProps = ThemedClassName; const SelectViewport = forwardRef( ({ classNames, children, ...props }, forwardedRef) => { const { tx } = useThemeContext(); return ( {children} ); }, ); SelectViewport.displayName = 'Select.Viewport'; type SelectItemProps = ThemedClassName; const SelectItem = forwardRef(({ classNames, ...props }, forwardedRef) => { const { tx } = useThemeContext(); return ; }); SelectItem.displayName = 'Select.Item'; type SelectItemTextProps = SelectPrimitive.SelectItemTextProps; const SelectItemText = SelectPrimitive.ItemText; type SelectItemIndicatorProps = ThemedClassName; const SelectItemIndicator = forwardRef( ({ classNames, children, ...props }, forwardedRef) => { const { tx } = useThemeContext(); return ( {children} ); }, ); SelectItemIndicator.displayName = 'Select.ItemIndicator'; type SelectOptionProps = SelectItemProps; const SelectOption = forwardRef(({ children, classNames, ...props }, forwardedRef) => { const { tx } = useThemeContext(); return ( {children} ); }); SelectOption.displayName = 'Select.Option'; 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 ; }); SelectSeparator.displayName = 'Select.Separator'; type SelectArrowProps = ThemedClassName; const SelectArrow = forwardRef(({ classNames, ...props }, forwardedRef) => { const { tx } = useThemeContext(); return ; }); SelectArrow.displayName = 'Select.Arrow'; 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 { SelectArrowProps, SelectContentProps, SelectGroupProps, SelectIconProps, SelectItemIndicatorProps, SelectItemProps, SelectItemTextProps, SelectLabelProps, SelectOptionProps, SelectPortalProps, SelectRootProps, SelectScrollDownButtonProps, SelectScrollUpButtonProps, SelectSeparatorProps, SelectTriggerButtonProps, SelectTriggerProps, SelectValueProps, SelectViewportProps, };