"use client" import * as SelectPrimitive from "@radix-ui/react-select" import { ChevronDown, ChevronUp } from "lucide-react" import { CheckIcon } from "../icons-v2-generated/signs-and-symbols/check-icon" import { Chevron02DownIcon } from "../icons-v2-generated/arrows/chevron-02-down-icon" import * as React from "react" import { cn } from "../../utils/cn" import { FieldWrapper } from "./field-wrapper" const Select = SelectPrimitive.Root const SelectGroup = SelectPrimitive.Group const SelectValue = SelectPrimitive.Value const SelectTrigger = React.forwardRef< React.ComponentRef, React.ComponentPropsWithoutRef & { invalid?: boolean label?: string /** Label scale forwarded to FieldWrapper ("large" = text-h4 for designs with body-scale field titles) */ labelVariant?: "default" | "large" error?: string } >(({ className, children, invalid, label, labelVariant, error, ...props }, ref) => { const isInvalid = invalid || !!error const trigger = ( UA default text-align:center, which the // SelectValue span inherits and would otherwise center short values, // reading as spurious left indentation on the selected value. "flex w-full items-center justify-between gap-2 rounded-[6px] border px-3 h-11 md:h-12 outline-none text-left", // Typography - match Input exactly "text-h4", // Theme palette - match Input exactly "bg-ods-card border-ods-border text-ods-text-primary data-[placeholder]:text-ods-text-secondary", "enabled:hover:bg-ods-bg-hover enabled:hover:border-ods-border-hover enabled:active:bg-ods-bg-active enabled:active:border-ods-border-active", !isInvalid && "data-[state=open]:border-ods-accent data-[state=open]:hover:border-ods-accent", "group", // Disabled - match Input exactly: value greys out, placeholder dims // further. The `data-[placeholder]` rule above is a class+attribute // selector, so the disabled placeholder rule stacks `:disabled` on top // of it to win on specificity rather than on source order. "disabled:!cursor-not-allowed disabled:bg-ods-bg", "disabled:text-ods-text-disabled disabled:data-[placeholder]:text-ods-border", // The chevron sets its own colour — grey it with the value. "disabled:[&_svg]:text-ods-text-disabled", "transition-colors duration-200 cursor-pointer", "[&>span]:line-clamp-1", isInvalid && "border-ods-error enabled:hover:border-ods-error enabled:active:border-ods-error data-[state=open]:border-ods-error", className )} {...props} > {children} ) return ( {trigger} ) }) SelectTrigger.displayName = SelectPrimitive.Trigger.displayName const SelectScrollUpButton = React.forwardRef< React.ComponentRef, React.ComponentPropsWithoutRef >(({ className, ...props }, ref) => ( )) SelectScrollUpButton.displayName = SelectPrimitive.ScrollUpButton.displayName const SelectScrollDownButton = React.forwardRef< React.ComponentRef, React.ComponentPropsWithoutRef >(({ className, ...props }, ref) => ( )) SelectScrollDownButton.displayName = SelectPrimitive.ScrollDownButton.displayName const SelectContent = React.forwardRef< React.ComponentRef, React.ComponentPropsWithoutRef >(({ className, children, position = "popper", ...props }, ref) => ( {children} )) SelectContent.displayName = SelectPrimitive.Content.displayName const SelectLabel = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef >(({ className, ...props }, ref) => ( )) SelectLabel.displayName = SelectPrimitive.Label.displayName const SelectItem = React.forwardRef< React.ComponentRef, React.ComponentPropsWithoutRef >(({ className, children, ...props }, ref) => ( {children} )) SelectItem.displayName = SelectPrimitive.Item.displayName const SelectSeparator = React.forwardRef< React.ComponentRef, React.ComponentPropsWithoutRef >(({ className, ...props }, ref) => ( )) SelectSeparator.displayName = SelectPrimitive.Separator.displayName export { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue }