|
| 1 | +import { type DialogProps } from "@radix-ui/react-dialog"; |
| 2 | +import { Command as CommandPrimitive } from "cmdk"; |
| 3 | +import * as React from "react"; |
| 4 | +import { cn } from "../../utilities"; |
| 5 | +import { Dialog, DialogContent } from "../Dialog"; |
| 6 | + |
| 7 | +const Command = React.forwardRef< |
| 8 | + React.ElementRef<typeof CommandPrimitive>, |
| 9 | + React.ComponentPropsWithoutRef<typeof CommandPrimitive> |
| 10 | +>(({ className, ...props }, ref) => ( |
| 11 | + <CommandPrimitive |
| 12 | + ref={ref} |
| 13 | + className={cn( |
| 14 | + "bg-theme-surface-primary text-theme-text-primary flex h-full w-full flex-col overflow-hidden rounded-md", |
| 15 | + className |
| 16 | + )} |
| 17 | + {...props} |
| 18 | + /> |
| 19 | +)); |
| 20 | +Command.displayName = CommandPrimitive.displayName; |
| 21 | + |
| 22 | +const CommandDialog = ({ children, ...props }: DialogProps) => { |
| 23 | + return ( |
| 24 | + <Dialog {...props}> |
| 25 | + <DialogContent className="overflow-hidden p-0"> |
| 26 | + <Command className="[&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[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"> |
| 27 | + {children} |
| 28 | + </Command> |
| 29 | + </DialogContent> |
| 30 | + </Dialog> |
| 31 | + ); |
| 32 | +}; |
| 33 | + |
| 34 | +const CommandInput = React.forwardRef< |
| 35 | + React.ElementRef<typeof CommandPrimitive.Input>, |
| 36 | + React.ComponentPropsWithoutRef<typeof CommandPrimitive.Input> |
| 37 | +>(({ ...props }, ref) => ( |
| 38 | + <div className="flex items-center p-2 [&>div]:w-full" cmdk-input-wrapper=""> |
| 39 | + <CommandPrimitive.Input asChild ref={ref} {...props}></CommandPrimitive.Input> |
| 40 | + </div> |
| 41 | +)); |
| 42 | + |
| 43 | +CommandInput.displayName = CommandPrimitive.Input.displayName; |
| 44 | + |
| 45 | +const CommandList = React.forwardRef< |
| 46 | + React.ElementRef<typeof CommandPrimitive.List>, |
| 47 | + React.ComponentPropsWithoutRef<typeof CommandPrimitive.List> |
| 48 | +>(({ className, ...props }, ref) => ( |
| 49 | + <CommandPrimitive.List |
| 50 | + ref={ref} |
| 51 | + className={cn("overflow-y-auto overflow-x-hidden", className)} |
| 52 | + {...props} |
| 53 | + /> |
| 54 | +)); |
| 55 | + |
| 56 | +CommandList.displayName = CommandPrimitive.List.displayName; |
| 57 | + |
| 58 | +const CommandEmpty = React.forwardRef< |
| 59 | + React.ElementRef<typeof CommandPrimitive.Empty>, |
| 60 | + React.ComponentPropsWithoutRef<typeof CommandPrimitive.Empty> |
| 61 | +>((props, ref) => ( |
| 62 | + <CommandPrimitive.Empty |
| 63 | + ref={ref} |
| 64 | + className="py-2 text-center text-text-sm text-theme-text-secondary" |
| 65 | + {...props} |
| 66 | + /> |
| 67 | +)); |
| 68 | + |
| 69 | +CommandEmpty.displayName = CommandPrimitive.Empty.displayName; |
| 70 | + |
| 71 | +const CommandGroup = React.forwardRef< |
| 72 | + React.ElementRef<typeof CommandPrimitive.Group>, |
| 73 | + React.ComponentPropsWithoutRef<typeof CommandPrimitive.Group> |
| 74 | +>(({ className, ...props }, ref) => ( |
| 75 | + <CommandPrimitive.Group |
| 76 | + ref={ref} |
| 77 | + className={cn( |
| 78 | + "text-theme-text-primary [&_[cmdk-group-heading]]:py-2 [&_[cmdk-group-heading]]:text-text-sm [&_[cmdk-group-heading]]:text-theme-text-secondary overflow-hidden [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-semibold", |
| 79 | + className |
| 80 | + )} |
| 81 | + {...props} |
| 82 | + /> |
| 83 | +)); |
| 84 | + |
| 85 | +CommandGroup.displayName = CommandPrimitive.Group.displayName; |
| 86 | + |
| 87 | +const CommandSeparator = React.forwardRef< |
| 88 | + React.ElementRef<typeof CommandPrimitive.Separator>, |
| 89 | + React.ComponentPropsWithoutRef<typeof CommandPrimitive.Separator> |
| 90 | +>(({ className, ...props }, ref) => ( |
| 91 | + <CommandPrimitive.Separator |
| 92 | + ref={ref} |
| 93 | + className={cn("-mx-1 h-[1px] bg-theme-border-moderate", className)} |
| 94 | + {...props} |
| 95 | + /> |
| 96 | +)); |
| 97 | +CommandSeparator.displayName = CommandPrimitive.Separator.displayName; |
| 98 | + |
| 99 | +const CommandItem = React.forwardRef< |
| 100 | + React.ElementRef<typeof CommandPrimitive.Item>, |
| 101 | + React.ComponentPropsWithoutRef<typeof CommandPrimitive.Item> |
| 102 | +>(({ className, ...props }, ref) => ( |
| 103 | + <CommandPrimitive.Item |
| 104 | + ref={ref} |
| 105 | + className={cn( |
| 106 | + "text-text-sm relative flex cursor-default select-none items-center gap-2 rounded-sm py-2 pl-2 pr-3 outline-none data-[disabled=true]:pointer-events-none data-[selected=true]:bg-primary-25 data-[selected=true]:text-theme-text-brand data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0", |
| 107 | + className |
| 108 | + )} |
| 109 | + {...props} |
| 110 | + /> |
| 111 | +)); |
| 112 | + |
| 113 | +CommandItem.displayName = CommandPrimitive.Item.displayName; |
| 114 | + |
| 115 | +const CommandShortcut = ({ className, ...props }: React.HTMLAttributes<HTMLSpanElement>) => { |
| 116 | + return ( |
| 117 | + <span |
| 118 | + className={cn("text-text- text-muted-foreground ml-auto tracking-widest", className)} |
| 119 | + {...props} |
| 120 | + /> |
| 121 | + ); |
| 122 | +}; |
| 123 | +CommandShortcut.displayName = "CommandShortcut"; |
| 124 | + |
| 125 | +export { |
| 126 | + Command, |
| 127 | + CommandDialog, |
| 128 | + CommandEmpty, |
| 129 | + CommandGroup, |
| 130 | + CommandInput, |
| 131 | + CommandItem, |
| 132 | + CommandList, |
| 133 | + CommandSeparator, |
| 134 | + CommandShortcut |
| 135 | +}; |
0 commit comments