Become a Pro / website · becomeapro.ai / src / components / ui / command.tsx
| 1 | "use client" |
| 2 | |
| 3 | import * as React from "react" |
| 4 | import { DialogProps } from "@radix-ui/react-dialog" |
| 5 | import { Command as CommandPrimitive } from "cmdk" |
| 6 | import { Search } from "lucide-react" |
| 7 | |
| 8 | import { cn } from "@/lib/utils" |
| 9 | import { Dialog, DialogContent } from "@/components/ui/dialog" |
| 10 | |
| 11 | const 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 | )) |
| 24 | Command.displayName = CommandPrimitive.displayName |
| 25 | |
| 26 | interface CommandDialogProps extends DialogProps {} |
| 27 | |
| 28 | const 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 | |
| 40 | const 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 | )) |
| 56 | CommandInput.displayName = CommandPrimitive.Input.displayName |
| 57 | |
| 58 | const 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 | )) |
| 68 | CommandList.displayName = CommandPrimitive.List.displayName |
| 69 | |
| 70 | const 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 | )) |
| 80 | CommandEmpty.displayName = CommandPrimitive.Empty.displayName |
| 81 | |
| 82 | const 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 | )) |
| 95 | CommandGroup.displayName = CommandPrimitive.Group.displayName |
| 96 | |
| 97 | const 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 | )) |
| 107 | CommandSeparator.displayName = CommandPrimitive.Separator.displayName |
| 108 | |
| 109 | const 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 | )) |
| 122 | CommandItem.displayName = CommandPrimitive.Item.displayName |
| 123 | |
| 124 | const 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 | } |
| 138 | CommandShortcut.displayName = "CommandShortcut" |
| 139 | |
| 140 | export { |
| 141 | Command, |
| 142 | CommandDialog, |
| 143 | CommandInput, |
| 144 | CommandList, |
| 145 | CommandEmpty, |
| 146 | CommandGroup, |
| 147 | CommandItem, |
| 148 | CommandShortcut, |
| 149 | CommandSeparator, |
| 150 | } |