|
1 | 1 | import * as React from "react"
|
2 | 2 | import { Command as CommandPrimitive } from "cmdk"
|
3 |
| -import { Search } from "lucide-react" |
| 3 | +import { MdOutlineSearch } from "react-icons/md" |
4 | 4 | import { type DialogProps } from "@radix-ui/react-dialog"
|
5 | 5 |
|
6 | 6 | import { Dialog, DialogContent } from "@/components/ui/dialog"
|
@@ -36,25 +36,42 @@ const CommandDialog = ({ children, ...props }: CommandDialogProps) => {
|
36 | 36 | )
|
37 | 37 | }
|
38 | 38 |
|
| 39 | +type CommandInputProps = React.ComponentPropsWithoutRef< |
| 40 | + typeof CommandPrimitive.Input |
| 41 | +> & { |
| 42 | + icon?: React.ElementType |
| 43 | + kbdShortcut?: string |
| 44 | +} |
| 45 | + |
39 | 46 | const CommandInput = React.forwardRef<
|
40 | 47 | React.ElementRef<typeof CommandPrimitive.Input>,
|
41 |
| - React.ComponentPropsWithoutRef<typeof CommandPrimitive.Input> |
42 |
| ->(({ className, ...props }, ref) => ( |
43 |
| - <div |
44 |
| - className="flex items-center rounded border border-body px-3" |
45 |
| - cmdk-input-wrapper="" |
46 |
| - > |
47 |
| - <CommandPrimitive.Input |
48 |
| - ref={ref} |
49 |
| - className={cn( |
50 |
| - "placeholder:text-muted-foreground flex h-11 w-full rounded-md bg-transparent py-3 text-sm outline-none disabled:cursor-not-allowed disabled:opacity-50", |
51 |
| - className |
| 48 | + CommandInputProps |
| 49 | +>(({ className, icon = MdOutlineSearch, kbdShortcut, ...props }, ref) => { |
| 50 | + const Icon = icon |
| 51 | + return ( |
| 52 | + <div |
| 53 | + className="flex items-center rounded border border-body px-3" |
| 54 | + cmdk-input-wrapper="" |
| 55 | + > |
| 56 | + <CommandPrimitive.Input |
| 57 | + ref={ref} |
| 58 | + className={cn( |
| 59 | + "placeholder:text-muted-foreground flex h-11 w-full rounded-md bg-transparent py-3 text-sm outline-none disabled:cursor-not-allowed disabled:opacity-50", |
| 60 | + className |
| 61 | + )} |
| 62 | + {...props} |
| 63 | + /> |
| 64 | + {kbdShortcut && ( |
| 65 | + <kbd className="rounded border border-solid border-disabled px-1 text-sm text-disabled"> |
| 66 | + {kbdShortcut} |
| 67 | + </kbd> |
52 | 68 | )}
|
53 |
| - {...props} |
54 |
| - /> |
55 |
| - <Search className="mr-2 h-4 w-4 shrink-0 opacity-50" /> |
56 |
| - </div> |
57 |
| -)) |
| 69 | + {!kbdShortcut && Icon && ( |
| 70 | + <Icon className="mr-2 h-4 w-4 shrink-0 opacity-50" /> |
| 71 | + )} |
| 72 | + </div> |
| 73 | + ) |
| 74 | +}) |
58 | 75 |
|
59 | 76 | CommandInput.displayName = CommandPrimitive.Input.displayName
|
60 | 77 |
|
|
0 commit comments