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-background/60 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 wrapperClassName,
94 placeholder = undefined,
95 ...props
96}: React.ComponentProps<typeof AutocompleteInput> & {
97 wrapperClassName?: string | undefined;
98}) {
99 return (
100 <div className={cn("px-2.5 py-1.5", wrapperClassName)}>
101 <AutocompleteInput
102 autoFocus
103 className={cn(
104 "border-transparent! bg-transparent! shadow-none before:hidden has-focus-visible:ring-0",
105 className,
106 )}
107 placeholder={placeholder}
108 size="lg"
109 startAddon={<SearchIcon />}
110 {...props}
111 />
112 </div>
113 );
114}
115
116function CommandList({ className, ...props }: React.ComponentProps<typeof AutocompleteList>) {
117 return (
118 <AutocompleteList
119 className={cn("not-empty:scroll-py-2 not-empty:p-2", className)}
120 data-slot="command-list"
121 {...props}
122 />
123 );
124}
125
126function CommandEmpty({ className, ...props }: React.ComponentProps<typeof AutocompleteEmpty>) {
127 return (
128 <AutocompleteEmpty
129 className={cn("not-empty:py-6", className)}
130 data-slot="command-empty"
131 {...props}
132 />
133 );
134}
135
136function CommandPanel({ className, ...props }: React.ComponentProps<"div">) {
137 return (
138 <div
139 className={cn(
140 "-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",
141 className,
142 )}
143 {...props}
144 />
145 );
146}
147
148function CommandGroup({ className, ...props }: React.ComponentProps<typeof AutocompleteGroup>) {
149 return <AutocompleteGroup className={className} data-slot="command-group" {...props} />;
150}
151
152function CommandGroupLabel({
153 className,
154 ...props
155}: React.ComponentProps<typeof AutocompleteGroupLabel>) {
156 return (
157 <AutocompleteGroupLabel className={className} data-slot="command-group-label" {...props} />
158 );
159}
160
161function CommandCollection({ ...props }: React.ComponentProps<typeof AutocompleteCollection>) {
162 return <AutocompleteCollection data-slot="command-collection" {...props} />;
163}
164
165function CommandItem({ className, ...props }: React.ComponentProps<typeof AutocompleteItem>) {
166 return (
167 <AutocompleteItem className={cn("py-1.5", className)} data-slot="command-item" {...props} />
168 );
169}
170
171function CommandSeparator({
172 className,
173 ...props
174}: React.ComponentProps<typeof AutocompleteSeparator>) {
175 return (
176 <AutocompleteSeparator
177 className={cn("my-2", className)}
178 data-slot="command-separator"
179 {...props}
180 />
181 );
182}
183
184function CommandShortcut({ className, ...props }: React.ComponentProps<"kbd">) {
185 return (
186 <kbd
187 className={cn(
188 "ms-auto font-medium font-sans text-muted-foreground/72 text-xs tracking-widest",
189 className,
190 )}
191 data-slot="command-shortcut"
192 {...props}
193 />
194 );
195}
196
197function CommandFooter({ className, ...props }: React.ComponentProps<"div">) {
198 return (
199 <div
200 className={cn(
201 "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",
202 className,
203 )}
204 data-slot="command-footer"
205 {...props}
206 />
207 );
208}
209
210export {
211 CommandCreateHandle,
212 Command,
213 CommandCollection,
214 CommandDialog,
215 CommandDialogPopup,
216 CommandDialogTrigger,
217 CommandEmpty,
218 CommandFooter,
219 CommandGroup,
220 CommandGroupLabel,
221 CommandInput,
222 CommandItem,
223 CommandList,
224 CommandPanel,
225 CommandSeparator,
226 CommandShortcut,
227};