@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
tsx 218 lines 8.79 KB
Raw
1 import { mergeProps } from "@base-ui/react/merge-props";
2 import { Select as SelectPrimitive } from "@base-ui/react/select";
3 import { useRender } from "@base-ui/react/use-render";
4 import { cva, type VariantProps } from "class-variance-authority";
5 import { ChevronDownIcon, ChevronUpIcon } from "lucide-react";
6 import type * as React from "react";
7
8 import { cn } from "~/lib/utils";
9
10 const Select = SelectPrimitive.Root;
11
12 const selectTriggerVariants = cva(
13 "relative inline-flex cursor-pointer select-none items-center justify-between gap-2 border rounded-lg text-left text-base outline-none transition-[color,box-shadow,background-color] data-disabled:pointer-events-none data-disabled:opacity-64 sm:text-sm [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4",
14 {
15 defaultVariants: {
16 size: "default",
17 variant: "default",
18 },
19 variants: {
20 variant: {
21 default:
22 "w-full min-w-36 border-input bg-background not-dark:bg-clip-padding text-foreground shadow-xs/5 ring-ring/24 before:pointer-events-none before:absolute before:inset-0 before:rounded-[calc(var(--radius-lg)-1px)] not-data-disabled:not-focus-visible:not-aria-invalid:not-data-pressed:before:shadow-[0_1px_--theme(--color-black/4%)] pointer-coarse:after:absolute pointer-coarse:after:size-full pointer-coarse:after:min-h-11 focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-inset aria-invalid:border-destructive/36 focus-visible:aria-invalid:border-destructive/64 focus-visible:aria-invalid:ring-destructive/16 dark:bg-input/32 dark:aria-invalid:ring-destructive/24 dark:not-data-disabled:not-focus-visible:not-aria-invalid:not-data-pressed:before:shadow-[0_-1px_--theme(--color-white/6%)] [&_svg:not([class*='opacity-'])]:opacity-80 [&_svg:not([class*='text-'])]:text-icon-muted [[data-disabled],:focus-visible,[aria-invalid],[data-pressed]]:shadow-none",
23 ghost:
24 "border-transparent text-secondary-label focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring data-pressed:bg-accent [:hover,[data-pressed]]:bg-accent [:hover,[data-pressed]]:text-foreground",
25 },
26 size: {
27 compact:
28 "h-7 gap-1 rounded-md px-[calc(--spacing(2)-1px)] text-xs before:rounded-[calc(var(--radius-md)-1px)] [&_svg:not([class*='size-'])]:size-3.5",
29 default: "min-h-9 px-[calc(--spacing(3)-1px)] sm:min-h-8",
30 lg: "min-h-10 px-[calc(--spacing(3)-1px)] sm:min-h-9",
31 sm: "min-h-8 gap-1.5 px-[calc(--spacing(2.5)-1px)] sm:min-h-7",
32 xs: "h-7 gap-1 rounded-md px-[calc(--spacing(2)-1px)] text-sm before:rounded-[calc(var(--radius-md)-1px)] sm:h-6 sm:text-xs [&_svg:not([class*='size-'])]:size-4 sm:[&_svg:not([class*='size-'])]:size-3.5",
33 },
34 },
35 },
36 );
37
38 function SelectTrigger({
39 className,
40 size = "default",
41 variant = "default",
42 children,
43 icon,
44 ...props
45 }: SelectPrimitive.Trigger.Props &
46 VariantProps<typeof selectTriggerVariants> & { icon?: React.ReactNode }) {
47 return (
48 <SelectPrimitive.Trigger
49 className={cn(selectTriggerVariants({ size, variant }), className)}
50 data-slot="select-trigger"
51 {...props}
52 >
53 {children}
54 <SelectPrimitive.Icon data-slot="select-icon">
55 {icon ?? <ChevronDownIcon className="-me-1 size-3.5 opacity-70" />}
56 </SelectPrimitive.Icon>
57 </SelectPrimitive.Trigger>
58 );
59 }
60
61 function SelectButton({
62 className,
63 size = "default",
64 children,
65 render,
66 ...props
67 }: useRender.ComponentProps<"button"> & Pick<VariantProps<typeof selectTriggerVariants>, "size">) {
68 const defaultProps = {
69 className: cn(selectTriggerVariants({ size }), className),
70 "data-slot": "select-trigger",
71 type: render ? undefined : ("button" as const),
72 };
73 return useRender({
74 defaultTagName: "button",
75 props: {
76 ...mergeProps<"button">(defaultProps, props),
77 children: (
78 <>
79 <span className="min-w-0 flex-1 truncate text-left">{children}</span>
80 <ChevronDownIcon aria-hidden className="-me-1 size-3.5 shrink-0 opacity-70" />
81 </>
82 ),
83 },
84 render,
85 });
86 }
87
88 function SelectValue({ className, ...props }: SelectPrimitive.Value.Props) {
89 return (
90 <SelectPrimitive.Value
91 className={cn("flex-1 truncate data-placeholder:text-placeholder", className)}
92 data-slot="select-value"
93 {...props}
94 />
95 );
96 }
97
98 function SelectPopup({
99 className,
100 children,
101 side = "bottom",
102 sideOffset = 4,
103 align = "start",
104 alignOffset = 0,
105 alignItemWithTrigger = true,
106 matchTriggerWidth = true,
107 anchor,
108 ...props
109 }: SelectPrimitive.Popup.Props & {
110 side?: SelectPrimitive.Positioner.Props["side"];
111 sideOffset?: SelectPrimitive.Positioner.Props["sideOffset"];
112 align?: SelectPrimitive.Positioner.Props["align"];
113 alignOffset?: SelectPrimitive.Positioner.Props["alignOffset"];
114 alignItemWithTrigger?: SelectPrimitive.Positioner.Props["alignItemWithTrigger"];
115 matchTriggerWidth?: boolean;
116 anchor?: SelectPrimitive.Positioner.Props["anchor"];
117 }) {
118 return (
119 <SelectPrimitive.Portal>
120 <SelectPrimitive.Positioner
121 align={align}
122 alignItemWithTrigger={alignItemWithTrigger}
123 alignOffset={alignOffset}
124 anchor={anchor}
125 className="z-[130] select-none"
126 data-slot="select-positioner"
127 side={side}
128 sideOffset={sideOffset}
129 >
130 <SelectPrimitive.Popup
131 // Electron drag hit-testing ignores z-index; items over a drag region would swallow clicks.
132 className="origin-(--transform-origin) rounded-lg text-foreground outline-none [-webkit-app-region:no-drag]"
133 data-slot="select-popup"
134 {...props}
135 >
136 <SelectPrimitive.ScrollUpArrow
137 className="top-0 z-50 flex h-6 w-full cursor-default items-center justify-center before:pointer-events-none before:absolute before:inset-x-px before:top-px before:h-[200%] before:rounded-t-[calc(var(--radius-lg)-1px)] before:bg-linear-to-b before:from-50% before:from-popover"
138 data-slot="select-scroll-up-arrow"
139 >
140 <ChevronUpIcon className="relative size-4.5 sm:size-4" />
141 </SelectPrimitive.ScrollUpArrow>
142 <div
143 className={cn(
144 "dropdown-glass relative h-full rounded-lg shadow-[0_16px_40px_-18px_rgb(0_0_0/55%)] dark:shadow-[0_18px_44px_-18px_rgb(0_0_0/80%)]",
145 matchTriggerWidth && "min-w-(--anchor-width)",
146 )}
147 >
148 <SelectPrimitive.List
149 className={cn("max-h-(--available-height) overflow-y-auto p-1", className)}
150 data-slot="select-list"
151 >
152 {children}
153 </SelectPrimitive.List>
154 </div>
155 <SelectPrimitive.ScrollDownArrow
156 className="bottom-0 z-50 flex h-6 w-full cursor-default items-center justify-center before:pointer-events-none before:absolute before:inset-x-px before:bottom-px before:h-[200%] before:rounded-b-[calc(var(--radius-lg)-1px)] before:bg-linear-to-t before:from-50% before:from-popover"
157 data-slot="select-scroll-down-arrow"
158 >
159 <ChevronDownIcon className="relative size-4.5 sm:size-4" />
160 </SelectPrimitive.ScrollDownArrow>
161 </SelectPrimitive.Popup>
162 </SelectPrimitive.Positioner>
163 </SelectPrimitive.Portal>
164 );
165 }
166
167 function SelectItem({
168 className,
169 children,
170 hideIndicator: _hideIndicator = false,
171 ...props
172 }: SelectPrimitive.Item.Props & {
173 hideIndicator?: boolean;
174 }) {
175 return (
176 <SelectPrimitive.Item
177 className={cn(
178 "flex min-h-8 in-data-[side=none]:min-w-[calc(var(--anchor-width)+1.25rem)] cursor-pointer items-center rounded-sm px-2 py-1 text-base outline-none data-selected:bg-foreground/[0.08] data-disabled:pointer-events-none data-disabled:cursor-not-allowed data-highlighted:bg-accent data-highlighted:text-accent-foreground data-disabled:opacity-64 sm:min-h-7 sm:text-sm [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0",
179 className,
180 )}
181 data-slot="select-item"
182 {...props}
183 >
184 <SelectPrimitive.ItemText
185 className="min-w-0 flex-1 [&_svg:not([class*='text-'])]:text-muted-foreground"
186 data-slot="select-item-text"
187 >
188 {children}
189 </SelectPrimitive.ItemText>
190 </SelectPrimitive.Item>
191 );
192 }
193
194 function SelectGroup(props: SelectPrimitive.Group.Props) {
195 return <SelectPrimitive.Group data-slot="select-group" {...props} />;
196 }
197
198 function SelectGroupLabel(props: SelectPrimitive.GroupLabel.Props) {
199 return (
200 <SelectPrimitive.GroupLabel
201 className="px-2 py-1.5 font-medium text-muted-foreground text-xs"
202 data-slot="select-group-label"
203 {...props}
204 />
205 );
206 }
207
208 export {
209 Select,
210 SelectTrigger,
211 SelectButton,
212 SelectValue,
213 SelectPopup,
214 SelectPopup as SelectContent,
215 SelectItem,
216 SelectGroup,
217 SelectGroupLabel,
218 };