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="-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"
137 {...props}
138 />
139 );
140}
141
142function CommandGroup({ className, ...props }: React.ComponentProps<typeof AutocompleteGroup>) {
143 return <AutocompleteGroup className={className} data-slot="command-group" {...props} />;
144}
145
146function CommandGroupLabel({
147 className,
148 ...props
149}: React.ComponentProps<typeof AutocompleteGroupLabel>) {
150 return (
151 <AutocompleteGroupLabel className={className} data-slot="command-group-label" {...props} />
152 );
153}
154
155function CommandCollection({ ...props }: React.ComponentProps<typeof AutocompleteCollection>) {
156 return <AutocompleteCollection data-slot="command-collection" {...props} />;
157}
158
159function CommandItem({ className, ...props }: React.ComponentProps<typeof AutocompleteItem>) {
160 return (
161 <AutocompleteItem className={cn("py-1.5", className)} data-slot="command-item" {...props} />
162 );
163}
164
165function CommandSeparator({
166 className,
167 ...props
168}: React.ComponentProps<typeof AutocompleteSeparator>) {
169 return (
170 <AutocompleteSeparator
171 className={cn("my-2", className)}
172 data-slot="command-separator"
173 {...props}
174 />
175 );
176}
177
178function CommandShortcut({ className, ...props }: React.ComponentProps<"kbd">) {
179 return (
180 <kbd
181 className={cn(
182 "ms-auto font-medium font-sans text-muted-foreground/72 text-xs tracking-widest",
183 className,
184 )}
185 data-slot="command-shortcut"
186 {...props}
187 />
188 );
189}
190
191function CommandFooter({ className, ...props }: React.ComponentProps<"div">) {
192 return (
193 <div
194 className={cn(
195 "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",
196 className,
197 )}
198 data-slot="command-footer"
199 {...props}
200 />
201 );
202}
203
204export {
205 CommandCreateHandle,
206 Command,
207 CommandCollection,
208 CommandDialog,
209 CommandDialogPopup,
210 CommandDialogTrigger,
211 CommandEmpty,
212 CommandFooter,
213 CommandGroup,
214 CommandGroupLabel,
215 CommandInput,
216 CommandItem,
217 CommandList,
218 CommandPanel,
219 CommandSeparator,
220 CommandShortcut,
221};