@glasshome/ui 1.22.1 → 1.24.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/dist/index.d.ts +1 -0
- package/dist/index.js +3 -3
- package/dist/lib/alert-tones.d.ts +1 -0
- package/dist/lib/anchor-placement.d.ts +3 -4
- package/dist/lib/hold.d.ts +6 -0
- package/dist/lib/motion-classes.d.ts +1 -1
- package/dist/solid/alert.d.ts +2 -0
- package/dist/solid/index.d.ts +1 -0
- package/dist/solid/index.js +4128 -4093
- package/dist/solid/toggle-group.d.ts +2 -0
- package/dist/{utils-BfU9dJev.js → utils-rZf2Zpkw.js} +463 -463
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/lib/alert-tones.ts +1 -0
- package/src/lib/anchor-placement.ts +38 -15
- package/src/lib/hold.ts +7 -0
- package/src/lib/motion-classes.ts +1 -1
- package/src/solid/alert.tsx +19 -2
- package/src/solid/dialog-parts.tsx +4 -3
- package/src/solid/dialog.tsx +16 -1
- package/src/solid/index.ts +1 -0
- package/src/solid/preview-tile.tsx +6 -4
- package/src/solid/toggle-group.tsx +11 -2
- package/src/styles/globals.css +8 -0
- package/src/styles/theme.css +4 -1
package/package.json
CHANGED
package/src/index.ts
CHANGED
package/src/lib/alert-tones.ts
CHANGED
|
@@ -66,6 +66,7 @@ export function alertIconBgStyle(color: string): Record<string, string> {
|
|
|
66
66
|
opacity: "0.32",
|
|
67
67
|
};
|
|
68
68
|
}
|
|
69
|
+
export const ALERT_SM_CLASS = "items-center gap-2 py-1.5 pr-1.5 pl-3";
|
|
69
70
|
export const ALERT_CONTENT_CLASS = "relative z-10 min-w-0 flex-1";
|
|
70
71
|
export const ALERT_TITLE_CLASS = "font-semibold text-base leading-snug";
|
|
71
72
|
export const ALERT_DESCRIPTION_CLASS = "gh-alert-desc text-foreground/80 text-sm leading-snug";
|
|
@@ -2,27 +2,50 @@ import type { JSX } from "solid-js";
|
|
|
2
2
|
|
|
3
3
|
const EDGE = 16;
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
interface Box {
|
|
6
|
+
left: number;
|
|
7
|
+
top: number;
|
|
8
|
+
width: number;
|
|
9
|
+
height: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** Where a panel of this size sits over its anchor: centred on it, shifted only as far as the
|
|
13
|
+
* screen needs, as wide as the anchor at least. Before the panel is measured (`height`
|
|
14
|
+
* undefined) its top sits on the anchor's top. */
|
|
15
|
+
function anchoredBox(
|
|
16
|
+
anchor: Box,
|
|
17
|
+
viewport: { width: number; height: number },
|
|
18
|
+
width: number,
|
|
19
|
+
height?: number,
|
|
20
|
+
): Box {
|
|
21
|
+
const clamp = (v: number, lo: number, hi: number) => Math.max(lo, Math.min(v, hi));
|
|
22
|
+
const w = Math.min(Math.max(width, anchor.width), viewport.width - 2 * EDGE);
|
|
23
|
+
const x = clamp(anchor.left + (anchor.width - w) / 2, EDGE, viewport.width - EDGE - w);
|
|
24
|
+
const h = Math.min(Math.max(height ?? 0, anchor.height), viewport.height - 2 * EDGE);
|
|
25
|
+
const y =
|
|
26
|
+
height === undefined
|
|
27
|
+
? clamp(anchor.top, EDGE, viewport.height - EDGE - h)
|
|
28
|
+
: clamp(anchor.top + (anchor.height - h) / 2, EDGE, viewport.height - EDGE - h);
|
|
29
|
+
return { left: x, top: y, width: w, height: h };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** A panel that grows out of the element that opened it. The --morph-* values start the panel
|
|
33
|
+
* clipped to the element's box (MORPH_MOTION's keyframes), so it unrolls out of it. */
|
|
34
|
+
export function overAnchor(anchor: HTMLElement, width: number, height?: number): JSX.CSSProperties {
|
|
9
35
|
const box = anchor.getBoundingClientRect();
|
|
10
|
-
const vw = window.innerWidth;
|
|
11
36
|
const vh = window.innerHeight;
|
|
12
|
-
const
|
|
13
|
-
const x = Math.max(EDGE, Math.min(box.left, vw - EDGE - w));
|
|
14
|
-
const y = Math.max(EDGE, Math.min(box.top, vh - EDGE - Math.max(box.height, 240)));
|
|
37
|
+
const placed = anchoredBox(box, { width: window.innerWidth, height: vh }, width, height);
|
|
15
38
|
const radius = getComputedStyle(anchor).borderTopLeftRadius || "0px";
|
|
16
39
|
return {
|
|
17
|
-
left: `${
|
|
18
|
-
top: `${
|
|
40
|
+
left: `${placed.left}px`,
|
|
41
|
+
top: `${placed.top}px`,
|
|
19
42
|
translate: "none",
|
|
20
|
-
width: `${
|
|
43
|
+
width: `${placed.width}px`,
|
|
21
44
|
"max-width": "none",
|
|
22
|
-
"min-height": `${Math.min(box.height, vh -
|
|
23
|
-
"max-height": `${vh -
|
|
24
|
-
"--morph-x": `${box.left -
|
|
25
|
-
"--morph-y": `${box.top -
|
|
45
|
+
"min-height": `${Math.min(box.height, vh - 2 * EDGE)}px`,
|
|
46
|
+
"max-height": `${vh - 2 * EDGE}px`,
|
|
47
|
+
"--morph-x": `${box.left - placed.left}px`,
|
|
48
|
+
"--morph-y": `${box.top - placed.top}px`,
|
|
26
49
|
"--morph-w": `${box.width}px`,
|
|
27
50
|
"--morph-h": `${box.height}px`,
|
|
28
51
|
"--morph-radius": radius,
|
package/src/lib/hold.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** A press held this long, without moving, is a hold. Matches Android's long-press timeout, so the
|
|
2
|
+
* browser's own long press never wins the race. */
|
|
3
|
+
export const HOLD_MS = 350;
|
|
4
|
+
|
|
5
|
+
/** A tap ends inside this window, so it never shows the hold fill. The fill then grows on
|
|
6
|
+
* --duration-hold, which is HOLD_MS - HOLD_GRACE_MS. */
|
|
7
|
+
export const HOLD_GRACE_MS = 100;
|
|
@@ -47,7 +47,7 @@ export const PRESS_DIP = "active:scale-[0.97]";
|
|
|
47
47
|
/* Hold progress: a fill grows out of the touch while held, dissolves once the
|
|
48
48
|
* hold fires, and drains back faster if let go early. The host sets data-hold / data-fired. */
|
|
49
49
|
export const HOLD_MOTION =
|
|
50
|
-
"scale-0 opacity-0 transition-[scale,opacity] duration-(--duration-state) ease-(--ease-contract) data-[hold]:scale-100 data-[hold]:opacity-100 data-[hold]:duration-(--duration-
|
|
50
|
+
"scale-0 opacity-0 transition-[scale,opacity] duration-(--duration-state) ease-(--ease-contract) data-[hold]:scale-100 data-[hold]:opacity-100 data-[hold]:duration-(--duration-hold) data-[hold]:ease-linear data-[fired]:scale-100 data-[fired]:opacity-0";
|
|
51
51
|
|
|
52
52
|
/* MODAL_MOTION's twin for a surface that stays mounted: it rises out of what
|
|
53
53
|
* opened it, and its closed state is a resting style, since a mount door's exit
|
package/src/solid/alert.tsx
CHANGED
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
ALERT_DESCRIPTION_CLASS,
|
|
14
14
|
ALERT_ICON_BG_CLASS,
|
|
15
15
|
ALERT_ICON_PATHS,
|
|
16
|
+
ALERT_SM_CLASS,
|
|
16
17
|
ALERT_TITLE_CLASS,
|
|
17
18
|
ALERT_TONES,
|
|
18
19
|
type AlertTone,
|
|
@@ -28,6 +29,8 @@ type AlertProps = ComponentProps<"div"> & {
|
|
|
28
29
|
icon?: JSX.Element;
|
|
29
30
|
title?: JSX.Element;
|
|
30
31
|
action?: JSX.Element;
|
|
32
|
+
/** `sm`: a one-line note inside a list, with tighter padding and smaller text. */
|
|
33
|
+
size?: "default" | "sm";
|
|
31
34
|
};
|
|
32
35
|
|
|
33
36
|
// Lets `AlertTitle`, used as a child, pick up the same tone colour the
|
|
@@ -38,14 +41,28 @@ type AlertProps = ComponentProps<"div"> & {
|
|
|
38
41
|
const AlertToneContext = createContext<() => string>();
|
|
39
42
|
|
|
40
43
|
const Alert: Component<AlertProps> = (props) => {
|
|
41
|
-
const [local, rest] = splitProps(props, [
|
|
44
|
+
const [local, rest] = splitProps(props, [
|
|
45
|
+
"class",
|
|
46
|
+
"tone",
|
|
47
|
+
"icon",
|
|
48
|
+
"title",
|
|
49
|
+
"action",
|
|
50
|
+
"children",
|
|
51
|
+
"size",
|
|
52
|
+
]);
|
|
42
53
|
const toneKey = () => local.tone ?? "info";
|
|
43
54
|
const tone = () => ALERT_TONES[toneKey()];
|
|
44
55
|
return (
|
|
45
56
|
<div
|
|
46
57
|
data-slot="alert"
|
|
47
58
|
role={local.tone === "destructive" ? "alert" : "status"}
|
|
48
|
-
|
|
59
|
+
data-size={local.size ?? "default"}
|
|
60
|
+
class={cn(
|
|
61
|
+
ALERT_CLASS,
|
|
62
|
+
"glass glass-tint",
|
|
63
|
+
local.size === "sm" && ALERT_SM_CLASS,
|
|
64
|
+
local.class,
|
|
65
|
+
)}
|
|
49
66
|
style={{ "--glass-tone": tone().color, color: "var(--foreground)" }}
|
|
50
67
|
{...rest}
|
|
51
68
|
>
|
|
@@ -67,7 +67,8 @@ export const ANCHORED_PANEL = `${OVERLAY_SURFACE} ${ANCHORED_MOTION} fixed flex
|
|
|
67
67
|
|
|
68
68
|
export const MODAL_SCRIM = `${SCRIM_MOTION} fixed inset-0 ${Z_CLASS.overlay} ${SCRIM_CLASS}`;
|
|
69
69
|
|
|
70
|
-
const MODAL_HEADER =
|
|
70
|
+
const MODAL_HEADER =
|
|
71
|
+
"flex shrink-0 items-start gap-4 px-6 pt-6 pb-3 in-data-[slot=bottom-sheet-content]:px-4 [[data-slot=bottom-sheet-handle]+&]:pt-1";
|
|
71
72
|
const MODAL_HEADER_MEDIA = "flex shrink-0 items-center";
|
|
72
73
|
/* `grow`, not `flex-1`: a zero basis would make the text column shrink to a
|
|
73
74
|
* word per line beside a wide action instead of pushing it onto the next line
|
|
@@ -85,10 +86,10 @@ const MODAL_HEADER_ACTION = "flex shrink-0 items-center gap-2";
|
|
|
85
86
|
* - The reserved scrollbar lives inside the right inset, so the content column
|
|
86
87
|
* ends where the Header's and Footer's do. */
|
|
87
88
|
const MODAL_BODY =
|
|
88
|
-
"gh-scroll gh-stagger flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto overscroll-contain [touch-action:pan-y_pinch-zoom] [scrollbar-gutter:stable] pl-6 pr-[calc(var(--spacing)*6-var(--scrollbar-w))] pt-6 pb-6 [[data-slot$='-header']~&]:pt-3 [&:has(~[data-slot$='-footer'])]:pb-3";
|
|
89
|
+
"gh-scroll gh-stagger flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto overscroll-contain [touch-action:pan-y_pinch-zoom] [scrollbar-gutter:stable] pl-6 pr-[calc(var(--spacing)*6-var(--scrollbar-w))] pt-6 pb-6 [[data-slot$='-header']~&]:pt-3 [&:has(~[data-slot$='-footer'])]:pb-3 in-data-[slot=bottom-sheet-content]:pl-4 in-data-[slot=bottom-sheet-content]:pr-[calc(var(--spacing)*4-var(--scrollbar-w))] [[data-slot=bottom-sheet-handle]+&]:pt-1";
|
|
89
90
|
|
|
90
91
|
const MODAL_FOOTER =
|
|
91
|
-
"gh-stagger flex shrink-0 flex-col-reverse gap-2 px-6 pt-3 pb-6 sm:flex-row sm:justify-end";
|
|
92
|
+
"gh-stagger flex shrink-0 flex-col-reverse gap-2 px-6 pt-3 pb-6 sm:flex-row sm:justify-end in-data-[slot=bottom-sheet-content]:px-4";
|
|
92
93
|
|
|
93
94
|
export const MODAL_TITLE = "font-semibold text-foreground text-lg leading-none tracking-tight";
|
|
94
95
|
export const MODAL_DESCRIPTION = "text-muted-foreground text-sm";
|
package/src/solid/dialog.tsx
CHANGED
|
@@ -87,25 +87,40 @@ const DialogContent: ParentComponent<DialogContentProps> = (props) => {
|
|
|
87
87
|
"ariaLabel",
|
|
88
88
|
"anchor",
|
|
89
89
|
"style",
|
|
90
|
+
"ref",
|
|
90
91
|
]);
|
|
91
92
|
const context = useDialogContext();
|
|
92
93
|
const [viewport, setViewport] = createSignal(0);
|
|
94
|
+
const [panel, setPanel] = createSignal<HTMLElement>();
|
|
95
|
+
const [height, setHeight] = createSignal<number>();
|
|
93
96
|
createEffect(() => {
|
|
94
97
|
if (!local.anchor || !context.isOpen()) return;
|
|
95
98
|
const measure = () => setViewport((n) => n + 1);
|
|
96
99
|
window.addEventListener("resize", measure);
|
|
97
100
|
onCleanup(() => window.removeEventListener("resize", measure));
|
|
98
101
|
});
|
|
102
|
+
createEffect(() => {
|
|
103
|
+
const el = panel();
|
|
104
|
+
if (!local.anchor || !el) return;
|
|
105
|
+
setHeight(el.offsetHeight);
|
|
106
|
+
const observer = new ResizeObserver(() => setHeight(el.offsetHeight));
|
|
107
|
+
observer.observe(el);
|
|
108
|
+
onCleanup(() => observer.disconnect());
|
|
109
|
+
});
|
|
99
110
|
const placement = () => {
|
|
100
111
|
viewport();
|
|
101
112
|
const a = local.anchor;
|
|
102
|
-
return a ? overAnchor(a, ANCHORED_WIDTH[local.size ?? "lg"]) : undefined;
|
|
113
|
+
return a ? overAnchor(a, ANCHORED_WIDTH[local.size ?? "lg"], height()) : undefined;
|
|
103
114
|
};
|
|
104
115
|
return (
|
|
105
116
|
<DialogPrimitive.Portal>
|
|
106
117
|
<ModalScrollLock />
|
|
107
118
|
<DialogPrimitive.Overlay data-slot="dialog-overlay" class={MODAL_SCRIM} />
|
|
108
119
|
<DialogPrimitive.Content
|
|
120
|
+
ref={(el: HTMLElement) => {
|
|
121
|
+
setPanel(el);
|
|
122
|
+
if (typeof local.ref === "function") local.ref(el);
|
|
123
|
+
}}
|
|
109
124
|
data-slot="dialog-content"
|
|
110
125
|
role="dialog"
|
|
111
126
|
aria-label={context.titleId() ? undefined : local.ariaLabel}
|
package/src/solid/index.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
export { type Color, parseColor } from "@kobalte/core/colors";
|
|
6
6
|
// Floating glass panel + its shared surface token.
|
|
7
7
|
export { SECTION_ROW_SURFACE } from "../lib/card-classes.js";
|
|
8
|
+
export { HOLD_GRACE_MS, HOLD_MS } from "../lib/hold.js";
|
|
8
9
|
export { RISE_MOTION, SETTLE_MOTION, TRAVEL_MOTION } from "../lib/motion-classes.js";
|
|
9
10
|
export { OVERLAY_SURFACE } from "../lib/overlay-classes.js";
|
|
10
11
|
// Section tokens re-exported from the Solid entry for convenience.
|
|
@@ -68,17 +68,19 @@ export function PreviewTile(props: {
|
|
|
68
68
|
<Show when={props.caption ?? true} fallback={<span class="sr-only">{props.label}</span>}>
|
|
69
69
|
<span
|
|
70
70
|
data-slot="preview-tile-caption"
|
|
71
|
-
class="text-
|
|
71
|
+
class="text-foreground flex min-w-0 items-center gap-1 text-xs font-medium"
|
|
72
72
|
>
|
|
73
73
|
<Show when={props.icon}>
|
|
74
|
-
{(icon) =>
|
|
74
|
+
{(icon) => (
|
|
75
|
+
<Icon icon={icon()} width={12} height={12} aria-hidden="true" class="shrink-0" />
|
|
76
|
+
)}
|
|
75
77
|
</Show>
|
|
76
|
-
{props.label}
|
|
78
|
+
<span class="truncate">{props.label}</span>
|
|
77
79
|
</span>
|
|
78
80
|
<Show when={props.meta}>
|
|
79
81
|
<span
|
|
80
82
|
data-slot="preview-tile-meta"
|
|
81
|
-
class="text-muted-foreground
|
|
83
|
+
class="text-muted-foreground -mt-1 truncate text-[11px] leading-tight"
|
|
82
84
|
>
|
|
83
85
|
{props.meta}
|
|
84
86
|
</span>
|
|
@@ -31,6 +31,8 @@ const ToggleGroup: ParentComponent<
|
|
|
31
31
|
VariantProps<typeof toggleVariants> & {
|
|
32
32
|
/** CSS colour for the selected segment's glass. Default `var(--primary)`. */
|
|
33
33
|
tone?: string;
|
|
34
|
+
/** One row that scrolls sideways when it outgrows its container, instead of wrapping. */
|
|
35
|
+
scroll?: boolean;
|
|
34
36
|
}
|
|
35
37
|
> = (props) => {
|
|
36
38
|
const [local, rest] = splitProps(props, [
|
|
@@ -38,6 +40,7 @@ const ToggleGroup: ParentComponent<
|
|
|
38
40
|
"variant",
|
|
39
41
|
"size",
|
|
40
42
|
"tone",
|
|
43
|
+
"scroll",
|
|
41
44
|
"children",
|
|
42
45
|
] as const);
|
|
43
46
|
// Read `multiple` without splitting it out: Kobalte's root is a single/multiple
|
|
@@ -49,8 +52,10 @@ const ToggleGroup: ParentComponent<
|
|
|
49
52
|
data-slot="toggle-group"
|
|
50
53
|
data-variant={local.variant}
|
|
51
54
|
data-size={local.size}
|
|
55
|
+
data-scroll={local.scroll ? "" : undefined}
|
|
52
56
|
class={cn(
|
|
53
57
|
`group/toggle-group flex w-fit max-w-full flex-wrap items-center gap-y-1 rounded-lg ${TRACK_SURFACE} p-1 data-[variant=outline]:shadow-xs`,
|
|
58
|
+
local.scroll && "[scrollbar-width:none] flex-nowrap overflow-x-auto",
|
|
54
59
|
local.class,
|
|
55
60
|
)}
|
|
56
61
|
{...rest}
|
|
@@ -65,8 +70,12 @@ const ToggleGroup: ParentComponent<
|
|
|
65
70
|
activeSelector="[data-pressed]"
|
|
66
71
|
indicatorClass="rounded-md"
|
|
67
72
|
indicatorTone={local.tone}
|
|
68
|
-
wrapped
|
|
69
|
-
class=
|
|
73
|
+
wrapped={!local.scroll}
|
|
74
|
+
class={
|
|
75
|
+
local.scroll
|
|
76
|
+
? "flex w-max flex-nowrap items-center"
|
|
77
|
+
: "flex w-full flex-wrap items-center gap-y-1"
|
|
78
|
+
}
|
|
70
79
|
>
|
|
71
80
|
{local.children}
|
|
72
81
|
</SlidingIndicator>
|
package/src/styles/globals.css
CHANGED
|
@@ -450,6 +450,14 @@
|
|
|
450
450
|
.gh-alert-desc:not(:first-child) {
|
|
451
451
|
margin-top: 0.125rem;
|
|
452
452
|
}
|
|
453
|
+
[data-slot="alert"][data-size="sm"] .gh-alert-desc {
|
|
454
|
+
font-size: var(--text-xs);
|
|
455
|
+
line-height: var(--text-xs--line-height);
|
|
456
|
+
}
|
|
457
|
+
[data-slot="alert"][data-size="sm"] .gh-alert-icon-bg {
|
|
458
|
+
transform: scale(0.5);
|
|
459
|
+
transform-origin: bottom right;
|
|
460
|
+
}
|
|
453
461
|
|
|
454
462
|
/* Carousel `wipe` puts every slide in one grid cell. This is
|
|
455
463
|
* structural, so it ships as real CSS: a Tailwind arbitrary variant written in
|
package/src/styles/theme.css
CHANGED
|
@@ -275,11 +275,13 @@
|
|
|
275
275
|
--ease-contract: cubic-bezier(0.4, 0, 1, 1);
|
|
276
276
|
/* A morph is a shape becoming another shape: slower than an arrival, and it
|
|
277
277
|
* leaves the start shape gently instead of snapping out of it. */
|
|
278
|
-
--duration-morph:
|
|
278
|
+
--duration-morph: 300ms;
|
|
279
279
|
--ease-morph: cubic-bezier(0.32, 0.72, 0, 1);
|
|
280
280
|
--duration-micro: 120ms;
|
|
281
281
|
--duration-state: 160ms;
|
|
282
282
|
--duration-expand: 200ms;
|
|
283
|
+
/* The hold fill: HOLD_MS - HOLD_GRACE_MS (lib/hold.ts), so it completes as the hold fires. */
|
|
284
|
+
--duration-hold: 250ms;
|
|
283
285
|
/* Ambient motion is an event (SPEC motion rule 5): 1 while the host holds
|
|
284
286
|
* html[data-motion="live"], else 0. Inherits into widget shadow roots, so a
|
|
285
287
|
* loop multiplies its duration by it: calc(var(--motion-ambient, 0) * 1s).
|
|
@@ -573,6 +575,7 @@ html[data-motion="live"] {
|
|
|
573
575
|
--duration-state: 0ms;
|
|
574
576
|
--duration-expand: 0ms;
|
|
575
577
|
--duration-morph: 0ms;
|
|
578
|
+
--duration-hold: 0ms;
|
|
576
579
|
}
|
|
577
580
|
/* tw-animate enter/exit classes carry their own fallback duration. */
|
|
578
581
|
.animate-in,
|