-
-
Notifications
You must be signed in to change notification settings - Fork 397
Expand file tree
/
Copy pathDropdown.tsx
More file actions
122 lines (110 loc) · 2.55 KB
/
Copy pathDropdown.tsx
File metadata and controls
122 lines (110 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import * as React from 'react'
import * as DropdownMenu from '@radix-ui/react-dropdown-menu'
import { twMerge } from 'tailwind-merge'
type DropdownProps = {
children: React.ReactNode
open?: boolean
onOpenChange?: (open: boolean) => void
modal?: boolean
}
type DropdownTriggerProps = {
children: React.ReactNode
className?: string
asChild?: boolean
}
type DropdownContentProps = {
children: React.ReactNode
className?: string
align?: 'start' | 'center' | 'end'
sideOffset?: number
portal?: boolean
}
type DropdownItemProps = {
children: React.ReactNode
className?: string
onSelect?: () => void
asChild?: boolean
}
type DropdownSeparatorProps = {
className?: string
}
export function Dropdown({
children,
open,
onOpenChange,
modal = false,
}: DropdownProps) {
return (
<DropdownMenu.Root open={open} onOpenChange={onOpenChange} modal={modal}>
{children}
</DropdownMenu.Root>
)
}
export function DropdownTrigger({
children,
className,
asChild = true,
}: DropdownTriggerProps) {
return (
<DropdownMenu.Trigger asChild={asChild} className={className}>
{children}
</DropdownMenu.Trigger>
)
}
export function DropdownContent({
children,
className,
align = 'end',
sideOffset = 6,
portal = true,
}: DropdownContentProps) {
const content = (
<DropdownMenu.Content
align={align}
sideOffset={sideOffset}
className={twMerge(
'dropdown-content z-[1000] min-w-48 rounded-lg p-1.5',
'border border-gray-200 dark:border-gray-700',
'bg-white dark:bg-gray-800',
'shadow-lg',
className,
)}
>
{children}
</DropdownMenu.Content>
)
if (!portal) {
return content
}
return <DropdownMenu.Portal>{content}</DropdownMenu.Portal>
}
export function DropdownItem({
children,
className,
onSelect,
asChild,
}: DropdownItemProps) {
return (
<DropdownMenu.Item
asChild={asChild}
onSelect={onSelect}
className={twMerge(
'flex cursor-pointer select-none items-center gap-2 rounded-md px-2 py-1.5 outline-none',
'text-sm text-gray-700 dark:text-gray-300',
'hover:bg-gray-100 dark:hover:bg-gray-700/50',
'focus:bg-gray-100 dark:focus:bg-gray-700/50',
'transition-colors duration-150',
className,
)}
>
{children}
</DropdownMenu.Item>
)
}
export function DropdownSeparator({ className }: DropdownSeparatorProps) {
return (
<DropdownMenu.Separator
className={twMerge('my-1 h-px bg-gray-200 dark:bg-gray-700', className)}
/>
)
}