|
| 1 | +"use client"; |
| 2 | +import * as React from "react" |
| 3 | +import { MagnifyingGlassIcon } from "@radix-ui/react-icons" |
| 4 | +import { Command as CommandPrimitive } from "cmdk" |
| 5 | + |
| 6 | +import { cn } from "@/lib/utils" |
| 7 | +import { Dialog, DialogContent } from "@/components/ui/dialog" |
| 8 | + |
| 9 | +const Command = React.forwardRef(({ className, ...props }, ref) => ( |
| 10 | + <CommandPrimitive |
| 11 | + ref={ref} |
| 12 | + className={cn( |
| 13 | + "flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground", |
| 14 | + className |
| 15 | + )} |
| 16 | + {...props} /> |
| 17 | +)) |
| 18 | +Command.displayName = CommandPrimitive.displayName |
| 19 | + |
| 20 | +const CommandDialog = ({ |
| 21 | + children, |
| 22 | + ...props |
| 23 | +}) => { |
| 24 | + return ( |
| 25 | + (<Dialog {...props}> |
| 26 | + <DialogContent className="overflow-hidden p-0"> |
| 27 | + <Command |
| 28 | + className="[&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground [&_[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"> |
| 29 | + {children} |
| 30 | + </Command> |
| 31 | + </DialogContent> |
| 32 | + </Dialog>) |
| 33 | + ); |
| 34 | +} |
| 35 | + |
| 36 | +const CommandInput = React.forwardRef(({ className, ...props }, ref) => ( |
| 37 | + <div className="flex items-center border-b px-3" cmdk-input-wrapper=""> |
| 38 | + <MagnifyingGlassIcon className="mr-2 h-4 w-4 shrink-0 opacity-50" /> |
| 39 | + <CommandPrimitive.Input |
| 40 | + ref={ref} |
| 41 | + className={cn( |
| 42 | + "flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50", |
| 43 | + className |
| 44 | + )} |
| 45 | + {...props} /> |
| 46 | + </div> |
| 47 | +)) |
| 48 | + |
| 49 | +CommandInput.displayName = CommandPrimitive.Input.displayName |
| 50 | + |
| 51 | +const CommandList = React.forwardRef(({ className, ...props }, ref) => ( |
| 52 | + <CommandPrimitive.List |
| 53 | + ref={ref} |
| 54 | + className={cn("max-h-[300px] overflow-y-auto overflow-x-hidden", className)} |
| 55 | + {...props} /> |
| 56 | +)) |
| 57 | + |
| 58 | +CommandList.displayName = CommandPrimitive.List.displayName |
| 59 | + |
| 60 | +const CommandEmpty = React.forwardRef((props, ref) => ( |
| 61 | + <CommandPrimitive.Empty ref={ref} className="py-6 text-center text-sm" {...props} /> |
| 62 | +)) |
| 63 | + |
| 64 | +CommandEmpty.displayName = CommandPrimitive.Empty.displayName |
| 65 | + |
| 66 | +const CommandGroup = React.forwardRef(({ className, ...props }, ref) => ( |
| 67 | + <CommandPrimitive.Group |
| 68 | + ref={ref} |
| 69 | + className={cn( |
| 70 | + "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", |
| 71 | + className |
| 72 | + )} |
| 73 | + {...props} /> |
| 74 | +)) |
| 75 | + |
| 76 | +CommandGroup.displayName = CommandPrimitive.Group.displayName |
| 77 | + |
| 78 | +const CommandSeparator = React.forwardRef(({ className, ...props }, ref) => ( |
| 79 | + <CommandPrimitive.Separator ref={ref} className={cn("-mx-1 h-px bg-border", className)} {...props} /> |
| 80 | +)) |
| 81 | +CommandSeparator.displayName = CommandPrimitive.Separator.displayName |
| 82 | + |
| 83 | +const CommandItem = React.forwardRef(({ className, ...props }, ref) => ( |
| 84 | + <CommandPrimitive.Item |
| 85 | + ref={ref} |
| 86 | + className={cn( |
| 87 | + "relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none aria-selected:bg-accent aria-selected:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50", |
| 88 | + className |
| 89 | + )} |
| 90 | + {...props} /> |
| 91 | +)) |
| 92 | + |
| 93 | +CommandItem.displayName = CommandPrimitive.Item.displayName |
| 94 | + |
| 95 | +const CommandShortcut = ({ |
| 96 | + className, |
| 97 | + ...props |
| 98 | +}) => { |
| 99 | + return ( |
| 100 | + (<span |
| 101 | + className={cn("ml-auto text-xs tracking-widest text-muted-foreground", className)} |
| 102 | + {...props} />) |
| 103 | + ); |
| 104 | +} |
| 105 | +CommandShortcut.displayName = "CommandShortcut" |
| 106 | + |
| 107 | +export { |
| 108 | + Command, |
| 109 | + CommandDialog, |
| 110 | + CommandInput, |
| 111 | + CommandList, |
| 112 | + CommandEmpty, |
| 113 | + CommandGroup, |
| 114 | + CommandItem, |
| 115 | + CommandShortcut, |
| 116 | + CommandSeparator, |
| 117 | +} |
0 commit comments