@glasshome/ui 1.41.0 → 1.43.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/SPEC.md +5 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -3
- package/dist/lib/anchor-placement.d.ts +34 -0
- package/dist/lib/balance-rows.d.ts +10 -4
- package/dist/lib/behavior/anchored.d.ts +26 -0
- package/dist/lib/behavior/button-root.d.ts +7 -0
- package/dist/lib/behavior/collection.d.ts +32 -0
- package/dist/lib/behavior/controllable.d.ts +8 -0
- package/dist/lib/behavior/dismiss.d.ts +13 -0
- package/dist/lib/behavior/focus-scope.d.ts +24 -0
- package/dist/lib/behavior/hide-outside.d.ts +7 -0
- package/dist/lib/behavior/layer-stack.d.ts +34 -0
- package/dist/lib/behavior/menu.d.ts +59 -0
- package/dist/lib/behavior/modal-root.d.ts +68 -0
- package/dist/lib/behavior/polymorphic.d.ts +6 -0
- package/dist/lib/behavior/presence.d.ts +18 -0
- package/dist/lib/behavior/range.d.ts +44 -0
- package/dist/lib/behavior/solid.d.ts +13 -0
- package/dist/lib/color/color.d.ts +41 -0
- package/dist/lib/color/index.d.ts +2 -0
- package/dist/lib/color/intl.d.ts +40 -0
- package/dist/lib/dock-slot-classes.d.ts +2 -0
- package/dist/lib/hold.d.ts +1 -1
- package/dist/lib/locale.d.ts +3 -0
- package/dist/lib/menu-classes.d.ts +2 -0
- package/dist/lib/motion-classes.d.ts +5 -2
- package/dist/lib/overlay-classes.d.ts +4 -0
- package/dist/lib/page-cover.d.ts +8 -0
- package/dist/lib/scroll-track.d.ts +3 -2
- package/dist/lib/section-tokens.d.ts +1 -1
- package/dist/lib/segment-classes.d.ts +2 -0
- package/dist/lib/shadow-layer.d.ts +0 -43
- package/dist/lib/toggle-set.d.ts +44 -0
- package/dist/lib/visually-hidden.d.ts +3 -0
- package/dist/solid/accordion.d.ts +35 -11
- package/dist/solid/alert-dialog.d.ts +5 -8
- package/dist/solid/avatar.d.ts +8 -4
- package/dist/solid/bottom-sheet/bottom-sheet.d.ts +2 -2
- package/dist/solid/bottom-sheet/constants.d.ts +1 -1
- package/dist/solid/button.d.ts +5 -4
- package/dist/solid/charts.d.ts +1 -1
- package/dist/solid/checkbox.d.ts +14 -4
- package/dist/solid/collapsible.d.ts +33 -5
- package/dist/solid/color-disc.d.ts +1 -1
- package/dist/solid/color-slider.d.ts +1 -1
- package/dist/solid/color-wheel.d.ts +1 -1
- package/dist/solid/context-menu.d.ts +58 -24
- package/dist/solid/dialog-parts.d.ts +53 -16
- package/dist/solid/dialog.d.ts +7 -10
- package/dist/solid/dropdown-menu.d.ts +55 -24
- package/dist/solid/empty.d.ts +1 -1
- package/dist/solid/form.d.ts +5 -6
- package/dist/solid/hover-card.d.ts +65 -9
- package/dist/solid/index.d.ts +5 -2
- package/dist/solid/index.js +8671 -14317
- package/dist/solid/input-group.d.ts +6 -6
- package/dist/solid/item.d.ts +1 -1
- package/dist/solid/menu-parts.d.ts +175 -24
- package/dist/solid/option-card.d.ts +1 -4
- package/dist/solid/picker-row.d.ts +2 -0
- package/dist/solid/popover.d.ts +77 -12
- package/dist/solid/progress.d.ts +11 -3
- package/dist/solid/radio-group.d.ts +31 -6
- package/dist/solid/responsive-dialog.d.ts +3 -1
- package/dist/solid/scroll-area.d.ts +1 -1
- package/dist/solid/section-card.d.ts +2 -3
- package/dist/solid/select.d.ts +107 -10
- package/dist/solid/selection.d.ts +10 -1
- package/dist/solid/sheet.d.ts +6 -9
- package/dist/solid/sliding-indicator.d.ts +1 -1
- package/dist/solid/sonner.d.ts +1 -1
- package/dist/solid/stale-veil.d.ts +7 -0
- package/dist/solid/tabs.d.ts +28 -9
- package/dist/solid/toggle-group.d.ts +30 -5
- package/dist/solid/toggle.d.ts +11 -3
- package/dist/solid/tooltip.d.ts +71 -9
- package/dist/tokens/index.js +54 -51
- package/dist/{utils-CGN4X-2O.js → utils-3Codx-NZ.js} +848 -618
- package/package.json +6 -7
- package/src/index.ts +1 -0
- package/src/lib/anchor-placement.ts +77 -4
- package/src/lib/balance-rows.ts +115 -40
- package/src/lib/behavior/anchored.ts +106 -0
- package/src/lib/behavior/button-root.tsx +103 -0
- package/src/lib/behavior/collection.ts +218 -0
- package/src/lib/behavior/controllable.ts +22 -0
- package/src/lib/behavior/dismiss.ts +185 -0
- package/src/lib/behavior/focus-scope.ts +227 -0
- package/src/lib/behavior/hide-outside.ts +85 -0
- package/src/lib/behavior/layer-stack.ts +150 -0
- package/src/lib/behavior/menu.ts +470 -0
- package/src/lib/behavior/modal-root.tsx +452 -0
- package/src/lib/behavior/polymorphic.tsx +30 -0
- package/src/lib/behavior/presence.ts +89 -0
- package/src/lib/behavior/range.ts +212 -0
- package/src/lib/behavior/solid.ts +30 -0
- package/src/lib/clipboard.ts +4 -4
- package/src/lib/color/color.ts +746 -0
- package/src/lib/color/index.ts +2 -0
- package/src/lib/color/intl.ts +60 -0
- package/src/lib/dock-slot-classes.ts +3 -0
- package/src/lib/hold.ts +1 -1
- package/src/lib/locale.ts +62 -0
- package/src/lib/menu-classes.ts +3 -0
- package/src/lib/motion-classes.ts +33 -8
- package/src/lib/overlay-classes.ts +8 -3
- package/src/lib/page-cover.ts +47 -0
- package/src/lib/scroll-track.ts +11 -6
- package/src/lib/section-tokens.ts +1 -1
- package/src/lib/segment-classes.ts +3 -0
- package/src/lib/shadow-layer.ts +0 -136
- package/src/lib/toggle-set.ts +133 -0
- package/src/lib/visually-hidden.ts +15 -0
- package/src/solid/accordion.tsx +294 -20
- package/src/solid/alert-dialog.tsx +36 -85
- package/src/solid/area-picker.tsx +5 -3
- package/src/solid/avatar.tsx +98 -24
- package/src/solid/badge.tsx +5 -5
- package/src/solid/bottom-sheet/bottom-sheet.tsx +73 -129
- package/src/solid/bottom-sheet/constants.ts +3 -1
- package/src/solid/bottom-sheet/drag-controller.ts +11 -0
- package/src/solid/breadcrumb.tsx +4 -4
- package/src/solid/button-group.tsx +4 -4
- package/src/solid/button.tsx +12 -6
- package/src/solid/card.tsx +5 -4
- package/src/solid/charts.tsx +1 -1
- package/src/solid/checkbox.tsx +167 -44
- package/src/solid/collapsible.tsx +260 -12
- package/src/solid/color-disc.tsx +11 -12
- package/src/solid/color-slider.tsx +114 -47
- package/src/solid/color-wheel.tsx +137 -39
- package/src/solid/context-menu.tsx +287 -86
- package/src/solid/dialog-parts.tsx +135 -46
- package/src/solid/dialog.tsx +44 -76
- package/src/solid/dock-edit.tsx +5 -4
- package/src/solid/dock.tsx +6 -5
- package/src/solid/dropdown-menu.tsx +252 -107
- package/src/solid/empty.tsx +1 -1
- package/src/solid/entity-selector.tsx +5 -3
- package/src/solid/face-toggle.tsx +43 -18
- package/src/solid/form.tsx +9 -9
- package/src/solid/glyph-tile.tsx +48 -21
- package/src/solid/hover-card.tsx +288 -21
- package/src/solid/icon-picker.tsx +2 -1
- package/src/solid/image-picker.tsx +6 -5
- package/src/solid/index.ts +5 -4
- package/src/solid/input-group.tsx +7 -5
- package/src/solid/input-otp.tsx +2 -1
- package/src/solid/item.tsx +5 -5
- package/src/solid/logo.tsx +5 -4
- package/src/solid/menu-parts.tsx +619 -145
- package/src/solid/option-card.tsx +6 -10
- package/src/solid/picker-row.tsx +10 -5
- package/src/solid/picker-search.tsx +2 -1
- package/src/solid/popover.tsx +424 -71
- package/src/solid/preview-tile.tsx +1 -1
- package/src/solid/progress.tsx +84 -15
- package/src/solid/radio-group.tsx +271 -34
- package/src/solid/responsive-dialog.tsx +10 -10
- package/src/solid/schema-form.tsx +1 -6
- package/src/solid/scroll-area.tsx +1 -1
- package/src/solid/section-card.tsx +3 -4
- package/src/solid/select.tsx +950 -95
- package/src/solid/selection.tsx +142 -66
- package/src/solid/sheet.tsx +48 -80
- package/src/solid/slider.tsx +115 -65
- package/src/solid/sliding-indicator.tsx +1 -1
- package/src/solid/sonner.tsx +1 -1
- package/src/solid/spotlight.tsx +23 -11
- package/src/solid/stale-veil.tsx +20 -0
- package/src/solid/switch.tsx +8 -6
- package/src/solid/tabs.tsx +377 -52
- package/src/solid/term.tsx +3 -4
- package/src/solid/toggle-group.tsx +237 -95
- package/src/solid/toggle.tsx +43 -9
- package/src/solid/tooltip.tsx +285 -26
- package/src/styles/globals.css +64 -10
- package/src/styles/theme.css +12 -4
- package/src/tokens/material.ts +11 -2
- package/dist/lib/when-animations-settle.d.ts +0 -4
- package/dist/solid/bottom-sheet/focus-trap.d.ts +0 -6
- package/dist/solid/bottom-sheet/scroll-lock.d.ts +0 -2
- package/dist/solid/bottom-sheet/sheet-motion.d.ts +0 -1
- package/src/lib/when-animations-settle.ts +0 -12
- package/src/solid/bottom-sheet/focus-trap.ts +0 -63
- package/src/solid/bottom-sheet/scroll-lock.ts +0 -66
- package/src/solid/bottom-sheet/sheet-motion.ts +0 -4
package/src/solid/menu-parts.tsx
CHANGED
|
@@ -1,48 +1,263 @@
|
|
|
1
|
-
import { DropdownMenu as MenuPrimitive } from "@kobalte/core/dropdown-menu";
|
|
2
|
-
import { useMenuContext } from "@kobalte/core/menu";
|
|
3
1
|
import {
|
|
2
|
+
type Accessor,
|
|
4
3
|
type Component,
|
|
5
4
|
type ComponentProps,
|
|
5
|
+
createContext,
|
|
6
6
|
createSignal,
|
|
7
|
+
createUniqueId,
|
|
8
|
+
type JSX,
|
|
9
|
+
onCleanup,
|
|
7
10
|
type ParentComponent,
|
|
11
|
+
Show,
|
|
8
12
|
splitProps,
|
|
13
|
+
untrack,
|
|
14
|
+
useContext,
|
|
15
|
+
type ValidComponent,
|
|
9
16
|
} from "solid-js";
|
|
17
|
+
import { Portal } from "solid-js/web";
|
|
18
|
+
import type { Align, Side } from "../lib/anchor-placement.js";
|
|
19
|
+
import { createControllableSignal } from "../lib/behavior/controllable.js";
|
|
20
|
+
import { createMenu, type Menu, type MenuOptions } from "../lib/behavior/menu.js";
|
|
21
|
+
import { Polymorphic } from "../lib/behavior/polymorphic.js";
|
|
22
|
+
import { createPresence } from "../lib/behavior/presence.js";
|
|
23
|
+
import { effect, merge } from "../lib/behavior/solid.js";
|
|
10
24
|
import { glassToneText } from "../lib/glass-tone.js";
|
|
11
|
-
import {
|
|
12
|
-
|
|
25
|
+
import {
|
|
26
|
+
MENU_ITEM,
|
|
27
|
+
MENU_ITEM_BASE,
|
|
28
|
+
MENU_ITEM_RADIUS,
|
|
29
|
+
MENU_LABEL,
|
|
30
|
+
MENU_SEPARATOR,
|
|
31
|
+
} from "../lib/menu-classes.js";
|
|
13
32
|
import { STAGGER } from "../lib/motion-classes.js";
|
|
14
|
-
import { ignoreOpeningRelease } from "../lib/opening-release.js";
|
|
15
33
|
import { FLOATING_PANEL } from "../lib/overlay-classes.js";
|
|
16
34
|
import { cn } from "../lib/utils.js";
|
|
17
35
|
import { Icon } from "./icon.js";
|
|
36
|
+
import { usePortalMount } from "./portal-mount.js";
|
|
18
37
|
import { SelectionHighlight, SelectionScope } from "./selection.js";
|
|
19
38
|
|
|
20
|
-
/*
|
|
21
|
-
* DropdownMenu and ContextMenu are two Root flavors over one Kobalte Menu
|
|
22
|
-
* engine: Item, CheckboxItem, RadioItem, SubTrigger, SubContent, GroupLabel,
|
|
23
|
-
* Separator and ItemIndicator are the identical components either family
|
|
24
|
-
* re-exports (see @kobalte/core's dropdown-menu and context-menu index,
|
|
25
|
-
* which both alias the same ../menu implementation), so they are styled once
|
|
26
|
-
* here under whichever Root happens to be an ancestor.
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
39
|
/* The panel without its motion: DropdownMenu morphs out of its trigger,
|
|
30
40
|
* ContextMenu unfolds from the pointer. */
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
/** Every menu content and sub content wraps its rows in one selection scope, keyed off
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
// an unnamed div there breaks the menu's ownership in the a11y tree.
|
|
38
|
-
<SelectionScope ref={ignoreOpeningRelease} role="none" class={STAGGER} marker="highlighted">
|
|
41
|
+
const MENU_CONTENT_CLASS = cn(FLOATING_PANEL, "min-w-[8rem] overflow-hidden p-1");
|
|
42
|
+
|
|
43
|
+
/** Every menu content and sub content wraps its rows in one selection scope, keyed off the highlighted row. */
|
|
44
|
+
const MenuContentIndicator: ParentComponent = (props) => (
|
|
45
|
+
// The one element between role="menu" and its rows: an unnamed div there breaks the menu's ownership in the a11y tree.
|
|
46
|
+
<SelectionScope role="none" class={STAGGER} marker="highlighted" radius={MENU_ITEM_RADIUS}>
|
|
39
47
|
{props.children}
|
|
40
48
|
</SelectionScope>
|
|
41
49
|
);
|
|
42
50
|
|
|
51
|
+
export type MenuPlacement = Side | `${Side}-${Exclude<Align, "center">}`;
|
|
52
|
+
|
|
53
|
+
export function parsePlacement(placement: MenuPlacement): [Side, Align] {
|
|
54
|
+
const [side, align] = placement.split("-") as [Side, Align?];
|
|
55
|
+
return [side, align ?? "center"];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** One open level of a menu tree: the root menu or a submenu, with the ids its trigger and panel name each other by. */
|
|
59
|
+
export interface MenuLevel {
|
|
60
|
+
menu: Menu;
|
|
61
|
+
parent: MenuLevel | undefined;
|
|
62
|
+
triggerId: Accessor<string | undefined>;
|
|
63
|
+
setTriggerId: (id: string | undefined) => void;
|
|
64
|
+
contentId: Accessor<string | undefined>;
|
|
65
|
+
setContentId: (id: string | undefined) => void;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const MenuLevelContext = createContext<MenuLevel>();
|
|
69
|
+
|
|
70
|
+
export const MenuLevelProvider = MenuLevelContext.Provider;
|
|
71
|
+
|
|
72
|
+
export function useMenuLevel(): MenuLevel {
|
|
73
|
+
const level = useContext(MenuLevelContext);
|
|
74
|
+
if (!level) throw new Error("Menu parts render inside a DropdownMenu or a ContextMenu");
|
|
75
|
+
return level;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function createMenuLevel(options: MenuOptions, parent?: MenuLevel): MenuLevel {
|
|
79
|
+
const menu = createMenu(parent ? merge(options, { parent: parent.menu }) : options);
|
|
80
|
+
const [triggerId, setTriggerId] = createSignal<string>();
|
|
81
|
+
const [contentId, setContentId] = createSignal<string>();
|
|
82
|
+
return { menu, parent, triggerId, setTriggerId, contentId, setContentId };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** @deprecated Ignored options; removed in 2.0.0. */
|
|
86
|
+
export interface DeprecatedMenuRootProps {
|
|
87
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
88
|
+
modal?: boolean;
|
|
89
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
90
|
+
preventScroll?: boolean;
|
|
91
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
92
|
+
id?: string;
|
|
93
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
94
|
+
forceMount?: boolean;
|
|
95
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
96
|
+
orientation?: "horizontal" | "vertical";
|
|
97
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
98
|
+
value?: string;
|
|
99
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
100
|
+
shift?: number;
|
|
101
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
102
|
+
flip?: boolean | string;
|
|
103
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
104
|
+
slide?: boolean;
|
|
105
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
106
|
+
overlap?: boolean;
|
|
107
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
108
|
+
sameWidth?: boolean;
|
|
109
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
110
|
+
fitViewport?: boolean;
|
|
111
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
112
|
+
hideWhenDetached?: boolean;
|
|
113
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
114
|
+
detachedPadding?: number;
|
|
115
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
116
|
+
arrowPadding?: number;
|
|
117
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
118
|
+
overflowPadding?: number;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** @deprecated Ignored callbacks; removed in 2.0.0. */
|
|
122
|
+
export interface DeprecatedMenuContentProps {
|
|
123
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
124
|
+
forceMount?: boolean;
|
|
125
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
126
|
+
onOpenAutoFocus?: (event: Event) => void;
|
|
127
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
128
|
+
onCloseAutoFocus?: (event: Event) => void;
|
|
129
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
130
|
+
onEscapeKeyDown?: (event: KeyboardEvent) => void;
|
|
131
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
132
|
+
onPointerDownOutside?: (event: Event) => void;
|
|
133
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
134
|
+
onFocusOutside?: (event: Event) => void;
|
|
135
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
136
|
+
onInteractOutside?: (event: Event) => void;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const DEPRECATED_CONTENT_PROPS = [
|
|
140
|
+
"forceMount",
|
|
141
|
+
"onOpenAutoFocus",
|
|
142
|
+
"onCloseAutoFocus",
|
|
143
|
+
"onEscapeKeyDown",
|
|
144
|
+
"onPointerDownOutside",
|
|
145
|
+
"onFocusOutside",
|
|
146
|
+
"onInteractOutside",
|
|
147
|
+
] as const;
|
|
148
|
+
|
|
149
|
+
export type MenuContentProps = Omit<ComponentProps<"div">, "role"> & DeprecatedMenuContentProps;
|
|
150
|
+
|
|
151
|
+
type MenuContentPartProps = MenuContentProps & {
|
|
152
|
+
slotName: string;
|
|
153
|
+
motionClass?: string;
|
|
154
|
+
exitMs: number;
|
|
155
|
+
onPanel?: (el: HTMLElement) => void;
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
export const MenuContentPart: Component<MenuContentPartProps> = (props) => {
|
|
159
|
+
const level = useMenuLevel();
|
|
160
|
+
const menu = level.menu;
|
|
161
|
+
const [local, rest] = splitProps(props, [
|
|
162
|
+
"class",
|
|
163
|
+
"children",
|
|
164
|
+
"ref",
|
|
165
|
+
"id",
|
|
166
|
+
"slotName",
|
|
167
|
+
"motionClass",
|
|
168
|
+
"exitMs",
|
|
169
|
+
"onPanel",
|
|
170
|
+
...DEPRECATED_CONTENT_PROPS,
|
|
171
|
+
]);
|
|
172
|
+
const fallback = createUniqueId();
|
|
173
|
+
const id = (): string => local.id ?? fallback;
|
|
174
|
+
effect(id, (value) => {
|
|
175
|
+
level.setContentId(value);
|
|
176
|
+
return () => level.setContentId(undefined);
|
|
177
|
+
});
|
|
178
|
+
const presence = createPresence({
|
|
179
|
+
present: menu.open,
|
|
180
|
+
element: menu.content,
|
|
181
|
+
exitMs: untrack(() => local.exitMs),
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
const Panel: Component = () => {
|
|
185
|
+
onCleanup(() => menu.setContent(undefined));
|
|
186
|
+
return (
|
|
187
|
+
<div
|
|
188
|
+
{...rest}
|
|
189
|
+
ref={(el) => {
|
|
190
|
+
menu.setContent(el);
|
|
191
|
+
local.onPanel?.(el);
|
|
192
|
+
if (typeof local.ref === "function") local.ref(el);
|
|
193
|
+
}}
|
|
194
|
+
id={id()}
|
|
195
|
+
role="menu"
|
|
196
|
+
tabIndex={-1}
|
|
197
|
+
aria-labelledby={level.triggerId()}
|
|
198
|
+
data-orientation="horizontal"
|
|
199
|
+
data-expanded={menu.open() ? "" : undefined}
|
|
200
|
+
data-closed={menu.open() ? undefined : ""}
|
|
201
|
+
data-slot={local.slotName}
|
|
202
|
+
class={cn(MENU_CONTENT_CLASS, local.motionClass, local.class)}
|
|
203
|
+
>
|
|
204
|
+
<MenuContentIndicator>{local.children}</MenuContentIndicator>
|
|
205
|
+
</div>
|
|
206
|
+
);
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
return (
|
|
210
|
+
<Show when={presence.mounted()}>
|
|
211
|
+
<Portal mount={usePortalMount()}>
|
|
212
|
+
<Panel />
|
|
213
|
+
</Portal>
|
|
214
|
+
</Show>
|
|
215
|
+
);
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
export interface MenuSubProps {
|
|
219
|
+
open?: boolean;
|
|
220
|
+
defaultOpen?: boolean;
|
|
221
|
+
onOpenChange?: (open: boolean) => void;
|
|
222
|
+
gutter?: number;
|
|
223
|
+
children?: JSX.Element;
|
|
224
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
225
|
+
shift?: number;
|
|
226
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
227
|
+
slide?: boolean;
|
|
228
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
229
|
+
overlap?: boolean;
|
|
230
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
231
|
+
fitViewport?: boolean;
|
|
232
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
233
|
+
hideWhenDetached?: boolean;
|
|
234
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
235
|
+
detachedPadding?: number;
|
|
236
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
237
|
+
arrowPadding?: number;
|
|
238
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
239
|
+
overflowPadding?: number;
|
|
240
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
241
|
+
getAnchorRect?: (anchor?: HTMLElement) => unknown;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
export const MenuSub: Component<MenuSubProps> = (props) => {
|
|
245
|
+
const parent = useMenuLevel();
|
|
246
|
+
const [open, setOpen] = createControllableSignal<boolean>({
|
|
247
|
+
value: () => props.open,
|
|
248
|
+
defaultValue: () => props.defaultOpen ?? false,
|
|
249
|
+
onChange: (next) => props.onOpenChange?.(next),
|
|
250
|
+
});
|
|
251
|
+
const level = createMenuLevel(
|
|
252
|
+
{ open, onOpenChange: setOpen, offset: untrack(() => props.gutter ?? 0) },
|
|
253
|
+
parent,
|
|
254
|
+
);
|
|
255
|
+
return <MenuLevelProvider value={level}>{props.children}</MenuLevelProvider>;
|
|
256
|
+
};
|
|
257
|
+
|
|
43
258
|
type ToneProps = {
|
|
44
259
|
tone?: string;
|
|
45
|
-
/** @deprecated
|
|
260
|
+
/** @deprecated `tone="var(--destructive)"`; removed in 2.0.0. */
|
|
46
261
|
variant?: "default" | "destructive";
|
|
47
262
|
};
|
|
48
263
|
|
|
@@ -54,9 +269,6 @@ function toneStyle(tone: string | undefined) {
|
|
|
54
269
|
return tone ? { "--selection-tone": tone, color: glassToneText(tone) } : undefined;
|
|
55
270
|
}
|
|
56
271
|
|
|
57
|
-
type MenuItemProps = ComponentProps<typeof MenuPrimitive.Item> &
|
|
58
|
-
ToneProps & { inset?: boolean; slotName: string; style?: Record<string, string> };
|
|
59
|
-
|
|
60
272
|
/* True order among the menu's rows, labels and separators, for the stagger:
|
|
61
273
|
* nth-child restarts inside a group, the DOM order does not. Refs fire before
|
|
62
274
|
* insertion, hence the microtask. */
|
|
@@ -69,181 +281,443 @@ function writeRowIndex(el: HTMLElement) {
|
|
|
69
281
|
});
|
|
70
282
|
}
|
|
71
283
|
|
|
72
|
-
|
|
284
|
+
interface RowOwnProps {
|
|
285
|
+
disabled?: boolean;
|
|
286
|
+
closeOnSelect?: boolean;
|
|
287
|
+
onSelect?: () => void;
|
|
288
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
289
|
+
textValue?: string;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/** A menu row's props over the element or component it renders `as`, a link for one. */
|
|
293
|
+
export type MenuRowProps<T extends ValidComponent = "div", Own = RowOwnProps> = Own & {
|
|
294
|
+
as?: T;
|
|
295
|
+
} & Omit<ComponentProps<T>, "as" | keyof Own>;
|
|
296
|
+
|
|
297
|
+
type RowKind = "item" | "checkbox" | "radio" | "sub";
|
|
298
|
+
|
|
299
|
+
const ROLE: Record<RowKind, string> = {
|
|
300
|
+
item: "menuitem",
|
|
301
|
+
checkbox: "menuitemcheckbox",
|
|
302
|
+
radio: "menuitemradio",
|
|
303
|
+
sub: "menuitem",
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
interface RowState {
|
|
307
|
+
checked: Accessor<boolean>;
|
|
308
|
+
indeterminate: Accessor<boolean>;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
const RowContext = createContext<RowState>();
|
|
312
|
+
|
|
313
|
+
type MenuRowPartProps = RowOwnProps &
|
|
314
|
+
ToneProps & {
|
|
315
|
+
kind: RowKind;
|
|
316
|
+
slotName: string;
|
|
317
|
+
inset?: boolean;
|
|
318
|
+
as?: ValidComponent;
|
|
319
|
+
id?: string;
|
|
320
|
+
ref?: unknown;
|
|
321
|
+
class?: string;
|
|
322
|
+
style?: JSX.CSSProperties;
|
|
323
|
+
children?: JSX.Element;
|
|
324
|
+
checked?: boolean;
|
|
325
|
+
indeterminate?: boolean;
|
|
326
|
+
choose?: () => void;
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
type RowInput = Omit<MenuRowPartProps, "kind">;
|
|
330
|
+
|
|
331
|
+
function MenuRow(props: MenuRowPartProps): JSX.Element {
|
|
332
|
+
const here = useMenuLevel();
|
|
333
|
+
const kind = untrack(() => props.kind);
|
|
334
|
+
const owner = kind === "sub" ? here.parent : here;
|
|
335
|
+
if (!owner) throw new Error("A sub trigger renders inside a Sub");
|
|
336
|
+
const submenu = kind === "sub" ? here : undefined;
|
|
337
|
+
const menu = owner.menu;
|
|
73
338
|
const [local, rest] = splitProps(props, [
|
|
74
|
-
"
|
|
339
|
+
"kind",
|
|
340
|
+
"slotName",
|
|
75
341
|
"inset",
|
|
76
342
|
"tone",
|
|
77
343
|
"variant",
|
|
78
|
-
"
|
|
344
|
+
"as",
|
|
345
|
+
"id",
|
|
346
|
+
"ref",
|
|
347
|
+
"class",
|
|
79
348
|
"style",
|
|
80
349
|
"children",
|
|
350
|
+
"disabled",
|
|
351
|
+
"closeOnSelect",
|
|
352
|
+
"onSelect",
|
|
353
|
+
"textValue",
|
|
354
|
+
"checked",
|
|
355
|
+
"indeterminate",
|
|
356
|
+
"choose",
|
|
81
357
|
]);
|
|
358
|
+
const key = untrack(() => local.id) ?? createUniqueId();
|
|
359
|
+
const disabled = () => local.disabled ?? false;
|
|
360
|
+
const checked = () => local.checked ?? false;
|
|
361
|
+
const indeterminate = () => local.indeterminate ?? false;
|
|
362
|
+
const checkable = kind === "checkbox" || kind === "radio";
|
|
82
363
|
const tone = () => resolveTone(local);
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
364
|
+
|
|
365
|
+
menu.register(key, {
|
|
366
|
+
disabled,
|
|
367
|
+
closeOnSelect: () => local.closeOnSelect ?? kind === "item",
|
|
368
|
+
onSelect: () => {
|
|
369
|
+
local.onSelect?.();
|
|
370
|
+
local.choose?.();
|
|
371
|
+
},
|
|
372
|
+
submenu: submenu?.menu,
|
|
373
|
+
});
|
|
374
|
+
if (submenu) {
|
|
375
|
+
submenu.setTriggerId(key);
|
|
376
|
+
onCleanup(() => {
|
|
377
|
+
submenu.menu.setTrigger(undefined);
|
|
378
|
+
submenu.setTriggerId(undefined);
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
const subOpen = () => submenu?.menu.open() ?? false;
|
|
383
|
+
const inner = (
|
|
384
|
+
<RowContext.Provider value={{ checked, indeterminate }}>
|
|
385
|
+
<SelectionHighlight active={menu.highlighted() === key} />
|
|
95
386
|
{local.children}
|
|
96
|
-
</
|
|
387
|
+
</RowContext.Provider>
|
|
97
388
|
);
|
|
98
|
-
|
|
389
|
+
return (
|
|
390
|
+
<Polymorphic
|
|
391
|
+
{...merge(rest, {
|
|
392
|
+
as: local.as,
|
|
393
|
+
defaultAs: "div" as ValidComponent,
|
|
394
|
+
ref: (el: HTMLElement) => {
|
|
395
|
+
writeRowIndex(el);
|
|
396
|
+
submenu?.menu.setTrigger(el);
|
|
397
|
+
if (typeof local.ref === "function") local.ref(el);
|
|
398
|
+
},
|
|
399
|
+
id: key,
|
|
400
|
+
"data-key": key,
|
|
401
|
+
role: ROLE[kind],
|
|
402
|
+
get tabIndex() {
|
|
403
|
+
return menu.tabIndex(key);
|
|
404
|
+
},
|
|
405
|
+
get "aria-checked"() {
|
|
406
|
+
if (!checkable) return undefined;
|
|
407
|
+
return indeterminate() ? "mixed" : checked() ? "true" : "false";
|
|
408
|
+
},
|
|
409
|
+
get "aria-disabled"() {
|
|
410
|
+
return disabled() ? "true" : undefined;
|
|
411
|
+
},
|
|
412
|
+
"aria-haspopup": submenu ? "true" : undefined,
|
|
413
|
+
get "aria-expanded"() {
|
|
414
|
+
return submenu ? subOpen() : undefined;
|
|
415
|
+
},
|
|
416
|
+
get "aria-controls"() {
|
|
417
|
+
return subOpen() ? submenu?.contentId() : undefined;
|
|
418
|
+
},
|
|
419
|
+
get "data-expanded"() {
|
|
420
|
+
return subOpen() ? "" : undefined;
|
|
421
|
+
},
|
|
422
|
+
get "data-closed"() {
|
|
423
|
+
return submenu && !subOpen() ? "" : undefined;
|
|
424
|
+
},
|
|
425
|
+
get "data-highlighted"() {
|
|
426
|
+
return menu.highlighted() === key ? "" : undefined;
|
|
427
|
+
},
|
|
428
|
+
get "data-disabled"() {
|
|
429
|
+
return disabled() ? "" : undefined;
|
|
430
|
+
},
|
|
431
|
+
get "data-checked"() {
|
|
432
|
+
return checkable && checked() ? "" : undefined;
|
|
433
|
+
},
|
|
434
|
+
get "data-indeterminate"() {
|
|
435
|
+
return indeterminate() ? "" : undefined;
|
|
436
|
+
},
|
|
437
|
+
"data-stagger-row": "",
|
|
438
|
+
get "data-slot"() {
|
|
439
|
+
return local.slotName;
|
|
440
|
+
},
|
|
441
|
+
get "data-inset"() {
|
|
442
|
+
return local.inset;
|
|
443
|
+
},
|
|
444
|
+
get "data-tone"() {
|
|
445
|
+
return tone() ? "" : undefined;
|
|
446
|
+
},
|
|
447
|
+
get class() {
|
|
448
|
+
return cn(
|
|
449
|
+
checkable ? cn(MENU_ITEM_BASE, "py-1.5 pr-2 pl-8") : MENU_ITEM,
|
|
450
|
+
local.inset && "pl-8",
|
|
451
|
+
local.class,
|
|
452
|
+
);
|
|
453
|
+
},
|
|
454
|
+
get style() {
|
|
455
|
+
return { ...toneStyle(tone()), ...local.style };
|
|
456
|
+
},
|
|
457
|
+
children: inner,
|
|
458
|
+
})}
|
|
459
|
+
/>
|
|
460
|
+
);
|
|
461
|
+
}
|
|
99
462
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
463
|
+
export interface ItemIndicatorProps {
|
|
464
|
+
forceMount?: boolean;
|
|
465
|
+
class?: string;
|
|
466
|
+
children?: JSX.Element;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
/** Shows its children while the row around it is checked. */
|
|
470
|
+
export const MenuItemIndicator: Component<ItemIndicatorProps> = (props) => {
|
|
471
|
+
const row = useContext(RowContext);
|
|
472
|
+
const [local, rest] = splitProps(props, ["forceMount"]);
|
|
473
|
+
const on = () => local.forceMount || row?.checked() || row?.indeterminate();
|
|
474
|
+
return (
|
|
475
|
+
<Show when={on()}>
|
|
476
|
+
<div
|
|
477
|
+
{...rest}
|
|
478
|
+
data-checked={row?.checked() ? "" : undefined}
|
|
479
|
+
data-indeterminate={row?.indeterminate() ? "" : undefined}
|
|
480
|
+
/>
|
|
481
|
+
</Show>
|
|
482
|
+
);
|
|
103
483
|
};
|
|
104
484
|
|
|
105
|
-
|
|
106
|
-
|
|
485
|
+
type ItemOwnProps = RowOwnProps & ToneProps & { inset?: boolean };
|
|
486
|
+
|
|
487
|
+
export type MenuItemProps<T extends ValidComponent = "div"> = MenuRowProps<T, ItemOwnProps>;
|
|
488
|
+
|
|
489
|
+
export function MenuItemPart(props: MenuItemProps<ValidComponent> & { slotName: string }) {
|
|
490
|
+
return <MenuRow kind="item" {...(props as RowInput)} />;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
type LabelOwnProps = { inset?: boolean; as?: ValidComponent };
|
|
494
|
+
|
|
495
|
+
export type MenuLabelProps = LabelOwnProps & Omit<ComponentProps<"span">, "as">;
|
|
496
|
+
|
|
497
|
+
const GroupContext = createContext<(id: string | undefined) => void>();
|
|
498
|
+
|
|
499
|
+
export const MenuLabelPart: Component<MenuLabelProps & { slotName: string }> = (props) => {
|
|
500
|
+
const register = useContext(GroupContext);
|
|
501
|
+
const [local, rest] = splitProps(props, ["class", "inset", "slotName", "id", "as", "ref"]);
|
|
502
|
+
const fallback = createUniqueId();
|
|
503
|
+
const id = (): string => local.id ?? fallback;
|
|
504
|
+
effect(id, (value) => {
|
|
505
|
+
register?.(value);
|
|
506
|
+
return () => register?.(undefined);
|
|
507
|
+
});
|
|
107
508
|
return (
|
|
108
|
-
<
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
509
|
+
<Polymorphic
|
|
510
|
+
{...merge(rest, {
|
|
511
|
+
as: local.as,
|
|
512
|
+
defaultAs: "span" as ValidComponent,
|
|
513
|
+
ref: (el: HTMLElement) => {
|
|
514
|
+
writeRowIndex(el);
|
|
515
|
+
if (typeof local.ref === "function") local.ref(el);
|
|
516
|
+
},
|
|
517
|
+
get id() {
|
|
518
|
+
return id();
|
|
519
|
+
},
|
|
520
|
+
"aria-hidden": "true",
|
|
521
|
+
"data-stagger-row": "",
|
|
522
|
+
get "data-slot"() {
|
|
523
|
+
return local.slotName;
|
|
524
|
+
},
|
|
525
|
+
get "data-inset"() {
|
|
526
|
+
return local.inset;
|
|
527
|
+
},
|
|
528
|
+
get class() {
|
|
529
|
+
return cn(MENU_LABEL, local.inset && "pl-8", local.class);
|
|
530
|
+
},
|
|
531
|
+
})}
|
|
115
532
|
/>
|
|
116
533
|
);
|
|
117
534
|
};
|
|
118
535
|
|
|
119
|
-
type
|
|
536
|
+
export type MenuGroupProps = { as?: ValidComponent } & Omit<ComponentProps<"div">, "as">;
|
|
120
537
|
|
|
121
|
-
export const
|
|
122
|
-
const [local, rest] = splitProps(props, ["
|
|
538
|
+
export const MenuGroup: Component<MenuGroupProps> = (props) => {
|
|
539
|
+
const [local, rest] = splitProps(props, ["as", "id"]);
|
|
540
|
+
const [labelId, setLabelId] = createSignal<string>();
|
|
541
|
+
const fallback = createUniqueId();
|
|
123
542
|
return (
|
|
124
|
-
<
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
543
|
+
<GroupContext.Provider value={setLabelId}>
|
|
544
|
+
<Polymorphic
|
|
545
|
+
{...merge(rest, {
|
|
546
|
+
as: local.as,
|
|
547
|
+
defaultAs: "div" as ValidComponent,
|
|
548
|
+
get id() {
|
|
549
|
+
return local.id ?? fallback;
|
|
550
|
+
},
|
|
551
|
+
role: "group",
|
|
552
|
+
get "aria-labelledby"() {
|
|
553
|
+
return labelId();
|
|
554
|
+
},
|
|
555
|
+
})}
|
|
556
|
+
/>
|
|
557
|
+
</GroupContext.Provider>
|
|
131
558
|
);
|
|
132
559
|
};
|
|
133
560
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
561
|
+
interface RadioState {
|
|
562
|
+
value: Accessor<string | undefined>;
|
|
563
|
+
setValue: (value: string) => void;
|
|
564
|
+
disabled: Accessor<boolean>;
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
const RadioContext = createContext<RadioState>();
|
|
568
|
+
|
|
569
|
+
export type MenuRadioGroupProps = Omit<MenuGroupProps, "onChange"> & {
|
|
570
|
+
value?: string;
|
|
571
|
+
defaultValue?: string;
|
|
572
|
+
onChange?: (value: string) => void;
|
|
573
|
+
disabled?: boolean;
|
|
137
574
|
};
|
|
138
575
|
|
|
139
|
-
export const
|
|
140
|
-
const [local, rest] = splitProps(props, ["
|
|
576
|
+
export const MenuRadioGroup: Component<MenuRadioGroupProps> = (props) => {
|
|
577
|
+
const [local, rest] = splitProps(props, ["value", "defaultValue", "onChange", "disabled"]);
|
|
578
|
+
const [value, setValue] = createControllableSignal<string | undefined>({
|
|
579
|
+
value: () => local.value,
|
|
580
|
+
defaultValue: () => local.defaultValue,
|
|
581
|
+
onChange: (next) => {
|
|
582
|
+
if (next !== undefined) local.onChange?.(next);
|
|
583
|
+
},
|
|
584
|
+
});
|
|
585
|
+
const state: RadioState = { value, setValue, disabled: () => local.disabled ?? false };
|
|
141
586
|
return (
|
|
142
|
-
<
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
data-slot={local.slotName}
|
|
146
|
-
data-inset={local.inset}
|
|
147
|
-
class={cn(MENU_ITEM, local.inset && "pl-8", local.class)}
|
|
148
|
-
{...rest}
|
|
149
|
-
>
|
|
150
|
-
<SelectionHighlight />
|
|
151
|
-
{local.children}
|
|
152
|
-
<Icon icon="lucide:chevron-right" width={16} height={16} class="ml-auto" />
|
|
153
|
-
</MenuPrimitive.SubTrigger>
|
|
587
|
+
<RadioContext.Provider value={state}>
|
|
588
|
+
<MenuGroup {...rest} />
|
|
589
|
+
</RadioContext.Provider>
|
|
154
590
|
);
|
|
155
591
|
};
|
|
156
592
|
|
|
157
|
-
type
|
|
593
|
+
type MenuSeparatorProps = ComponentProps<"hr"> & { slotName: string };
|
|
158
594
|
|
|
159
|
-
export const
|
|
160
|
-
const [local, rest] = splitProps(props, [
|
|
161
|
-
"class",
|
|
162
|
-
"children",
|
|
163
|
-
"slotName",
|
|
164
|
-
"ref",
|
|
165
|
-
"onInteractOutside",
|
|
166
|
-
"onCloseAutoFocus",
|
|
167
|
-
]);
|
|
168
|
-
const menu = useMenuContext();
|
|
169
|
-
const [panel, setPanel] = createSignal<HTMLElement>();
|
|
170
|
-
const layer = shadowLayer({
|
|
171
|
-
content: panel,
|
|
172
|
-
open: () => menu.isOpen(),
|
|
173
|
-
dismiss: () => menu.close(),
|
|
174
|
-
trigger: () => menu.triggerRef(),
|
|
175
|
-
tree: true,
|
|
176
|
-
consumer: local,
|
|
177
|
-
});
|
|
595
|
+
export const MenuSeparatorPart: Component<MenuSeparatorProps> = (props) => {
|
|
596
|
+
const [local, rest] = splitProps(props, ["class", "slotName", "ref"]);
|
|
178
597
|
return (
|
|
179
|
-
<
|
|
180
|
-
|
|
181
|
-
|
|
598
|
+
<hr
|
|
599
|
+
{...rest}
|
|
600
|
+
ref={(el) => {
|
|
601
|
+
writeRowIndex(el);
|
|
182
602
|
if (typeof local.ref === "function") local.ref(el);
|
|
183
603
|
}}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
layer.onCloseAutoFocus(e);
|
|
187
|
-
// As Kobalte's own submenu: closing one never moves focus.
|
|
188
|
-
e.preventDefault();
|
|
189
|
-
}}
|
|
190
|
-
// Kobalte's submenu closes on any focus outside it, past preventDefault; in a shadow root every
|
|
191
|
-
// focus inside reaches the page as one on the host, so the host is excluded instead.
|
|
192
|
-
excludedElements={[() => menu.triggerRef(), layer.host]}
|
|
604
|
+
data-orientation="horizontal"
|
|
605
|
+
data-stagger-row=""
|
|
193
606
|
data-slot={local.slotName}
|
|
194
|
-
class={cn(
|
|
195
|
-
|
|
196
|
-
>
|
|
197
|
-
<MenuContentIndicator>{local.children}</MenuContentIndicator>
|
|
198
|
-
</MenuPrimitive.SubContent>
|
|
607
|
+
class={cn(MENU_SEPARATOR, local.class)}
|
|
608
|
+
/>
|
|
199
609
|
);
|
|
200
610
|
};
|
|
201
611
|
|
|
202
|
-
type
|
|
203
|
-
|
|
612
|
+
type SubTriggerOwnProps = Omit<RowOwnProps, "closeOnSelect" | "onSelect"> & { inset?: boolean };
|
|
613
|
+
|
|
614
|
+
export type MenuSubTriggerProps<T extends ValidComponent = "div"> = MenuRowProps<
|
|
615
|
+
T,
|
|
616
|
+
SubTriggerOwnProps
|
|
617
|
+
>;
|
|
618
|
+
|
|
619
|
+
export function MenuSubTriggerPart(
|
|
620
|
+
props: MenuSubTriggerProps<ValidComponent> & { slotName: string },
|
|
621
|
+
) {
|
|
622
|
+
const [local, rest] = splitProps(props as RowInput, ["children"]);
|
|
623
|
+
return (
|
|
624
|
+
<MenuRow kind="sub" {...rest}>
|
|
625
|
+
{local.children}
|
|
626
|
+
<Icon icon="lucide:chevron-right" width={16} height={16} class="ml-auto" />
|
|
627
|
+
</MenuRow>
|
|
628
|
+
);
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
export const MenuSubContentPart: Component<MenuContentProps & { slotName: string }> = (props) => (
|
|
632
|
+
<MenuContentPart exitMs={0} {...props} />
|
|
633
|
+
);
|
|
634
|
+
|
|
635
|
+
type CheckboxOwnProps = Omit<RowOwnProps, "closeOnSelect"> & {
|
|
636
|
+
closeOnSelect?: boolean;
|
|
637
|
+
checked?: boolean;
|
|
638
|
+
defaultChecked?: boolean;
|
|
639
|
+
onChange?: (checked: boolean) => void;
|
|
640
|
+
indeterminate?: boolean;
|
|
204
641
|
};
|
|
205
642
|
|
|
206
|
-
export
|
|
207
|
-
|
|
643
|
+
export type MenuCheckboxItemProps<T extends ValidComponent = "div"> = MenuRowProps<
|
|
644
|
+
T,
|
|
645
|
+
CheckboxOwnProps
|
|
646
|
+
>;
|
|
647
|
+
|
|
648
|
+
export function MenuCheckboxItemPart(
|
|
649
|
+
props: MenuCheckboxItemProps<ValidComponent> & { slotName: string },
|
|
650
|
+
) {
|
|
651
|
+
const [local, rest] = splitProps(props as RowInput & CheckboxOwnProps, [
|
|
652
|
+
"children",
|
|
653
|
+
"checked",
|
|
654
|
+
"defaultChecked",
|
|
655
|
+
"onChange",
|
|
656
|
+
]);
|
|
657
|
+
const [checked, setChecked] = createControllableSignal<boolean>({
|
|
658
|
+
value: () => local.checked,
|
|
659
|
+
defaultValue: () => local.defaultChecked ?? false,
|
|
660
|
+
onChange: (next) => local.onChange?.(next),
|
|
661
|
+
});
|
|
208
662
|
return (
|
|
209
|
-
<
|
|
210
|
-
|
|
211
|
-
data-stagger-row=""
|
|
212
|
-
data-slot={local.slotName}
|
|
213
|
-
class={cn(MENU_ITEM_BASE, "py-1.5 pr-2 pl-8", local.class)}
|
|
663
|
+
<MenuRow
|
|
664
|
+
kind="checkbox"
|
|
214
665
|
{...rest}
|
|
666
|
+
checked={checked()}
|
|
667
|
+
choose={() => setChecked(!untrack(checked))}
|
|
215
668
|
>
|
|
216
|
-
<SelectionHighlight />
|
|
217
669
|
<span class="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
|
|
218
|
-
<
|
|
670
|
+
<MenuItemIndicator>
|
|
219
671
|
<Icon icon="lucide:check" width={16} height={16} class="size-4" />
|
|
220
|
-
</
|
|
672
|
+
</MenuItemIndicator>
|
|
221
673
|
</span>
|
|
222
674
|
{local.children}
|
|
223
|
-
</
|
|
675
|
+
</MenuRow>
|
|
224
676
|
);
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
type RadioOwnProps = Omit<RowOwnProps, "closeOnSelect"> & {
|
|
680
|
+
closeOnSelect?: boolean;
|
|
681
|
+
value: string;
|
|
225
682
|
};
|
|
226
683
|
|
|
227
|
-
type MenuRadioItemProps =
|
|
684
|
+
export type MenuRadioItemProps<T extends ValidComponent = "div"> = MenuRowProps<T, RadioOwnProps>;
|
|
228
685
|
|
|
229
|
-
export
|
|
230
|
-
|
|
686
|
+
export function MenuRadioItemPart(
|
|
687
|
+
props: MenuRadioItemProps<ValidComponent> & { slotName: string },
|
|
688
|
+
) {
|
|
689
|
+
const group = useContext(RadioContext);
|
|
690
|
+
const [local, rest] = splitProps(props as RowInput & RadioOwnProps, [
|
|
691
|
+
"children",
|
|
692
|
+
"value",
|
|
693
|
+
"disabled",
|
|
694
|
+
]);
|
|
231
695
|
return (
|
|
232
|
-
<
|
|
233
|
-
|
|
234
|
-
data-stagger-row=""
|
|
235
|
-
data-slot={local.slotName}
|
|
236
|
-
class={cn(MENU_ITEM_BASE, "py-1.5 pr-2 pl-8", local.class)}
|
|
696
|
+
<MenuRow
|
|
697
|
+
kind="radio"
|
|
237
698
|
{...rest}
|
|
699
|
+
disabled={local.disabled || group?.disabled()}
|
|
700
|
+
checked={group?.value() === local.value}
|
|
701
|
+
choose={() => group?.setValue(local.value)}
|
|
238
702
|
>
|
|
239
|
-
<SelectionHighlight />
|
|
240
703
|
<span class="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
|
|
241
|
-
<
|
|
704
|
+
<MenuItemIndicator>
|
|
242
705
|
{/* mdi:circle is filled; lucide:circle is stroke-only and invisible at 8px. */}
|
|
243
706
|
<Icon icon="mdi:circle" width={8} height={8} class="size-2" />
|
|
244
|
-
</
|
|
707
|
+
</MenuItemIndicator>
|
|
245
708
|
</span>
|
|
246
709
|
{local.children}
|
|
247
|
-
</
|
|
710
|
+
</MenuRow>
|
|
248
711
|
);
|
|
249
|
-
}
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
/** @deprecated Drop the wrapper; the content portals itself; removed in 2.0.0. */
|
|
715
|
+
export const MenuPortal: Component<{ children?: JSX.Element; mount?: Node }> = (props) => (
|
|
716
|
+
<>{props.children}</>
|
|
717
|
+
);
|
|
718
|
+
|
|
719
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
720
|
+
export const MenuArrow: Component = () => null;
|
|
721
|
+
|
|
722
|
+
/** @deprecated Use a plain `span`; removed in 2.0.0. */
|
|
723
|
+
export const MenuTextPart: Component<ComponentProps<"span">> = (props) => <span {...props} />;
|