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