@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/dialog.tsx
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
import { Dialog as DialogPrimitive, useDialogContext } from "@kobalte/core/dialog";
|
|
2
1
|
import { usePortalMount } from "./portal-mount.js";
|
|
3
2
|
import type { VariantProps } from "cva";
|
|
4
3
|
import {
|
|
5
4
|
type Component,
|
|
6
5
|
type ComponentProps,
|
|
7
6
|
createEffect,
|
|
7
|
+
createMemo,
|
|
8
8
|
createSignal,
|
|
9
|
+
type JSX,
|
|
9
10
|
onCleanup,
|
|
10
11
|
type ParentComponent,
|
|
11
12
|
splitProps,
|
|
12
13
|
} from "solid-js";
|
|
13
14
|
import { overAnchor } from "../lib/anchor-placement.js";
|
|
14
|
-
import {
|
|
15
|
+
import { ModalFrame, useDialogContext } from "../lib/behavior/modal-root.js";
|
|
16
|
+
import { MOTION_EXIT_MS } from "../lib/motion-classes.js";
|
|
15
17
|
import { buttonVariants } from "../lib/button-variants.js";
|
|
16
18
|
import { cn } from "../lib/utils.js";
|
|
17
19
|
import {
|
|
@@ -19,33 +21,30 @@ import {
|
|
|
19
21
|
createModalDismiss,
|
|
20
22
|
createModalHead,
|
|
21
23
|
createModalParts,
|
|
24
|
+
createModalRootSkin,
|
|
25
|
+
createModalTextParts,
|
|
22
26
|
MODAL_ANCHOR,
|
|
23
|
-
MODAL_DESCRIPTION,
|
|
24
27
|
MODAL_PANEL,
|
|
25
28
|
MODAL_SCRIM,
|
|
26
|
-
MODAL_TITLE,
|
|
27
29
|
MODAL_WIDTH,
|
|
30
|
+
type ModalContentProps,
|
|
28
31
|
type ModalDismissProps,
|
|
29
|
-
|
|
32
|
+
ModalCover,
|
|
30
33
|
type ModalSize,
|
|
31
34
|
} from "./dialog-parts.js";
|
|
32
35
|
|
|
33
|
-
|
|
34
|
-
* (bottom-sheet/scroll-lock.ts) serves every modal family, so a nested modal
|
|
35
|
-
* cannot release the page early. */
|
|
36
|
-
const Dialog: ParentComponent<ComponentProps<typeof DialogPrimitive>> = (props) => {
|
|
37
|
-
const mount = usePortalMount();
|
|
38
|
-
return <DialogPrimitive modal={!inShadowRoot(mount)} {...props} preventScroll={false} />;
|
|
39
|
-
};
|
|
36
|
+
const Dialog = createModalRootSkin("dialog");
|
|
40
37
|
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
38
|
+
const {
|
|
39
|
+
Trigger: DialogTrigger,
|
|
40
|
+
Title: DialogTitle,
|
|
41
|
+
Description: DialogDescription,
|
|
42
|
+
} = createModalTextParts("dialog");
|
|
44
43
|
|
|
45
44
|
type DialogCloseProps = ModalDismissProps &
|
|
46
45
|
Partial<Pick<VariantProps<typeof buttonVariants>, "variant" | "size">>;
|
|
47
46
|
|
|
48
|
-
const DialogDismiss = createModalDismiss("dialog-close");
|
|
47
|
+
const DialogDismiss = createModalDismiss("dialog-close", useDialogContext);
|
|
49
48
|
|
|
50
49
|
/** Already the outline button, so `as` is for a non-button element (a link),
|
|
51
50
|
* never for `Button`: two buttonVariants() calls leave tone knobs side by side
|
|
@@ -65,7 +64,7 @@ const DialogClose: ParentComponent<DialogCloseProps> = (props) => {
|
|
|
65
64
|
);
|
|
66
65
|
};
|
|
67
66
|
|
|
68
|
-
type DialogContentProps =
|
|
67
|
+
type DialogContentProps = ModalContentProps & {
|
|
69
68
|
size?: ModalSize;
|
|
70
69
|
/** Names a panel that has no `DialogTitle`. A registered Title wins. */
|
|
71
70
|
ariaLabel?: string;
|
|
@@ -92,97 +91,66 @@ const DialogContent: ParentComponent<DialogContentProps> = (props) => {
|
|
|
92
91
|
"anchor",
|
|
93
92
|
"style",
|
|
94
93
|
"ref",
|
|
95
|
-
"
|
|
96
|
-
"
|
|
97
|
-
"onOpenAutoFocus",
|
|
94
|
+
"onFocusOutside",
|
|
95
|
+
"forceMount",
|
|
98
96
|
]);
|
|
99
|
-
const
|
|
97
|
+
const ctx = useDialogContext();
|
|
100
98
|
const [viewport, setViewport] = createSignal(0);
|
|
101
|
-
const [panel, setPanel] = createSignal<HTMLElement>();
|
|
102
|
-
const layer = shadowLayer({
|
|
103
|
-
content: panel,
|
|
104
|
-
open: () => context.isOpen(),
|
|
105
|
-
dismiss: () => context.close(),
|
|
106
|
-
trapsFocus: true,
|
|
107
|
-
consumer: local,
|
|
108
|
-
});
|
|
109
99
|
const [height, setHeight] = createSignal<number>();
|
|
110
100
|
createEffect(() => {
|
|
111
|
-
if (!local.anchor || !
|
|
101
|
+
if (!local.anchor || !ctx.isOpen()) return;
|
|
112
102
|
const measure = () => setViewport((n) => n + 1);
|
|
113
103
|
window.addEventListener("resize", measure);
|
|
114
104
|
onCleanup(() => window.removeEventListener("resize", measure));
|
|
115
105
|
});
|
|
116
106
|
createEffect(() => {
|
|
117
|
-
const el = panel();
|
|
107
|
+
const el = ctx.panel();
|
|
118
108
|
if (!local.anchor || !el) return;
|
|
119
109
|
setHeight(el.offsetHeight);
|
|
120
110
|
const observer = new ResizeObserver(() => setHeight(el.offsetHeight));
|
|
121
111
|
observer.observe(el);
|
|
122
112
|
onCleanup(() => observer.disconnect());
|
|
123
113
|
});
|
|
124
|
-
const placement = () => {
|
|
114
|
+
const placement = createMemo<JSX.CSSProperties | undefined>((last) => {
|
|
115
|
+
if (!ctx.isOpen()) return last;
|
|
125
116
|
viewport();
|
|
126
117
|
const a = local.anchor;
|
|
127
118
|
return a ? overAnchor(a, ANCHORED_WIDTH[local.size ?? "lg"], height()) : undefined;
|
|
128
|
-
};
|
|
119
|
+
});
|
|
129
120
|
return (
|
|
130
|
-
|
|
131
|
-
<
|
|
132
|
-
<
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
data-slot="dialog-content"
|
|
139
|
-
role="dialog"
|
|
140
|
-
aria-label={context.titleId() ? undefined : local.ariaLabel}
|
|
141
|
-
class={cn(
|
|
121
|
+
<>
|
|
122
|
+
<ModalCover panel={ctx.panel} open={ctx.isOpen} dormant={ctx.dormant} />
|
|
123
|
+
<ModalFrame
|
|
124
|
+
slot="dialog"
|
|
125
|
+
mount={usePortalMount()}
|
|
126
|
+
exitMs={local.anchor ? MOTION_EXIT_MS.anchored : MOTION_EXIT_MS.modal}
|
|
127
|
+
scrimClass={MODAL_SCRIM}
|
|
128
|
+
panelClass={cn(
|
|
142
129
|
local.anchor ? ANCHORED_PANEL : MODAL_PANEL,
|
|
143
130
|
!local.anchor && MODAL_WIDTH[local.size ?? "lg"],
|
|
144
131
|
!local.anchor && MODAL_ANCHOR[local.size ?? "lg"],
|
|
145
132
|
local.class,
|
|
146
133
|
)}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
134
|
+
panelStyle={{ ...(typeof local.style === "object" ? local.style : {}), ...placement() }}
|
|
135
|
+
ariaLabel={local.ariaLabel}
|
|
136
|
+
ref={(el: HTMLElement) => {
|
|
137
|
+
if (typeof local.ref === "function") local.ref(el as HTMLDivElement);
|
|
138
|
+
}}
|
|
151
139
|
{...others}
|
|
152
140
|
>
|
|
153
141
|
{local.children}
|
|
154
|
-
</
|
|
155
|
-
|
|
142
|
+
</ModalFrame>
|
|
143
|
+
</>
|
|
156
144
|
);
|
|
157
145
|
};
|
|
158
146
|
|
|
159
147
|
const { Header: DialogHeader, Body: DialogBody, Footer: DialogFooter } = createModalParts("dialog");
|
|
160
148
|
|
|
161
|
-
const
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
class={cn(MODAL_TITLE, local.class)}
|
|
167
|
-
{...others}
|
|
168
|
-
/>
|
|
169
|
-
);
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
const DialogDescription: Component<ComponentProps<typeof DialogPrimitive.Description>> = (
|
|
173
|
-
props,
|
|
174
|
-
) => {
|
|
175
|
-
const [local, others] = splitProps(props, ["class"]);
|
|
176
|
-
return (
|
|
177
|
-
<DialogPrimitive.Description
|
|
178
|
-
data-slot="dialog-description"
|
|
179
|
-
class={cn(MODAL_DESCRIPTION, local.class)}
|
|
180
|
-
{...others}
|
|
181
|
-
/>
|
|
182
|
-
);
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
const DialogHead = createModalHead(DialogHeader, DialogTitle, DialogDescription);
|
|
149
|
+
const DialogHead = createModalHead(
|
|
150
|
+
DialogHeader,
|
|
151
|
+
DialogTitle as Component<ComponentProps<"h2">>,
|
|
152
|
+
DialogDescription as Component<ComponentProps<"p">>,
|
|
153
|
+
);
|
|
186
154
|
|
|
187
155
|
export {
|
|
188
156
|
Dialog,
|
package/src/solid/dock-edit.tsx
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createSignal, For, onCleanup, Show } from "solid-js";
|
|
2
2
|
import { Portal } from "solid-js/web";
|
|
3
|
+
import { focusWithoutTracking } from "../lib/behavior/focus-scope.js";
|
|
3
4
|
import { Z_CLASS } from "../lib/layers.js";
|
|
4
5
|
import { cn } from "../lib/utils.js";
|
|
5
6
|
import { type EdgeZone, edgeZone, moveId, slotAt } from "./dock-paging.js";
|
|
@@ -136,10 +137,10 @@ export function createDockReorder(options: ReorderOptions) {
|
|
|
136
137
|
if (ids.indexOf(id) < 0 || to < 0 || to >= ids.length) return;
|
|
137
138
|
options.onReorder(moveId(ids, id, to));
|
|
138
139
|
requestAnimationFrame(() =>
|
|
139
|
-
|
|
140
|
-
.bar()
|
|
141
|
-
|
|
142
|
-
|
|
140
|
+
focusWithoutTracking(
|
|
141
|
+
options.bar()?.querySelector<HTMLElement>(`[data-dock-id="${CSS.escape(id)}"]`),
|
|
142
|
+
{ preventScroll: false },
|
|
143
|
+
),
|
|
143
144
|
);
|
|
144
145
|
}
|
|
145
146
|
|
package/src/solid/dock.tsx
CHANGED
|
@@ -13,9 +13,9 @@ import {
|
|
|
13
13
|
Show,
|
|
14
14
|
splitProps,
|
|
15
15
|
} from "solid-js";
|
|
16
|
-
import {
|
|
16
|
+
import { Polymorphic } from "../lib/behavior/polymorphic.js";
|
|
17
17
|
import { CARD_SURFACE } from "../lib/card-classes.js";
|
|
18
|
-
import { DOCK_SLOT_SHAPE } from "../lib/dock-slot-classes.js";
|
|
18
|
+
import { DOCK_SLOT_RADIUS, DOCK_SLOT_SHAPE } from "../lib/dock-slot-classes.js";
|
|
19
19
|
import {
|
|
20
20
|
DOCK_ARRIVE_MOTION,
|
|
21
21
|
DOCK_EDIT_MOTION,
|
|
@@ -119,7 +119,7 @@ const DockIconButton: Component<DockIconButtonProps> = (props) => {
|
|
|
119
119
|
data-arrived={local.arrived ? "" : undefined}
|
|
120
120
|
{...rest}
|
|
121
121
|
>
|
|
122
|
-
<SelectionHighlight />
|
|
122
|
+
<SelectionHighlight active={local.lit ?? false} />
|
|
123
123
|
<Show when={local.arrived}>
|
|
124
124
|
<span data-slot="dock-item-arrival" aria-hidden="true" class={DOCK_ARRIVE_MOTION} />
|
|
125
125
|
</Show>
|
|
@@ -133,8 +133,8 @@ const DockIconButton: Component<DockIconButtonProps> = (props) => {
|
|
|
133
133
|
{isElement() ? (
|
|
134
134
|
(local.icon as JSX.Element)
|
|
135
135
|
) : (
|
|
136
|
-
<
|
|
137
|
-
|
|
136
|
+
<Polymorphic
|
|
137
|
+
defaultAs={local.icon as Component<{ class?: string }>}
|
|
138
138
|
class="h-5 w-5 sm:h-6 sm:w-6"
|
|
139
139
|
/>
|
|
140
140
|
)}
|
|
@@ -511,6 +511,7 @@ const Dock: Component<DockProps> = (props) => {
|
|
|
511
511
|
>
|
|
512
512
|
<SelectionScope
|
|
513
513
|
marker="lit"
|
|
514
|
+
radius={DOCK_SLOT_RADIUS}
|
|
514
515
|
class={cn("flex items-center gap-0.5 sm:gap-1", vertical() && "flex-col")}
|
|
515
516
|
>
|
|
516
517
|
<Index each={local.items}>
|
|
@@ -1,143 +1,262 @@
|
|
|
1
|
-
import { DropdownMenu as DropdownMenuPrimitive } from "@kobalte/core/dropdown-menu";
|
|
2
|
-
import { usePortalMount } from "./portal-mount.js";
|
|
3
|
-
import { useMenuContext } from "@kobalte/core/menu";
|
|
4
1
|
import {
|
|
5
2
|
type Component,
|
|
6
3
|
type ComponentProps,
|
|
7
4
|
createSignal,
|
|
8
|
-
|
|
5
|
+
createUniqueId,
|
|
6
|
+
type JSX,
|
|
9
7
|
splitProps,
|
|
8
|
+
untrack,
|
|
9
|
+
type ValidComponent,
|
|
10
10
|
} from "solid-js";
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
11
|
+
import type { AnchorLike } from "../lib/behavior/anchored.js";
|
|
12
|
+
import { ButtonRoot, type ButtonRootProps } from "../lib/behavior/button-root.js";
|
|
13
|
+
import { createControllableSignal } from "../lib/behavior/controllable.js";
|
|
14
|
+
import { createMenuButton } from "../lib/behavior/menu.js";
|
|
15
|
+
import { callEventHandler, effect, merge } from "../lib/behavior/solid.js";
|
|
16
|
+
import { MORPH_MOTION, MOTION_EXIT_MS } from "../lib/motion-classes.js";
|
|
14
17
|
import { cn } from "../lib/utils.js";
|
|
15
18
|
import {
|
|
16
|
-
|
|
19
|
+
createMenuLevel,
|
|
20
|
+
type DeprecatedMenuRootProps,
|
|
21
|
+
MenuArrow,
|
|
22
|
+
type MenuCheckboxItemProps,
|
|
17
23
|
MenuCheckboxItemPart,
|
|
18
|
-
|
|
24
|
+
MenuContentPart,
|
|
25
|
+
type MenuContentProps,
|
|
26
|
+
MenuGroup,
|
|
27
|
+
MenuItemIndicator,
|
|
28
|
+
type MenuItemProps,
|
|
19
29
|
MenuItemPart,
|
|
30
|
+
type MenuLabelProps,
|
|
20
31
|
MenuLabelPart,
|
|
32
|
+
MenuLevelProvider,
|
|
33
|
+
type MenuPlacement,
|
|
34
|
+
MenuPortal,
|
|
35
|
+
MenuRadioGroup,
|
|
36
|
+
type MenuRadioItemProps,
|
|
21
37
|
MenuRadioItemPart,
|
|
22
38
|
MenuSeparatorPart,
|
|
39
|
+
MenuSub,
|
|
23
40
|
MenuSubContentPart,
|
|
41
|
+
type MenuSubTriggerProps,
|
|
24
42
|
MenuSubTriggerPart,
|
|
43
|
+
MenuTextPart,
|
|
44
|
+
parsePlacement,
|
|
45
|
+
useMenuLevel,
|
|
25
46
|
} from "./menu-parts.js";
|
|
47
|
+
import { controlRadius } from "../lib/anchor-placement.js";
|
|
26
48
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
49
|
+
type AnchorRect = { x?: number; y?: number; width?: number; height?: number };
|
|
50
|
+
|
|
51
|
+
interface DropdownMenuRootProps extends DeprecatedMenuRootProps {
|
|
52
|
+
open?: boolean;
|
|
53
|
+
defaultOpen?: boolean;
|
|
54
|
+
onOpenChange?: (open: boolean) => void;
|
|
55
|
+
placement?: MenuPlacement;
|
|
56
|
+
gutter?: number;
|
|
57
|
+
/** The box the panel sits beside, read from the trigger; unset, the panel covers the trigger. */
|
|
58
|
+
getAnchorRect?: (anchor?: HTMLElement) => AnchorRect | undefined;
|
|
59
|
+
children?: JSX.Element;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function rectOf(trigger: HTMLElement, read: (el?: HTMLElement) => AnchorRect | undefined) {
|
|
63
|
+
const anchor: AnchorLike = {
|
|
64
|
+
getBoundingClientRect: () => {
|
|
65
|
+
const rect = read(trigger) ?? {};
|
|
66
|
+
return {
|
|
67
|
+
left: rect.x ?? 0,
|
|
68
|
+
top: rect.y ?? 0,
|
|
69
|
+
width: rect.width ?? 0,
|
|
70
|
+
height: rect.height ?? 0,
|
|
71
|
+
};
|
|
72
|
+
},
|
|
73
|
+
getRootNode: () => trigger.getRootNode(),
|
|
74
|
+
};
|
|
75
|
+
return anchor;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const DropdownMenuRoot: Component<DropdownMenuRootProps> = (props) => {
|
|
79
|
+
const [open, setOpen] = createControllableSignal<boolean>({
|
|
80
|
+
value: () => props.open,
|
|
81
|
+
defaultValue: () => props.defaultOpen ?? false,
|
|
82
|
+
onChange: (next) => props.onOpenChange?.(next),
|
|
83
|
+
});
|
|
84
|
+
const placement = () => parsePlacement(props.placement ?? "bottom-start");
|
|
85
|
+
const level = createMenuLevel({
|
|
86
|
+
open,
|
|
87
|
+
onOpenChange: setOpen,
|
|
88
|
+
anchor: (trigger) => {
|
|
89
|
+
const read = props.getAnchorRect;
|
|
90
|
+
return read && trigger ? rectOf(trigger, read) : trigger;
|
|
91
|
+
},
|
|
92
|
+
coverAnchor: !props.getAnchorRect,
|
|
93
|
+
side: () => placement()[0],
|
|
94
|
+
align: () => placement()[1],
|
|
95
|
+
offset: untrack(() => props.gutter ?? 0),
|
|
96
|
+
});
|
|
97
|
+
return <MenuLevelProvider value={level}>{props.children}</MenuLevelProvider>;
|
|
40
98
|
};
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const DropdownMenuTrigger: Component<ComponentProps<typeof DropdownMenuPrimitive.Trigger>> = (
|
|
50
|
-
props,
|
|
51
|
-
) => {
|
|
52
|
-
return <DropdownMenuPrimitive.Trigger data-slot="dropdown-menu-trigger" {...props} />;
|
|
99
|
+
|
|
100
|
+
type TriggerHandlers = {
|
|
101
|
+
id?: string;
|
|
102
|
+
ref?: unknown;
|
|
103
|
+
onPointerDown?: JSX.EventHandlerUnion<HTMLElement, PointerEvent>;
|
|
104
|
+
onKeyDown?: JSX.EventHandlerUnion<HTMLElement, KeyboardEvent>;
|
|
105
|
+
onClick?: JSX.EventHandlerUnion<HTMLElement, MouseEvent>;
|
|
53
106
|
};
|
|
54
107
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
108
|
+
type Bound<E extends Event> = E & { currentTarget: HTMLElement; target: Element };
|
|
109
|
+
|
|
110
|
+
function DropdownMenuTrigger<T extends ValidComponent = "button">(
|
|
111
|
+
props: ButtonRootProps<T>,
|
|
112
|
+
): JSX.Element {
|
|
113
|
+
const level = useMenuLevel();
|
|
114
|
+
const menu = level.menu;
|
|
115
|
+
const [local, rest] = splitProps(props as ButtonRootProps<ValidComponent> & TriggerHandlers, [
|
|
116
|
+
"id",
|
|
61
117
|
"ref",
|
|
62
|
-
"
|
|
63
|
-
"
|
|
118
|
+
"disabled",
|
|
119
|
+
"onPointerDown",
|
|
120
|
+
"onKeyDown",
|
|
121
|
+
"onClick",
|
|
64
122
|
]);
|
|
65
|
-
const
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
dismiss: () => menu.close(true),
|
|
71
|
-
trigger: () => menu.triggerRef(),
|
|
72
|
-
tree: true,
|
|
73
|
-
consumer: local,
|
|
123
|
+
const fallback = createUniqueId();
|
|
124
|
+
const id = (): string => local.id ?? fallback;
|
|
125
|
+
effect(id, (value) => {
|
|
126
|
+
level.setTriggerId(value);
|
|
127
|
+
return () => level.setTriggerId(undefined);
|
|
74
128
|
});
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
)
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
129
|
+
const button = createMenuButton(menu, () => local.disabled ?? false);
|
|
130
|
+
const [el, setEl] = createSignal<HTMLElement>();
|
|
131
|
+
|
|
132
|
+
// Bound on the element, since Solid's delegated handlers never reach inside a closed shadow root.
|
|
133
|
+
effect(el, (node) => {
|
|
134
|
+
if (!node) return;
|
|
135
|
+
const down = (event: PointerEvent) => {
|
|
136
|
+
callEventHandler(event as Bound<PointerEvent>, local.onPointerDown);
|
|
137
|
+
button.onPointerDown(event);
|
|
138
|
+
};
|
|
139
|
+
const key = (event: KeyboardEvent) => {
|
|
140
|
+
callEventHandler(event as Bound<KeyboardEvent>, local.onKeyDown);
|
|
141
|
+
button.onKeyDown(event);
|
|
142
|
+
};
|
|
143
|
+
node.addEventListener("pointerdown", down);
|
|
144
|
+
node.addEventListener("keydown", key);
|
|
145
|
+
return () => {
|
|
146
|
+
node.removeEventListener("pointerdown", down);
|
|
147
|
+
node.removeEventListener("keydown", key);
|
|
148
|
+
if (untrack(menu.trigger) === node) menu.setTrigger(undefined);
|
|
149
|
+
};
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
return (
|
|
153
|
+
<ButtonRoot
|
|
154
|
+
{...merge({ "data-slot": "dropdown-menu-trigger" }, rest, {
|
|
155
|
+
get disabled() {
|
|
156
|
+
return local.disabled;
|
|
157
|
+
},
|
|
158
|
+
get id() {
|
|
159
|
+
return id();
|
|
160
|
+
},
|
|
161
|
+
ref: (node: HTMLElement) => {
|
|
162
|
+
setEl(node);
|
|
163
|
+
menu.setTrigger(node);
|
|
164
|
+
if (typeof local.ref === "function") local.ref(node);
|
|
165
|
+
},
|
|
166
|
+
"aria-haspopup": "true",
|
|
167
|
+
get "aria-expanded"() {
|
|
168
|
+
return menu.open();
|
|
169
|
+
},
|
|
170
|
+
get "aria-controls"() {
|
|
171
|
+
return menu.open() ? level.contentId() : undefined;
|
|
172
|
+
},
|
|
173
|
+
get "data-expanded"() {
|
|
174
|
+
return menu.open() ? "" : undefined;
|
|
175
|
+
},
|
|
176
|
+
get "data-closed"() {
|
|
177
|
+
return menu.open() ? undefined : "";
|
|
178
|
+
},
|
|
179
|
+
onClick: (event: Bound<MouseEvent>) => {
|
|
180
|
+
callEventHandler(event, local.onClick);
|
|
181
|
+
button.onClick();
|
|
182
|
+
},
|
|
183
|
+
})}
|
|
184
|
+
/>
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/* The panel opens as its trigger's box. */
|
|
189
|
+
function writeMorphStart(trigger: HTMLElement | undefined, el: HTMLElement) {
|
|
190
|
+
if (!trigger) return;
|
|
191
|
+
const box = trigger.getBoundingClientRect();
|
|
192
|
+
el.style.setProperty("--kb-popper-anchor-width", `${box.width}px`);
|
|
193
|
+
el.style.setProperty("--morph-h", `${box.height}px`);
|
|
194
|
+
el.style.setProperty("--morph-radius", controlRadius(box.height));
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const DropdownMenuContent: Component<MenuContentProps> = (props) => {
|
|
198
|
+
const level = useMenuLevel();
|
|
89
199
|
return (
|
|
90
|
-
<
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
onInteractOutside={layer.onInteractOutside}
|
|
98
|
-
onCloseAutoFocus={layer.onCloseAutoFocus}
|
|
99
|
-
data-slot="dropdown-menu-content"
|
|
100
|
-
class={cn(MENU_CONTENT_CLASS, MORPH_MOTION, local.class)}
|
|
101
|
-
{...others}
|
|
102
|
-
>
|
|
103
|
-
<MenuContentIndicator>{local.children}</MenuContentIndicator>
|
|
104
|
-
</DropdownMenuPrimitive.Content>
|
|
105
|
-
</DropdownMenuPrimitive.Portal>
|
|
200
|
+
<MenuContentPart
|
|
201
|
+
slotName="dropdown-menu-content"
|
|
202
|
+
motionClass={MORPH_MOTION}
|
|
203
|
+
exitMs={MOTION_EXIT_MS.anchored}
|
|
204
|
+
onPanel={(el) => writeMorphStart(untrack(level.menu.trigger), el)}
|
|
205
|
+
{...props}
|
|
206
|
+
/>
|
|
106
207
|
);
|
|
107
208
|
};
|
|
108
209
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
variant?: "default" | "destructive";
|
|
115
|
-
}
|
|
116
|
-
> = (props) => <MenuItemPart slotName="dropdown-menu-item" {...props} />;
|
|
210
|
+
function DropdownMenuItem<T extends ValidComponent = "div">(props: MenuItemProps<T>): JSX.Element {
|
|
211
|
+
return (
|
|
212
|
+
<MenuItemPart slotName="dropdown-menu-item" {...(props as MenuItemProps<ValidComponent>)} />
|
|
213
|
+
);
|
|
214
|
+
}
|
|
117
215
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
216
|
+
function DropdownMenuSubTrigger<T extends ValidComponent = "div">(
|
|
217
|
+
props: MenuSubTriggerProps<T>,
|
|
218
|
+
): JSX.Element {
|
|
219
|
+
return (
|
|
220
|
+
<MenuSubTriggerPart
|
|
221
|
+
slotName="dropdown-menu-sub-trigger"
|
|
222
|
+
{...(props as MenuSubTriggerProps<ValidComponent>)}
|
|
223
|
+
/>
|
|
224
|
+
);
|
|
225
|
+
}
|
|
121
226
|
|
|
122
|
-
const DropdownMenuSubContent:
|
|
123
|
-
|
|
124
|
-
|
|
227
|
+
const DropdownMenuSubContent: Component<MenuContentProps> = (props) => (
|
|
228
|
+
<MenuSubContentPart slotName="dropdown-menu-sub-content" {...props} />
|
|
229
|
+
);
|
|
125
230
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
231
|
+
function DropdownMenuCheckboxItem<T extends ValidComponent = "div">(
|
|
232
|
+
props: MenuCheckboxItemProps<T>,
|
|
233
|
+
): JSX.Element {
|
|
234
|
+
return (
|
|
235
|
+
<MenuCheckboxItemPart
|
|
236
|
+
slotName="dropdown-menu-checkbox-item"
|
|
237
|
+
{...(props as MenuCheckboxItemProps<ValidComponent>)}
|
|
238
|
+
/>
|
|
239
|
+
);
|
|
240
|
+
}
|
|
129
241
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
242
|
+
function DropdownMenuRadioItem<T extends ValidComponent = "div">(
|
|
243
|
+
props: MenuRadioItemProps<T>,
|
|
244
|
+
): JSX.Element {
|
|
245
|
+
return (
|
|
246
|
+
<MenuRadioItemPart
|
|
247
|
+
slotName="dropdown-menu-radio-item"
|
|
248
|
+
{...(props as MenuRadioItemProps<ValidComponent>)}
|
|
249
|
+
/>
|
|
250
|
+
);
|
|
251
|
+
}
|
|
133
252
|
|
|
134
|
-
const DropdownMenuSeparator: Component<ComponentProps<
|
|
135
|
-
props
|
|
136
|
-
)
|
|
253
|
+
const DropdownMenuSeparator: Component<ComponentProps<"hr">> = (props) => (
|
|
254
|
+
<MenuSeparatorPart slotName="dropdown-menu-separator" {...props} />
|
|
255
|
+
);
|
|
137
256
|
|
|
138
|
-
const DropdownMenuLabel: Component<
|
|
139
|
-
|
|
140
|
-
|
|
257
|
+
const DropdownMenuLabel: Component<MenuLabelProps> = (props) => (
|
|
258
|
+
<MenuLabelPart slotName="dropdown-menu-label" {...props} />
|
|
259
|
+
);
|
|
141
260
|
|
|
142
261
|
const DropdownMenuShortcut: Component<ComponentProps<"span">> = (props) => {
|
|
143
262
|
const [local, others] = splitProps(props, ["class"]);
|
|
@@ -150,6 +269,32 @@ const DropdownMenuShortcut: Component<ComponentProps<"span">> = (props) => {
|
|
|
150
269
|
);
|
|
151
270
|
};
|
|
152
271
|
|
|
272
|
+
const DropdownMenuGroup = MenuGroup;
|
|
273
|
+
const DropdownMenuSub = MenuSub;
|
|
274
|
+
const DropdownMenuRadioGroup = MenuRadioGroup;
|
|
275
|
+
|
|
276
|
+
const DropdownMenu = Object.assign(DropdownMenuRoot, {
|
|
277
|
+
Root: DropdownMenuRoot,
|
|
278
|
+
Trigger: DropdownMenuTrigger,
|
|
279
|
+
Portal: MenuPortal,
|
|
280
|
+
Content: DropdownMenuContent,
|
|
281
|
+
Arrow: MenuArrow,
|
|
282
|
+
Item: DropdownMenuItem,
|
|
283
|
+
CheckboxItem: DropdownMenuCheckboxItem,
|
|
284
|
+
RadioGroup: DropdownMenuRadioGroup,
|
|
285
|
+
RadioItem: DropdownMenuRadioItem,
|
|
286
|
+
Group: DropdownMenuGroup,
|
|
287
|
+
GroupLabel: DropdownMenuLabel,
|
|
288
|
+
Separator: DropdownMenuSeparator,
|
|
289
|
+
Sub: DropdownMenuSub,
|
|
290
|
+
SubTrigger: DropdownMenuSubTrigger,
|
|
291
|
+
SubContent: DropdownMenuSubContent,
|
|
292
|
+
ItemIndicator: MenuItemIndicator,
|
|
293
|
+
Icon: MenuTextPart,
|
|
294
|
+
ItemLabel: MenuTextPart,
|
|
295
|
+
ItemDescription: MenuTextPart,
|
|
296
|
+
});
|
|
297
|
+
|
|
153
298
|
export {
|
|
154
299
|
DropdownMenu,
|
|
155
300
|
DropdownMenuCheckboxItem,
|