Branchwell

AI Resource Pro / website · airesourcepro.com / src / components / ui / command.tsx

Raw 4.8 KB on 6c7ce85c3441baadd17890ab9cc9bf8ed5112901
1"use client"
2
3import * as React from "react"
4import { DialogProps } from "@radix-ui/react-dialog"
5import { Command as CommandPrimitive } from "cmdk"
6import { Search } from "lucide-react"
7
8import { cn } from "@/lib/utils"
9import { Dialog, DialogContent } from "@/components/ui/dialog"
10
11const Command = React.forwardRef<
12 React.ElementRef<typeof CommandPrimitive>,
13 React.ComponentPropsWithoutRef<typeof CommandPrimitive>
14>(({ className, ...props }, ref) => (
15 <CommandPrimitive
16 ref={ref}
17 className={cn(
18 "flex h-full w-full flex-col overflow-hidden rounded-md bg-black/40 text-white dark:bg-slate-950 dark:text-slate-50",
19 className
20 )}
21 {...props}
22 />
23))
24Command.displayName = CommandPrimitive.displayName
25
26interface CommandDialogProps extends DialogProps {}
27
28const CommandDialog = ({ children, ...props }: CommandDialogProps) => {
29 return (
30 <Dialog {...props}>
31 <DialogContent className="overflow-hidden p-0 shadow-lg">
32 <Command className="[&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-slate-500 [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-group]]:px-2 [&_[cmdk-input-wrapper]_svg]:h-5 [&_[cmdk-input-wrapper]_svg]:w-5 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-3 [&_[cmdk-item]_svg]:h-5 [&_[cmdk-item]_svg]:w-5">
33 {children}
34 </Command>
35 </DialogContent>
36 </Dialog>
37 )
38}
39
40const CommandInput = React.forwardRef<
41 React.ElementRef<typeof CommandPrimitive.Input>,
42 React.ComponentPropsWithoutRef<typeof CommandPrimitive.Input>
43>(({ className, ...props }, ref) => (
44 <div className="flex items-center border-b border-white/10 px-3" cmdk-input-wrapper="">
45 <Search className="mr-2 h-4 w-4 shrink-0 text-primary" />
46 <CommandPrimitive.Input
47 ref={ref}
48 className={cn(
49 "flex h-11 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-gray-400 disabled:cursor-not-allowed disabled:opacity-50",
50 className
51 )}
52 {...props}
53 />
54 </div>
55))
56CommandInput.displayName = CommandPrimitive.Input.displayName
57
58const CommandList = React.forwardRef<
59 React.ElementRef<typeof CommandPrimitive.List>,
60 React.ComponentPropsWithoutRef<typeof CommandPrimitive.List>
61>(({ className, ...props }, ref) => (
62 <CommandPrimitive.List
63 ref={ref}
64 className={cn("max-h-[300px] overflow-y-auto overflow-x-hidden", className)}
65 {...props}
66 />
67))
68CommandList.displayName = CommandPrimitive.List.displayName
69
70const CommandEmpty = React.forwardRef<
71 React.ElementRef<typeof CommandPrimitive.Empty>,
72 React.ComponentPropsWithoutRef<typeof CommandPrimitive.Empty>
73>((props, ref) => (
74 <CommandPrimitive.Empty
75 ref={ref}
76 className="py-6 text-center text-sm text-gray-400"
77 {...props}
78 />
79))
80CommandEmpty.displayName = CommandPrimitive.Empty.displayName
81
82const CommandGroup = React.forwardRef<
83 React.ElementRef<typeof CommandPrimitive.Group>,
84 React.ComponentPropsWithoutRef<typeof CommandPrimitive.Group>
85>(({ className, ...props }, ref) => (
86 <CommandPrimitive.Group
87 ref={ref}
88 className={cn(
89 "overflow-hidden p-1 text-white [&_[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-gray-400",
90 className
91 )}
92 {...props}
93 />
94))
95CommandGroup.displayName = CommandPrimitive.Group.displayName
96
97const CommandSeparator = React.forwardRef<
98 React.ElementRef<typeof CommandPrimitive.Separator>,
99 React.ComponentPropsWithoutRef<typeof CommandPrimitive.Separator>
100>(({ className, ...props }, ref) => (
101 <CommandPrimitive.Separator
102 ref={ref}
103 className={cn("-mx-1 h-px bg-white/10", className)}
104 {...props}
105 />
106))
107CommandSeparator.displayName = CommandPrimitive.Separator.displayName
108
109const CommandItem = React.forwardRef<
110 React.ElementRef<typeof CommandPrimitive.Item>,
111 React.ComponentPropsWithoutRef<typeof CommandPrimitive.Item>
112>(({ className, ...props }, ref) => (
113 <CommandPrimitive.Item
114 ref={ref}
115 className={cn(
116 "relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none aria-selected:bg-white/10 aria-selected:text-white data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
117 className
118 )}
119 {...props}
120 />
121))
122CommandItem.displayName = CommandPrimitive.Item.displayName
123
124const CommandShortcut = ({
125 className,
126 ...props
127}: React.HTMLAttributes<HTMLSpanElement>) => {
128 return (
129 <span
130 className={cn(
131 "ml-auto text-xs tracking-widest text-gray-400",
132 className
133 )}
134 {...props}
135 />
136 )
137}
138CommandShortcut.displayName = "CommandShortcut"
139
140export {
141 Command,
142 CommandDialog,
143 CommandInput,
144 CommandList,
145 CommandEmpty,
146 CommandGroup,
147 CommandItem,
148 CommandShortcut,
149 CommandSeparator,
150}