File size: 6,628 Bytes
9697ede | 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 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | import { DropdownMenu } from "@kobalte/core/dropdown-menu"
import { ContextMenu } from "@kobalte/core/context-menu"
import { Show, splitProps, type Component, type ComponentProps, type JSX, type ParentProps } from "solid-js"
import "./menu-v2.css"
const ChevronRight: Component = () => (
<svg
data-slot="menu-v2-item-chevron"
width="16"
height="16"
viewBox="0 0 16 16"
fill="none"
xmlns="http://www.w3.org/2000/svg"
aria-hidden="true"
>
<path d="M6 4L10 8L6 12V4Z" fill="currentColor" />
</svg>
)
const CheckMark: Component = () => (
<svg width="14" height="14" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
<path
d="M3.53564 8.17857L6.39279 11.75L12.4642 4.25"
stroke="currentColor"
stroke-width="1"
stroke-linecap="round"
stroke-linejoin="round"
/>
</svg>
)
function ItemBody(
props: ParentProps<{
shortcut?: JSX.Element | string
badge?: JSX.Element | string
trailing?: JSX.Element
}>,
) {
return (
<>
<span data-slot="menu-v2-item-content">{props.children}</span>
<Show when={props.shortcut}>{(shortcut) => <span data-slot="menu-v2-item-shortcut">{shortcut()}</span>}</Show>
<Show when={props.badge}>{(badge) => <span data-slot="menu-v2-item-badge">{badge()}</span>}</Show>
{props.trailing}
</>
)
}
export interface MenuV2ItemProps extends ComponentProps<typeof DropdownMenu.Item> {
shortcut?: JSX.Element | string
badge?: JSX.Element | string
}
function MenuV2Item(props: ParentProps<MenuV2ItemProps>) {
const [s, r] = splitProps(props, ["class", "classList", "children", "shortcut", "badge"])
return (
<DropdownMenu.Item {...r} data-component="menu-v2-item" classList={{ ...s.classList, [s.class ?? ""]: !!s.class }}>
<ItemBody shortcut={s.shortcut} badge={s.badge}>
{s.children}
</ItemBody>
</DropdownMenu.Item>
)
}
export interface MenuV2CheckboxItemProps extends ComponentProps<typeof DropdownMenu.CheckboxItem> {
shortcut?: JSX.Element | string
badge?: JSX.Element | string
}
function MenuV2CheckboxItem(props: ParentProps<MenuV2CheckboxItemProps>) {
const [s, r] = splitProps(props, ["class", "classList", "children", "shortcut", "badge"])
return (
<DropdownMenu.CheckboxItem
{...r}
data-component="menu-v2-item"
classList={{ ...s.classList, [s.class ?? ""]: !!s.class }}
>
<ItemBody
shortcut={s.shortcut}
badge={s.badge}
trailing={
<DropdownMenu.ItemIndicator data-slot="menu-v2-item-indicator" forceMount>
<CheckMark />
</DropdownMenu.ItemIndicator>
}
>
{s.children}
</ItemBody>
</DropdownMenu.CheckboxItem>
)
}
export interface MenuV2RadioItemProps extends ComponentProps<typeof DropdownMenu.RadioItem> {
shortcut?: JSX.Element | string
badge?: JSX.Element | string
}
function MenuV2RadioItem(props: ParentProps<MenuV2RadioItemProps>) {
const [s, r] = splitProps(props, ["class", "classList", "children", "shortcut", "badge"])
return (
<DropdownMenu.RadioItem
{...r}
data-component="menu-v2-item"
classList={{ ...s.classList, [s.class ?? ""]: !!s.class }}
>
<ItemBody
shortcut={s.shortcut}
badge={s.badge}
trailing={
<DropdownMenu.ItemIndicator data-slot="menu-v2-item-indicator" forceMount>
<CheckMark />
</DropdownMenu.ItemIndicator>
}
>
{s.children}
</ItemBody>
</DropdownMenu.RadioItem>
)
}
export interface MenuV2SubTriggerProps extends ComponentProps<typeof DropdownMenu.SubTrigger> {
shortcut?: JSX.Element | string
badge?: JSX.Element | string
}
function MenuV2SubTrigger(props: ParentProps<MenuV2SubTriggerProps>) {
const [s, r] = splitProps(props, ["class", "classList", "children", "shortcut", "badge"])
return (
<DropdownMenu.SubTrigger
{...r}
data-component="menu-v2-item"
classList={{ ...s.classList, [s.class ?? ""]: !!s.class }}
>
<ItemBody shortcut={s.shortcut} badge={s.badge} trailing={<ChevronRight />}>
{s.children}
</ItemBody>
</DropdownMenu.SubTrigger>
)
}
function MenuV2SubContent(props: ComponentProps<typeof DropdownMenu.SubContent>) {
const [s, r] = splitProps(props, ["class", "classList"])
return (
<DropdownMenu.SubContent
{...r}
data-component="menu-v2-content"
classList={{ ...s.classList, [s.class ?? ""]: !!s.class }}
/>
)
}
function MenuV2GroupLabel(props: ComponentProps<typeof DropdownMenu.GroupLabel>) {
const [s, r] = splitProps(props, ["class", "classList"])
return (
<DropdownMenu.GroupLabel
{...r}
data-slot="menu-v2-group-label"
classList={{ ...s.classList, [s.class ?? ""]: !!s.class }}
/>
)
}
function MenuV2Separator(props: ComponentProps<typeof DropdownMenu.Separator>) {
const [s, r] = splitProps(props, ["class", "classList"])
return (
<DropdownMenu.Separator
{...r}
data-slot="menu-v2-separator"
classList={{ ...s.classList, [s.class ?? ""]: !!s.class }}
/>
)
}
function MenuV2Content(props: ComponentProps<typeof DropdownMenu.Content>) {
const [s, r] = splitProps(props, ["class", "classList"])
return (
<DropdownMenu.Content
{...r}
data-component="menu-v2-content"
classList={{ ...s.classList, [s.class ?? ""]: !!s.class }}
/>
)
}
function MenuV2Root(props: ComponentProps<typeof DropdownMenu>) {
return <DropdownMenu {...props} />
}
function MenuV2ContextRoot(props: ComponentProps<typeof ContextMenu>) {
return <ContextMenu {...props} />
}
function MenuV2ContextContent(props: ComponentProps<typeof ContextMenu.Content>) {
const [s, r] = splitProps(props, ["class", "classList"])
return (
<ContextMenu.Content
{...r}
data-component="menu-v2-content"
classList={{ ...s.classList, [s.class ?? ""]: !!s.class }}
/>
)
}
const MenuV2Context = Object.assign(MenuV2ContextRoot, {
Trigger: ContextMenu.Trigger,
Portal: ContextMenu.Portal,
Content: MenuV2ContextContent,
})
export const MenuV2 = Object.assign(MenuV2Root, {
Trigger: DropdownMenu.Trigger,
Portal: DropdownMenu.Portal,
Content: MenuV2Content,
Item: MenuV2Item,
CheckboxItem: MenuV2CheckboxItem,
RadioGroup: DropdownMenu.RadioGroup,
RadioItem: MenuV2RadioItem,
Group: DropdownMenu.Group,
GroupLabel: MenuV2GroupLabel,
Separator: MenuV2Separator,
Sub: DropdownMenu.Sub,
SubTrigger: MenuV2SubTrigger,
SubContent: MenuV2SubContent,
Context: MenuV2Context,
})
|