|
1 | | -import { |
2 | | - CommandDialog, |
3 | | - CommandEmpty, |
4 | | - CommandGroup, |
5 | | - CommandInput, |
6 | | - CommandItem, |
7 | | - CommandList, |
8 | | - CommandRoot, |
9 | | -} from "cmdk"; |
| 1 | +import { Command as CmdkCommand } from "cmdk"; |
10 | 2 | import React from "react"; |
11 | 3 | import "./Command.css"; |
12 | 4 |
|
13 | | -type CommandRootProps = React.ComponentPropsWithoutRef<typeof CommandRoot> & { |
| 5 | +interface CommandRootProps extends React.ComponentProps<typeof CmdkCommand> { |
14 | 6 | className?: string; |
15 | | -}; |
| 7 | +} |
16 | 8 |
|
17 | | -const CommandRootWrapper = React.forwardRef< |
18 | | - React.ElementRef<typeof CommandRoot>, |
| 9 | +const CommandRoot = React.forwardRef< |
| 10 | + React.ElementRef<typeof CmdkCommand>, |
19 | 11 | CommandRootProps |
20 | 12 | >(({ className, ...props }, ref) => { |
21 | 13 | return ( |
22 | | - <CommandRoot |
| 14 | + <CmdkCommand |
23 | 15 | ref={ref} |
24 | 16 | className={`flex h-full w-full flex-col overflow-hidden ${className || ""}`} |
25 | 17 | {...props} |
26 | 18 | /> |
27 | 19 | ); |
28 | 20 | }); |
29 | 21 |
|
30 | | -CommandRootWrapper.displayName = "CommandRoot"; |
| 22 | +CommandRoot.displayName = "CommandRoot"; |
31 | 23 |
|
32 | | -type CommandInputProps = React.ComponentPropsWithoutRef<typeof CommandInput> & { |
| 24 | +interface CommandInputProps |
| 25 | + extends React.ComponentProps<typeof CmdkCommand.Input> { |
33 | 26 | className?: string; |
34 | | -}; |
| 27 | +} |
35 | 28 |
|
36 | | -const CommandInputWrapper = React.forwardRef< |
37 | | - React.ElementRef<typeof CommandInput>, |
| 29 | +const CommandInput = React.forwardRef< |
| 30 | + React.ElementRef<typeof CmdkCommand.Input>, |
38 | 31 | CommandInputProps |
39 | 32 | >(({ className, ...props }, ref) => { |
40 | | - return <CommandInput ref={ref} className={className} {...props} />; |
| 33 | + return <CmdkCommand.Input ref={ref} className={className} {...props} />; |
41 | 34 | }); |
42 | 35 |
|
43 | | -CommandInputWrapper.displayName = "CommandInput"; |
| 36 | +CommandInput.displayName = "CommandInput"; |
44 | 37 |
|
45 | | -type CommandListProps = React.ComponentPropsWithoutRef<typeof CommandList> & { |
| 38 | +interface CommandListProps |
| 39 | + extends React.ComponentProps<typeof CmdkCommand.List> { |
46 | 40 | className?: string; |
47 | | -}; |
| 41 | +} |
48 | 42 |
|
49 | | -const CommandListWrapper = React.forwardRef< |
50 | | - React.ElementRef<typeof CommandList>, |
| 43 | +const CommandList = React.forwardRef< |
| 44 | + React.ElementRef<typeof CmdkCommand.List>, |
51 | 45 | CommandListProps |
52 | 46 | >(({ className, ...props }, ref) => { |
53 | 47 | return ( |
54 | | - <CommandList |
| 48 | + <CmdkCommand.List |
55 | 49 | ref={ref} |
56 | 50 | className={`overflow-y-auto ${className || ""}`} |
57 | 51 | {...props} |
58 | 52 | /> |
59 | 53 | ); |
60 | 54 | }); |
61 | 55 |
|
62 | | -CommandListWrapper.displayName = "CommandList"; |
| 56 | +CommandList.displayName = "CommandList"; |
63 | 57 |
|
64 | | -type CommandItemProps = React.ComponentPropsWithoutRef<typeof CommandItem> & { |
| 58 | +interface CommandItemProps |
| 59 | + extends React.ComponentProps<typeof CmdkCommand.Item> { |
65 | 60 | className?: string; |
66 | | -}; |
| 61 | +} |
67 | 62 |
|
68 | | -const CommandItemWrapper = React.forwardRef< |
69 | | - React.ElementRef<typeof CommandItem>, |
| 63 | +const CommandItem = React.forwardRef< |
| 64 | + React.ElementRef<typeof CmdkCommand.Item>, |
70 | 65 | CommandItemProps |
71 | 66 | >(({ className, ...props }, ref) => { |
72 | 67 | return ( |
73 | | - <CommandItem |
| 68 | + <CmdkCommand.Item |
74 | 69 | ref={ref} |
75 | 70 | className={`relative flex cursor-pointer select-none items-center px-3 py-2 text-sm outline-none data-[disabled=true]:pointer-events-none data-[selected=true]:bg-accent-3 data-[disabled=true]:opacity-50 ${className || ""}`} |
76 | 71 | {...props} |
77 | 72 | /> |
78 | 73 | ); |
79 | 74 | }); |
80 | 75 |
|
81 | | -CommandItemWrapper.displayName = "CommandItem"; |
| 76 | +CommandItem.displayName = "CommandItem"; |
82 | 77 |
|
83 | | -type CommandGroupProps = React.ComponentPropsWithoutRef<typeof CommandGroup> & { |
| 78 | +interface CommandGroupProps |
| 79 | + extends React.ComponentProps<typeof CmdkCommand.Group> { |
84 | 80 | className?: string; |
85 | 81 | heading?: string; |
86 | | -}; |
| 82 | +} |
87 | 83 |
|
88 | | -const CommandGroupWrapper = React.forwardRef< |
89 | | - React.ElementRef<typeof CommandGroup>, |
| 84 | +const CommandGroup = React.forwardRef< |
| 85 | + React.ElementRef<typeof CmdkCommand.Group>, |
90 | 86 | CommandGroupProps |
91 | 87 | >(({ className, heading, children, ...props }, ref) => { |
92 | 88 | return ( |
93 | | - <CommandGroup ref={ref} className={`p-1 ${className || ""}`} {...props}> |
| 89 | + <CmdkCommand.Group |
| 90 | + ref={ref} |
| 91 | + className={`p-1 ${className || ""}`} |
| 92 | + {...props} |
| 93 | + > |
94 | 94 | {heading && ( |
95 | 95 | <div className="px-2 py-1.5 text-gray-11" style={{ fontSize: "14px" }}> |
96 | 96 | {heading} |
97 | 97 | </div> |
98 | 98 | )} |
99 | 99 | {children} |
100 | | - </CommandGroup> |
| 100 | + </CmdkCommand.Group> |
101 | 101 | ); |
102 | 102 | }); |
103 | 103 |
|
104 | | -CommandGroupWrapper.displayName = "CommandGroup"; |
| 104 | +CommandGroup.displayName = "CommandGroup"; |
105 | 105 |
|
106 | | -type CommandEmptyProps = React.ComponentPropsWithoutRef<typeof CommandEmpty> & { |
| 106 | +interface CommandEmptyProps |
| 107 | + extends React.ComponentProps<typeof CmdkCommand.Empty> { |
107 | 108 | className?: string; |
108 | | -}; |
| 109 | +} |
109 | 110 |
|
110 | | -const CommandEmptyWrapper = React.forwardRef< |
111 | | - React.ElementRef<typeof CommandEmpty>, |
| 111 | +const CommandEmpty = React.forwardRef< |
| 112 | + React.ElementRef<typeof CmdkCommand.Empty>, |
112 | 113 | CommandEmptyProps |
113 | 114 | >(({ className, ...props }, ref) => { |
114 | 115 | return ( |
115 | | - <CommandEmpty |
| 116 | + <CmdkCommand.Empty |
116 | 117 | ref={ref} |
117 | 118 | className={`py-6 text-center text-sm ${className || ""}`} |
118 | 119 | {...props} |
119 | 120 | /> |
120 | 121 | ); |
121 | 122 | }); |
122 | 123 |
|
123 | | -CommandEmptyWrapper.displayName = "CommandEmpty"; |
| 124 | +CommandEmpty.displayName = "CommandEmpty"; |
124 | 125 |
|
125 | | -type CommandDialogProps = React.ComponentPropsWithoutRef< |
126 | | - typeof CommandDialog |
127 | | -> & { |
| 126 | +interface CommandDialogProps |
| 127 | + extends React.ComponentProps<typeof CmdkCommand.Dialog> { |
128 | 128 | className?: string; |
129 | 129 | contentClassName?: string; |
130 | | -}; |
| 130 | +} |
131 | 131 |
|
132 | | -const CommandDialogWrapper = ({ |
| 132 | +const CommandDialog = ({ |
133 | 133 | className, |
134 | 134 | contentClassName, |
135 | 135 | children, |
136 | 136 | ...props |
137 | 137 | }: CommandDialogProps) => { |
138 | 138 | return ( |
139 | | - <CommandDialog |
| 139 | + <CmdkCommand.Dialog |
140 | 140 | label="Command menu" |
141 | 141 | className={className} |
142 | 142 | contentClassName={`command-dialog-content ${contentClassName || ""}`} |
143 | 143 | overlayClassName="command-dialog-overlay" |
144 | 144 | {...props} |
145 | 145 | > |
146 | 146 | {children} |
147 | | - </CommandDialog> |
| 147 | + </CmdkCommand.Dialog> |
148 | 148 | ); |
149 | 149 | }; |
150 | 150 |
|
151 | | -CommandDialogWrapper.displayName = "CommandDialog"; |
| 151 | +CommandDialog.displayName = "CommandDialog"; |
152 | 152 |
|
153 | 153 | export const Command = { |
154 | | - Root: CommandRootWrapper, |
155 | | - Dialog: CommandDialogWrapper, |
156 | | - Input: CommandInputWrapper, |
157 | | - List: CommandListWrapper, |
158 | | - Item: CommandItemWrapper, |
159 | | - Group: CommandGroupWrapper, |
160 | | - Empty: CommandEmptyWrapper, |
| 154 | + Root: CommandRoot, |
| 155 | + Dialog: CommandDialog, |
| 156 | + Input: CommandInput, |
| 157 | + List: CommandList, |
| 158 | + Item: CommandItem, |
| 159 | + Group: CommandGroup, |
| 160 | + Empty: CommandEmpty, |
161 | 161 | }; |
0 commit comments