select.tsx
This file
Path
apps/web/src/components/ui/select.tsx
199 lines · 6.5 KiB · TypeScript
Last changed by
Draw text, controls, prose and code from one set of tokensoscabrielbefore adoption60f862e
History of this fileTake it
Give the web its W9 dependencies, components, project nav, line and revision helpers, and a stub for every new pageoscabrielbefore adoption254268a
lines 1–40why, one step back1import { Select as SelectPrimitive } from "@base-ui/react/select";2import { cn } from "cn";3import { ChevronDownIcon, CheckIcon, ChevronUpIcon } from "lucide-react";4import * as React from "react";56const Select = SelectPrimitive.Root;78function SelectGroup({ className, ...props }: SelectPrimitive.Group.Props) {9 return (10 <SelectPrimitive.Group11 data-slot="select-group"12 className={cn("scroll-my-1", className)}13 {...props}14 />15 );16}1718function SelectValue({ className, ...props }: SelectPrimitive.Value.Props) {19 return (20 <SelectPrimitive.Value21 data-slot="select-value"22 className={cn("flex flex-1 text-left", className)}23 {...props}24 />25 );26}2728function SelectTrigger({29 className,30 size = "default",31 children,32 ...props33}: SelectPrimitive.Trigger.Props & {34 size?: "sm" | "default";35}) {36 return (37 <SelectPrimitive.Trigger38 data-slot="select-trigger"39 data-size={size}40 className={cn(Draw text, controls, prose and code from one set of tokensoscabrielbefore adoption60f862e
line 41why, one step back41 "border-input focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-placeholder:text-muted-foreground dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 sm:text-ui flex w-fit items-center justify-between gap-1.5 rounded-none border bg-transparent py-2 pr-2 pl-2.5 text-base whitespace-nowrap transition-colors outline-none select-none focus-visible:ring-1 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:ring-1 data-[size=default]:h-9 data-[size=sm]:h-8 data-[size=sm]:rounded-none *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-1.5 sm:data-[size=default]:h-8 sm:data-[size=sm]:h-7 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",Give the web its W9 dependencies, components, project nav, line and revision helpers, and a stub for every new pageoscabrielbefore adoption254268a
lines 42–83why, one step back42 className43 )}44 {...props}45 >46 {children}47 <SelectPrimitive.Icon48 render={49 <ChevronDownIcon className="text-muted-foreground pointer-events-none size-4" />50 }51 />52 </SelectPrimitive.Trigger>53 );54}5556function SelectContent({57 className,58 children,59 side = "bottom",60 sideOffset = 4,61 align = "center",62 alignOffset = 0,63 alignItemWithTrigger = true,64 ...props65}: SelectPrimitive.Popup.Props &66 Pick<67 SelectPrimitive.Positioner.Props,68 "align" | "alignOffset" | "side" | "sideOffset" | "alignItemWithTrigger"69 >) {70 return (71 <SelectPrimitive.Portal>72 <SelectPrimitive.Positioner73 side={side}74 sideOffset={sideOffset}75 align={align}76 alignOffset={alignOffset}77 alignItemWithTrigger={alignItemWithTrigger}78 className="isolate z-50"79 >80 <SelectPrimitive.Popup81 data-slot="select-content"82 data-align-trigger={alignItemWithTrigger}83 className={cn(Draw text, controls, prose and code from one set of tokensoscabrielbefore adoption60f862e
line 84why, one step back84 "bg-popover text-popover-foreground ring-input data-[side=bottom]:slide-in-from-top-2 data-[side=inline-end]:slide-in-from-left-2 data-[side=inline-start]:slide-in-from-right-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 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95 relative isolate z-50 max-h-(--available-height) w-(--anchor-width) min-w-36 origin-(--transform-origin) overflow-x-hidden overflow-y-auto rounded-none ring-1 duration-100 data-[align-trigger=true]:animate-none",Give the web its W9 dependencies, components, project nav, line and revision helpers, and a stub for every new pageoscabrielbefore adoption254268a
lines 85–104why, one step back85 className86 )}87 {...props}88 >89 <SelectScrollUpButton />90 <SelectPrimitive.List>{children}</SelectPrimitive.List>91 <SelectScrollDownButton />92 </SelectPrimitive.Popup>93 </SelectPrimitive.Positioner>94 </SelectPrimitive.Portal>95 );96}9798function SelectLabel({99 className,100 ...props101}: SelectPrimitive.GroupLabel.Props) {102 return (103 <SelectPrimitive.GroupLabel104 data-slot="select-label"Draw text, controls, prose and code from one set of tokensoscabrielbefore adoption60f862e
line 105why, one step back105 className={cn("text-muted-foreground text-label px-2 py-2", className)}Give the web its W9 dependencies, components, project nav, line and revision helpers, and a stub for every new pageoscabrielbefore adoption254268a
lines 106–119why, one step back106 {...props}107 />108 );109}110111function SelectItem({112 className,113 children,114 ...props115}: SelectPrimitive.Item.Props) {116 return (117 <SelectPrimitive.Item118 data-slot="select-item"119 className={cn(Draw text, controls, prose and code from one set of tokensoscabrielbefore adoption60f862e
line 120why, one step back120 "focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground text-ui relative flex w-full cursor-default items-center gap-2 rounded-none py-2 pr-8 pl-2 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",Give the web its W9 dependencies, components, project nav, line and revision helpers, and a stub for every new pageoscabrielbefore adoption254268a
lines 121–199why, one step back121 className122 )}123 {...props}124 >125 <SelectPrimitive.ItemText className="flex flex-1 shrink-0 gap-2 whitespace-nowrap">126 {children}127 </SelectPrimitive.ItemText>128 <SelectPrimitive.ItemIndicator129 render={130 <span className="pointer-events-none absolute right-2 flex size-4 items-center justify-center" />131 }132 >133 <CheckIcon className="pointer-events-none" />134 </SelectPrimitive.ItemIndicator>135 </SelectPrimitive.Item>136 );137}138139function SelectSeparator({140 className,141 ...props142}: SelectPrimitive.Separator.Props) {143 return (144 <SelectPrimitive.Separator145 data-slot="select-separator"146 className={cn("bg-border pointer-events-none -mx-1 h-px", className)}147 {...props}148 />149 );150}151152function SelectScrollUpButton({153 className,154 ...props155}: React.ComponentProps<typeof SelectPrimitive.ScrollUpArrow>) {156 return (157 <SelectPrimitive.ScrollUpArrow158 data-slot="select-scroll-up-button"159 className={cn(160 "bg-popover top-0 z-10 flex w-full cursor-default items-center justify-center py-1 [&_svg:not([class*='size-'])]:size-4",161 className162 )}163 {...props}164 >165 <ChevronUpIcon />166 </SelectPrimitive.ScrollUpArrow>167 );168}169170function SelectScrollDownButton({171 className,172 ...props173}: React.ComponentProps<typeof SelectPrimitive.ScrollDownArrow>) {174 return (175 <SelectPrimitive.ScrollDownArrow176 data-slot="select-scroll-down-button"177 className={cn(178 "bg-popover bottom-0 z-10 flex w-full cursor-default items-center justify-center py-1 [&_svg:not([class*='size-'])]:size-4",179 className180 )}181 {...props}182 >183 <ChevronDownIcon />184 </SelectPrimitive.ScrollDownArrow>185 );186}187188export {189 Select,190 SelectContent,191 SelectGroup,192 SelectItem,193 SelectLabel,194 SelectScrollDownButton,195 SelectScrollUpButton,196 SelectSeparator,197 SelectTrigger,198 SelectValue,199};