返回 presentation-ai
command.tsx
根目录 / src / components / plate / ui / command.tsx
1 "use client";
2
3 import { Command as CommandPrimitive } from "cmdk";
4 import { SearchIcon } from "lucide-react";
5 import type * as React from "react";
6
7 import {
8 Dialog,
9 DialogContent,
10 DialogDescription,
11 DialogHeader,
12 DialogTitle,
13 } from "@/components/plate/ui/dialog";
14 import { cn } from "@/lib/utils";
15
16 function Command({
17 className,
18 ...props
19 }: React.ComponentProps<typeof CommandPrimitive>) {
20 return (
21 <CommandPrimitive
22 data-slot="command"
23 className={cn(
24 "flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",
25 className,
26 )}
27 {...props}
28 />
29 );
30 }
31
32 function CommandDialog({
33 title = "Command Palette",
34 description = "Search for a command to run...",
35 children,
36 className,
37 showCloseButton = true,
38 ...props
39 }: React.ComponentProps<typeof Dialog> & {
40 title?: string;
41 description?: string;
42 className?: string;
43 showCloseButton?: boolean;
44 }) {
45 return (
46 <Dialog {...props}>
47 <DialogHeader className="sr-only">
48 <DialogTitle>{title}</DialogTitle>
49 <DialogDescription>{description}</DialogDescription>
50 </DialogHeader>
51 <DialogContent
52 className={cn("overflow-hidden p-0", className)}
53 showCloseButton={showCloseButton}
54 >
55 <Command className="data-[slot=command-input-wrapper]:**:h-12 [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-input-wrapper]_svg]:h-5 [&_[cmdk-input-wrapper]_svg]:w-5 [&_[cmdk-item]_svg]:h-5 [&_[cmdk-item]_svg]:w-5 **:[[cmdk-group-heading]]:px-2 **:[[cmdk-group-heading]]:font-medium **:[[cmdk-group-heading]]:text-muted-foreground **:[[cmdk-group]]:px-2 **:[[cmdk-input]]:h-12 **:[[cmdk-item]]:px-2 **:[[cmdk-item]]:py-3">
56 {children}
57 </Command>
58 </DialogContent>
59 </Dialog>
60 );
61 }
62
63 function CommandInput({
64 className,
65 ...props
66 }: React.ComponentProps<typeof CommandPrimitive.Input>) {
67 return (
68 <div
69 data-slot="command-input-wrapper"
70 className="flex h-9 items-center gap-2 border-b px-3"
71 >
72 <SearchIcon className="size-4 shrink-0 opacity-50" />
73 <CommandPrimitive.Input
74 data-slot="command-input"
75 className={cn(
76 "flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-hidden placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",
77 className,
78 )}
79 {...props}
80 />
81 </div>
82 );
83 }
84
85 function CommandList({
86 className,
87 ...props
88 }: React.ComponentProps<typeof CommandPrimitive.List>) {
89 return (
90 <CommandPrimitive.List
91 data-slot="command-list"
92 className={cn(
93 "max-h-75 scroll-py-1 overflow-x-hidden overflow-y-auto",
94 className,
95 )}
96 {...props}
97 />
98 );
99 }
100
101 function CommandEmpty({
102 ...props
103 }: React.ComponentProps<typeof CommandPrimitive.Empty>) {
104 return (
105 <CommandPrimitive.Empty
106 data-slot="command-empty"
107 className="py-6 text-center text-sm"
108 {...props}
109 />
110 );
111 }
112
113 function CommandGroup({
114 className,
115 ...props
116 }: React.ComponentProps<typeof CommandPrimitive.Group>) {
117 return (
118 <CommandPrimitive.Group
119 data-slot="command-group"
120 className={cn(
121 "overflow-hidden p-1 text-foreground **:[[cmdk-group-heading]]:px-2 **:[[cmdk-group-heading]]:py-1.5 **:[[cmdk-group-heading]]:text-xs **:[[cmdk-group-heading]]:font-medium **:[[cmdk-group-heading]]:text-muted-foreground",
122 className,
123 )}
124 {...props}
125 />
126 );
127 }
128
129 function CommandSeparator({
130 className,
131 ...props
132 }: React.ComponentProps<typeof CommandPrimitive.Separator>) {
133 return (
134 <CommandPrimitive.Separator
135 data-slot="command-separator"
136 className={cn("-mx-1 h-px bg-border", className)}
137 {...props}
138 />
139 );
140 }
141
142 function CommandItem({
143 className,
144 ...props
145 }: React.ComponentProps<typeof CommandPrimitive.Item>) {
146 return (
147 <CommandPrimitive.Item
148 data-slot="command-item"
149 className={cn(
150 "relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 data-[selected=true]:bg-accent data-[selected=true]:text-accent-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground",
151 className,
152 )}
153 {...props}
154 />
155 );
156 }
157
158 function CommandShortcut({
159 className,
160 ...props
161 }: React.ComponentProps<"span">) {
162 return (
163 <span
164 data-slot="command-shortcut"
165 className={cn(
166 "ml-auto text-xs tracking-widest text-muted-foreground",
167 className,
168 )}
169 {...props}
170 />
171 );
172 }
173
174 export {
175 Command,
176 CommandDialog,
177 CommandEmpty,
178 CommandGroup,
179 CommandInput,
180 CommandItem,
181 CommandList,
182 CommandSeparator,
183 CommandShortcut,
184 };
185
185 lines Plain Text