| 5 | import { cn } from "../lib/utils"; |
| 6 | |
| 7 | function NativeSelect({ |
| 8 | className, |
| 9 | size = "default", |
| 10 | style, |
| 11 | ...props |
| 12 | }: Omit<React.ComponentProps<"select">, "size"> & { size?: "sm" | "default" }) { |
| 13 | const isDark = useIsDark(); |
| 14 | return ( |
| 15 | <div |
| 16 | className="group/native-select relative w-fit has-[select:disabled]:opacity-50" |
| 17 | data-slot="native-select-wrapper" |
| 18 | > |
| 19 | {/* The native option popup follows the select's opaque background and |
| 20 | color-scheme, not option-level styles. Give it a solid themed surface |
| 21 | and pin color-scheme so options stay readable in dark mode, which is |
| 22 | driven by prefers-color-scheme (no .dark class in this app). */} |
| 23 | {/* oxlint-disable-next-line react/forbid-elements */} |
| 24 | <select |
| 25 | data-slot="native-select" |
| 26 | data-size={size} |
| 27 | style={{ colorScheme: isDark ? "dark" : "light", ...style }} |
| 28 | className={cn( |
| 29 | "h-9 w-full min-w-0 appearance-none rounded-md border border-input bg-popover text-popover-foreground px-3 py-2 pr-9 text-sm shadow-xs transition-[color,box-shadow] outline-none selection:bg-primary selection:text-primary-foreground placeholder:text-muted-foreground hover:bg-accent disabled:pointer-events-none disabled:cursor-not-allowed data-[size=sm]:h-8 data-[size=sm]:py-1", |
| 30 | "focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50", |
| 31 | "aria-invalid:border-destructive aria-invalid:ring-destructive/20", |
| 32 | className, |
| 33 | )} |
| 34 | {...props} |
| 35 | /> |
| 36 | <ChevronDownIcon |
| 37 | className="pointer-events-none absolute top-1/2 right-3.5 size-4 -translate-y-1/2 text-muted-foreground opacity-50 select-none" |
| 38 | aria-hidden="true" |
| 39 | data-slot="native-select-icon" |
| 40 | /> |
| 41 | </div> |
| 42 | ); |
| 43 | } |
| 44 | |
| 45 | function NativeSelectOption({ ...props }: React.ComponentProps<"option">) { |
| 46 | return <option data-slot="native-select-option" {...props} />; |