@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,302 @@
|
|
|
1
|
+
import EmblaCarousel, {
|
|
2
|
+
type EmblaCarouselType,
|
|
3
|
+
type EmblaOptionsType,
|
|
4
|
+
type EmblaPluginType,
|
|
5
|
+
} from "embla-carousel";
|
|
6
|
+
import Autoplay from "embla-carousel-autoplay";
|
|
7
|
+
import Fade from "embla-carousel-fade";
|
|
8
|
+
import {
|
|
9
|
+
type Accessor,
|
|
10
|
+
type Component,
|
|
11
|
+
type ComponentProps,
|
|
12
|
+
createContext,
|
|
13
|
+
createEffect,
|
|
14
|
+
createSignal,
|
|
15
|
+
onCleanup,
|
|
16
|
+
type ParentComponent,
|
|
17
|
+
splitProps,
|
|
18
|
+
useContext,
|
|
19
|
+
} from "solid-js";
|
|
20
|
+
import {
|
|
21
|
+
CAROUSEL_DOTS,
|
|
22
|
+
CAROUSEL_VIEWPORT,
|
|
23
|
+
type CarouselTransition,
|
|
24
|
+
carouselDot,
|
|
25
|
+
carouselItem,
|
|
26
|
+
carouselTrack,
|
|
27
|
+
} from "../lib/carousel-classes.js";
|
|
28
|
+
import { cn } from "../lib/utils.js";
|
|
29
|
+
import { Button } from "./button.js";
|
|
30
|
+
import { Icon } from "./icon.js";
|
|
31
|
+
|
|
32
|
+
type CarouselApi = EmblaCarouselType;
|
|
33
|
+
|
|
34
|
+
interface CarouselContextProps {
|
|
35
|
+
viewportRef: (el: HTMLDivElement) => void;
|
|
36
|
+
api: Accessor<CarouselApi | undefined>;
|
|
37
|
+
scrollPrev: () => void;
|
|
38
|
+
scrollNext: () => void;
|
|
39
|
+
canScrollPrev: Accessor<boolean>;
|
|
40
|
+
canScrollNext: Accessor<boolean>;
|
|
41
|
+
orientation: Accessor<"horizontal" | "vertical">;
|
|
42
|
+
transition: Accessor<CarouselTransition>;
|
|
43
|
+
selected: Accessor<number>;
|
|
44
|
+
slideCount: Accessor<number>;
|
|
45
|
+
scrollTo: (index: number) => void;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const CarouselContext = createContext<CarouselContextProps>();
|
|
49
|
+
|
|
50
|
+
function useCarousel() {
|
|
51
|
+
const context = useContext(CarouselContext);
|
|
52
|
+
if (!context) {
|
|
53
|
+
throw new Error("useCarousel must be used within a <Carousel />");
|
|
54
|
+
}
|
|
55
|
+
return context;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const Carousel: ParentComponent<
|
|
59
|
+
ComponentProps<"div"> & {
|
|
60
|
+
opts?: EmblaOptionsType;
|
|
61
|
+
plugins?: EmblaPluginType[];
|
|
62
|
+
orientation?: "horizontal" | "vertical";
|
|
63
|
+
transition?: CarouselTransition;
|
|
64
|
+
/** Advance every N ms. Ignored under prefers-reduced-motion. */
|
|
65
|
+
autoplay?: number;
|
|
66
|
+
setApi?: (api: CarouselApi) => void;
|
|
67
|
+
}
|
|
68
|
+
> = (props) => {
|
|
69
|
+
const [local, rest] = splitProps(props, [
|
|
70
|
+
"class",
|
|
71
|
+
"children",
|
|
72
|
+
"opts",
|
|
73
|
+
"plugins",
|
|
74
|
+
"orientation",
|
|
75
|
+
"transition",
|
|
76
|
+
"autoplay",
|
|
77
|
+
"setApi",
|
|
78
|
+
]);
|
|
79
|
+
const orientation = () => local.orientation ?? "horizontal";
|
|
80
|
+
const transition = () => local.transition ?? "slide";
|
|
81
|
+
let viewportEl: HTMLDivElement | undefined;
|
|
82
|
+
const [api, setApi] = createSignal<CarouselApi>();
|
|
83
|
+
const [canScrollPrev, setCanScrollPrev] = createSignal(false);
|
|
84
|
+
const [canScrollNext, setCanScrollNext] = createSignal(false);
|
|
85
|
+
const [selected, setSelected] = createSignal(0);
|
|
86
|
+
const [slideCount, setSlideCount] = createSignal(0);
|
|
87
|
+
|
|
88
|
+
const viewportRef = (el: HTMLDivElement) => {
|
|
89
|
+
viewportEl = el;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
// Tracks autoplay: a widget whose config changes the interval (or supplies one
|
|
93
|
+
// after the first mount) gets a re-initialised engine, old timers destroyed.
|
|
94
|
+
createEffect(() => {
|
|
95
|
+
const delay = local.autoplay;
|
|
96
|
+
if (!viewportEl) return;
|
|
97
|
+
// Reduced motion keeps the carousel usable but stops it moving on its own.
|
|
98
|
+
const reduced = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
99
|
+
const plugins = [...(local.plugins ?? [])];
|
|
100
|
+
if (transition() !== "slide") plugins.push(Fade());
|
|
101
|
+
if (delay && !reduced) {
|
|
102
|
+
// Manual nav should not kill autoplay for good; hover/focus pauses it.
|
|
103
|
+
plugins.push(
|
|
104
|
+
Autoplay({
|
|
105
|
+
delay,
|
|
106
|
+
stopOnInteraction: false,
|
|
107
|
+
stopOnMouseEnter: true,
|
|
108
|
+
stopOnFocusIn: true,
|
|
109
|
+
}),
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
const embla = EmblaCarousel(
|
|
113
|
+
viewportEl,
|
|
114
|
+
{ axis: orientation() === "horizontal" ? "x" : "y", ...local.opts },
|
|
115
|
+
plugins,
|
|
116
|
+
);
|
|
117
|
+
setApi(embla);
|
|
118
|
+
local.setApi?.(embla);
|
|
119
|
+
|
|
120
|
+
let previous = -1;
|
|
121
|
+
const onSelect = () => {
|
|
122
|
+
setCanScrollPrev(embla.canScrollPrev());
|
|
123
|
+
setCanScrollNext(embla.canScrollNext());
|
|
124
|
+
setSelected(embla.selectedScrollSnap());
|
|
125
|
+
setSlideCount(embla.scrollSnapList().length);
|
|
126
|
+
// Slides carry their own selected state so CSS (wipe) can key off it;
|
|
127
|
+
// embla itself only drives transform and opacity. data-prev keeps the
|
|
128
|
+
// outgoing slide one layer down until the sweep lands.
|
|
129
|
+
const active = embla.selectedScrollSnap();
|
|
130
|
+
embla.slideNodes().forEach((node, i) => {
|
|
131
|
+
node.toggleAttribute("data-selected", i === active);
|
|
132
|
+
node.toggleAttribute("data-prev", i === previous && i !== active);
|
|
133
|
+
});
|
|
134
|
+
previous = active;
|
|
135
|
+
};
|
|
136
|
+
onSelect();
|
|
137
|
+
embla.on("reInit", onSelect);
|
|
138
|
+
embla.on("select", onSelect);
|
|
139
|
+
|
|
140
|
+
onCleanup(() => embla.destroy());
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
const scrollPrev = () => api()?.scrollPrev();
|
|
144
|
+
const scrollNext = () => api()?.scrollNext();
|
|
145
|
+
const scrollTo = (index: number) => api()?.scrollTo(index);
|
|
146
|
+
|
|
147
|
+
const handleKeyDown = (e: KeyboardEvent) => {
|
|
148
|
+
if (e.key === "ArrowLeft") {
|
|
149
|
+
e.preventDefault();
|
|
150
|
+
scrollPrev();
|
|
151
|
+
} else if (e.key === "ArrowRight") {
|
|
152
|
+
e.preventDefault();
|
|
153
|
+
scrollNext();
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
return (
|
|
158
|
+
<CarouselContext.Provider
|
|
159
|
+
value={{
|
|
160
|
+
viewportRef,
|
|
161
|
+
api,
|
|
162
|
+
scrollPrev,
|
|
163
|
+
scrollNext,
|
|
164
|
+
canScrollPrev,
|
|
165
|
+
canScrollNext,
|
|
166
|
+
orientation,
|
|
167
|
+
transition,
|
|
168
|
+
selected,
|
|
169
|
+
slideCount,
|
|
170
|
+
scrollTo,
|
|
171
|
+
}}
|
|
172
|
+
>
|
|
173
|
+
{/* biome-ignore lint/a11y/useSemanticElements: role=region + aria-roledescription is the canonical ARIA carousel pattern; section would change document outline semantics. */}
|
|
174
|
+
<div
|
|
175
|
+
onKeyDown={handleKeyDown}
|
|
176
|
+
class={cn("relative", local.class)}
|
|
177
|
+
role="region"
|
|
178
|
+
aria-roledescription="carousel"
|
|
179
|
+
data-slot="carousel"
|
|
180
|
+
{...rest}
|
|
181
|
+
>
|
|
182
|
+
{local.children}
|
|
183
|
+
</div>
|
|
184
|
+
</CarouselContext.Provider>
|
|
185
|
+
);
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
const CarouselContent: Component<ComponentProps<"div">> = (props) => {
|
|
189
|
+
const [local, rest] = splitProps(props, ["class"]);
|
|
190
|
+
const { viewportRef, orientation, transition } = useCarousel();
|
|
191
|
+
|
|
192
|
+
return (
|
|
193
|
+
<div ref={viewportRef} class={CAROUSEL_VIEWPORT} data-slot="carousel-content">
|
|
194
|
+
<div
|
|
195
|
+
class={cn(carouselTrack(transition(), orientation()), local.class)}
|
|
196
|
+
data-transition={transition()}
|
|
197
|
+
{...rest}
|
|
198
|
+
/>
|
|
199
|
+
</div>
|
|
200
|
+
);
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
const CarouselItem: Component<ComponentProps<"div">> = (props) => {
|
|
204
|
+
const [local, rest] = splitProps(props, ["class"]);
|
|
205
|
+
const { orientation, transition } = useCarousel();
|
|
206
|
+
|
|
207
|
+
return (
|
|
208
|
+
// biome-ignore lint/a11y/useSemanticElements: role=group + aria-roledescription=slide is the canonical ARIA carousel slide; no HTML element maps to group.
|
|
209
|
+
<div
|
|
210
|
+
role="group"
|
|
211
|
+
aria-roledescription="slide"
|
|
212
|
+
data-slot="carousel-item"
|
|
213
|
+
class={cn(carouselItem(transition(), orientation()), local.class)}
|
|
214
|
+
{...rest}
|
|
215
|
+
/>
|
|
216
|
+
);
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
/** Slide indicators. Stays in sync with drag, autoplay, and prev/next alike. */
|
|
220
|
+
const CarouselDots: Component<ComponentProps<"div">> = (props) => {
|
|
221
|
+
const [local, rest] = splitProps(props, ["class"]);
|
|
222
|
+
const { selected, slideCount, scrollTo } = useCarousel();
|
|
223
|
+
|
|
224
|
+
return (
|
|
225
|
+
<div class={cn(CAROUSEL_DOTS, local.class)} data-slot="carousel-dots" {...rest}>
|
|
226
|
+
{Array.from({ length: slideCount() }, (_, i) => (
|
|
227
|
+
<button
|
|
228
|
+
type="button"
|
|
229
|
+
data-slot="carousel-dot"
|
|
230
|
+
data-active={selected() === i ? "" : undefined}
|
|
231
|
+
aria-label={`Go to slide ${i + 1}`}
|
|
232
|
+
aria-current={selected() === i}
|
|
233
|
+
class={carouselDot(selected() === i)}
|
|
234
|
+
onClick={() => scrollTo(i)}
|
|
235
|
+
/>
|
|
236
|
+
))}
|
|
237
|
+
</div>
|
|
238
|
+
);
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
const CarouselPrevious: Component<ComponentProps<typeof Button>> = (props) => {
|
|
242
|
+
const [local, rest] = splitProps(props, ["class", "variant", "size"]);
|
|
243
|
+
const { orientation, scrollPrev, canScrollPrev } = useCarousel();
|
|
244
|
+
|
|
245
|
+
return (
|
|
246
|
+
<Button
|
|
247
|
+
data-slot="carousel-previous"
|
|
248
|
+
variant={local.variant ?? "outline"}
|
|
249
|
+
size={local.size ?? "icon"}
|
|
250
|
+
class={cn(
|
|
251
|
+
"absolute size-8 rounded-full",
|
|
252
|
+
orientation() === "horizontal"
|
|
253
|
+
? "top-1/2 -left-12 -translate-y-1/2"
|
|
254
|
+
: "-top-12 left-1/2 -translate-x-1/2 rotate-90",
|
|
255
|
+
local.class,
|
|
256
|
+
)}
|
|
257
|
+
disabled={!canScrollPrev()}
|
|
258
|
+
onClick={scrollPrev}
|
|
259
|
+
{...rest}
|
|
260
|
+
>
|
|
261
|
+
<Icon icon="lucide:arrow-left" width={16} height={16} />
|
|
262
|
+
<span class="sr-only">Previous slide</span>
|
|
263
|
+
</Button>
|
|
264
|
+
);
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
const CarouselNext: Component<ComponentProps<typeof Button>> = (props) => {
|
|
268
|
+
const [local, rest] = splitProps(props, ["class", "variant", "size"]);
|
|
269
|
+
const { orientation, scrollNext, canScrollNext } = useCarousel();
|
|
270
|
+
|
|
271
|
+
return (
|
|
272
|
+
<Button
|
|
273
|
+
data-slot="carousel-next"
|
|
274
|
+
variant={local.variant ?? "outline"}
|
|
275
|
+
size={local.size ?? "icon"}
|
|
276
|
+
class={cn(
|
|
277
|
+
"absolute size-8 rounded-full",
|
|
278
|
+
orientation() === "horizontal"
|
|
279
|
+
? "top-1/2 -right-12 -translate-y-1/2"
|
|
280
|
+
: "-bottom-12 left-1/2 -translate-x-1/2 rotate-90",
|
|
281
|
+
local.class,
|
|
282
|
+
)}
|
|
283
|
+
disabled={!canScrollNext()}
|
|
284
|
+
onClick={scrollNext}
|
|
285
|
+
{...rest}
|
|
286
|
+
>
|
|
287
|
+
<Icon icon="lucide:arrow-right" width={16} height={16} />
|
|
288
|
+
<span class="sr-only">Next slide</span>
|
|
289
|
+
</Button>
|
|
290
|
+
);
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
export {
|
|
294
|
+
Carousel,
|
|
295
|
+
type CarouselApi,
|
|
296
|
+
CarouselContent,
|
|
297
|
+
CarouselDots,
|
|
298
|
+
CarouselItem,
|
|
299
|
+
CarouselNext,
|
|
300
|
+
CarouselPrevious,
|
|
301
|
+
type CarouselTransition,
|
|
302
|
+
};
|
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
import { createMemo, createSignal, createUniqueId, For, Show } from "solid-js";
|
|
2
|
+
import { FIELD_CHROME } from "../lib/input-classes.js";
|
|
3
|
+
import { cn } from "../lib/utils.js";
|
|
4
|
+
import { Overlay } from "./overlay.js";
|
|
5
|
+
import { Tabs, TabsList, TabsTrigger } from "./tabs.js";
|
|
6
|
+
|
|
7
|
+
const numberFmt = new Intl.NumberFormat("en-US");
|
|
8
|
+
|
|
9
|
+
/* Bars and chart backings wear the field chrome so a ranked bar reads as a
|
|
10
|
+
* static slider; fills are the slider's own tinted glass. One radius for the
|
|
11
|
+
* pill-shaped wells (BarList/StackedBar); AreaChart's rectangular sparkline
|
|
12
|
+
* background is a legitimately different shape and keeps its own rounded-xl. */
|
|
13
|
+
const SLIDER_WELL = FIELD_CHROME;
|
|
14
|
+
const SLIDER_WELL_RADIUS = "rounded-full";
|
|
15
|
+
const SLIDER_FILL = "glass glass-tint [--glass-tone:var(--primary)]";
|
|
16
|
+
|
|
17
|
+
function formatDayLabel(day: string): string {
|
|
18
|
+
// `day` is a "YYYY-MM-DD" UTC key; render as e.g. "Jul 1".
|
|
19
|
+
const d = new Date(`${day}T00:00:00Z`);
|
|
20
|
+
if (Number.isNaN(d.getTime())) return day;
|
|
21
|
+
return d.toLocaleDateString("en-US", { month: "short", day: "numeric", timeZone: "UTC" });
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function formatCompact(n: number): string {
|
|
25
|
+
if (!Number.isFinite(n)) return "0";
|
|
26
|
+
if (Math.abs(n) >= 1000) return `${(n / 1000).toFixed(1).replace(/\.0$/, "")}k`;
|
|
27
|
+
return numberFmt.format(n);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const BYTE_UNITS: [string, number][] = [
|
|
31
|
+
["GB", 1024 ** 3],
|
|
32
|
+
["MB", 1024 ** 2],
|
|
33
|
+
["KB", 1024],
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
export function formatBytes(bytes: number): string {
|
|
37
|
+
if (!(bytes > 0)) return "0 KB";
|
|
38
|
+
const [unit, size] = BYTE_UNITS.find(([, s]) => bytes >= s) ?? ["KB", 1024];
|
|
39
|
+
const val = bytes / size;
|
|
40
|
+
return `${val.toFixed(Number(val < 10))} ${unit}`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Filled area + line chart for a daily series. `data` is oldest-first
|
|
45
|
+
* [{day,count}]. Renders a scaling SVG; the caller sizes the container.
|
|
46
|
+
*/
|
|
47
|
+
const CHART_H = 32;
|
|
48
|
+
|
|
49
|
+
type ChartGeom = { line: string; area: string; max: number; yFrac: number[] };
|
|
50
|
+
|
|
51
|
+
function chartGeom(data: { count: number }[]): ChartGeom | null {
|
|
52
|
+
if (data.length < 2) return null;
|
|
53
|
+
const max = Math.max(1, ...data.map((p) => p.count));
|
|
54
|
+
const step = 100 / (data.length - 1);
|
|
55
|
+
// yFrac: vertical position as a 0..1 fraction of the box (0 = top), reused by
|
|
56
|
+
// the HTML hover marker so it lines up with the SVG.
|
|
57
|
+
const yFrac = data.map((p) => (CHART_H - 1 - (p.count / max) * (CHART_H - 2)) / CHART_H);
|
|
58
|
+
const coords = data.map(
|
|
59
|
+
(_, i) => `${(i * step).toFixed(2)},${((yFrac[i] ?? 0) * CHART_H).toFixed(2)}`,
|
|
60
|
+
);
|
|
61
|
+
return {
|
|
62
|
+
line: coords.join(" "),
|
|
63
|
+
area: `0,${CHART_H} ${coords.join(" ")} 100,${CHART_H}`,
|
|
64
|
+
max,
|
|
65
|
+
yFrac,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Guide line + marker dot + tooltip for the hovered point, in HTML space. */
|
|
70
|
+
function ChartHover(props: {
|
|
71
|
+
point: { day: string; count: number };
|
|
72
|
+
leftPct: number;
|
|
73
|
+
topPct: number;
|
|
74
|
+
format?: (n: number) => string;
|
|
75
|
+
}) {
|
|
76
|
+
const label = () =>
|
|
77
|
+
props.format ? props.format(props.point.count) : numberFmt.format(props.point.count);
|
|
78
|
+
return (
|
|
79
|
+
<>
|
|
80
|
+
<div
|
|
81
|
+
class="pointer-events-none absolute inset-y-0 w-px bg-primary/30"
|
|
82
|
+
style={{ left: `${props.leftPct}%` }}
|
|
83
|
+
/>
|
|
84
|
+
<div
|
|
85
|
+
class="pointer-events-none absolute size-2 -translate-x-1/2 -translate-y-1/2 rounded-full border border-background bg-primary"
|
|
86
|
+
style={{ left: `${props.leftPct}%`, top: `${props.topPct}%` }}
|
|
87
|
+
/>
|
|
88
|
+
<Overlay
|
|
89
|
+
class="pointer-events-none absolute z-10 -translate-x-1/2 -translate-y-full whitespace-nowrap px-2 py-1 text-xs"
|
|
90
|
+
style={{
|
|
91
|
+
left: `${Math.min(92, Math.max(8, props.leftPct))}%`,
|
|
92
|
+
top: `${Math.max(0, props.topPct - 6)}%`,
|
|
93
|
+
}}
|
|
94
|
+
>
|
|
95
|
+
<span class="font-mono font-semibold tabular-nums">{label()}</span>
|
|
96
|
+
<span class="ml-1 text-muted-foreground">{formatDayLabel(props.point.day)}</span>
|
|
97
|
+
</Overlay>
|
|
98
|
+
</>
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Filled area + line chart for a daily series. `data` is oldest-first
|
|
104
|
+
* [{day,count}]. Renders a scaling SVG; the caller sizes the container.
|
|
105
|
+
*/
|
|
106
|
+
export function AreaChart(props: {
|
|
107
|
+
data: { day: string; count: number }[];
|
|
108
|
+
class?: string;
|
|
109
|
+
height?: number;
|
|
110
|
+
/** Tooltip value formatter (e.g. formatBytes for a size series). */
|
|
111
|
+
format?: (n: number) => string;
|
|
112
|
+
}) {
|
|
113
|
+
const geom = createMemo(() => chartGeom(props.data));
|
|
114
|
+
const height = () => props.height ?? 48;
|
|
115
|
+
const gid = createUniqueId();
|
|
116
|
+
const [hover, setHover] = createSignal<number | null>(null);
|
|
117
|
+
|
|
118
|
+
const onMove = (e: PointerEvent & { currentTarget: HTMLDivElement }) => {
|
|
119
|
+
if (props.data.length < 2) return;
|
|
120
|
+
const rect = e.currentTarget.getBoundingClientRect();
|
|
121
|
+
const ratio = Math.min(1, Math.max(0, (e.clientX - rect.left) / rect.width));
|
|
122
|
+
setHover(Math.round(ratio * (props.data.length - 1)));
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const leftPct = () => {
|
|
126
|
+
const h = hover();
|
|
127
|
+
return h == null ? 0 : (h / (props.data.length - 1)) * 100;
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
return (
|
|
131
|
+
<Show
|
|
132
|
+
when={geom()}
|
|
133
|
+
fallback={
|
|
134
|
+
<div
|
|
135
|
+
data-slot="area-chart"
|
|
136
|
+
class={cn("flex items-center justify-center text-muted-foreground text-xs", props.class)}
|
|
137
|
+
style={{ height: `${height()}px` }}
|
|
138
|
+
>
|
|
139
|
+
Not enough data yet
|
|
140
|
+
</div>
|
|
141
|
+
}
|
|
142
|
+
>
|
|
143
|
+
{(g) => (
|
|
144
|
+
<div
|
|
145
|
+
data-slot="area-chart"
|
|
146
|
+
class={cn("relative overflow-hidden rounded-xl px-px", SLIDER_WELL)}
|
|
147
|
+
style={{ height: `${height()}px` }}
|
|
148
|
+
onPointerMove={onMove}
|
|
149
|
+
onPointerLeave={() => setHover(null)}
|
|
150
|
+
>
|
|
151
|
+
<svg
|
|
152
|
+
viewBox="0 0 100 32"
|
|
153
|
+
preserveAspectRatio="none"
|
|
154
|
+
class={cn("h-full w-full text-primary", props.class)}
|
|
155
|
+
role="img"
|
|
156
|
+
aria-label={`Peak ${g().max} per day`}
|
|
157
|
+
>
|
|
158
|
+
<defs>
|
|
159
|
+
<linearGradient id={gid} x1="0" y1="0" x2="0" y2="1">
|
|
160
|
+
<stop offset="0%" stop-color="currentColor" stop-opacity="0.28" />
|
|
161
|
+
<stop offset="100%" stop-color="currentColor" stop-opacity="0" />
|
|
162
|
+
</linearGradient>
|
|
163
|
+
</defs>
|
|
164
|
+
<polygon points={g().area} fill={`url(#${gid})`} />
|
|
165
|
+
<polyline
|
|
166
|
+
points={g().line}
|
|
167
|
+
fill="none"
|
|
168
|
+
stroke="currentColor"
|
|
169
|
+
stroke-width="1.5"
|
|
170
|
+
stroke-linejoin="round"
|
|
171
|
+
vector-effect="non-scaling-stroke"
|
|
172
|
+
/>
|
|
173
|
+
</svg>
|
|
174
|
+
<Show when={hover() != null && props.data[hover() as number]}>
|
|
175
|
+
{(point) => (
|
|
176
|
+
<ChartHover
|
|
177
|
+
point={point()}
|
|
178
|
+
leftPct={leftPct()}
|
|
179
|
+
topPct={(g().yFrac[hover() as number] ?? 0) * 100}
|
|
180
|
+
format={props.format}
|
|
181
|
+
/>
|
|
182
|
+
)}
|
|
183
|
+
</Show>
|
|
184
|
+
</div>
|
|
185
|
+
)}
|
|
186
|
+
</Show>
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Horizontal bar list: one row per item, bar width proportional to `value`.
|
|
192
|
+
* `format` renders the trailing value label (defaults to compact number).
|
|
193
|
+
*/
|
|
194
|
+
export function BarList(props: {
|
|
195
|
+
items: { label: string; value: number; sublabel?: string; href?: string }[];
|
|
196
|
+
format?: (value: number) => string;
|
|
197
|
+
empty?: string;
|
|
198
|
+
}) {
|
|
199
|
+
const max = createMemo(() => Math.max(1, ...props.items.map((i) => i.value)));
|
|
200
|
+
const fmt = (v: number) => (props.format ? props.format(v) : formatCompact(v));
|
|
201
|
+
return (
|
|
202
|
+
<Show
|
|
203
|
+
when={props.items.length > 0}
|
|
204
|
+
fallback={
|
|
205
|
+
<div data-slot="bar-list" class="py-2 text-muted-foreground text-xs">
|
|
206
|
+
{props.empty ?? "No data"}
|
|
207
|
+
</div>
|
|
208
|
+
}
|
|
209
|
+
>
|
|
210
|
+
<div data-slot="bar-list" class="flex flex-col gap-1.5">
|
|
211
|
+
<For each={props.items}>
|
|
212
|
+
{(item) => {
|
|
213
|
+
const pct = () => `${Math.max(2, (item.value / max()) * 100).toFixed(1)}%`;
|
|
214
|
+
const Row = (
|
|
215
|
+
<div class="group flex items-center gap-2 text-xs">
|
|
216
|
+
<div
|
|
217
|
+
class={cn(
|
|
218
|
+
"relative min-w-0 flex-1 overflow-hidden",
|
|
219
|
+
SLIDER_WELL_RADIUS,
|
|
220
|
+
SLIDER_WELL,
|
|
221
|
+
)}
|
|
222
|
+
>
|
|
223
|
+
<div
|
|
224
|
+
class={cn(
|
|
225
|
+
"absolute inset-y-0 left-0 transition-[width]",
|
|
226
|
+
SLIDER_WELL_RADIUS,
|
|
227
|
+
SLIDER_FILL,
|
|
228
|
+
)}
|
|
229
|
+
style={{ width: pct() }}
|
|
230
|
+
/>
|
|
231
|
+
<div class="relative flex items-center justify-between gap-2 px-2 py-1">
|
|
232
|
+
<span class="truncate">{item.label}</span>
|
|
233
|
+
<Show when={item.sublabel}>
|
|
234
|
+
<span class="shrink-0 text-muted-foreground text-xs">{item.sublabel}</span>
|
|
235
|
+
</Show>
|
|
236
|
+
</div>
|
|
237
|
+
</div>
|
|
238
|
+
<span class="w-12 shrink-0 text-right font-mono tabular-nums">
|
|
239
|
+
{fmt(item.value)}
|
|
240
|
+
</span>
|
|
241
|
+
</div>
|
|
242
|
+
);
|
|
243
|
+
return item.href ? (
|
|
244
|
+
<a href={item.href} class="block hover:opacity-80">
|
|
245
|
+
{Row}
|
|
246
|
+
</a>
|
|
247
|
+
) : (
|
|
248
|
+
Row
|
|
249
|
+
);
|
|
250
|
+
}}
|
|
251
|
+
</For>
|
|
252
|
+
</div>
|
|
253
|
+
</Show>
|
|
254
|
+
);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const RANGE_OPTIONS = [
|
|
258
|
+
{ label: "7d", value: 7 },
|
|
259
|
+
{ label: "30d", value: 30 },
|
|
260
|
+
{ label: "90d", value: 90 },
|
|
261
|
+
{ label: "1y", value: 365 },
|
|
262
|
+
];
|
|
263
|
+
|
|
264
|
+
/** Segmented control for the chart time window — the shipped Tabs (sliding
|
|
265
|
+
* `.glass` primary indicator). Values are numeric days; Tabs speaks strings, so
|
|
266
|
+
* map at the edge. */
|
|
267
|
+
export function RangeToggle(props: { value: number; onChange: (days: number) => void }) {
|
|
268
|
+
return (
|
|
269
|
+
<Tabs value={String(props.value)} onChange={(v) => props.onChange(Number(v))}>
|
|
270
|
+
<TabsList class="w-auto">
|
|
271
|
+
<For each={RANGE_OPTIONS}>
|
|
272
|
+
{(opt) => <TabsTrigger value={String(opt.value)}>{opt.label}</TabsTrigger>}
|
|
273
|
+
</For>
|
|
274
|
+
</TabsList>
|
|
275
|
+
</Tabs>
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
type StackedBarSegment = {
|
|
280
|
+
label: string;
|
|
281
|
+
value: number;
|
|
282
|
+
/** CSS color driving the segment's own glass tint. */
|
|
283
|
+
tone?: string;
|
|
284
|
+
/** @deprecated pass `tone` instead */
|
|
285
|
+
class?: string;
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
function segmentClass(s: StackedBarSegment) {
|
|
289
|
+
return cn(s.tone && "glass glass-tint", s.class);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
function segmentStyle(s: StackedBarSegment) {
|
|
293
|
+
return s.tone ? { "--glass-tone": s.tone } : undefined;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/** Segmented proportion bar (e.g. staleness fresh/aging/stale). */
|
|
297
|
+
export function StackedBar(props: { segments: StackedBarSegment[] }) {
|
|
298
|
+
const total = createMemo(() => props.segments.reduce((a, s) => a + s.value, 0) || 1);
|
|
299
|
+
return (
|
|
300
|
+
<div data-slot="stacked-bar" class="flex flex-col gap-2">
|
|
301
|
+
<div class={cn("relative flex h-2.5 overflow-hidden", SLIDER_WELL_RADIUS, SLIDER_WELL)}>
|
|
302
|
+
<For each={props.segments}>
|
|
303
|
+
{(s) => (
|
|
304
|
+
<Show when={s.value > 0}>
|
|
305
|
+
<div
|
|
306
|
+
class={segmentClass(s)}
|
|
307
|
+
style={{ width: `${(s.value / total()) * 100}%`, ...segmentStyle(s) }}
|
|
308
|
+
title={`${s.label}: ${s.value}`}
|
|
309
|
+
/>
|
|
310
|
+
</Show>
|
|
311
|
+
)}
|
|
312
|
+
</For>
|
|
313
|
+
{/* re-laid over the opaque segments, which paint above the well's own
|
|
314
|
+
box-shadow, so the filled bar still catches light like glass. */}
|
|
315
|
+
<div
|
|
316
|
+
class={cn(
|
|
317
|
+
"pointer-events-none absolute inset-0 shadow-[inset_0_1px_0_oklch(1_0_0/var(--glass-rim))]",
|
|
318
|
+
SLIDER_WELL_RADIUS,
|
|
319
|
+
)}
|
|
320
|
+
/>
|
|
321
|
+
</div>
|
|
322
|
+
<div class="flex flex-wrap gap-x-3 gap-y-1 text-xs">
|
|
323
|
+
<For each={props.segments}>
|
|
324
|
+
{(s) => (
|
|
325
|
+
<span class="inline-flex items-center gap-1.5 text-muted-foreground">
|
|
326
|
+
<span
|
|
327
|
+
class={cn("inline-block size-2 rounded-full", segmentClass(s))}
|
|
328
|
+
style={segmentStyle(s)}
|
|
329
|
+
/>
|
|
330
|
+
{s.label}
|
|
331
|
+
<span class="font-mono text-foreground tabular-nums">{s.value}</span>
|
|
332
|
+
</span>
|
|
333
|
+
)}
|
|
334
|
+
</For>
|
|
335
|
+
</div>
|
|
336
|
+
</div>
|
|
337
|
+
);
|
|
338
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Checkbox as CheckboxPrimitive } from "@kobalte/core/checkbox";
|
|
2
|
+
import { type Component, type ComponentProps, type JSX, splitProps } from "solid-js";
|
|
3
|
+
import { FIELD_CHROME } from "../lib/input-classes.js";
|
|
4
|
+
import { cn } from "../lib/utils.js";
|
|
5
|
+
import { Icon } from "./icon.js";
|
|
6
|
+
|
|
7
|
+
/* Two box sizes and the glyph that fits each: `sm` is the row-embedded control
|
|
8
|
+
* (picker rows, dense lists), `default` the touch target of a standalone one. */
|
|
9
|
+
const CHECKBOX_SIZE = {
|
|
10
|
+
sm: { box: "size-5", glyph: "size-3.5", px: 14 },
|
|
11
|
+
default: { box: "size-7", glyph: "size-5", px: 20 },
|
|
12
|
+
} as const;
|
|
13
|
+
|
|
14
|
+
type CheckboxSize = keyof typeof CHECKBOX_SIZE;
|
|
15
|
+
|
|
16
|
+
const Checkbox: Component<ComponentProps<typeof CheckboxPrimitive> & { size?: CheckboxSize }> = (
|
|
17
|
+
props,
|
|
18
|
+
) => {
|
|
19
|
+
const [local, others] = splitProps(props, ["class", "children", "size"]);
|
|
20
|
+
const label = () => local.children as JSX.Element;
|
|
21
|
+
const size = () => CHECKBOX_SIZE[local.size ?? "default"];
|
|
22
|
+
return (
|
|
23
|
+
<CheckboxPrimitive data-slot="checkbox" {...others}>
|
|
24
|
+
{/* One <label> row: the box is a plain span, not a Kobalte Control, so a
|
|
25
|
+
click anywhere toggles exactly once. */}
|
|
26
|
+
{(state) => (
|
|
27
|
+
<CheckboxPrimitive.Label
|
|
28
|
+
data-slot="checkbox-label"
|
|
29
|
+
class="group inline-flex cursor-pointer select-none items-center gap-2.5 data-[disabled]:cursor-not-allowed"
|
|
30
|
+
>
|
|
31
|
+
<CheckboxPrimitive.Input class="peer" />
|
|
32
|
+
<span
|
|
33
|
+
aria-hidden="true"
|
|
34
|
+
data-slot="checkbox-box"
|
|
35
|
+
data-size={local.size ?? "default"}
|
|
36
|
+
class={cn(
|
|
37
|
+
"box-border inline-flex shrink-0 items-center justify-center overflow-hidden rounded-xs transition-glass duration-200 ease-out group-active:scale-90",
|
|
38
|
+
size().box,
|
|
39
|
+
"peer-focus-visible:ring-[3px] peer-focus-visible:ring-ring/50 peer-focus-visible:[--glass-edge:var(--ring)]",
|
|
40
|
+
state.checked()
|
|
41
|
+
? "glass glass-tint text-foreground [--glass-tone:var(--primary)]"
|
|
42
|
+
: FIELD_CHROME,
|
|
43
|
+
props.disabled && "cursor-not-allowed opacity-40",
|
|
44
|
+
local.class,
|
|
45
|
+
)}
|
|
46
|
+
>
|
|
47
|
+
{/* Always mounted so the box keeps constant height. */}
|
|
48
|
+
<Icon
|
|
49
|
+
icon="lucide:check"
|
|
50
|
+
width={size().px}
|
|
51
|
+
height={size().px}
|
|
52
|
+
class={cn(
|
|
53
|
+
size().glyph,
|
|
54
|
+
"transition-glass duration-200 ease-out",
|
|
55
|
+
state.checked() ? "scale-100 opacity-100" : "scale-0 opacity-0",
|
|
56
|
+
)}
|
|
57
|
+
/>
|
|
58
|
+
</span>
|
|
59
|
+
{local.children && (
|
|
60
|
+
<span data-slot="checkbox-text" class="text-sm leading-none">
|
|
61
|
+
{label()}
|
|
62
|
+
</span>
|
|
63
|
+
)}
|
|
64
|
+
</CheckboxPrimitive.Label>
|
|
65
|
+
)}
|
|
66
|
+
</CheckboxPrimitive>
|
|
67
|
+
);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export { Checkbox };
|