Path: blob/master/gate-controller/components/ui/select.tsx
1082 views
"use client"12import * as React from "react"3import * as SelectPrimitive from "@radix-ui/react-select"4import { CheckIcon, ChevronDownIcon, ChevronUpIcon } from "lucide-react"56import { cn } from "@/lib/utils"78function Select({9...props10}: React.ComponentProps<typeof SelectPrimitive.Root>) {11return <SelectPrimitive.Root data-slot="select" {...props} />12}1314function SelectGroup({15...props16}: React.ComponentProps<typeof SelectPrimitive.Group>) {17return <SelectPrimitive.Group data-slot="select-group" {...props} />18}1920function SelectValue({21...props22}: React.ComponentProps<typeof SelectPrimitive.Value>) {23return <SelectPrimitive.Value data-slot="select-value" {...props} />24}2526function SelectTrigger({27className,28size = "default",29children,30...props31}: React.ComponentProps<typeof SelectPrimitive.Trigger> & {32size?: "sm" | "default"33}) {34return (35<SelectPrimitive.Trigger36data-slot="select-trigger"37data-size={size}38className={cn(39"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",40className41)}42{...props}43>44{children}45<SelectPrimitive.Icon asChild>46<ChevronDownIcon className="size-4 opacity-50" />47</SelectPrimitive.Icon>48</SelectPrimitive.Trigger>49)50}5152function SelectContent({53className,54children,55position = "popper",56align = "center",57...props58}: React.ComponentProps<typeof SelectPrimitive.Content>) {59return (60<SelectPrimitive.Portal>61<SelectPrimitive.Content62data-slot="select-content"63className={cn(64"bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 relative z-50 max-h-(--radix-select-content-available-height) min-w-[8rem] origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border shadow-md",65position === "popper" &&66"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",67className68)}69position={position}70align={align}71{...props}72>73<SelectScrollUpButton />74<SelectPrimitive.Viewport75className={cn(76"p-1",77position === "popper" &&78"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1"79)}80>81{children}82</SelectPrimitive.Viewport>83<SelectScrollDownButton />84</SelectPrimitive.Content>85</SelectPrimitive.Portal>86)87}8889function SelectLabel({90className,91...props92}: React.ComponentProps<typeof SelectPrimitive.Label>) {93return (94<SelectPrimitive.Label95data-slot="select-label"96className={cn("text-muted-foreground px-2 py-1.5 text-xs", className)}97{...props}98/>99)100}101102function SelectItem({103className,104children,105...props106}: React.ComponentProps<typeof SelectPrimitive.Item>) {107return (108<SelectPrimitive.Item109data-slot="select-item"110className={cn(111"focus:bg-accent focus:text-accent-foreground [&_svg:not([class*='text-'])]:text-muted-foreground relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",112className113)}114{...props}115>116<span className="absolute right-2 flex size-3.5 items-center justify-center">117<SelectPrimitive.ItemIndicator>118<CheckIcon className="size-4" />119</SelectPrimitive.ItemIndicator>120</span>121<SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>122</SelectPrimitive.Item>123)124}125126function SelectSeparator({127className,128...props129}: React.ComponentProps<typeof SelectPrimitive.Separator>) {130return (131<SelectPrimitive.Separator132data-slot="select-separator"133className={cn("bg-border pointer-events-none -mx-1 my-1 h-px", className)}134{...props}135/>136)137}138139function SelectScrollUpButton({140className,141...props142}: React.ComponentProps<typeof SelectPrimitive.ScrollUpButton>) {143return (144<SelectPrimitive.ScrollUpButton145data-slot="select-scroll-up-button"146className={cn(147"flex cursor-default items-center justify-center py-1",148className149)}150{...props}151>152<ChevronUpIcon className="size-4" />153</SelectPrimitive.ScrollUpButton>154)155}156157function SelectScrollDownButton({158className,159...props160}: React.ComponentProps<typeof SelectPrimitive.ScrollDownButton>) {161return (162<SelectPrimitive.ScrollDownButton163data-slot="select-scroll-down-button"164className={cn(165"flex cursor-default items-center justify-center py-1",166className167)}168{...props}169>170<ChevronDownIcon className="size-4" />171</SelectPrimitive.ScrollDownButton>172)173}174175export {176Select,177SelectContent,178SelectGroup,179SelectItem,180SelectLabel,181SelectScrollDownButton,182SelectScrollUpButton,183SelectSeparator,184SelectTrigger,185SelectValue,186}187188189