2026-09-10 11:10:51 +08:00
|
|
|
import * as React from "react";
|
|
|
|
|
import * as SelectPrimitive from "@radix-ui/react-select";
|
|
|
|
|
import { Check, ChevronDown, ChevronUp } from "lucide-react";
|
|
|
|
|
|
|
|
|
|
import { floatingSurfaceElevationClassName, floatingItemClassName } from "@/components/ui/floating-surface";
|
|
|
|
|
import { useFloatingPortal } from "@/components/ui/floating-portal";
|
|
|
|
|
import { cn } from "@/lib/utils";
|
2026-10-09 17:05:10 +08:00
|
|
|
import { ControlChevron } from "@/components/ui/control-chevron";
|
2026-09-10 11:10:51 +08:00
|
|
|
|
|
|
|
|
export const Select = SelectPrimitive.Root;
|
|
|
|
|
export const SelectValue = SelectPrimitive.Value;
|
2026-10-11 04:30:43 +08:00
|
|
|
export const SelectSeparator = SelectPrimitive.Separator;
|
2026-09-10 11:10:51 +08:00
|
|
|
|
|
|
|
|
export const SelectTrigger = React.forwardRef<
|
|
|
|
|
React.ElementRef<typeof SelectPrimitive.Trigger>,
|
|
|
|
|
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Trigger>
|
|
|
|
|
>(({ className, children, ...props }, ref) => (
|
|
|
|
|
<SelectPrimitive.Trigger ref={ref} {...props}
|
2026-10-09 17:05:10 +08:00
|
|
|
className={cn("control-layout justify-between rounded-control border-input bg-background text-[13px] outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-50 [&>span:first-child]:truncate", className)}>
|
2026-09-10 11:10:51 +08:00
|
|
|
{children}
|
2026-10-09 17:05:10 +08:00
|
|
|
<SelectPrimitive.Icon><ControlChevron /></SelectPrimitive.Icon>
|
2026-09-10 11:10:51 +08:00
|
|
|
</SelectPrimitive.Trigger>
|
|
|
|
|
));
|
|
|
|
|
SelectTrigger.displayName = "SelectTrigger";
|
|
|
|
|
|
2026-09-14 11:13:40 +08:00
|
|
|
export function SelectContent({ children, ...props }: Pick<
|
|
|
|
|
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Content>,
|
2026-10-11 04:30:43 +08:00
|
|
|
"children" | "onPointerUpCapture" | "onPointerDownOutside" | "onKeyDownCapture" | "onEscapeKeyDown" | "onCloseAutoFocus"
|
2026-09-14 11:13:40 +08:00
|
|
|
>) {
|
2026-09-10 11:10:51 +08:00
|
|
|
const container = useFloatingPortal();
|
|
|
|
|
return (
|
|
|
|
|
<SelectPrimitive.Portal container={container ?? undefined}>
|
2026-09-14 11:13:40 +08:00
|
|
|
<SelectPrimitive.Content {...props} position="item-aligned" className={cn("z-50 max-h-[min(24rem,calc(100dvh-2rem))] min-w-[10rem] overflow-hidden rounded-control border border-transparent", floatingSurfaceElevationClassName)}>
|
2026-09-10 11:10:51 +08:00
|
|
|
<SelectPrimitive.ScrollUpButton className="flex h-6 items-center justify-center"><ChevronUp className="h-3.5 w-3.5" /></SelectPrimitive.ScrollUpButton>
|
|
|
|
|
<SelectPrimitive.Viewport className="p-1">
|
|
|
|
|
{children}
|
|
|
|
|
</SelectPrimitive.Viewport>
|
|
|
|
|
<SelectPrimitive.ScrollDownButton className="flex h-6 items-center justify-center"><ChevronDown className="h-3.5 w-3.5" /></SelectPrimitive.ScrollDownButton>
|
|
|
|
|
</SelectPrimitive.Content>
|
|
|
|
|
</SelectPrimitive.Portal>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function SelectItem({ children, className, ...props }: React.ComponentPropsWithoutRef<typeof SelectPrimitive.Item>) {
|
|
|
|
|
return (
|
|
|
|
|
<SelectPrimitive.Item {...props} className={cn(floatingItemClassName, "h-9 py-0 pl-2 pr-8 data-[state=checked]:bg-muted data-[highlighted]:bg-muted data-[disabled]:opacity-50", className)}>
|
|
|
|
|
<SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>
|
|
|
|
|
<SelectPrimitive.ItemIndicator className="absolute right-2 flex items-center"><Check className="h-3.5 w-3.5" aria-hidden /></SelectPrimitive.ItemIndicator>
|
|
|
|
|
</SelectPrimitive.Item>
|
|
|
|
|
);
|
|
|
|
|
}
|