@glasshome/ui 1.9.0 → 1.10.1
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/README.md +2 -13
- package/SPEC.md +4 -4
- package/dist/lib/badge-tone.d.ts +0 -2
- package/dist/solid/badge.d.ts +1 -1
- package/dist/solid/card.d.ts +4 -2
- package/dist/solid/icon.d.ts +14 -0
- package/dist/solid/index.js +1645 -1632
- package/dist/solid/spinner.d.ts +1 -1
- package/package.json +9 -12
- package/scripts/check-pack.ts +32 -0
- package/src/index.ts +111 -0
- package/src/lib/badge-tone.ts +0 -4
- package/src/lib/carousel-classes.ts +2 -3
- package/src/solid/accordion.tsx +60 -0
- package/src/solid/alert-dialog.tsx +148 -0
- package/src/solid/alert.tsx +118 -0
- package/src/solid/area-picker.tsx +225 -0
- package/src/solid/aspect-ratio.tsx +21 -0
- package/src/solid/avatar.tsx +41 -0
- package/src/solid/badge.tsx +74 -0
- package/src/solid/bottom-sheet/arbitration.ts +40 -0
- package/src/solid/bottom-sheet/bottom-sheet.tsx +457 -0
- package/src/solid/bottom-sheet/constants.ts +8 -0
- package/src/solid/bottom-sheet/drag-controller.ts +221 -0
- package/src/solid/bottom-sheet/focus-trap.ts +56 -0
- package/src/solid/bottom-sheet/index.ts +14 -0
- package/src/solid/bottom-sheet/keyboard.ts +35 -0
- package/src/solid/bottom-sheet/scroll-lock.ts +64 -0
- package/src/solid/bottom-sheet/state-machine.ts +40 -0
- package/src/solid/bottom-sheet/velocity.ts +42 -0
- package/src/solid/breadcrumb.tsx +105 -0
- package/src/solid/button-group.tsx +66 -0
- package/src/solid/button.tsx +20 -0
- package/src/solid/card.tsx +101 -0
- package/src/solid/carousel.tsx +302 -0
- package/src/solid/charts.tsx +338 -0
- package/src/solid/checkbox.tsx +70 -0
- package/src/solid/collapsible.tsx +38 -0
- package/src/solid/color-slider.tsx +98 -0
- package/src/solid/color-wheel.tsx +77 -0
- package/src/solid/context-menu.tsx +109 -0
- package/src/solid/copy-button.tsx +46 -0
- package/src/solid/count-pill.tsx +24 -0
- package/src/solid/data-table.tsx +248 -0
- package/src/solid/dialog-parts.tsx +242 -0
- package/src/solid/dialog.tsx +121 -0
- package/src/solid/dock.tsx +186 -0
- package/src/solid/dropdown-menu.tsx +130 -0
- package/src/solid/empty.tsx +99 -0
- package/src/solid/entity-data.ts +78 -0
- package/src/solid/entity-selector.tsx +697 -0
- package/src/solid/field.tsx +253 -0
- package/src/solid/form.tsx +231 -0
- package/src/solid/hero-action.tsx +117 -0
- package/src/solid/hover-card.tsx +26 -0
- package/src/solid/icon-picker.tsx +432 -0
- package/src/solid/icon.tsx +20 -0
- package/src/solid/image-picker.tsx +380 -0
- package/src/solid/index.ts +417 -0
- package/src/solid/input-group.tsx +170 -0
- package/src/solid/input-otp.tsx +175 -0
- package/src/solid/input.tsx +12 -0
- package/src/solid/item.tsx +179 -0
- package/src/solid/kbd.tsx +30 -0
- package/src/solid/label.tsx +19 -0
- package/src/solid/list-reorder.ts +148 -0
- package/src/solid/logo.tsx +79 -0
- package/src/solid/media-copy.ts +37 -0
- package/src/solid/media-store.ts +110 -0
- package/src/solid/media-tile.tsx +100 -0
- package/src/solid/menu-parts.tsx +248 -0
- package/src/solid/number-field.tsx +72 -0
- package/src/solid/option-card.tsx +218 -0
- package/src/solid/ornament.tsx +53 -0
- package/src/solid/overlay.tsx +16 -0
- package/src/solid/page-header.tsx +102 -0
- package/src/solid/pagination.tsx +111 -0
- package/src/solid/password-input.tsx +69 -0
- package/src/solid/picker-row.tsx +102 -0
- package/src/solid/picker-search.tsx +78 -0
- package/src/solid/popover.tsx +103 -0
- package/src/solid/progress.tsx +31 -0
- package/src/solid/radio-group.tsx +60 -0
- package/src/solid/resizable.tsx +149 -0
- package/src/solid/responsive-dialog.tsx +180 -0
- package/src/solid/schema-form.tsx +830 -0
- package/src/solid/scope-indicator.tsx +13 -0
- package/src/solid/scroll-area.tsx +27 -0
- package/src/solid/section-card.tsx +358 -0
- package/src/solid/select.tsx +139 -0
- package/src/solid/separator.tsx +35 -0
- package/src/solid/settings-row.tsx +159 -0
- package/src/solid/sheet.tsx +157 -0
- package/src/solid/skeleton.tsx +15 -0
- package/src/solid/slider.tsx +148 -0
- package/src/solid/sliding-indicator.tsx +294 -0
- package/src/solid/sonner.tsx +219 -0
- package/src/solid/spinner.tsx +20 -0
- package/src/solid/step-indicator.tsx +30 -0
- package/src/solid/switch.tsx +62 -0
- package/src/solid/table.tsx +98 -0
- package/src/solid/tabs.tsx +86 -0
- package/src/solid/textarea.tsx +16 -0
- package/src/solid/toggle-group.tsx +102 -0
- package/src/solid/toggle.tsx +57 -0
- package/src/solid/tooltip.tsx +38 -0
- package/src/solid/widget-card.tsx +117 -0
- package/src/solid/widget-identity.tsx +135 -0
- package/src/solid/widget-trust-badge.tsx +37 -0
- package/src/tokens/hex.ts +50 -0
- package/src/tokens/index.ts +8 -0
- package/src/tokens/presets.ts +192 -0
- package/src/tokens/theme-colors.ts +147 -0
- package/dist/lib/carousel-init.d.ts +0 -9
- package/src/astro/Alert.astro +0 -63
- package/src/astro/Badge.astro +0 -18
- package/src/astro/Button.astro +0 -47
- package/src/astro/Card.astro +0 -48
- package/src/astro/Carousel.astro +0 -82
- package/src/astro/Logo.astro +0 -73
- package/src/astro/TierBadge.astro +0 -33
- package/src/lib/carousel-init.ts +0 -87
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { createMemo, createSignal, For, Show } from "solid-js";
|
|
2
|
+
import { MENU_ITEM } from "../lib/menu-classes.js";
|
|
3
|
+
import { STAGGER } from "../lib/motion-classes.js";
|
|
4
|
+
import { PICKER_LIST, PICKER_TRIGGER } from "../lib/picker-classes.js";
|
|
5
|
+
import { cn } from "../lib/utils.js";
|
|
6
|
+
import { useEntityData } from "./entity-data.js";
|
|
7
|
+
import { Icon } from "./icon.js";
|
|
8
|
+
import { PickerRow } from "./picker-row.js";
|
|
9
|
+
import { PickerSearch } from "./picker-search.js";
|
|
10
|
+
import { Popover, PopoverAnchor, PopoverContent } from "./popover.js";
|
|
11
|
+
import { SlidingIndicator } from "./sliding-indicator.js";
|
|
12
|
+
|
|
13
|
+
interface AreaPickerBaseProps {
|
|
14
|
+
placeholder?: string;
|
|
15
|
+
class?: string;
|
|
16
|
+
/** false: a re-tap on the picked area keeps it instead of clearing. */
|
|
17
|
+
allowClear?: boolean;
|
|
18
|
+
disabled?: boolean;
|
|
19
|
+
/** Id of the element naming the trigger, for forms that label it outside. */
|
|
20
|
+
"aria-labelledby"?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface AreaPickerSingleProps extends AreaPickerBaseProps {
|
|
24
|
+
value: string;
|
|
25
|
+
onChange: (value: string) => void;
|
|
26
|
+
values?: undefined;
|
|
27
|
+
onValuesChange?: undefined;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
interface AreaPickerMultiProps extends AreaPickerBaseProps {
|
|
31
|
+
values: string[];
|
|
32
|
+
onValuesChange: (values: string[]) => void;
|
|
33
|
+
value?: undefined;
|
|
34
|
+
onChange?: undefined;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
type AreaPickerProps = AreaPickerSingleProps | AreaPickerMultiProps;
|
|
38
|
+
|
|
39
|
+
export function AreaPicker(props: AreaPickerProps) {
|
|
40
|
+
const data = useEntityData();
|
|
41
|
+
const [open, setOpen] = createSignal(false);
|
|
42
|
+
const [search, setSearch] = createSignal("");
|
|
43
|
+
|
|
44
|
+
const areas = data.useAreas();
|
|
45
|
+
|
|
46
|
+
const areaList = createMemo(() =>
|
|
47
|
+
areas().map((a) => ({
|
|
48
|
+
id: a.id,
|
|
49
|
+
name: a.name,
|
|
50
|
+
icon: a.icon,
|
|
51
|
+
entityCount: a.entityIds.length,
|
|
52
|
+
})),
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
const filtered = createMemo(() => {
|
|
56
|
+
const q = search().trim().toLowerCase();
|
|
57
|
+
if (!q) return areaList();
|
|
58
|
+
return areaList().filter(
|
|
59
|
+
(a) => a.name.toLowerCase().includes(q) || a.id.toLowerCase().includes(q),
|
|
60
|
+
);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const multi = () => props.values !== undefined;
|
|
64
|
+
// Only ids the home still has: a stale grant shows as its own greyed row and
|
|
65
|
+
// leaves the value on the next toggle.
|
|
66
|
+
const selected = createMemo(() => {
|
|
67
|
+
const ids = props.values ?? [];
|
|
68
|
+
return ids.filter((id) => areaList().some((a) => a.id === id));
|
|
69
|
+
});
|
|
70
|
+
const missing = createMemo(() => {
|
|
71
|
+
const q = search().trim().toLowerCase();
|
|
72
|
+
return (props.values ?? [])
|
|
73
|
+
.filter((id) => !areaList().some((a) => a.id === id))
|
|
74
|
+
.filter((id) => !q || id.toLowerCase().includes(q));
|
|
75
|
+
});
|
|
76
|
+
const isSelected = (areaId: string) =>
|
|
77
|
+
multi() ? selected().includes(areaId) : props.value === areaId;
|
|
78
|
+
|
|
79
|
+
const triggerArea = createMemo(() => {
|
|
80
|
+
if (!multi()) {
|
|
81
|
+
const v = props.value;
|
|
82
|
+
return v ? areaList().find((a) => a.id === v) : undefined;
|
|
83
|
+
}
|
|
84
|
+
const only = selected();
|
|
85
|
+
return only.length === 1 ? areaList().find((a) => a.id === only[0]) : undefined;
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// One glass pill (SlidingIndicator) tracks the highlighted row and animates
|
|
89
|
+
// between rows, exactly like the Select. Hover wins; otherwise the pill rests
|
|
90
|
+
// on a selected row, which in multi mode is the first one still listed.
|
|
91
|
+
const [hovered, setHovered] = createSignal<string | null>(null);
|
|
92
|
+
const restingId = createMemo(() => {
|
|
93
|
+
const list = filtered();
|
|
94
|
+
if (!multi()) return list.some((a) => a.id === props.value) ? (props.value ?? null) : null;
|
|
95
|
+
const ids = selected();
|
|
96
|
+
return list.find((a) => ids.includes(a.id))?.id ?? null;
|
|
97
|
+
});
|
|
98
|
+
const highlightedId = () => hovered() ?? restingId();
|
|
99
|
+
|
|
100
|
+
// A re-tap on the picked area clears it, the way every other picker toggles.
|
|
101
|
+
const selectArea = (areaId: string) => {
|
|
102
|
+
if (props.disabled) return;
|
|
103
|
+
props.onChange?.(areaId === props.value && props.allowClear !== false ? "" : areaId);
|
|
104
|
+
setOpen(false);
|
|
105
|
+
setSearch("");
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const toggleArea = (areaId: string) => {
|
|
109
|
+
if (props.disabled) return;
|
|
110
|
+
const current = selected();
|
|
111
|
+
props.onValuesChange?.(
|
|
112
|
+
current.includes(areaId) ? current.filter((id) => id !== areaId) : [...current, areaId],
|
|
113
|
+
);
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
return (
|
|
117
|
+
<Popover
|
|
118
|
+
surface="field"
|
|
119
|
+
open={open()}
|
|
120
|
+
onOpenChange={(isOpen) => {
|
|
121
|
+
if (!isOpen) {
|
|
122
|
+
setOpen(false);
|
|
123
|
+
setSearch("");
|
|
124
|
+
}
|
|
125
|
+
}}
|
|
126
|
+
modal
|
|
127
|
+
>
|
|
128
|
+
<PopoverAnchor as="div" class={props.class}>
|
|
129
|
+
<button
|
|
130
|
+
type="button"
|
|
131
|
+
data-slot="area-picker-trigger"
|
|
132
|
+
data-expanded={open() || undefined}
|
|
133
|
+
aria-labelledby={props["aria-labelledby"]}
|
|
134
|
+
class={PICKER_TRIGGER}
|
|
135
|
+
disabled={props.disabled}
|
|
136
|
+
onClick={() => setOpen(!open())}
|
|
137
|
+
>
|
|
138
|
+
<Show
|
|
139
|
+
when={triggerArea()}
|
|
140
|
+
fallback={
|
|
141
|
+
<Show
|
|
142
|
+
when={selected().length > 1}
|
|
143
|
+
fallback={
|
|
144
|
+
<span class="flex-1 text-left text-muted-foreground">
|
|
145
|
+
{props.placeholder ?? (multi() ? "Select areas..." : "Select area...")}
|
|
146
|
+
</span>
|
|
147
|
+
}
|
|
148
|
+
>
|
|
149
|
+
<span class="flex-1 truncate text-left">{selected().length} rooms</span>
|
|
150
|
+
</Show>
|
|
151
|
+
}
|
|
152
|
+
>
|
|
153
|
+
{(area) => (
|
|
154
|
+
<>
|
|
155
|
+
<div class="flex size-4 shrink-0 items-center justify-center">
|
|
156
|
+
<Icon icon={area().icon || "mdi:home-floor-1"} width={16} height={16} />
|
|
157
|
+
</div>
|
|
158
|
+
<span class="flex-1 truncate text-left">{area().name}</span>
|
|
159
|
+
</>
|
|
160
|
+
)}
|
|
161
|
+
</Show>
|
|
162
|
+
<Icon
|
|
163
|
+
icon="mdi:chevron-down"
|
|
164
|
+
width={16}
|
|
165
|
+
height={16}
|
|
166
|
+
class="shrink-0 text-muted-foreground"
|
|
167
|
+
/>
|
|
168
|
+
</button>
|
|
169
|
+
</PopoverAnchor>
|
|
170
|
+
<PopoverContent
|
|
171
|
+
onOpenAutoFocus={(e) => e.preventDefault()}
|
|
172
|
+
onInteractOutside={() => setOpen(false)}
|
|
173
|
+
>
|
|
174
|
+
<div class="flex flex-col">
|
|
175
|
+
<PickerSearch
|
|
176
|
+
value={search()}
|
|
177
|
+
onValueChange={setSearch}
|
|
178
|
+
placeholder="Search areas..."
|
|
179
|
+
aria-label="Search areas"
|
|
180
|
+
/>
|
|
181
|
+
<SlidingIndicator
|
|
182
|
+
activeSelector="[data-highlighted]"
|
|
183
|
+
orientation="vertical"
|
|
184
|
+
indicatorClass="rounded-sm"
|
|
185
|
+
class={cn("flex flex-col gap-0.5 p-1", STAGGER, PICKER_LIST)}
|
|
186
|
+
onMouseLeave={() => setHovered(null)}
|
|
187
|
+
>
|
|
188
|
+
<Show when={filtered().length === 0 && missing().length === 0}>
|
|
189
|
+
<div class="py-4 text-center text-muted-foreground text-sm">No areas found</div>
|
|
190
|
+
</Show>
|
|
191
|
+
<For each={missing()}>
|
|
192
|
+
{(areaId) => (
|
|
193
|
+
<div
|
|
194
|
+
data-slot="area-picker-missing"
|
|
195
|
+
class={cn(MENU_ITEM, "text-muted-foreground/60")}
|
|
196
|
+
>
|
|
197
|
+
<span class="truncate">{areaId}</span>
|
|
198
|
+
<span class="shrink-0 text-xs">no longer exists</span>
|
|
199
|
+
</div>
|
|
200
|
+
)}
|
|
201
|
+
</For>
|
|
202
|
+
<For each={filtered()}>
|
|
203
|
+
{(area) => (
|
|
204
|
+
<PickerRow
|
|
205
|
+
as="button"
|
|
206
|
+
type="button"
|
|
207
|
+
data-slot="area-picker-row"
|
|
208
|
+
data-highlighted={highlightedId() === area.id || undefined}
|
|
209
|
+
aria-pressed={multi() ? isSelected(area.id) : undefined}
|
|
210
|
+
icon={area.icon || "mdi:home-floor-1"}
|
|
211
|
+
title={area.name}
|
|
212
|
+
subtitle={`${area.entityCount} ${area.entityCount === 1 ? "entity" : "entities"}`}
|
|
213
|
+
selected={isSelected(area.id)}
|
|
214
|
+
multi={multi()}
|
|
215
|
+
onMouseEnter={() => setHovered(area.id)}
|
|
216
|
+
onClick={() => (multi() ? toggleArea(area.id) : selectArea(area.id))}
|
|
217
|
+
/>
|
|
218
|
+
)}
|
|
219
|
+
</For>
|
|
220
|
+
</SlidingIndicator>
|
|
221
|
+
</div>
|
|
222
|
+
</PopoverContent>
|
|
223
|
+
</Popover>
|
|
224
|
+
);
|
|
225
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type ParentComponent, splitProps } from "solid-js";
|
|
2
|
+
import { cn } from "../lib/utils.js";
|
|
3
|
+
|
|
4
|
+
const AspectRatio: ParentComponent<{
|
|
5
|
+
class?: string;
|
|
6
|
+
ratio?: number;
|
|
7
|
+
}> = (props) => {
|
|
8
|
+
const [local, rest] = splitProps(props, ["class", "ratio", "children"]);
|
|
9
|
+
return (
|
|
10
|
+
<div
|
|
11
|
+
data-slot="aspect-ratio"
|
|
12
|
+
class={cn("relative w-full", local.class)}
|
|
13
|
+
style={{ "aspect-ratio": String(local.ratio ?? 1) }}
|
|
14
|
+
{...rest}
|
|
15
|
+
>
|
|
16
|
+
{local.children}
|
|
17
|
+
</div>
|
|
18
|
+
);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export { AspectRatio };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Image as ImagePrimitive } from "@kobalte/core/image";
|
|
2
|
+
import { type Component, type ComponentProps, splitProps } from "solid-js";
|
|
3
|
+
import { cn } from "../lib/utils.js";
|
|
4
|
+
|
|
5
|
+
const Avatar: Component<ComponentProps<typeof ImagePrimitive>> = (props) => {
|
|
6
|
+
const [local, rest] = splitProps(props, ["class"]);
|
|
7
|
+
return (
|
|
8
|
+
<ImagePrimitive
|
|
9
|
+
data-slot="avatar"
|
|
10
|
+
class={cn("relative flex size-10 shrink-0 overflow-hidden rounded-full", local.class)}
|
|
11
|
+
{...rest}
|
|
12
|
+
/>
|
|
13
|
+
);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const AvatarImage: Component<ComponentProps<typeof ImagePrimitive.Img>> = (props) => {
|
|
17
|
+
const [local, rest] = splitProps(props, ["class"]);
|
|
18
|
+
return (
|
|
19
|
+
<ImagePrimitive.Img
|
|
20
|
+
data-slot="avatar-image"
|
|
21
|
+
class={cn("aspect-square size-full", local.class)}
|
|
22
|
+
{...rest}
|
|
23
|
+
/>
|
|
24
|
+
);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const AvatarFallback: Component<ComponentProps<typeof ImagePrimitive.Fallback>> = (props) => {
|
|
28
|
+
const [local, rest] = splitProps(props, ["class"]);
|
|
29
|
+
return (
|
|
30
|
+
<ImagePrimitive.Fallback
|
|
31
|
+
data-slot="avatar-fallback"
|
|
32
|
+
class={cn(
|
|
33
|
+
"glass flex size-full items-center justify-center rounded-full font-semibold [--glass-tone:var(--primary)]",
|
|
34
|
+
local.class,
|
|
35
|
+
)}
|
|
36
|
+
{...rest}
|
|
37
|
+
/>
|
|
38
|
+
);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export { Avatar, AvatarFallback, AvatarImage };
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { type Component, type ComponentProps, splitProps, type ValidComponent } from "solid-js";
|
|
2
|
+
import { Dynamic } from "solid-js/web";
|
|
3
|
+
import { BADGE_DEFAULT_TONE, BADGE_NEUTRAL_KNOBS } from "../lib/badge-tone.js";
|
|
4
|
+
import { isNeutralTone } from "../lib/glass-tone.js";
|
|
5
|
+
import { CHIP } from "../lib/pill-classes.js";
|
|
6
|
+
import { TIER_BADGE_CLASS, tierBadgeStyle } from "../lib/tier-badge.js";
|
|
7
|
+
import { cn } from "../lib/utils.js";
|
|
8
|
+
|
|
9
|
+
type BadgeProps = ComponentProps<"span"> &
|
|
10
|
+
Partial<Pick<ComponentProps<"a">, "href" | "target" | "rel">> & {
|
|
11
|
+
as?: ValidComponent;
|
|
12
|
+
/** Any CSS color (semantic token or arbitrary hue). Defaults to var(--primary). */
|
|
13
|
+
tone?: string;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const Badge: Component<BadgeProps> = (props) => {
|
|
17
|
+
const [local, others] = splitProps(props, ["class", "as", "tone", "children", "style"]);
|
|
18
|
+
const Comp = () => local.as || "span";
|
|
19
|
+
const c = () => local.tone ?? BADGE_DEFAULT_TONE;
|
|
20
|
+
return (
|
|
21
|
+
<Dynamic
|
|
22
|
+
component={Comp()}
|
|
23
|
+
data-slot="badge"
|
|
24
|
+
class={cn(CHIP, isNeutralTone(c()) && BADGE_NEUTRAL_KNOBS, local.class)}
|
|
25
|
+
style={{ "--glass-tone": c(), ...(local.style as Record<string, string>) }}
|
|
26
|
+
{...others}
|
|
27
|
+
>
|
|
28
|
+
{local.children}
|
|
29
|
+
</Dynamic>
|
|
30
|
+
);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
type TierBadgeProps = ComponentProps<"span"> & {
|
|
34
|
+
/** Gradient high stop (the near end of the diagonal sweep, and by default
|
|
35
|
+
* the far end too). */
|
|
36
|
+
hi: string;
|
|
37
|
+
/** Gradient low stop (the dip). */
|
|
38
|
+
lo: string;
|
|
39
|
+
/** Dark label color. */
|
|
40
|
+
text: string;
|
|
41
|
+
/** Far end of the sweep. Default: `hi` (symmetric brushed look). */
|
|
42
|
+
end?: string;
|
|
43
|
+
/** Where `lo` sits, in percent. Default: 50. */
|
|
44
|
+
stop?: number;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Metallic tier chip (PRO / EARLY BIRD / CREATOR): a brushed-metal pill with a
|
|
49
|
+
* 135deg corner-to-corner sweep (bright ends, dip in the middle) and dark text.
|
|
50
|
+
* One family; only the hi/lo/text triplet changes per tier.
|
|
51
|
+
*/
|
|
52
|
+
const TierBadge: Component<TierBadgeProps> = (props) => {
|
|
53
|
+
const [local, others] = splitProps(props, [
|
|
54
|
+
"class",
|
|
55
|
+
"hi",
|
|
56
|
+
"lo",
|
|
57
|
+
"text",
|
|
58
|
+
"end",
|
|
59
|
+
"stop",
|
|
60
|
+
"children",
|
|
61
|
+
]);
|
|
62
|
+
return (
|
|
63
|
+
<span
|
|
64
|
+
data-slot="tier-badge"
|
|
65
|
+
class={cn(TIER_BADGE_CLASS, local.class)}
|
|
66
|
+
style={tierBadgeStyle(local.hi, local.lo, local.text, { end: local.end, stop: local.stop })}
|
|
67
|
+
{...others}
|
|
68
|
+
>
|
|
69
|
+
{local.children}
|
|
70
|
+
</span>
|
|
71
|
+
);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export { Badge, TierBadge };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// Decides drag vs scroll. Walks event.target ancestors; if any scrollable
|
|
2
|
+
// ancestor can still scroll in the drag direction, yield to scroll.
|
|
3
|
+
// Markers: data-sheet-no-drag (abort), data-sheet-scroll (force scrollable).
|
|
4
|
+
|
|
5
|
+
type Direction = "down" | "up";
|
|
6
|
+
|
|
7
|
+
function isScrollableAxis(el: Element): boolean {
|
|
8
|
+
if (el.hasAttribute("data-sheet-scroll")) return true;
|
|
9
|
+
const overflowY = getComputedStyle(el).overflowY;
|
|
10
|
+
if (overflowY !== "auto" && overflowY !== "scroll" && overflowY !== "overlay") return false;
|
|
11
|
+
return el.scrollHeight > el.clientHeight;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function canScrollFurther(el: Element, dir: Direction): boolean {
|
|
15
|
+
if (dir === "down") return el.scrollTop > 0;
|
|
16
|
+
return el.scrollTop + el.clientHeight < el.scrollHeight - 1;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function hasNoDragAncestor(target: Element | null, root: Element): boolean {
|
|
20
|
+
let cur: Element | null = target;
|
|
21
|
+
while (cur && cur !== root.parentElement) {
|
|
22
|
+
if (cur.hasAttribute("data-sheet-no-drag")) return true;
|
|
23
|
+
cur = cur.parentElement;
|
|
24
|
+
}
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function shouldDrag(target: Element | null, root: Element, dy: number, dx: number): boolean {
|
|
29
|
+
if (Math.abs(dx) > Math.abs(dy)) return false;
|
|
30
|
+
if (hasNoDragAncestor(target, root)) return false;
|
|
31
|
+
|
|
32
|
+
const dir: Direction = dy > 0 ? "down" : "up";
|
|
33
|
+
let cur: Element | null = target;
|
|
34
|
+
while (cur && cur !== root.parentElement) {
|
|
35
|
+
if (isScrollableAxis(cur) && canScrollFurther(cur, dir)) return false;
|
|
36
|
+
if (cur === root) break;
|
|
37
|
+
cur = cur.parentElement;
|
|
38
|
+
}
|
|
39
|
+
return true;
|
|
40
|
+
}
|