From 01b546cc816c4fb6b7389e5122b7802d7e724a2b Mon Sep 17 00:00:00 2001 From: 苏向夜 Date: Sun, 22 Feb 2026 19:47:13 +0800 Subject: refactor(shadcn): use base lyra instead --- packages/ui-new/src/components/ui/select.tsx | 143 ++++++++++++++------------- 1 file changed, 77 insertions(+), 66 deletions(-) (limited to 'packages/ui-new/src/components/ui/select.tsx') diff --git a/packages/ui-new/src/components/ui/select.tsx b/packages/ui-new/src/components/ui/select.tsx index c611948..210adba 100644 --- a/packages/ui-new/src/components/ui/select.tsx +++ b/packages/ui-new/src/components/ui/select.tsx @@ -1,25 +1,28 @@ -import * as SelectPrimitive from "@radix-ui/react-select"; +import { Select as SelectPrimitive } from "@base-ui/react/select"; import { CheckIcon, ChevronDownIcon, ChevronUpIcon } from "lucide-react"; import type * as React from "react"; - import { cn } from "@/lib/utils"; -function Select({ - ...props -}: React.ComponentProps) { - return ; -} +const Select = SelectPrimitive.Root; -function SelectGroup({ - ...props -}: React.ComponentProps) { - return ; +function SelectGroup({ className, ...props }: SelectPrimitive.Group.Props) { + return ( + + ); } -function SelectValue({ - ...props -}: React.ComponentProps) { - return ; +function SelectValue({ className, ...props }: SelectPrimitive.Value.Props) { + return ( + + ); } function SelectTrigger({ @@ -27,7 +30,7 @@ function SelectTrigger({ size = "default", children, ...props -}: React.ComponentProps & { +}: SelectPrimitive.Trigger.Props & { size?: "sm" | "default"; }) { return ( @@ -35,15 +38,17 @@ function SelectTrigger({ data-slot="select-trigger" data-size={size} className={cn( - "border-input data-[placeholder]:text-muted-foreground [&_svg:not([class*='text-'])]:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 dark:hover:bg-input/50 flex w-fit items-center justify-between gap-2 rounded-md border bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4", + "border-input data-placeholder:text-muted-foreground dark:bg-input/30 dark:hover:bg-input/50 focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:aria-invalid:border-destructive/50 gap-1.5 rounded-none border bg-transparent py-2 pr-2 pl-2.5 text-xs transition-colors select-none focus-visible:ring-1 aria-invalid:ring-1 data-[size=default]:h-8 data-[size=sm]:h-7 data-[size=sm]:rounded-none *:data-[slot=select-value]:gap-1.5 [&_svg:not([class*='size-'])]:size-4 flex w-fit items-center justify-between whitespace-nowrap outline-none disabled:cursor-not-allowed disabled:opacity-50 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center [&_svg]:pointer-events-none [&_svg]:shrink-0", className, )} {...props} > {children} - - - + + } + /> ); } @@ -51,36 +56,41 @@ function SelectTrigger({ function SelectContent({ className, children, - position = "item-aligned", + side = "bottom", + sideOffset = 4, align = "center", + alignOffset = 0, + alignItemWithTrigger = true, ...props -}: React.ComponentProps) { +}: SelectPrimitive.Popup.Props & + Pick< + SelectPrimitive.Positioner.Props, + "align" | "alignOffset" | "side" | "sideOffset" | "alignItemWithTrigger" + >) { return ( - - - - {children} - - - + + {children} + + + ); } @@ -88,11 +98,11 @@ function SelectContent({ function SelectLabel({ className, ...props -}: React.ComponentProps) { +}: SelectPrimitive.GroupLabel.Props) { return ( - ); @@ -102,25 +112,26 @@ function SelectItem({ className, children, ...props -}: React.ComponentProps) { +}: SelectPrimitive.Item.Props) { return ( - + {children} + + + } > - - - - - {children} + + ); } @@ -128,11 +139,11 @@ function SelectItem({ function SelectSeparator({ className, ...props -}: React.ComponentProps) { +}: SelectPrimitive.Separator.Props) { return ( ); @@ -141,36 +152,36 @@ function SelectSeparator({ function SelectScrollUpButton({ className, ...props -}: React.ComponentProps) { +}: React.ComponentProps) { return ( - - - + + ); } function SelectScrollDownButton({ className, ...props -}: React.ComponentProps) { +}: React.ComponentProps) { return ( - - - + + ); } -- cgit v1.2.3-70-g09d2