Open History to see the last commit
1import * as React from "react";
2import { cn } from "@/lib/utils";
3import { DropdownMenu as DropdownMenuPrimitive } from "radix-ui";
4import { CheckIcon, ChevronRightIcon } from "lucide-react";
5
6function DropdownMenu({ ...props }: React.ComponentProps<typeof DropdownMenuPrimitive.Root>) {
7 return <DropdownMenuPrimitive.Root data-slot="dropdown-menu" {...props} />;
8}
9
10function DropdownMenuPortal({
11 ...props
12}: React.ComponentProps<typeof DropdownMenuPrimitive.Portal>) {
13 return <DropdownMenuPrimitive.Portal data-slot="dropdown-menu-portal" {...props} />;
14}
15
16function DropdownMenuTrigger({
17 ...props
18}: React.ComponentProps<typeof DropdownMenuPrimitive.Trigger>) {
19 return <DropdownMenuPrimitive.Trigger data-slot="dropdown-menu-trigger" {...props} />;
20}
21
22function DropdownMenuContent({
23 className,
24 align = "start",
25 sideOffset = 4,
26 ...props
27}: React.ComponentProps<typeof DropdownMenuPrimitive.Content>) {
28 return (
29 <DropdownMenuPrimitive.Portal>
30 <DropdownMenuPrimitive.Content
31 data-slot="dropdown-menu-content"
32 sideOffset={sideOffset}
33 align={align}
34 className={cn(
35 "z-50 max-h-(--radix-dropdown-menu-content-available-height) w-(--radix-dropdown-menu-trigger-width) min-w-32 origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-lg bg-popover p-1 text-popover-foreground shadow-md ring-1 ring-foreground/10 duration-100 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:overflow-hidden data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",
36 className,
37 )}
38 {...props}
39 />
40 </DropdownMenuPrimitive.Portal>
41 );
42}
43
44function DropdownMenuGroup({ ...props }: React.ComponentProps<typeof DropdownMenuPrimitive.Group>) {
45 return <DropdownMenuPrimitive.Group data-slot="dropdown-menu-group" {...props} />;
46}
47
48function DropdownMenuItem({
49 className,
50 inset,
51 variant = "default",
52 ...props
53}: React.ComponentProps<typeof DropdownMenuPrimitive.Item> & {
54 inset?: boolean;
55 variant?: "default" | "destructive";
56}) {
57 return (
58 <DropdownMenuPrimitive.Item
59 data-slot="dropdown-menu-item"
60 data-inset={inset}
61 data-variant={variant}
62 className={cn(
63 "group/dropdown-menu-item relative flex cursor-default items-center gap-1.5 rounded-md px-1.5 py-1 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground data-inset:pl-7 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 data-[variant=destructive]:*:[svg]:text-destructive",
64 className,
65 )}
66 {...props}
67 />
68 );
69}
70
71function DropdownMenuCheckboxItem({
72 className,
73 children,
74 checked,
75 inset,
76 ...props
77}: React.ComponentProps<typeof DropdownMenuPrimitive.CheckboxItem> & {
78 inset?: boolean;
79}) {
80 return (
81 <DropdownMenuPrimitive.CheckboxItem
82 data-slot="dropdown-menu-checkbox-item"
83 data-inset={inset}
84 className={cn(
85 "relative flex cursor-default items-center gap-1.5 rounded-md py-1 pr-8 pl-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground focus:**:text-accent-foreground data-inset:pl-7 data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
86 className,
87 )}
88 checked={checked}
89 {...props}
90 >
91 <span
92 className="pointer-events-none absolute right-2 flex items-center justify-center"
93 data-slot="dropdown-menu-checkbox-item-indicator"
94 >
95 <DropdownMenuPrimitive.ItemIndicator>
96 <CheckIcon />
97 </DropdownMenuPrimitive.ItemIndicator>
98 </span>
99 {children}
100 </DropdownMenuPrimitive.CheckboxItem>
101 );
102}
103
104function DropdownMenuRadioGroup({
105 ...props
106}: React.ComponentProps<typeof DropdownMenuPrimitive.RadioGroup>) {
107 return <DropdownMenuPrimitive.RadioGroup data-slot="dropdown-menu-radio-group" {...props} />;
108}
109
110function DropdownMenuRadioItem({
111 className,
112 children,
113 inset,
114 ...props
115}: React.ComponentProps<typeof DropdownMenuPrimitive.RadioItem> & {
116 inset?: boolean;
117}) {
118 return (
119 <DropdownMenuPrimitive.RadioItem
120 data-slot="dropdown-menu-radio-item"
121 data-inset={inset}
122 className={cn(
123 "relative flex cursor-default items-center gap-1.5 rounded-md py-1 pr-8 pl-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground focus:**:text-accent-foreground data-inset:pl-7 data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
124 className,
125 )}
126 {...props}
127 >
128 <span
129 className="pointer-events-none absolute right-2 flex items-center justify-center"
130 data-slot="dropdown-menu-radio-item-indicator"
131 >
132 <DropdownMenuPrimitive.ItemIndicator>
133 <CheckIcon />
134 </DropdownMenuPrimitive.ItemIndicator>
135 </span>
136 {children}
137 </DropdownMenuPrimitive.RadioItem>
138 );
139}
140
141function DropdownMenuLabel({
142 className,
143 inset,
144 ...props
145}: React.ComponentProps<typeof DropdownMenuPrimitive.Label> & {
146 inset?: boolean;
147}) {
148 return (
149 <DropdownMenuPrimitive.Label
150 data-slot="dropdown-menu-label"
151 data-inset={inset}
152 className={cn(
153 "px-1.5 py-1 text-xs font-medium text-muted-foreground data-inset:pl-7",
154 className,
155 )}
156 {...props}
157 />
158 );
159}
160
161function DropdownMenuSeparator({
162 className,
163 ...props
164}: React.ComponentProps<typeof DropdownMenuPrimitive.Separator>) {
165 return (
166 <DropdownMenuPrimitive.Separator
167 data-slot="dropdown-menu-separator"
168 className={cn("-mx-1 my-1 h-px bg-border", className)}
169 {...props}
170 />
171 );
172}
173
174function DropdownMenuShortcut({ className, ...props }: React.ComponentProps<"span">) {
175 return (
176 <span
177 data-slot="dropdown-menu-shortcut"
178 className={cn(
179 "ml-auto text-xs tracking-widest text-muted-foreground group-focus/dropdown-menu-item:text-accent-foreground",
180 className,
181 )}
182 {...props}
183 />
184 );
185}
186
187function DropdownMenuSub({ ...props }: React.ComponentProps<typeof DropdownMenuPrimitive.Sub>) {
188 return <DropdownMenuPrimitive.Sub data-slot="dropdown-menu-sub" {...props} />;
189}
190
191function DropdownMenuSubTrigger({
192 className,
193 inset,
194 children,
195 ...props
196}: React.ComponentProps<typeof DropdownMenuPrimitive.SubTrigger> & {
197 inset?: boolean;
198}) {
199 return (
200 <DropdownMenuPrimitive.SubTrigger
201 data-slot="dropdown-menu-sub-trigger"
202 data-inset={inset}
203 className={cn(
204 "flex cursor-default items-center gap-1.5 rounded-md px-1.5 py-1 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground data-inset:pl-7 data-open:bg-accent data-open:text-accent-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
205 className,
206 )}
207 {...props}
208 >
209 {children}
210 <ChevronRightIcon className="ml-auto" />
211 </DropdownMenuPrimitive.SubTrigger>
212 );
213}
214
215function DropdownMenuSubContent({
216 className,
217 ...props
218}: React.ComponentProps<typeof DropdownMenuPrimitive.SubContent>) {
219 return (
220 <DropdownMenuPrimitive.SubContent
221 data-slot="dropdown-menu-sub-content"
222 className={cn(
223 "z-50 min-w-[96px] origin-(--radix-dropdown-menu-content-transform-origin) overflow-hidden rounded-lg bg-popover p-1 text-popover-foreground shadow-lg ring-1 ring-foreground/10 duration-100 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",
224 className,
225 )}
226 {...props}
227 />
228 );
229}
230
231export {
232 DropdownMenu,
233 DropdownMenuPortal,
234 DropdownMenuTrigger,
235 DropdownMenuContent,
236 DropdownMenuGroup,
237 DropdownMenuLabel,
238 DropdownMenuItem,
239 DropdownMenuCheckboxItem,
240 DropdownMenuRadioGroup,
241 DropdownMenuRadioItem,
242 DropdownMenuSeparator,
243 DropdownMenuShortcut,
244 DropdownMenuSub,
245 DropdownMenuSubTrigger,
246 DropdownMenuSubContent,
247};