Open History to see the last commit
1"use client";
2
3import { Dialog as CommandDialogPrimitive } from "@base-ui/react/dialog";
4import { SearchIcon } from "lucide-react";
5import type * as React from "react";
6import { cn } from "~/lib/utils";
7import {
8 Autocomplete,
9 AutocompleteCollection,
10 AutocompleteEmpty,
11 AutocompleteGroup,
12 AutocompleteGroupLabel,
13 AutocompleteInput,
14 AutocompleteItem,
15 AutocompleteList,
16 AutocompleteSeparator,
17} from "~/components/ui/autocomplete";
18
19const CommandDialog = CommandDialogPrimitive.Root;
20
21const CommandDialogPortal = CommandDialogPrimitive.Portal;
22
23const CommandCreateHandle = CommandDialogPrimitive.createHandle;
24
25function CommandDialogTrigger(props: CommandDialogPrimitive.Trigger.Props) {
26 return <CommandDialogPrimitive.Trigger data-slot="command-dialog-trigger" {...props} />;
27}
28
29function CommandDialogBackdrop({ className, ...props }: CommandDialogPrimitive.Backdrop.Props) {
30 return (
31 <CommandDialogPrimitive.Backdrop
32 className={cn(
33 "fixed inset-0 z-50 bg-black/32 backdrop-blur-sm transition-all duration-200 data-ending-style:opacity-0 data-starting-style:opacity-0",
34 className,
35 )}
36 data-slot="command-dialog-backdrop"
37 {...props}
38 />
39 );
40}
41
42function CommandDialogViewport({ className, ...props }: CommandDialogPrimitive.Viewport.Props) {
43 return (
44 <CommandDialogPrimitive.Viewport
45 className={cn(
46 "fixed inset-0 z-50 flex flex-col items-center px-4 py-[max(--spacing(4),4vh)] sm:py-[10vh]",
47 className,
48 )}
49 data-slot="command-dialog-viewport"
50 {...props}
51 />
52 );
53}
54
55function CommandDialogPopup({ className, children, ...props }: CommandDialogPrimitive.Popup.Props) {
56 return (
57 <CommandDialogPortal>
58 <CommandDialogBackdrop />
59 <CommandDialogViewport>
60 <CommandDialogPrimitive.Popup
61 className={cn(
62 "-translate-y-[calc(1.25rem*var(--nested-dialogs))] relative row-start-2 flex max-h-105 min-h-0 w-full min-w-0 max-w-xl scale-[calc(1-0.1*var(--nested-dialogs))] flex-col rounded-2xl border bg-popover not-dark:bg-clip-padding text-popover-foreground opacity-[calc(1-0.1*var(--nested-dialogs))] shadow-lg/5 outline-none transition-[scale,opacity,translate] duration-200 ease-in-out will-change-transform before:pointer-events-none before:absolute before:inset-0 before:rounded-[calc(var(--radius-2xl)-1px)] before:bg-muted/72 before:shadow-[0_1px_--theme(--color-black/4%)] data-nested:data-ending-style:translate-y-8 data-nested:data-starting-style:translate-y-8 data-nested-dialog-open:origin-top data-ending-style:scale-98 data-starting-style:scale-98 data-ending-style:opacity-0 data-starting-style:opacity-0 **:data-[slot=scroll-area-viewport]:data-has-overflow-y:pe-1 dark:before:shadow-[0_-1px_--theme(--color-white/6%)]",
63 className,
64 )}
65 data-slot="command-dialog-popup"
66 {...props}
67 >
68 {children}
69 </CommandDialogPrimitive.Popup>
70 </CommandDialogViewport>
71 </CommandDialogPortal>
72 );
73}
74
75function Command({
76 autoHighlight = "always",
77 keepHighlight = true,
78 ...props
79}: React.ComponentProps<typeof Autocomplete>) {
80 return (
81 <Autocomplete
82 autoHighlight={autoHighlight}
83 inline
84 keepHighlight={keepHighlight}
85 open
86 {...props}
87 />
88 );
89}
90
91function CommandInput({
92 className,
93 placeholder = undefined,
94 ...props
95}: React.ComponentProps<typeof AutocompleteInput>) {
96 return (
97 <div className="px-2.5 py-1.5">
98 <AutocompleteInput
99 autoFocus
100 className={cn(
101 "border-transparent! bg-transparent! shadow-none before:hidden has-focus-visible:ring-0",
102 className,
103 )}
104 placeholder={placeholder}
105 size="lg"
106 startAddon={<SearchIcon />}
107 {...props}
108 />
109 </div>
110 );
111}
112
113function CommandList({ className, ...props }: React.ComponentProps<typeof AutocompleteList>) {
114 return (
115 <AutocompleteList
116 className={cn("not-empty:scroll-py-2 not-empty:p-2", className)}
117 data-slot="command-list"
118 {...props}
119 />
120 );
121}
122
123function CommandEmpty({ className, ...props }: React.ComponentProps<typeof AutocompleteEmpty>) {
124 return (
125 <AutocompleteEmpty
126 className={cn("not-empty:py-6", className)}
127 data-slot="command-empty"
128 {...props}
129 />
130 );
131}
132
133function CommandPanel({ className, ...props }: React.ComponentProps<"div">) {
134 return (
135 <div
136 className={cn(
137 "-mx-px not-has-[+[data-slot=command-footer]]:-mb-px relative min-h-0 rounded-t-xl not-has-[+[data-slot=command-footer]]:rounded-b-2xl border border-b-0 bg-popover bg-clip-padding shadow-xs/5 [clip-path:inset(0_1px)] not-has-[+[data-slot=command-footer]]:[clip-path:inset(0_1px_1px_1px_round_0_0_calc(var(--radius-2xl)-1px)_calc(var(--radius-2xl)-1px))] before:pointer-events-none before:absolute before:inset-0 before:rounded-t-[calc(var(--radius-xl)-1px)] **:data-[slot=scroll-area-scrollbar]:mt-2",
138 className,
139 )}
140 {...props}
141 />
142 );
143}
144
145function CommandGroup({ className, ...props }: React.ComponentProps<typeof AutocompleteGroup>) {
146 return <AutocompleteGroup className={className} data-slot="command-group" {...props} />;
147}
148
149function CommandGroupLabel({
150 className,
151 ...props
152}: React.ComponentProps<typeof AutocompleteGroupLabel>) {
153 return (
154 <AutocompleteGroupLabel className={className} data-slot="command-group-label" {...props} />
155 );
156}
157
158function CommandCollection({ ...props }: React.ComponentProps<typeof AutocompleteCollection>) {
159 return <AutocompleteCollection data-slot="command-collection" {...props} />;
160}
161
162function CommandItem({ className, ...props }: React.ComponentProps<typeof AutocompleteItem>) {
163 return (
164 <AutocompleteItem className={cn("py-1.5", className)} data-slot="command-item" {...props} />
165 );
166}
167
168function CommandSeparator({
169 className,
170 ...props
171}: React.ComponentProps<typeof AutocompleteSeparator>) {
172 return (
173 <AutocompleteSeparator
174 className={cn("my-2", className)}
175 data-slot="command-separator"
176 {...props}
177 />
178 );
179}
180
181function CommandShortcut({ className, ...props }: React.ComponentProps<"kbd">) {
182 return (
183 <kbd
184 className={cn(
185 "ms-auto font-medium font-sans text-muted-foreground/72 text-xs tracking-widest",
186 className,
187 )}
188 data-slot="command-shortcut"
189 {...props}
190 />
191 );
192}
193
194function CommandFooter({ className, ...props }: React.ComponentProps<"div">) {
195 return (
196 <div
197 className={cn(
198 "flex items-center justify-between gap-2 rounded-b-[calc(var(--radius-2xl)-1px)] border-t px-5 py-3 text-muted-foreground text-xs",
199 className,
200 )}
201 data-slot="command-footer"
202 {...props}
203 />
204 );
205}
206
207export {
208 CommandCreateHandle,
209 Command,
210 CommandCollection,
211 CommandDialog,
212 CommandDialogPopup,
213 CommandDialogTrigger,
214 CommandEmpty,
215 CommandFooter,
216 CommandGroup,
217 CommandGroupLabel,
218 CommandInput,
219 CommandItem,
220 CommandList,
221 CommandPanel,
222 CommandSeparator,
223 CommandShortcut,
224};