@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/empty.tsx
CHANGED
|
@@ -36,7 +36,7 @@ const EMPTY_MEDIA: Record<EmptyMediaKind, string> = {
|
|
|
36
36
|
const EmptyMedia: Component<
|
|
37
37
|
ComponentProps<"div"> & {
|
|
38
38
|
media?: EmptyMediaKind;
|
|
39
|
-
/** @deprecated `media
|
|
39
|
+
/** @deprecated `media`; removed in 2.0.0. */
|
|
40
40
|
variant?: EmptyMediaKind | "default";
|
|
41
41
|
}
|
|
42
42
|
> = (props) => {
|
|
@@ -9,7 +9,8 @@ import {
|
|
|
9
9
|
type ParentComponent,
|
|
10
10
|
Show,
|
|
11
11
|
} from "solid-js";
|
|
12
|
-
import {
|
|
12
|
+
import { focusWithoutTracking } from "../lib/behavior/focus-scope.js";
|
|
13
|
+
import { MENU_ITEM_RADIUS, MENU_LABEL } from "../lib/menu-classes.js";
|
|
13
14
|
import { PICKER_LIST } from "../lib/picker-classes.js";
|
|
14
15
|
import { createIsMobile } from "../lib/use-is-mobile.js";
|
|
15
16
|
import { cn } from "../lib/utils.js";
|
|
@@ -430,7 +431,7 @@ export function EntitySelector(props: EntitySelectorProps) {
|
|
|
430
431
|
id={optionId(p.entityIndex)}
|
|
431
432
|
data-slot="entity-selector-row"
|
|
432
433
|
aria-selected={selected()}
|
|
433
|
-
|
|
434
|
+
highlighted={!isMobile() && activeIndex() === p.entityIndex}
|
|
434
435
|
class="absolute inset-x-0"
|
|
435
436
|
style={{ top: `${p.top}px`, height: `${ROW_HEIGHT}px` }}
|
|
436
437
|
icon={view()?.icon ?? FALLBACK_ICON}
|
|
@@ -531,6 +532,7 @@ export function EntitySelector(props: EntitySelectorProps) {
|
|
|
531
532
|
>
|
|
532
533
|
<SelectionScope
|
|
533
534
|
marker="highlighted"
|
|
535
|
+
radius={MENU_ITEM_RADIUS}
|
|
534
536
|
role="presentation"
|
|
535
537
|
style={{ height: `${totalHeight()}px` }}
|
|
536
538
|
>
|
|
@@ -627,7 +629,7 @@ export function EntitySelector(props: EntitySelectorProps) {
|
|
|
627
629
|
e.preventDefault();
|
|
628
630
|
// preventScroll: the panel is portalled at (0,0) until the popper places it,
|
|
629
631
|
// so a plain focus() scrolls the page to the top.
|
|
630
|
-
inputRef
|
|
632
|
+
focusWithoutTracking(inputRef);
|
|
631
633
|
}}
|
|
632
634
|
onInteractOutside={() => closePicker()}
|
|
633
635
|
>
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { createContext, createMemo, createSignal, type JSX, Show, useContext } from "solid-js";
|
|
2
|
+
import { createToggleItem, createToggleSet, type ToggleSet } from "../lib/toggle-set.js";
|
|
3
3
|
import { cn } from "../lib/utils.js";
|
|
4
4
|
import { Avatar, AvatarFallback } from "./avatar.js";
|
|
5
5
|
import { Icon } from "./icon.js";
|
|
6
6
|
|
|
7
|
-
const
|
|
7
|
+
const FaceContext = createContext<{ locked: () => ReadonlySet<string>; set: ToggleSet }>();
|
|
8
|
+
|
|
9
|
+
const sameList = (a: readonly string[], b: readonly string[]) =>
|
|
10
|
+
a.length === b.length && a.every((v, i) => v === b[i]);
|
|
8
11
|
|
|
9
12
|
/** People and screens to turn on or off. Faces in `lockedIds` always count: shown on, never reported in `onChange`. */
|
|
10
13
|
export function FaceToggleGroup(props: {
|
|
@@ -18,19 +21,33 @@ export function FaceToggleGroup(props: {
|
|
|
18
21
|
}) {
|
|
19
22
|
const locked = createMemo(() => new Set(props.lockedIds ?? []));
|
|
20
23
|
const pressed = () => [...new Set([...props.value, ...locked()])];
|
|
24
|
+
const [root, setRoot] = createSignal<HTMLElement>();
|
|
25
|
+
const set = createToggleSet({
|
|
26
|
+
root,
|
|
27
|
+
itemSelector: '[data-slot="face-toggle"][data-key]',
|
|
28
|
+
values: pressed,
|
|
29
|
+
setValues: (next) => {
|
|
30
|
+
const chosen = next.filter((id) => !locked().has(id));
|
|
31
|
+
if (!sameList(chosen, props.value)) props.onChange(chosen);
|
|
32
|
+
},
|
|
33
|
+
multiple: () => true,
|
|
34
|
+
disabledFocusable: true,
|
|
35
|
+
});
|
|
21
36
|
return (
|
|
22
|
-
<
|
|
23
|
-
<
|
|
24
|
-
|
|
37
|
+
<FaceContext.Provider value={{ locked, set }}>
|
|
38
|
+
<div
|
|
39
|
+
ref={setRoot}
|
|
40
|
+
role="group"
|
|
41
|
+
id={set.id()}
|
|
42
|
+
data-orientation={set.orientation()}
|
|
25
43
|
data-slot="face-toggle-group"
|
|
26
44
|
aria-label={props["aria-label"]}
|
|
27
|
-
value={pressed()}
|
|
28
|
-
onChange={(next: string[]) => props.onChange(next.filter((id) => !locked().has(id)))}
|
|
29
45
|
class={cn("flex flex-wrap gap-x-3 gap-y-2", props.class)}
|
|
46
|
+
on:keydown={(event) => set.collection.onKeyDown(event)}
|
|
30
47
|
>
|
|
31
48
|
{props.children}
|
|
32
|
-
</
|
|
33
|
-
</
|
|
49
|
+
</div>
|
|
50
|
+
</FaceContext.Provider>
|
|
34
51
|
);
|
|
35
52
|
}
|
|
36
53
|
|
|
@@ -40,11 +57,19 @@ export function FaceToggle(props: {
|
|
|
40
57
|
kind: "person" | "screen";
|
|
41
58
|
class?: string;
|
|
42
59
|
}) {
|
|
43
|
-
const
|
|
44
|
-
|
|
60
|
+
const group = useContext(FaceContext);
|
|
61
|
+
if (!group) throw new Error("FaceToggle renders inside a FaceToggleGroup");
|
|
62
|
+
const isLocked = () => group.locked().has(props.id);
|
|
63
|
+
const item = createToggleItem(group.set, {
|
|
64
|
+
value: () => props.id,
|
|
65
|
+
disabled: () => false,
|
|
66
|
+
locked: isLocked,
|
|
67
|
+
});
|
|
45
68
|
return (
|
|
46
|
-
<
|
|
47
|
-
|
|
69
|
+
<button
|
|
70
|
+
ref={item.ref}
|
|
71
|
+
type="button"
|
|
72
|
+
{...item.props}
|
|
48
73
|
data-slot="face-toggle"
|
|
49
74
|
aria-disabled={isLocked() ? "true" : undefined}
|
|
50
75
|
class={cn(
|
|
@@ -53,7 +78,7 @@ export function FaceToggle(props: {
|
|
|
53
78
|
)}
|
|
54
79
|
>
|
|
55
80
|
<span aria-hidden="true" class="relative">
|
|
56
|
-
<Avatar class="group-data-[pressed]/face-toggle:ring-primary group-data-[pressed]/face-toggle:ring-offset-background size-11 opacity-50 transition-opacity duration-
|
|
81
|
+
<Avatar class="group-data-[pressed]/face-toggle:ring-primary group-data-[pressed]/face-toggle:ring-offset-background size-11 opacity-50 transition-opacity duration-(--duration-expand) group-active/face-toggle:scale-[0.97] group-data-[pressed]/face-toggle:opacity-100 group-data-[pressed]/face-toggle:ring-2 group-data-[pressed]/face-toggle:ring-offset-2">
|
|
57
82
|
<AvatarFallback>
|
|
58
83
|
<Show when={props.kind === "screen"} fallback={props.name.slice(0, 1)}>
|
|
59
84
|
<Icon icon="lucide:monitor-smartphone" width={18} height={18} />
|
|
@@ -81,13 +106,13 @@ export function FaceToggle(props: {
|
|
|
81
106
|
</span>
|
|
82
107
|
<span
|
|
83
108
|
data-slot="face-toggle-name"
|
|
84
|
-
class="text-muted-foreground group-data-[pressed]/face-toggle:text-foreground max-w-full truncate transition-colors duration-
|
|
109
|
+
class="text-muted-foreground group-data-[pressed]/face-toggle:text-foreground max-w-full truncate transition-colors duration-(--duration-expand)"
|
|
85
110
|
>
|
|
86
111
|
{props.name}
|
|
87
112
|
</span>
|
|
88
113
|
<Show when={isLocked()}>
|
|
89
|
-
<span class="sr-only">always sees it</span>
|
|
114
|
+
<span class="sr-only">{" always sees it"}</span>
|
|
90
115
|
</Show>
|
|
91
|
-
</
|
|
116
|
+
</button>
|
|
92
117
|
);
|
|
93
118
|
}
|
package/src/solid/form.tsx
CHANGED
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
useContext,
|
|
17
17
|
type ValidComponent,
|
|
18
18
|
} from "solid-js";
|
|
19
|
-
import {
|
|
19
|
+
import { Polymorphic } from "../lib/behavior/polymorphic.js";
|
|
20
20
|
import { cn } from "../lib/utils.js";
|
|
21
21
|
import { Field, FieldDescription, FieldError, FieldLabel } from "./field.js";
|
|
22
22
|
import { Input } from "./input.js";
|
|
@@ -95,7 +95,7 @@ const FormField: ParentComponent<{ name: string }> = (props) => {
|
|
|
95
95
|
);
|
|
96
96
|
};
|
|
97
97
|
|
|
98
|
-
/** @deprecated
|
|
98
|
+
/** @deprecated `Field`; removed in 2.0.0. */
|
|
99
99
|
const FormItem: ParentComponent<ComponentProps<typeof Field>> = (props) => {
|
|
100
100
|
const id = createUniqueId();
|
|
101
101
|
const [hasDescription, setHasDescription] = createSignal(false);
|
|
@@ -107,7 +107,7 @@ const FormItem: ParentComponent<ComponentProps<typeof Field>> = (props) => {
|
|
|
107
107
|
);
|
|
108
108
|
};
|
|
109
109
|
|
|
110
|
-
/** @deprecated
|
|
110
|
+
/** @deprecated `FieldLabel`; removed in 2.0.0. */
|
|
111
111
|
const FormLabel: Component<ComponentProps<typeof FieldLabel>> = (props) => {
|
|
112
112
|
const [local, rest] = splitProps(props, ["class"]);
|
|
113
113
|
const { error, formItemId } = useFormField();
|
|
@@ -145,8 +145,7 @@ function warnFormControlWrapper() {
|
|
|
145
145
|
* Passing children keeps the old wrapper shape working: a `div` carrying the
|
|
146
146
|
* same id and aria, with the children inside.
|
|
147
147
|
*
|
|
148
|
-
* @deprecated
|
|
149
|
-
* describedby land on the element a screen reader announces.
|
|
148
|
+
* @deprecated With `children`, render the control itself; removed in 2.0.0.
|
|
150
149
|
*/
|
|
151
150
|
const FormControl = <T extends ValidComponent = typeof Input>(
|
|
152
151
|
props: { as?: T } & ComponentProps<T>,
|
|
@@ -174,8 +173,9 @@ const FormControl = <T extends ValidComponent = typeof Input>(
|
|
|
174
173
|
<Show
|
|
175
174
|
when={wrapped()}
|
|
176
175
|
fallback={
|
|
177
|
-
<
|
|
178
|
-
|
|
176
|
+
<Polymorphic
|
|
177
|
+
defaultAs={Input}
|
|
178
|
+
as={local.as}
|
|
179
179
|
id={formItemId()}
|
|
180
180
|
aria-describedby={describedBy()}
|
|
181
181
|
aria-invalid={error() ? true : undefined}
|
|
@@ -196,7 +196,7 @@ const FormControl = <T extends ValidComponent = typeof Input>(
|
|
|
196
196
|
);
|
|
197
197
|
};
|
|
198
198
|
|
|
199
|
-
/** @deprecated
|
|
199
|
+
/** @deprecated `FieldDescription`; removed in 2.0.0. */
|
|
200
200
|
const FormDescription: Component<ComponentProps<typeof FieldDescription>> = (props) => {
|
|
201
201
|
const itemContext = useContext(FormItemContext);
|
|
202
202
|
const { formDescriptionId } = useFormField();
|
|
@@ -207,7 +207,7 @@ const FormDescription: Component<ComponentProps<typeof FieldDescription>> = (pro
|
|
|
207
207
|
return <FieldDescription id={formDescriptionId()} {...props} />;
|
|
208
208
|
};
|
|
209
209
|
|
|
210
|
-
/** @deprecated
|
|
210
|
+
/** @deprecated `FieldError`; removed in 2.0.0. */
|
|
211
211
|
const FormMessage: ParentComponent<ComponentProps<typeof FieldError>> = (props) => {
|
|
212
212
|
const [local, rest] = splitProps(props, ["children"]);
|
|
213
213
|
const { error, formMessageId } = useFormField();
|
package/src/solid/glyph-tile.tsx
CHANGED
|
@@ -1,10 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
createContext,
|
|
3
|
+
createSignal,
|
|
4
|
+
type JSX,
|
|
5
|
+
onCleanup,
|
|
6
|
+
onMount,
|
|
7
|
+
Show,
|
|
8
|
+
useContext,
|
|
9
|
+
} from "solid-js";
|
|
3
10
|
import { FIELD_CHROME } from "../lib/input-classes.js";
|
|
4
11
|
import { SCROLL_TRACK_FADE, trackScroll } from "../lib/scroll-track.js";
|
|
12
|
+
import { createToggleItem, createToggleSet, type ToggleSet } from "../lib/toggle-set.js";
|
|
5
13
|
import { cn } from "../lib/utils.js";
|
|
6
14
|
import { Icon } from "./icon.js";
|
|
7
15
|
|
|
16
|
+
const GlyphContext = createContext<ToggleSet>();
|
|
17
|
+
|
|
8
18
|
/** Tiles that scroll sideways below `sm` and wrap from `sm` up. Tapping the picked tile again clears the pick. */
|
|
9
19
|
export function GlyphTileGroup(props: {
|
|
10
20
|
value: string | null;
|
|
@@ -13,24 +23,36 @@ export function GlyphTileGroup(props: {
|
|
|
13
23
|
class?: string;
|
|
14
24
|
children: JSX.Element;
|
|
15
25
|
}) {
|
|
16
|
-
|
|
26
|
+
const [root, setRoot] = createSignal<HTMLDivElement>();
|
|
27
|
+
const set = createToggleSet({
|
|
28
|
+
root,
|
|
29
|
+
itemSelector: '[data-slot="glyph-tile"][data-key]',
|
|
30
|
+
values: () => (props.value === null ? [] : [props.value]),
|
|
31
|
+
setValues: (next) => props.onChange(next[0] ?? null),
|
|
32
|
+
multiple: () => false,
|
|
33
|
+
});
|
|
17
34
|
onMount(() => {
|
|
18
|
-
|
|
35
|
+
const group = root();
|
|
36
|
+
if (group) onCleanup(trackScroll(group, "[data-pressed]", () => props.value));
|
|
19
37
|
});
|
|
20
38
|
return (
|
|
21
|
-
<
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
39
|
+
<GlyphContext.Provider value={set}>
|
|
40
|
+
<div
|
|
41
|
+
ref={setRoot}
|
|
42
|
+
role="group"
|
|
43
|
+
id={set.id()}
|
|
44
|
+
data-orientation={set.orientation()}
|
|
45
|
+
data-slot="glyph-tile-group"
|
|
46
|
+
aria-label={props["aria-label"]}
|
|
47
|
+
class={cn(
|
|
48
|
+
`flex snap-x snap-proximity [scrollbar-width:none] gap-2 overflow-x-auto overscroll-x-contain py-0.5 [&::-webkit-scrollbar]:hidden ${SCROLL_TRACK_FADE} sm:flex-wrap sm:overflow-visible`,
|
|
49
|
+
props.class,
|
|
50
|
+
)}
|
|
51
|
+
on:keydown={(event) => set.collection.onKeyDown(event)}
|
|
52
|
+
>
|
|
53
|
+
{props.children}
|
|
54
|
+
</div>
|
|
55
|
+
</GlyphContext.Provider>
|
|
34
56
|
);
|
|
35
57
|
}
|
|
36
58
|
|
|
@@ -43,13 +65,18 @@ export function GlyphTile(props: {
|
|
|
43
65
|
badge?: string;
|
|
44
66
|
class?: string;
|
|
45
67
|
}) {
|
|
68
|
+
const set = useContext(GlyphContext);
|
|
69
|
+
if (!set) throw new Error("GlyphTile renders inside a GlyphTileGroup");
|
|
70
|
+
const item = createToggleItem(set, { value: () => props.value, disabled: () => false });
|
|
46
71
|
return (
|
|
47
|
-
<
|
|
48
|
-
|
|
72
|
+
<button
|
|
73
|
+
ref={item.ref}
|
|
74
|
+
type="button"
|
|
75
|
+
{...item.props}
|
|
49
76
|
data-slot="glyph-tile"
|
|
50
77
|
class={cn(
|
|
51
78
|
FIELD_CHROME,
|
|
52
|
-
"transition-glass group/glyph-tile focus-visible:ring-ring/50 relative flex h-17 w-22 shrink-0 touch-manipulation snap-start flex-col items-center justify-center gap-1.5 rounded-2xl px-1 text-xs font-medium duration-
|
|
79
|
+
"transition-glass group/glyph-tile focus-visible:ring-ring/50 relative flex h-17 w-22 shrink-0 touch-manipulation snap-start flex-col items-center justify-center gap-1.5 rounded-2xl px-1 text-xs font-medium duration-(--duration-expand) outline-none focus-visible:ring-[3px] active:scale-[0.97] data-[pressed]:[--glass-base:color-mix(in_oklab,var(--primary)_16%,var(--input))] data-[pressed]:[--glass-edge:var(--primary)]",
|
|
53
80
|
props.class,
|
|
54
81
|
)}
|
|
55
82
|
>
|
|
@@ -72,6 +99,6 @@ export function GlyphTile(props: {
|
|
|
72
99
|
</span>
|
|
73
100
|
)}
|
|
74
101
|
</Show>
|
|
75
|
-
</
|
|
102
|
+
</button>
|
|
76
103
|
);
|
|
77
104
|
}
|
package/src/solid/hover-card.tsx
CHANGED
|
@@ -1,36 +1,303 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import {
|
|
2
|
+
type Accessor,
|
|
3
|
+
type Component,
|
|
4
|
+
type ComponentProps,
|
|
5
|
+
createContext,
|
|
6
|
+
createSignal,
|
|
7
|
+
type JSX,
|
|
8
|
+
onCleanup,
|
|
9
|
+
Show,
|
|
10
|
+
splitProps,
|
|
11
|
+
untrack,
|
|
12
|
+
useContext,
|
|
13
|
+
type ValidComponent,
|
|
14
|
+
} from "solid-js";
|
|
15
|
+
import { Portal } from "solid-js/web";
|
|
16
|
+
import type { Align, Side } from "../lib/anchor-placement.js";
|
|
17
|
+
import { createAnchored } from "../lib/behavior/anchored.js";
|
|
18
|
+
import { createControllableSignal } from "../lib/behavior/controllable.js";
|
|
19
|
+
import { createDismiss } from "../lib/behavior/dismiss.js";
|
|
20
|
+
import { registerLayer } from "../lib/behavior/layer-stack.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";
|
|
24
|
+
import { MOTION_EXIT_MS, OVERLAY_MOTION } from "../lib/motion-classes.js";
|
|
6
25
|
import { FLOATING_PANEL } from "../lib/overlay-classes.js";
|
|
7
26
|
import { cn } from "../lib/utils.js";
|
|
27
|
+
import { usePortalMount } from "./portal-mount.js";
|
|
28
|
+
|
|
29
|
+
type Placement = Side | `${Side}-${Exclude<Align, "center">}`;
|
|
30
|
+
|
|
31
|
+
interface HoverCardProps {
|
|
32
|
+
open?: boolean;
|
|
33
|
+
defaultOpen?: boolean;
|
|
34
|
+
onOpenChange?: (open: boolean) => void;
|
|
35
|
+
openDelay?: number;
|
|
36
|
+
closeDelay?: number;
|
|
37
|
+
placement?: Placement;
|
|
38
|
+
gutter?: number;
|
|
39
|
+
children?: JSX.Element;
|
|
40
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
41
|
+
id?: string;
|
|
42
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
43
|
+
ignoreSafeArea?: boolean;
|
|
44
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
45
|
+
forceMount?: boolean;
|
|
46
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
47
|
+
getAnchorRect?: (anchor?: HTMLElement) => unknown;
|
|
48
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
49
|
+
shift?: number;
|
|
50
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
51
|
+
flip?: boolean | string;
|
|
52
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
53
|
+
slide?: boolean;
|
|
54
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
55
|
+
overlap?: boolean;
|
|
56
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
57
|
+
sameWidth?: boolean;
|
|
58
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
59
|
+
fitViewport?: boolean;
|
|
60
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
61
|
+
hideWhenDetached?: boolean;
|
|
62
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
63
|
+
detachedPadding?: number;
|
|
64
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
65
|
+
arrowPadding?: number;
|
|
66
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
67
|
+
overflowPadding?: number;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
interface HoverCardContextValue {
|
|
71
|
+
open: Accessor<boolean>;
|
|
72
|
+
trigger: Accessor<HTMLElement | undefined>;
|
|
73
|
+
setTrigger: (el: HTMLElement | undefined) => void;
|
|
74
|
+
card: Accessor<HTMLElement | undefined>;
|
|
75
|
+
setCard: (el: HTMLElement | undefined) => void;
|
|
76
|
+
side: Accessor<Side>;
|
|
77
|
+
align: Accessor<Align>;
|
|
78
|
+
gutter: number;
|
|
79
|
+
show: () => void;
|
|
80
|
+
hide: (delayed: boolean) => void;
|
|
81
|
+
hold: () => void;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const HoverCardContext = createContext<HoverCardContextValue | null>(null);
|
|
8
85
|
|
|
9
|
-
const
|
|
86
|
+
const useHoverCard = (): HoverCardContextValue => {
|
|
87
|
+
const ctx = useContext(HoverCardContext);
|
|
88
|
+
if (!ctx) throw new Error("HoverCard parts render inside a HoverCard");
|
|
89
|
+
return ctx;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const OPEN_DELAY_MS = 700;
|
|
93
|
+
const CLOSE_DELAY_MS = 300;
|
|
94
|
+
|
|
95
|
+
const ORIGIN_BY_SIDE =
|
|
96
|
+
"data-[side=bottom]:origin-top data-[side=top]:origin-bottom data-[side=left]:origin-right data-[side=right]:origin-left";
|
|
10
97
|
|
|
11
|
-
const
|
|
12
|
-
|
|
98
|
+
const HoverCardRoot: Component<HoverCardProps> = (props) => {
|
|
99
|
+
const [open, setOpen] = createControllableSignal<boolean>({
|
|
100
|
+
value: () => props.open,
|
|
101
|
+
defaultValue: () => props.defaultOpen ?? false,
|
|
102
|
+
onChange: (next) => props.onOpenChange?.(next),
|
|
103
|
+
});
|
|
104
|
+
const [trigger, setTrigger] = createSignal<HTMLElement>();
|
|
105
|
+
const [card, setCard] = createSignal<HTMLElement>();
|
|
106
|
+
const placement = () => (props.placement ?? "bottom").split("-") as [Side, Align?];
|
|
107
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
108
|
+
const hold = () => clearTimeout(timer);
|
|
109
|
+
const schedule = (next: boolean, delay: number) => {
|
|
110
|
+
hold();
|
|
111
|
+
if (delay <= 0) setOpen(next);
|
|
112
|
+
else timer = setTimeout(() => setOpen(next), delay);
|
|
113
|
+
};
|
|
114
|
+
onCleanup(hold);
|
|
115
|
+
|
|
116
|
+
const value: HoverCardContextValue = {
|
|
117
|
+
open,
|
|
118
|
+
trigger,
|
|
119
|
+
setTrigger: (el) => setTrigger(el),
|
|
120
|
+
card,
|
|
121
|
+
setCard: (el) => setCard(el),
|
|
122
|
+
side: () => placement()[0],
|
|
123
|
+
align: () => placement()[1] ?? "center",
|
|
124
|
+
gutter: untrack(() => props.gutter ?? 0),
|
|
125
|
+
show: () => {
|
|
126
|
+
if (untrack(open)) hold();
|
|
127
|
+
else schedule(true, props.openDelay ?? OPEN_DELAY_MS);
|
|
128
|
+
},
|
|
129
|
+
hide: (delayed) => schedule(false, delayed ? (props.closeDelay ?? CLOSE_DELAY_MS) : 0),
|
|
130
|
+
hold,
|
|
131
|
+
};
|
|
132
|
+
return <HoverCardContext.Provider value={value}>{props.children}</HoverCardContext.Provider>;
|
|
13
133
|
};
|
|
14
134
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
135
|
+
type HoverCardTriggerProps<T extends ValidComponent> = { as?: T } & Omit<ComponentProps<T>, "as">;
|
|
136
|
+
|
|
137
|
+
function HoverCardTrigger<T extends ValidComponent = "a">(
|
|
138
|
+
props: HoverCardTriggerProps<T>,
|
|
139
|
+
): JSX.Element {
|
|
140
|
+
const ctx = useHoverCard();
|
|
141
|
+
const [local, rest] = splitProps(props as HoverCardTriggerProps<ValidComponent>, ["as", "ref"]);
|
|
142
|
+
const [own, setOwn] = createSignal<HTMLElement>();
|
|
143
|
+
const nativeLink = () => local.as === undefined || local.as === "a";
|
|
144
|
+
|
|
145
|
+
onCleanup(() => {
|
|
146
|
+
if (untrack(ctx.trigger) === untrack(own)) ctx.setTrigger(undefined);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
effect(own, (el) => {
|
|
150
|
+
if (!el) return;
|
|
151
|
+
let touched = false;
|
|
152
|
+
const mouseLike = (e: PointerEvent) => e.pointerType !== "touch";
|
|
153
|
+
const enter = (e: PointerEvent) => mouseLike(e) && ctx.show();
|
|
154
|
+
const leave = (e: PointerEvent) => mouseLike(e) && ctx.hide(true);
|
|
155
|
+
const down = (e: PointerEvent) => {
|
|
156
|
+
touched = !mouseLike(e);
|
|
157
|
+
};
|
|
158
|
+
const focus = () => {
|
|
159
|
+
if (!touched) ctx.show();
|
|
160
|
+
};
|
|
161
|
+
const blur = (e: FocusEvent) => {
|
|
162
|
+
touched = false;
|
|
163
|
+
const next = e.relatedTarget;
|
|
164
|
+
if (next instanceof Node && untrack(ctx.card)?.contains(next)) return;
|
|
165
|
+
ctx.hide(true);
|
|
166
|
+
};
|
|
167
|
+
el.addEventListener("pointerenter", enter);
|
|
168
|
+
el.addEventListener("pointerleave", leave);
|
|
169
|
+
el.addEventListener("pointerdown", down);
|
|
170
|
+
el.addEventListener("focus", focus);
|
|
171
|
+
el.addEventListener("blur", blur);
|
|
172
|
+
return () => {
|
|
173
|
+
el.removeEventListener("pointerenter", enter);
|
|
174
|
+
el.removeEventListener("pointerleave", leave);
|
|
175
|
+
el.removeEventListener("pointerdown", down);
|
|
176
|
+
el.removeEventListener("focus", focus);
|
|
177
|
+
el.removeEventListener("blur", blur);
|
|
178
|
+
};
|
|
179
|
+
});
|
|
180
|
+
|
|
20
181
|
return (
|
|
21
|
-
<
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
182
|
+
<Polymorphic
|
|
183
|
+
{...merge(
|
|
184
|
+
{
|
|
185
|
+
"data-slot": "hover-card-trigger",
|
|
186
|
+
get role() {
|
|
187
|
+
return nativeLink() ? undefined : "link";
|
|
188
|
+
},
|
|
189
|
+
get tabIndex() {
|
|
190
|
+
return nativeLink() ? undefined : 0;
|
|
191
|
+
},
|
|
192
|
+
},
|
|
193
|
+
rest,
|
|
194
|
+
{
|
|
195
|
+
as: local.as,
|
|
196
|
+
defaultAs: "a" as ValidComponent,
|
|
197
|
+
ref: (el: HTMLElement) => {
|
|
198
|
+
setOwn(el);
|
|
199
|
+
ctx.setTrigger(el);
|
|
200
|
+
if (typeof local.ref === "function") local.ref(el);
|
|
201
|
+
},
|
|
202
|
+
get "data-expanded"() {
|
|
203
|
+
return ctx.open() ? "" : undefined;
|
|
204
|
+
},
|
|
205
|
+
get "data-closed"() {
|
|
206
|
+
return ctx.open() ? undefined : "";
|
|
207
|
+
},
|
|
208
|
+
},
|
|
209
|
+
)}
|
|
210
|
+
/>
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
interface HoverCardContentProps extends ComponentProps<"div"> {
|
|
215
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
216
|
+
forceMount?: boolean;
|
|
217
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
218
|
+
onEscapeKeyDown?: (event: Event) => void;
|
|
219
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
220
|
+
onPointerDownOutside?: (event: Event) => void;
|
|
221
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
222
|
+
onFocusOutside?: (event: Event) => void;
|
|
223
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
224
|
+
onInteractOutside?: (event: Event) => void;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const HoverCardContent: Component<HoverCardContentProps> = (props) => {
|
|
228
|
+
const ctx = useHoverCard();
|
|
229
|
+
const [local, others] = splitProps(props, [
|
|
230
|
+
"class",
|
|
231
|
+
"ref",
|
|
232
|
+
"forceMount",
|
|
233
|
+
"onEscapeKeyDown",
|
|
234
|
+
"onPointerDownOutside",
|
|
235
|
+
"onFocusOutside",
|
|
236
|
+
"onInteractOutside",
|
|
237
|
+
]);
|
|
238
|
+
const presence = createPresence({
|
|
239
|
+
present: ctx.open,
|
|
240
|
+
element: ctx.card,
|
|
241
|
+
exitMs: MOTION_EXIT_MS.overlay,
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
const layer = registerLayer({
|
|
245
|
+
element: ctx.card,
|
|
246
|
+
open: ctx.open,
|
|
247
|
+
kind: "popover",
|
|
248
|
+
escape: () => true,
|
|
249
|
+
dismiss: () => ctx.hide(false),
|
|
250
|
+
trigger: ctx.trigger,
|
|
251
|
+
});
|
|
252
|
+
createDismiss({ layer, escapeFrom: "document", onDismiss: () => ctx.hide(false) });
|
|
253
|
+
createAnchored({
|
|
254
|
+
anchor: ctx.trigger,
|
|
255
|
+
floating: ctx.card,
|
|
256
|
+
open: ctx.open,
|
|
257
|
+
side: ctx.side,
|
|
258
|
+
align: ctx.align,
|
|
259
|
+
offset: ctx.gutter,
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
const Card: Component = () => {
|
|
263
|
+
onCleanup(() => ctx.setCard(undefined));
|
|
264
|
+
return (
|
|
265
|
+
<div
|
|
266
|
+
{...others}
|
|
267
|
+
ref={(el) => {
|
|
268
|
+
ctx.setCard(el);
|
|
25
269
|
if (typeof local.ref === "function") local.ref(el);
|
|
26
270
|
}}
|
|
27
|
-
onInteractOutside={onInteractOutside}
|
|
28
271
|
data-slot="hover-card-content"
|
|
29
|
-
|
|
30
|
-
{
|
|
272
|
+
data-expanded={ctx.open() ? "" : undefined}
|
|
273
|
+
data-closed={ctx.open() ? undefined : ""}
|
|
274
|
+
on:pointerenter={ctx.hold}
|
|
275
|
+
on:pointerleave={() => ctx.hide(true)}
|
|
276
|
+
class={cn(FLOATING_PANEL, OVERLAY_MOTION, ORIGIN_BY_SIDE, "w-64 p-4", local.class)}
|
|
31
277
|
/>
|
|
32
|
-
|
|
278
|
+
);
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
return (
|
|
282
|
+
<Show when={presence.mounted()}>
|
|
283
|
+
<Portal mount={usePortalMount()}>
|
|
284
|
+
<Card />
|
|
285
|
+
</Portal>
|
|
286
|
+
</Show>
|
|
33
287
|
);
|
|
34
288
|
};
|
|
35
289
|
|
|
290
|
+
/** @deprecated Drop the wrapper; the content portals itself; removed in 2.0.0. */
|
|
291
|
+
const HoverCardPortal: Component<{ children?: JSX.Element }> = (props) => <>{props.children}</>;
|
|
292
|
+
|
|
293
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
294
|
+
const HoverCardArrow: Component = () => null;
|
|
295
|
+
|
|
296
|
+
const HoverCard = Object.assign(HoverCardRoot, {
|
|
297
|
+
Trigger: HoverCardTrigger,
|
|
298
|
+
Content: HoverCardContent,
|
|
299
|
+
Portal: HoverCardPortal,
|
|
300
|
+
Arrow: HoverCardArrow,
|
|
301
|
+
});
|
|
302
|
+
|
|
36
303
|
export { HoverCard, HoverCardContent, HoverCardTrigger };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createMemo, createSignal, For, Show } from "solid-js";
|
|
2
|
+
import { focusWithoutTracking } from "../lib/behavior/focus-scope.js";
|
|
2
3
|
import { STAGGER } from "../lib/motion-classes.js";
|
|
3
4
|
import { PICKER_LIST } from "../lib/picker-classes.js";
|
|
4
5
|
import { CHIP, ICON_PILL_TINT } from "../lib/pill-classes.js";
|
|
@@ -381,7 +382,7 @@ export function IconPicker(props: IconPickerProps) {
|
|
|
381
382
|
e.preventDefault();
|
|
382
383
|
// preventScroll: the panel is portalled at (0,0) until the popper places it,
|
|
383
384
|
// so a plain focus() scrolls the page to the top.
|
|
384
|
-
searchRef
|
|
385
|
+
focusWithoutTracking(searchRef);
|
|
385
386
|
}}
|
|
386
387
|
onInteractOutside={() => setOpen(false)}
|
|
387
388
|
>
|