@underpin/ui 0.0.0 → 2.1.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/LICENSE +21 -0
- package/README.md +44 -1
- package/components/autocomplete.d.ts +25 -0
- package/components/autocomplete.js +71 -0
- package/components/autocomplete.js.map +1 -0
- package/components/avatar.d.ts +5 -0
- package/components/avatar.js +26 -0
- package/components/avatar.js.map +1 -0
- package/components/badge.d.ts +36 -0
- package/components/badge.js +140 -0
- package/components/badge.js.map +1 -0
- package/components/bar-list.d.ts +133 -0
- package/components/bar-list.js +204 -0
- package/components/bar-list.js.map +1 -0
- package/components/breakdown-card.d.ts +30 -0
- package/components/breakdown-card.js +43 -0
- package/components/breakdown-card.js.map +1 -0
- package/components/bulk-action-bar.d.ts +21 -0
- package/components/bulk-action-bar.js +38 -0
- package/components/bulk-action-bar.js.map +1 -0
- package/components/button-group.d.ts +21 -0
- package/components/button-group.js +32 -0
- package/components/button-group.js.map +1 -0
- package/components/button.d.ts +39 -0
- package/components/button.js +145 -0
- package/components/button.js.map +1 -0
- package/components/calendar.d.ts +27 -0
- package/components/calendar.js +95 -0
- package/components/calendar.js.map +1 -0
- package/components/callout.d.ts +26 -0
- package/components/callout.js +71 -0
- package/components/callout.js.map +1 -0
- package/components/card.d.ts +55 -0
- package/components/card.js +96 -0
- package/components/card.js.map +1 -0
- package/components/chart.d.ts +32 -0
- package/components/chart.js +43 -0
- package/components/chart.js.map +1 -0
- package/components/checkbox.d.ts +15 -0
- package/components/checkbox.js +42 -0
- package/components/checkbox.js.map +1 -0
- package/components/code-block.d.ts +21 -0
- package/components/code-block.js +35 -0
- package/components/code-block.js.map +1 -0
- package/components/collapse.d.ts +14 -0
- package/components/collapse.js +25 -0
- package/components/collapse.js.map +1 -0
- package/components/combobox.d.ts +71 -0
- package/components/combobox.js +155 -0
- package/components/combobox.js.map +1 -0
- package/components/copy-button.d.ts +29 -0
- package/components/copy-button.js +100 -0
- package/components/copy-button.js.map +1 -0
- package/components/copy-input.d.ts +15 -0
- package/components/copy-input.js +51 -0
- package/components/copy-input.js.map +1 -0
- package/components/data-table.d.ts +120 -0
- package/components/data-table.js +336 -0
- package/components/data-table.js.map +1 -0
- package/components/date-picker-trigger.d.ts +12 -0
- package/components/date-picker-trigger.js +30 -0
- package/components/date-picker-trigger.js.map +1 -0
- package/components/date-picker.d.ts +36 -0
- package/components/date-picker.js +70 -0
- package/components/date-picker.js.map +1 -0
- package/components/detail-row.d.ts +51 -0
- package/components/detail-row.js +77 -0
- package/components/detail-row.js.map +1 -0
- package/components/dialog.d.ts +121 -0
- package/components/dialog.js +327 -0
- package/components/dialog.js.map +1 -0
- package/components/disabled-reason.d.ts +31 -0
- package/components/disabled-reason.js +67 -0
- package/components/disabled-reason.js.map +1 -0
- package/components/empty-state.d.ts +41 -0
- package/components/empty-state.js +84 -0
- package/components/empty-state.js.map +1 -0
- package/components/entity-avatar.d.ts +54 -0
- package/components/entity-avatar.js +68 -0
- package/components/entity-avatar.js.map +1 -0
- package/components/form-section.d.ts +22 -0
- package/components/form-section.js +38 -0
- package/components/form-section.js.map +1 -0
- package/components/form.d.ts +199 -0
- package/components/form.js +456 -0
- package/components/form.js.map +1 -0
- package/components/formatted-number.d.ts +21 -0
- package/components/formatted-number.js +13 -0
- package/components/formatted-number.js.map +1 -0
- package/components/heading.d.ts +23 -0
- package/components/heading.js +44 -0
- package/components/heading.js.map +1 -0
- package/components/icon-swap.d.ts +15 -0
- package/components/icon-swap.js +29 -0
- package/components/icon-swap.js.map +1 -0
- package/components/inline-action.d.ts +21 -0
- package/components/inline-action.js +36 -0
- package/components/inline-action.js.map +1 -0
- package/components/input.d.ts +51 -0
- package/components/input.js +52 -0
- package/components/input.js.map +1 -0
- package/components/kbd.d.ts +17 -0
- package/components/kbd.js +34 -0
- package/components/kbd.js.map +1 -0
- package/components/label.d.ts +10 -0
- package/components/label.js +20 -0
- package/components/label.js.map +1 -0
- package/components/menu.d.ts +77 -0
- package/components/menu.js +189 -0
- package/components/menu.js.map +1 -0
- package/components/nav-button.d.ts +34 -0
- package/components/nav-button.js +71 -0
- package/components/nav-button.js.map +1 -0
- package/components/nav.d.ts +39 -0
- package/components/nav.js +68 -0
- package/components/nav.js.map +1 -0
- package/components/number-input.d.ts +16 -0
- package/components/number-input.js +25 -0
- package/components/number-input.js.map +1 -0
- package/components/page.d.ts +14 -0
- package/components/page.js +23 -0
- package/components/page.js.map +1 -0
- package/components/pagination.d.ts +73 -0
- package/components/pagination.js +212 -0
- package/components/pagination.js.map +1 -0
- package/components/ping.d.ts +38 -0
- package/components/ping.js +50 -0
- package/components/ping.js.map +1 -0
- package/components/popover.d.ts +5 -0
- package/components/popover.js +25 -0
- package/components/popover.js.map +1 -0
- package/components/radio-group.d.ts +35 -0
- package/components/radio-group.js +81 -0
- package/components/radio-group.js.map +1 -0
- package/components/relative-time.d.ts +25 -0
- package/components/relative-time.js +51 -0
- package/components/relative-time.js.map +1 -0
- package/components/saved-mark.d.ts +15 -0
- package/components/saved-mark.js +45 -0
- package/components/saved-mark.js.map +1 -0
- package/components/search-input.d.ts +13 -0
- package/components/search-input.js +44 -0
- package/components/search-input.js.map +1 -0
- package/components/section-header.d.ts +83 -0
- package/components/section-header.js +170 -0
- package/components/section-header.js.map +1 -0
- package/components/segmented-control.d.ts +24 -0
- package/components/segmented-control.js +70 -0
- package/components/segmented-control.js.map +1 -0
- package/components/select.d.ts +28 -0
- package/components/select.js +129 -0
- package/components/select.js.map +1 -0
- package/components/shortcut-keys.d.ts +14 -0
- package/components/shortcut-keys.js +32 -0
- package/components/shortcut-keys.js.map +1 -0
- package/components/shortcuts-dialog.d.ts +10 -0
- package/components/shortcuts-dialog.js +92 -0
- package/components/shortcuts-dialog.js.map +1 -0
- package/components/skeleton.d.ts +8 -0
- package/components/skeleton.js +23 -0
- package/components/skeleton.js.map +1 -0
- package/components/sparkline.d.ts +25 -0
- package/components/sparkline.js +70 -0
- package/components/sparkline.js.map +1 -0
- package/components/stack.d.ts +21 -0
- package/components/stack.js +45 -0
- package/components/stack.js.map +1 -0
- package/components/stat-strip.d.ts +43 -0
- package/components/stat-strip.js +151 -0
- package/components/stat-strip.js.map +1 -0
- package/components/steps.d.ts +19 -0
- package/components/steps.js +25 -0
- package/components/steps.js.map +1 -0
- package/components/switch.d.ts +16 -0
- package/components/switch.js +29 -0
- package/components/switch.js.map +1 -0
- package/components/table-toolbar.d.ts +55 -0
- package/components/table-toolbar.js +119 -0
- package/components/table-toolbar.js.map +1 -0
- package/components/table.d.ts +276 -0
- package/components/table.js +572 -0
- package/components/table.js.map +1 -0
- package/components/tabs.d.ts +36 -0
- package/components/tabs.js +120 -0
- package/components/tabs.js.map +1 -0
- package/components/text-link.d.ts +16 -0
- package/components/text-link.js +32 -0
- package/components/text-link.js.map +1 -0
- package/components/textarea.d.ts +10 -0
- package/components/textarea.js +23 -0
- package/components/textarea.js.map +1 -0
- package/components/theme.d.ts +28 -0
- package/components/theme.js +158 -0
- package/components/theme.js.map +1 -0
- package/components/time-series-chart.d.ts +122 -0
- package/components/time-series-chart.js +722 -0
- package/components/time-series-chart.js.map +1 -0
- package/components/toaster.d.ts +3 -0
- package/components/toaster.js +44 -0
- package/components/toaster.js.map +1 -0
- package/components/tooltip.d.ts +64 -0
- package/components/tooltip.js +126 -0
- package/components/tooltip.js.map +1 -0
- package/components/view-picker.d.ts +20 -0
- package/components/view-picker.js +24 -0
- package/components/view-picker.js.map +1 -0
- package/fonts/inter-OFL.txt +93 -0
- package/fonts/inter-cyrillic-ext.woff2 +0 -0
- package/fonts/inter-cyrillic.woff2 +0 -0
- package/fonts/inter-greek-ext.woff2 +0 -0
- package/fonts/inter-greek.woff2 +0 -0
- package/fonts/inter-latin-ext.woff2 +0 -0
- package/fonts/inter-latin.woff2 +0 -0
- package/fonts/inter-vietnamese.woff2 +0 -0
- package/fonts.css +83 -0
- package/lib/animation.d.ts +14 -0
- package/lib/animation.js +20 -0
- package/lib/animation.js.map +1 -0
- package/lib/aria.d.ts +5 -0
- package/lib/aria.js +12 -0
- package/lib/aria.js.map +1 -0
- package/lib/chart-curve.d.ts +13 -0
- package/lib/chart-curve.js +79 -0
- package/lib/chart-curve.js.map +1 -0
- package/lib/classes.d.ts +134 -0
- package/lib/classes.js +152 -0
- package/lib/classes.js.map +1 -0
- package/lib/color.d.ts +25 -0
- package/lib/color.js +149 -0
- package/lib/color.js.map +1 -0
- package/lib/data-table-state.d.ts +87 -0
- package/lib/data-table-state.js +92 -0
- package/lib/data-table-state.js.map +1 -0
- package/lib/day.d.ts +9 -0
- package/lib/day.js +20 -0
- package/lib/day.js.map +1 -0
- package/lib/design-tokens.d.ts +56 -0
- package/lib/design-tokens.js +196 -0
- package/lib/design-tokens.js.map +1 -0
- package/lib/icon.d.ts +17 -0
- package/lib/icon.js +34 -0
- package/lib/icon.js.map +1 -0
- package/lib/icons.d.ts +29 -0
- package/lib/icons.js +34 -0
- package/lib/icons.js.map +1 -0
- package/lib/interactive.d.ts +21 -0
- package/lib/interactive.js +31 -0
- package/lib/interactive.js.map +1 -0
- package/lib/load-more.d.ts +14 -0
- package/lib/load-more.js +27 -0
- package/lib/load-more.js.map +1 -0
- package/lib/media.d.ts +58 -0
- package/lib/media.js +116 -0
- package/lib/media.js.map +1 -0
- package/lib/segmented.d.ts +57 -0
- package/lib/segmented.js +83 -0
- package/lib/segmented.js.map +1 -0
- package/lib/shortcuts.d.ts +94 -0
- package/lib/shortcuts.js +271 -0
- package/lib/shortcuts.js.map +1 -0
- package/lib/slot.d.ts +9 -0
- package/lib/slot.js +18 -0
- package/lib/slot.js.map +1 -0
- package/lib/time-series.d.ts +100 -0
- package/lib/time-series.js +144 -0
- package/lib/time-series.js.map +1 -0
- package/lib/tone.d.ts +6 -0
- package/lib/tone.js +0 -0
- package/lib/variants.d.ts +12 -0
- package/lib/variants.js +14 -0
- package/lib/variants.js.map +1 -0
- package/package.json +122 -3
- package/styles.css +630 -0
- package/tokens.d.ts +104 -0
- package/tokens.js +108 -0
- package/tokens.js.map +1 -0
- package/publish.log +0 -1
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { SegmentedStyle, segmentedVariants } from "../lib/segmented.js";
|
|
2
|
+
import { VariantProps } from "../lib/variants.js";
|
|
3
|
+
import { ComponentProps } from "react";
|
|
4
|
+
import { Tabs as Tabs$1 } from "@base-ui/react/tabs";
|
|
5
|
+
/**
|
|
6
|
+
* Tabs that switch a panel: each `TabsTrigger` shows its `TabsPanel`, and a screen reader
|
|
7
|
+
* announces the pair. A row that picks a value and shows nothing of its own is a
|
|
8
|
+
* `SegmentedControl`.
|
|
9
|
+
*/
|
|
10
|
+
declare const Tabs: import("react").ForwardRefExoticComponent<Omit<import("@base-ui/react").TabsRootProps, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
|
|
11
|
+
/**
|
|
12
|
+
* The content of one tab, rendered while its trigger is active and labelled by it. Give it the
|
|
13
|
+
* `value` of its `TabsTrigger`.
|
|
14
|
+
*/
|
|
15
|
+
declare const TabsPanel: import("react").ForwardRefExoticComponent<Omit<import("@base-ui/react").TabsPanelProps, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
|
|
16
|
+
type TabsVariant = SegmentedStyle["variant"] | "underline";
|
|
17
|
+
type TabsListProps = Tabs$1.List.Props & Omit<VariantProps<typeof segmentedVariants>, "variant"> & {
|
|
18
|
+
/** `underline` for the view tabs above a table. */
|
|
19
|
+
variant?: TabsVariant;
|
|
20
|
+
};
|
|
21
|
+
declare function TabsList({ className, children, variant, size, ...props }: TabsListProps): import("react").JSX.Element;
|
|
22
|
+
declare const TabsTrigger: import("react").MemoExoticComponent<({ className, ...props }: Tabs$1.Tab.Props) => import("react").JSX.Element>;
|
|
23
|
+
declare const tabsCountVariants: import("tailwind-variants").TVReturnType<{
|
|
24
|
+
tone: {
|
|
25
|
+
muted: string;
|
|
26
|
+
warning: string;
|
|
27
|
+
danger: string;
|
|
28
|
+
};
|
|
29
|
+
}, undefined, "inline-flex h-4.5 items-center rounded-full px-1.5 font-medium text-2xs tabular-nums", undefined, undefined, undefined>;
|
|
30
|
+
type TabsCountProps = ComponentProps<"span"> & VariantProps<typeof tabsCountVariants>;
|
|
31
|
+
/**
|
|
32
|
+
* The row count after a view tab's label, formatted by the caller. `warning` or `danger` marks
|
|
33
|
+
* a count that needs attention (Needs review 3, Reported 2).
|
|
34
|
+
*/
|
|
35
|
+
declare function TabsCount({ tone, className, ...props }: TabsCountProps): import("react").JSX.Element;
|
|
36
|
+
export { Tabs, TabsCount, TabsList, TabsPanel, TabsTrigger };
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { interactiveVariants } from "../lib/interactive.js";
|
|
3
|
+
import { segmentedVariants } from "../lib/segmented.js";
|
|
4
|
+
import { cn, variants } from "../lib/variants.js";
|
|
5
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
import { createContext, memo, use, useEffect, useRef } from "react";
|
|
7
|
+
import { Tabs as Tabs$1 } from "@base-ui/react/tabs";
|
|
8
|
+
// src/components/tabs.tsx
|
|
9
|
+
/**
|
|
10
|
+
* Tabs that switch a panel: each `TabsTrigger` shows its `TabsPanel`, and a screen reader
|
|
11
|
+
* announces the pair. A row that picks a value and shows nothing of its own is a
|
|
12
|
+
* `SegmentedControl`.
|
|
13
|
+
*/
|
|
14
|
+
const Tabs = Tabs$1.Root;
|
|
15
|
+
/**
|
|
16
|
+
* The content of one tab, rendered while its trigger is active and labelled by it. Give it the
|
|
17
|
+
* `value` of its `TabsTrigger`.
|
|
18
|
+
*/
|
|
19
|
+
const TabsPanel = Tabs$1.Panel;
|
|
20
|
+
const TabsVariantContext = createContext({
|
|
21
|
+
variant: "segmented",
|
|
22
|
+
size: "md"
|
|
23
|
+
});
|
|
24
|
+
/**
|
|
25
|
+
* The view tabs above a table: a row of labels on a hairline, the chosen one in ink over a 2px
|
|
26
|
+
* ink underline that slides to it. Each label may carry a `TabsCount`. The size does not apply:
|
|
27
|
+
* every tab is 36px, so the row reads as part of the page rather than a control. A row wider
|
|
28
|
+
* than its box scrolls sideways rather than wrapping.
|
|
29
|
+
*/
|
|
30
|
+
const UNDERLINE_CLASSES = {
|
|
31
|
+
root: "relative flex items-center gap-5 overflow-x-auto border-b py-px [scrollbar-width:none]",
|
|
32
|
+
indicator: [
|
|
33
|
+
"absolute bottom-0 left-0 h-0.5 bg-ink",
|
|
34
|
+
"w-(--active-tab-width) translate-x-(--active-tab-left)",
|
|
35
|
+
"transition-[translate,width] duration-200 ease-out-expo"
|
|
36
|
+
].join(" "),
|
|
37
|
+
item: cn(interactiveVariants({ interactive: false }), "relative inline-flex h-9 shrink-0 items-center gap-1.5 whitespace-nowrap font-medium text-control text-ink-secondary", "hover:text-ink data-active:text-ink")
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Sliding highlight that tracks the active tab via Base UI's --active-tab-* CSS variables.
|
|
41
|
+
* Rendered automatically by TabsList, so every tab group shares one pill.
|
|
42
|
+
*/
|
|
43
|
+
function TabsIndicator({ className, ...props }) {
|
|
44
|
+
const { variant, size } = use(TabsVariantContext);
|
|
45
|
+
return /* @__PURE__ */ jsx(Tabs$1.Indicator, {
|
|
46
|
+
className: cn(variant === "underline" ? UNDERLINE_CLASSES.indicator : [segmentedVariants({
|
|
47
|
+
variant,
|
|
48
|
+
size
|
|
49
|
+
}).indicator(), "h-(--active-tab-height) w-(--active-tab-width) translate-x-(--active-tab-left) translate-y-(--active-tab-top)"], className),
|
|
50
|
+
...props
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
function TabsList({ className, children, variant = "segmented", size = "md", ...props }) {
|
|
54
|
+
const listRef = useRef(null);
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
const list = listRef.current;
|
|
57
|
+
if (variant !== "underline" || !list) return;
|
|
58
|
+
function reveal() {
|
|
59
|
+
const active = list?.querySelector("[data-active]");
|
|
60
|
+
if (!list || !active) return;
|
|
61
|
+
const end = active.offsetLeft + active.offsetWidth;
|
|
62
|
+
if (end > list.scrollLeft + list.clientWidth) list.scrollLeft = end - list.clientWidth;
|
|
63
|
+
}
|
|
64
|
+
reveal();
|
|
65
|
+
if (typeof ResizeObserver === "undefined") return;
|
|
66
|
+
const observer = new ResizeObserver(reveal);
|
|
67
|
+
for (const tab of list.children) observer.observe(tab);
|
|
68
|
+
return () => observer.disconnect();
|
|
69
|
+
}, [variant]);
|
|
70
|
+
return /* @__PURE__ */ jsx(TabsVariantContext, {
|
|
71
|
+
value: {
|
|
72
|
+
variant,
|
|
73
|
+
size
|
|
74
|
+
},
|
|
75
|
+
children: /* @__PURE__ */ jsxs(Tabs$1.List, {
|
|
76
|
+
ref: listRef,
|
|
77
|
+
className: cn(variant === "underline" ? UNDERLINE_CLASSES.root : segmentedVariants({
|
|
78
|
+
variant,
|
|
79
|
+
size
|
|
80
|
+
}).root(), className),
|
|
81
|
+
...props,
|
|
82
|
+
children: [/* @__PURE__ */ jsx(TabsIndicator, {}), children]
|
|
83
|
+
})
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
const TabsTrigger = memo(function TabsTrigger({ className, ...props }) {
|
|
87
|
+
const { variant, size } = use(TabsVariantContext);
|
|
88
|
+
return /* @__PURE__ */ jsx(Tabs$1.Tab, {
|
|
89
|
+
className: cn(variant === "underline" ? UNDERLINE_CLASSES.item : [segmentedVariants({
|
|
90
|
+
variant,
|
|
91
|
+
size
|
|
92
|
+
}).item(), "data-active:text-ink"], "not-disabled:cursor-pointer disabled:opacity-50", className),
|
|
93
|
+
...props
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
const tabsCountVariants = variants({
|
|
97
|
+
base: "inline-flex h-4.5 items-center rounded-full px-1.5 font-medium text-2xs tabular-nums",
|
|
98
|
+
variants: { tone: {
|
|
99
|
+
muted: "bg-fill text-ink-muted",
|
|
100
|
+
warning: "bg-warning-subtle text-warning-ink",
|
|
101
|
+
danger: "bg-danger-subtle text-danger-ink"
|
|
102
|
+
} },
|
|
103
|
+
defaultVariants: { tone: "muted" }
|
|
104
|
+
});
|
|
105
|
+
/**
|
|
106
|
+
* The row count after a view tab's label, formatted by the caller. `warning` or `danger` marks
|
|
107
|
+
* a count that needs attention (Needs review 3, Reported 2).
|
|
108
|
+
*/
|
|
109
|
+
function TabsCount({ tone, className, ...props }) {
|
|
110
|
+
return /* @__PURE__ */ jsx("span", {
|
|
111
|
+
className: tabsCountVariants({
|
|
112
|
+
tone,
|
|
113
|
+
className
|
|
114
|
+
}),
|
|
115
|
+
...props
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
export { Tabs, TabsCount, TabsList, TabsPanel, TabsTrigger };
|
|
119
|
+
|
|
120
|
+
//# sourceMappingURL=tabs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tabs.js","names":["TabsPrimitive"],"sources":["../../src/components/tabs.tsx"],"sourcesContent":["\"use client\"\n\nimport { Tabs as TabsPrimitive } from \"@base-ui/react/tabs\"\nimport { type ComponentProps, createContext, memo, use, useEffect, useRef } from \"react\"\nimport { interactiveVariants } from \"../lib/interactive\"\nimport { type SegmentedStyle, segmentedVariants } from \"../lib/segmented\"\nimport { cn, variants, type VariantProps } from \"../lib/variants\"\n\n/**\n * Tabs that switch a panel: each `TabsTrigger` shows its `TabsPanel`, and a screen reader\n * announces the pair. A row that picks a value and shows nothing of its own is a\n * `SegmentedControl`.\n */\nconst Tabs = TabsPrimitive.Root\n\n/**\n * The content of one tab, rendered while its trigger is active and labelled by it. Give it the\n * `value` of its `TabsTrigger`.\n */\nconst TabsPanel = TabsPrimitive.Panel\n\n// The parts below merge `className` outside the variants call, unlike everywhere else: Base UI\n// types it as a function of the part's own state too, which `variants` cannot take.\n\ntype TabsVariant = SegmentedStyle[\"variant\"] | \"underline\"\n\ninterface TabsStyle {\n variant: TabsVariant\n size: SegmentedStyle[\"size\"]\n}\n\nconst TabsVariantContext = createContext<TabsStyle>({\n variant: \"segmented\",\n size: \"md\",\n})\n\n/**\n * The view tabs above a table: a row of labels on a hairline, the chosen one in ink over a 2px\n * ink underline that slides to it. Each label may carry a `TabsCount`. The size does not apply:\n * every tab is 36px, so the row reads as part of the page rather than a control. A row wider\n * than its box scrolls sideways rather than wrapping.\n */\nconst UNDERLINE_CLASSES = {\n // A row wider than its box (a phone) scrolls sideways, with no bar under the hairline. The\n // pixel above and below keeps the focus ring, drawn a pixel outside a tab, out of the clip.\n root: \"relative flex items-center gap-5 overflow-x-auto border-b py-px [scrollbar-width:none]\",\n indicator: [\n \"absolute bottom-0 left-0 h-0.5 bg-ink\",\n \"w-(--active-tab-width) translate-x-(--active-tab-left)\",\n \"transition-[translate,width] duration-200 ease-out-expo\",\n ].join(\" \"),\n item: cn(\n interactiveVariants({ interactive: false }),\n \"relative inline-flex h-9 shrink-0 items-center gap-1.5 whitespace-nowrap font-medium text-control text-ink-secondary\",\n \"hover:text-ink data-active:text-ink\",\n ),\n}\n\n/**\n * Sliding highlight that tracks the active tab via Base UI's --active-tab-* CSS variables.\n * Rendered automatically by TabsList, so every tab group shares one pill.\n */\nfunction TabsIndicator({ className, ...props }: TabsPrimitive.Indicator.Props) {\n const { variant, size } = use(TabsVariantContext)\n\n return (\n <TabsPrimitive.Indicator\n className={cn(\n variant === \"underline\"\n ? UNDERLINE_CLASSES.indicator\n : [\n segmentedVariants({ variant, size }).indicator(),\n \"h-(--active-tab-height) w-(--active-tab-width) translate-x-(--active-tab-left) translate-y-(--active-tab-top)\",\n ],\n className,\n )}\n {...props}\n />\n )\n}\n\ntype TabsListProps = TabsPrimitive.List.Props &\n Omit<VariantProps<typeof segmentedVariants>, \"variant\"> & {\n /** `underline` for the view tabs above a table. */\n variant?: TabsVariant\n }\n\nfunction TabsList({\n className,\n children,\n variant = \"segmented\",\n size = \"md\",\n ...props\n}: TabsListProps) {\n const listRef = useRef<HTMLDivElement>(null)\n\n // A row that scrolls keeps its active tab in view, for a link straight to a view far along\n // it. It checks again whenever a tab changes size (a count arriving widens every label), and\n // never when the reader scrolls the row themselves.\n useEffect(() => {\n const list = listRef.current\n if (variant !== \"underline\" || !list) return\n\n function reveal() {\n const active = list?.querySelector<HTMLElement>(\"[data-active]\")\n if (!list || !active) return\n const end = active.offsetLeft + active.offsetWidth\n if (end > list.scrollLeft + list.clientWidth) list.scrollLeft = end - list.clientWidth\n }\n\n reveal()\n if (typeof ResizeObserver === \"undefined\") return\n const observer = new ResizeObserver(reveal)\n for (const tab of list.children) observer.observe(tab)\n return () => observer.disconnect()\n }, [variant])\n\n return (\n <TabsVariantContext value={{ variant, size }}>\n <TabsPrimitive.List\n ref={listRef}\n className={cn(\n variant === \"underline\"\n ? UNDERLINE_CLASSES.root\n : segmentedVariants({ variant, size }).root(),\n className,\n )}\n {...props}\n >\n <TabsIndicator />\n {children}\n </TabsPrimitive.List>\n </TabsVariantContext>\n )\n}\n\n// Memoised: a tab row re-renders with its card, and its triggers rarely change with it.\nconst TabsTrigger = memo(function TabsTrigger({ className, ...props }: TabsPrimitive.Tab.Props) {\n const { variant, size } = use(TabsVariantContext)\n\n return (\n <TabsPrimitive.Tab\n className={cn(\n variant === \"underline\"\n ? UNDERLINE_CLASSES.item\n : [segmentedVariants({ variant, size }).item(), \"data-active:text-ink\"],\n \"not-disabled:cursor-pointer disabled:opacity-50\",\n className,\n )}\n {...props}\n />\n )\n})\n\nconst tabsCountVariants = variants({\n base: \"inline-flex h-4.5 items-center rounded-full px-1.5 font-medium text-2xs tabular-nums\",\n\n variants: {\n tone: {\n muted: \"bg-fill text-ink-muted\",\n warning: \"bg-warning-subtle text-warning-ink\",\n danger: \"bg-danger-subtle text-danger-ink\",\n },\n },\n\n defaultVariants: {\n tone: \"muted\",\n },\n})\n\ntype TabsCountProps = ComponentProps<\"span\"> & VariantProps<typeof tabsCountVariants>\n\n/**\n * The row count after a view tab's label, formatted by the caller. `warning` or `danger` marks\n * a count that needs attention (Needs review 3, Reported 2).\n */\nfunction TabsCount({ tone, className, ...props }: TabsCountProps) {\n return <span className={tabsCountVariants({ tone, className })} {...props} />\n}\n\nexport { Tabs, TabsCount, TabsList, TabsPanel, TabsTrigger }\n"],"mappings":";;;;;;;;;;;;;AAaA,MAAM,OAAOA,OAAc;;;;;AAM3B,MAAM,YAAYA,OAAc;AAYhC,MAAM,qBAAqB,cAAyB;CAClD,SAAS;CACT,MAAM;AACR,CAAC;;;;;;;AAQD,MAAM,oBAAoB;CAGxB,MAAM;CACN,WAAW;EACT;EACA;EACA;CACF,CAAC,CAAC,KAAK,GAAG;CACV,MAAM,GACJ,oBAAoB,EAAE,aAAa,MAAM,CAAC,GAC1C,wHACA,qCACF;AACF;;;;;AAMA,SAAS,cAAc,EAAE,WAAW,GAAG,SAAwC;CAC7E,MAAM,EAAE,SAAS,SAAS,IAAI,kBAAkB;CAEhD,OACE,oBAACA,OAAc,WAAf;EACE,WAAW,GACT,YAAY,cACR,kBAAkB,YAClB,CACE,kBAAkB;GAAE;GAAS;EAAK,CAAC,CAAC,CAAC,UAAU,GAC/C,+GACF,GACJ,SACF;EACA,GAAI;CACL,CAAA;AAEL;AAQA,SAAS,SAAS,EAChB,WACA,UACA,UAAU,aACV,OAAO,MACP,GAAG,SACa;CAChB,MAAM,UAAU,OAAuB,IAAI;CAK3C,gBAAgB;EACd,MAAM,OAAO,QAAQ;EACrB,IAAI,YAAY,eAAe,CAAC,MAAM;EAEtC,SAAS,SAAS;GAChB,MAAM,SAAS,MAAM,cAA2B,eAAe;GAC/D,IAAI,CAAC,QAAQ,CAAC,QAAQ;GACtB,MAAM,MAAM,OAAO,aAAa,OAAO;GACvC,IAAI,MAAM,KAAK,aAAa,KAAK,aAAa,KAAK,aAAa,MAAM,KAAK;EAC7E;EAEA,OAAO;EACP,IAAI,OAAO,mBAAmB,aAAa;EAC3C,MAAM,WAAW,IAAI,eAAe,MAAM;EAC1C,KAAK,MAAM,OAAO,KAAK,UAAU,SAAS,QAAQ,GAAG;EACrD,aAAa,SAAS,WAAW;CACnC,GAAG,CAAC,OAAO,CAAC;CAEZ,OACE,oBAAC,oBAAD;EAAoB,OAAO;GAAE;GAAS;EAAK;EACzC,UAAA,qBAACA,OAAc,MAAf;GACE,KAAK;GACL,WAAW,GACT,YAAY,cACR,kBAAkB,OAClB,kBAAkB;IAAE;IAAS;GAAK,CAAC,CAAC,CAAC,KAAK,GAC9C,SACF;GACA,GAAI;GARN,UAAA,CAUE,oBAAC,eAAD,CAAgB,CAAA,GACf,QACiB;;CACF,CAAA;AAExB;AAGA,MAAM,cAAc,KAAK,SAAS,YAAY,EAAE,WAAW,GAAG,SAAkC;CAC9F,MAAM,EAAE,SAAS,SAAS,IAAI,kBAAkB;CAEhD,OACE,oBAACA,OAAc,KAAf;EACE,WAAW,GACT,YAAY,cACR,kBAAkB,OAClB,CAAC,kBAAkB;GAAE;GAAS;EAAK,CAAC,CAAC,CAAC,KAAK,GAAG,sBAAsB,GACxE,mDACA,SACF;EACA,GAAI;CACL,CAAA;AAEL,CAAC;AAED,MAAM,oBAAoB,SAAS;CACjC,MAAM;CAEN,UAAU,EACR,MAAM;EACJ,OAAO;EACP,SAAS;EACT,QAAQ;CACV,EACF;CAEA,iBAAiB,EACf,MAAM,QACR;AACF,CAAC;;;;;AAQD,SAAS,UAAU,EAAE,MAAM,WAAW,GAAG,SAAyB;CAChE,OAAO,oBAAC,QAAD;EAAM,WAAW,kBAAkB;GAAE;GAAM;EAAU,CAAC;EAAG,GAAI;CAAQ,CAAA;AAC9E"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { VariantProps } from "../lib/variants.js";
|
|
2
|
+
import { useRender } from "@base-ui/react/use-render";
|
|
3
|
+
declare const textLinkVariants: import("tailwind-variants").TVReturnType<{
|
|
4
|
+
tone: {
|
|
5
|
+
brand: string;
|
|
6
|
+
muted: string;
|
|
7
|
+
};
|
|
8
|
+
}, undefined, "underline decoration-1 underline-offset-3 decoration-current/40 transition-[text-decoration-color] duration-150 ease-out hover:decoration-current", undefined, undefined, undefined>;
|
|
9
|
+
export interface TextLinkProps extends useRender.ComponentProps<"a">, VariantProps<typeof textLinkVariants> {}
|
|
10
|
+
/**
|
|
11
|
+
* A link inside running text: a sentence in a description, a callout or an empty state. It
|
|
12
|
+
* sets colour and underline and nothing else, so it wraps with the words around it and reads
|
|
13
|
+
* at their size. A standalone control beside prose is `InlineAction` or `Button` instead.
|
|
14
|
+
*/
|
|
15
|
+
declare function TextLink({ className, tone, render, ...props }: TextLinkProps): import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
16
|
+
export { TextLink };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { variants } from "../lib/variants.js";
|
|
2
|
+
import { useRender } from "@base-ui/react/use-render";
|
|
3
|
+
// src/components/text-link.tsx
|
|
4
|
+
const textLinkVariants = variants({
|
|
5
|
+
base: "underline decoration-1 underline-offset-3 decoration-current/40 transition-[text-decoration-color] duration-150 ease-out hover:decoration-current",
|
|
6
|
+
variants: { tone: {
|
|
7
|
+
brand: "text-brand-ink",
|
|
8
|
+
muted: ""
|
|
9
|
+
} },
|
|
10
|
+
defaultVariants: { tone: "brand" }
|
|
11
|
+
});
|
|
12
|
+
/**
|
|
13
|
+
* A link inside running text: a sentence in a description, a callout or an empty state. It
|
|
14
|
+
* sets colour and underline and nothing else, so it wraps with the words around it and reads
|
|
15
|
+
* at their size. A standalone control beside prose is `InlineAction` or `Button` instead.
|
|
16
|
+
*/
|
|
17
|
+
function TextLink({ className, tone, render, ...props }) {
|
|
18
|
+
return useRender({
|
|
19
|
+
render,
|
|
20
|
+
defaultTagName: "a",
|
|
21
|
+
props: {
|
|
22
|
+
className: textLinkVariants({
|
|
23
|
+
tone,
|
|
24
|
+
className
|
|
25
|
+
}),
|
|
26
|
+
...props
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
export { TextLink };
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=text-link.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text-link.js","names":[],"sources":["../../src/components/text-link.tsx"],"sourcesContent":["import { useRender } from \"@base-ui/react/use-render\"\nimport { variants, type VariantProps } from \"../lib/variants\"\n\nconst textLinkVariants = variants({\n // Underlined in every tone, because a link inside a sentence has no shape of its own to mark\n // it: colour alone fails for a reader who cannot separate the two hues. The 1px rule sits 3px\n // down, clear of the descenders, in the link's colour at 40%, and turns solid under the pointer.\n base: \"underline decoration-1 underline-offset-3 decoration-current/40 transition-[text-decoration-color] duration-150 ease-out hover:decoration-current\",\n\n variants: {\n tone: {\n brand: \"text-brand-ink\",\n // Takes the sentence's colour, for fine print that should not draw the eye.\n muted: \"\",\n },\n },\n\n defaultVariants: {\n tone: \"brand\",\n },\n})\n\nexport interface TextLinkProps\n extends useRender.ComponentProps<\"a\">, VariantProps<typeof textLinkVariants> {}\n\n/**\n * A link inside running text: a sentence in a description, a callout or an empty state. It\n * sets colour and underline and nothing else, so it wraps with the words around it and reads\n * at their size. A standalone control beside prose is `InlineAction` or `Button` instead.\n */\nfunction TextLink({ className, tone, render, ...props }: TextLinkProps) {\n return useRender({\n render,\n defaultTagName: \"a\",\n props: { className: textLinkVariants({ tone, className }), ...props },\n })\n}\n\nexport { TextLink }\n"],"mappings":";;;AAGA,MAAM,mBAAmB,SAAS;CAIhC,MAAM;CAEN,UAAU,EACR,MAAM;EACJ,OAAO;EAEP,OAAO;CACT,EACF;CAEA,iBAAiB,EACf,MAAM,QACR;AACF,CAAC;;;;;;AAUD,SAAS,SAAS,EAAE,WAAW,MAAM,QAAQ,GAAG,SAAwB;CACtE,OAAO,UAAU;EACf;EACA,gBAAgB;EAChB,OAAO;GAAE,WAAW,iBAAiB;IAAE;IAAM;GAAU,CAAC;GAAG,GAAG;EAAM;CACtE,CAAC;AACH"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { VariantProps } from "../lib/variants.js";
|
|
2
|
+
import { PasswordManagerProps, inputVariants } from "./input.js";
|
|
3
|
+
import { ComponentProps } from "react";
|
|
4
|
+
type TextareaProps = Omit<ComponentProps<"textarea">, "size"> & VariantProps<typeof inputVariants> & PasswordManagerProps;
|
|
5
|
+
/**
|
|
6
|
+
* A multi-line field that grows with its text up to 320px, then scrolls. A browser without
|
|
7
|
+
* `field-sizing` keeps the `rows` height and scrolls from there.
|
|
8
|
+
*/
|
|
9
|
+
declare function Textarea({ className, interactive, bordered, size, allowPasswordManager, ...props }: TextareaProps): import("react").JSX.Element;
|
|
10
|
+
export { Textarea };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { cn } from "../lib/variants.js";
|
|
2
|
+
import { inputVariants, passwordManagerAttributes } from "./input.js";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
// src/components/textarea.tsx
|
|
5
|
+
/**
|
|
6
|
+
* A multi-line field that grows with its text up to 320px, then scrolls. A browser without
|
|
7
|
+
* `field-sizing` keeps the `rows` height and scrolls from there.
|
|
8
|
+
*/
|
|
9
|
+
function Textarea({ className, interactive, bordered, size, allowPasswordManager, ...props }) {
|
|
10
|
+
return /* @__PURE__ */ jsx("textarea", {
|
|
11
|
+
className: inputVariants({
|
|
12
|
+
interactive,
|
|
13
|
+
bordered,
|
|
14
|
+
size,
|
|
15
|
+
className: cn("max-h-80 overflow-y-auto text-copy resize-none field-sizing-content", className)
|
|
16
|
+
}),
|
|
17
|
+
...passwordManagerAttributes(allowPasswordManager),
|
|
18
|
+
...props
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
export { Textarea };
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=textarea.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"textarea.js","names":[],"sources":["../../src/components/textarea.tsx"],"sourcesContent":["import type { ComponentProps } from \"react\"\nimport { cn, type VariantProps } from \"../lib/variants\"\nimport { inputVariants, passwordManagerAttributes, type PasswordManagerProps } from \"./input\"\n\ntype TextareaProps = Omit<ComponentProps<\"textarea\">, \"size\"> &\n VariantProps<typeof inputVariants> &\n PasswordManagerProps\n\n/**\n * A multi-line field that grows with its text up to 320px, then scrolls. A browser without\n * `field-sizing` keeps the `rows` height and scrolls from there.\n */\nfunction Textarea({\n className,\n interactive,\n bordered,\n size,\n allowPasswordManager,\n ...props\n}: TextareaProps) {\n return (\n <textarea\n className={inputVariants({\n interactive,\n bordered,\n size,\n className: cn(\n \"max-h-80 overflow-y-auto text-copy resize-none field-sizing-content\",\n className,\n ),\n })}\n {...passwordManagerAttributes(allowPasswordManager)}\n {...props}\n />\n )\n}\n\nexport { Textarea }\n"],"mappings":";;;;;;;;AAYA,SAAS,SAAS,EAChB,WACA,aACA,UACA,MACA,sBACA,GAAG,SACa;CAChB,OACE,oBAAC,YAAD;EACE,WAAW,cAAc;GACvB;GACA;GACA;GACA,WAAW,GACT,uEACA,SACF;EACF,CAAC;EACD,GAAI,0BAA0B,oBAAoB;EAClD,GAAI;CACL,CAAA;AAEL"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { SegmentedControlProps } from "./segmented-control.js";
|
|
2
|
+
export type Theme = "system" | "light" | "dark";
|
|
3
|
+
/**
|
|
4
|
+
* The current theme and its setter. Persists to `localStorage["theme"]`, stays in sync across
|
|
5
|
+
* tabs, and drives the stylesheet's `light-dark()` tokens by setting `data-theme` on `<html>`
|
|
6
|
+
* (`system` removes it so the OS decides). SSR-safe: the server renders `system`.
|
|
7
|
+
*
|
|
8
|
+
* The hook only applies the stored theme once the first subscriber mounts. To avoid a flash of
|
|
9
|
+
* the wrong scheme, apply it before first paint with this inline script in `<head>`:
|
|
10
|
+
*
|
|
11
|
+
* ```html
|
|
12
|
+
* <script>try{var t=localStorage.theme;if(t==="light"||t==="dark")document.documentElement.dataset.theme=t}catch(e){}</script>
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare function useTheme(): [Theme, (theme: Theme) => void];
|
|
16
|
+
interface ThemeSelectProps extends Omit<SegmentedControlProps<Theme>, "value" | "defaultValue" | "onValueChange" | "variant" | "size"> {
|
|
17
|
+
/**
|
|
18
|
+
* The smallest track with one icon per theme, for a menu row where the labelled control
|
|
19
|
+
* would not fit.
|
|
20
|
+
*/
|
|
21
|
+
compact?: boolean;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Segmented System / Light / Dark control bound to `useTheme`, for a settings page or an
|
|
25
|
+
* account menu.
|
|
26
|
+
*/
|
|
27
|
+
export declare function ThemeSelect({ compact, ...props }: ThemeSelectProps): import("react").JSX.Element;
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { ComputerIcon, MoonIcon, SunIcon } from "../lib/icons.js";
|
|
3
|
+
import { SegmentedControl, SegmentedControlItem } from "./segmented-control.js";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
import { useSyncExternalStore } from "react";
|
|
6
|
+
// src/components/theme.tsx
|
|
7
|
+
const STORAGE_KEY = "theme";
|
|
8
|
+
const OS_DARK_QUERY = "(prefers-color-scheme: dark)";
|
|
9
|
+
const THEMES = [
|
|
10
|
+
"system",
|
|
11
|
+
"light",
|
|
12
|
+
"dark"
|
|
13
|
+
];
|
|
14
|
+
/**
|
|
15
|
+
* Tiny module store behind `useTheme`. One value shared by every subscriber, kept in step with
|
|
16
|
+
* `localStorage` (and with other tabs through the `storage` event) and mirrored onto
|
|
17
|
+
* `<html data-theme>`, which is what the stylesheet's `color-scheme` rules key on.
|
|
18
|
+
*/
|
|
19
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
20
|
+
let current;
|
|
21
|
+
let osScheme;
|
|
22
|
+
function isTheme(value) {
|
|
23
|
+
return typeof value === "string" && THEMES.includes(value);
|
|
24
|
+
}
|
|
25
|
+
function readStored() {
|
|
26
|
+
try {
|
|
27
|
+
const stored = localStorage.getItem(STORAGE_KEY);
|
|
28
|
+
return isTheme(stored) ? stored : "system";
|
|
29
|
+
} catch {
|
|
30
|
+
return "system";
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function writeStored(theme) {
|
|
34
|
+
try {
|
|
35
|
+
if (theme === "system") localStorage.removeItem(STORAGE_KEY);
|
|
36
|
+
else localStorage.setItem(STORAGE_KEY, theme);
|
|
37
|
+
} catch {}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* `system` clears the attribute so `color-scheme: light dark` follows the OS; anything else
|
|
41
|
+
* pins it.
|
|
42
|
+
*/
|
|
43
|
+
function applyTheme(theme) {
|
|
44
|
+
const root = document.documentElement;
|
|
45
|
+
if (theme === "system") delete root.dataset.theme;
|
|
46
|
+
else root.dataset.theme = theme;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Narrows every transition to geometry until the next style pass is done. A theme change swaps
|
|
50
|
+
* every token at once, and anything that transitions a colour (a card's edge, a button's fill)
|
|
51
|
+
* would otherwise tween into the new scheme while the rest of the page flips. Movement keeps
|
|
52
|
+
* its transition: the theme picker's pill slides to the chosen option in the same frames.
|
|
53
|
+
* Called before the change, or from the OS scheme's change event, which fires before the
|
|
54
|
+
* browser restyles.
|
|
55
|
+
*/
|
|
56
|
+
function suspendColorTransitions() {
|
|
57
|
+
const style = document.createElement("style");
|
|
58
|
+
style.textContent = "*,*::before,*::after{transition-property:translate,transform,width,height!important}";
|
|
59
|
+
document.head.append(style);
|
|
60
|
+
requestAnimationFrame(() => requestAnimationFrame(() => style.remove()));
|
|
61
|
+
}
|
|
62
|
+
function emit() {
|
|
63
|
+
for (const listener of listeners) listener();
|
|
64
|
+
}
|
|
65
|
+
function onStorage(event) {
|
|
66
|
+
if (event.key !== null && event.key !== STORAGE_KEY) return;
|
|
67
|
+
current = readStored();
|
|
68
|
+
suspendColorTransitions();
|
|
69
|
+
applyTheme(current);
|
|
70
|
+
emit();
|
|
71
|
+
}
|
|
72
|
+
function onSchemeChange() {
|
|
73
|
+
if (current === "system") suspendColorTransitions();
|
|
74
|
+
}
|
|
75
|
+
function getSnapshot() {
|
|
76
|
+
current ??= readStored();
|
|
77
|
+
return current;
|
|
78
|
+
}
|
|
79
|
+
function getServerSnapshot() {
|
|
80
|
+
return "system";
|
|
81
|
+
}
|
|
82
|
+
function subscribe(listener) {
|
|
83
|
+
if (listeners.size === 0) {
|
|
84
|
+
window.addEventListener("storage", onStorage);
|
|
85
|
+
osScheme = window.matchMedia(OS_DARK_QUERY);
|
|
86
|
+
osScheme.addEventListener("change", onSchemeChange);
|
|
87
|
+
applyTheme(getSnapshot());
|
|
88
|
+
}
|
|
89
|
+
listeners.add(listener);
|
|
90
|
+
return () => {
|
|
91
|
+
listeners.delete(listener);
|
|
92
|
+
if (listeners.size > 0) return;
|
|
93
|
+
window.removeEventListener("storage", onStorage);
|
|
94
|
+
osScheme?.removeEventListener("change", onSchemeChange);
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function setTheme(theme) {
|
|
98
|
+
if (theme === current) return;
|
|
99
|
+
current = theme;
|
|
100
|
+
writeStored(theme);
|
|
101
|
+
suspendColorTransitions();
|
|
102
|
+
applyTheme(theme);
|
|
103
|
+
emit();
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* The current theme and its setter. Persists to `localStorage["theme"]`, stays in sync across
|
|
107
|
+
* tabs, and drives the stylesheet's `light-dark()` tokens by setting `data-theme` on `<html>`
|
|
108
|
+
* (`system` removes it so the OS decides). SSR-safe: the server renders `system`.
|
|
109
|
+
*
|
|
110
|
+
* The hook only applies the stored theme once the first subscriber mounts. To avoid a flash of
|
|
111
|
+
* the wrong scheme, apply it before first paint with this inline script in `<head>`:
|
|
112
|
+
*
|
|
113
|
+
* ```html
|
|
114
|
+
* <script>try{var t=localStorage.theme;if(t==="light"||t==="dark")document.documentElement.dataset.theme=t}catch(e){}<\/script>
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
function useTheme() {
|
|
118
|
+
return [useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot), setTheme];
|
|
119
|
+
}
|
|
120
|
+
const THEME_OPTIONS = [
|
|
121
|
+
{
|
|
122
|
+
value: "system",
|
|
123
|
+
label: "System",
|
|
124
|
+
icon: ComputerIcon
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
value: "light",
|
|
128
|
+
label: "Light",
|
|
129
|
+
icon: SunIcon
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
value: "dark",
|
|
133
|
+
label: "Dark",
|
|
134
|
+
icon: MoonIcon
|
|
135
|
+
}
|
|
136
|
+
];
|
|
137
|
+
/**
|
|
138
|
+
* Segmented System / Light / Dark control bound to `useTheme`, for a settings page or an
|
|
139
|
+
* account menu.
|
|
140
|
+
*/
|
|
141
|
+
function ThemeSelect({ compact, ...props }) {
|
|
142
|
+
const [theme, setTheme] = useTheme();
|
|
143
|
+
return /* @__PURE__ */ jsx(SegmentedControl, {
|
|
144
|
+
value: theme,
|
|
145
|
+
size: compact ? "xs" : "md",
|
|
146
|
+
"aria-label": "Theme",
|
|
147
|
+
onValueChange: setTheme,
|
|
148
|
+
...props,
|
|
149
|
+
children: THEME_OPTIONS.map(({ value, label, icon: Icon }) => /* @__PURE__ */ jsx(SegmentedControlItem, {
|
|
150
|
+
value,
|
|
151
|
+
"aria-label": compact ? label : void 0,
|
|
152
|
+
children: compact ? /* @__PURE__ */ jsx(Icon, {}) : label
|
|
153
|
+
}, value))
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
export { ThemeSelect, useTheme };
|
|
157
|
+
|
|
158
|
+
//# sourceMappingURL=theme.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"theme.js","names":[],"sources":["../../src/components/theme.tsx"],"sourcesContent":["\"use client\"\n\nimport { useSyncExternalStore } from \"react\"\nimport { ComputerIcon, MoonIcon, SunIcon } from \"../lib/icons\"\nimport {\n SegmentedControl,\n SegmentedControlItem,\n type SegmentedControlProps,\n} from \"./segmented-control\"\n\nexport type Theme = \"system\" | \"light\" | \"dark\"\n\nconst STORAGE_KEY = \"theme\"\nconst OS_DARK_QUERY = \"(prefers-color-scheme: dark)\"\nconst THEMES: readonly Theme[] = [\"system\", \"light\", \"dark\"]\n\n/**\n * Tiny module store behind `useTheme`. One value shared by every subscriber, kept in step with\n * `localStorage` (and with other tabs through the `storage` event) and mirrored onto\n * `<html data-theme>`, which is what the stylesheet's `color-scheme` rules key on.\n */\nconst listeners = new Set<() => void>()\nlet current: Theme | undefined\n// Kept, not re-queried: `matchMedia` returns a new list per call, and a listener only comes off\n// the list it was added to.\nlet osScheme: MediaQueryList | undefined\n\nfunction isTheme(value: unknown): value is Theme {\n return typeof value === \"string\" && THEMES.includes(value as Theme)\n}\n\nfunction readStored(): Theme {\n try {\n const stored = localStorage.getItem(STORAGE_KEY)\n return isTheme(stored) ? stored : \"system\"\n } catch {\n // Storage can be unavailable (privacy mode, sandboxed iframe) — fall back to the OS.\n return \"system\"\n }\n}\n\nfunction writeStored(theme: Theme) {\n try {\n if (theme === \"system\") localStorage.removeItem(STORAGE_KEY)\n else localStorage.setItem(STORAGE_KEY, theme)\n } catch {\n // Storage being unavailable only costs persistence; the in-memory value still applies.\n }\n}\n\n/**\n * `system` clears the attribute so `color-scheme: light dark` follows the OS; anything else\n * pins it.\n */\nfunction applyTheme(theme: Theme) {\n const root = document.documentElement\n\n if (theme === \"system\") delete root.dataset.theme\n else root.dataset.theme = theme\n}\n\n/**\n * Narrows every transition to geometry until the next style pass is done. A theme change swaps\n * every token at once, and anything that transitions a colour (a card's edge, a button's fill)\n * would otherwise tween into the new scheme while the rest of the page flips. Movement keeps\n * its transition: the theme picker's pill slides to the chosen option in the same frames.\n * Called before the change, or from the OS scheme's change event, which fires before the\n * browser restyles.\n */\nfunction suspendColorTransitions() {\n const style = document.createElement(\"style\")\n style.textContent =\n \"*,*::before,*::after{transition-property:translate,transform,width,height!important}\"\n document.head.append(style)\n\n // Two frames: a callback queued from the media query event can still run before that\n // frame's style pass, and the override has to outlive it.\n requestAnimationFrame(() => requestAnimationFrame(() => style.remove()))\n}\n\nfunction emit() {\n for (const listener of listeners) listener()\n}\n\nfunction onStorage(event: StorageEvent) {\n // `key === null` is a `clear()` from another tab; treat it as a reset.\n if (event.key !== null && event.key !== STORAGE_KEY) return\n\n current = readStored()\n suspendColorTransitions()\n applyTheme(current)\n emit()\n}\n\nfunction onSchemeChange() {\n // A pinned theme ignores the OS; only `system` repaints when it flips.\n if (current === \"system\") suspendColorTransitions()\n}\n\nfunction getSnapshot(): Theme {\n current ??= readStored()\n return current\n}\n\nfunction getServerSnapshot(): Theme {\n return \"system\"\n}\n\nfunction subscribe(listener: () => void) {\n if (listeners.size === 0) {\n window.addEventListener(\"storage\", onStorage)\n osScheme = window.matchMedia(OS_DARK_QUERY)\n osScheme.addEventListener(\"change\", onSchemeChange)\n // Apps that skip the inline script still land on the stored theme, one paint late.\n applyTheme(getSnapshot())\n }\n\n listeners.add(listener)\n\n return () => {\n listeners.delete(listener)\n if (listeners.size > 0) return\n\n window.removeEventListener(\"storage\", onStorage)\n osScheme?.removeEventListener(\"change\", onSchemeChange)\n }\n}\n\nfunction setTheme(theme: Theme) {\n if (theme === current) return\n\n current = theme\n writeStored(theme)\n suspendColorTransitions()\n applyTheme(theme)\n emit()\n}\n\n/**\n * The current theme and its setter. Persists to `localStorage[\"theme\"]`, stays in sync across\n * tabs, and drives the stylesheet's `light-dark()` tokens by setting `data-theme` on `<html>`\n * (`system` removes it so the OS decides). SSR-safe: the server renders `system`.\n *\n * The hook only applies the stored theme once the first subscriber mounts. To avoid a flash of\n * the wrong scheme, apply it before first paint with this inline script in `<head>`:\n *\n * ```html\n * <script>try{var t=localStorage.theme;if(t===\"light\"||t===\"dark\")document.documentElement.dataset.theme=t}catch(e){}</script>\n * ```\n */\nexport function useTheme(): [Theme, (theme: Theme) => void] {\n const theme = useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot)\n\n return [theme, setTheme]\n}\n\nconst THEME_OPTIONS = [\n { value: \"system\", label: \"System\", icon: ComputerIcon },\n { value: \"light\", label: \"Light\", icon: SunIcon },\n { value: \"dark\", label: \"Dark\", icon: MoonIcon },\n] as const\n\ninterface ThemeSelectProps extends Omit<\n SegmentedControlProps<Theme>,\n \"value\" | \"defaultValue\" | \"onValueChange\" | \"variant\" | \"size\"\n> {\n /**\n * The smallest track with one icon per theme, for a menu row where the labelled control\n * would not fit.\n */\n compact?: boolean\n}\n\n/**\n * Segmented System / Light / Dark control bound to `useTheme`, for a settings page or an\n * account menu.\n */\nexport function ThemeSelect({ compact, ...props }: ThemeSelectProps) {\n const [theme, setTheme] = useTheme()\n\n return (\n <SegmentedControl\n value={theme}\n size={compact ? \"xs\" : \"md\"}\n aria-label=\"Theme\"\n onValueChange={setTheme}\n {...props}\n >\n {THEME_OPTIONS.map(({ value, label, icon: Icon }) => (\n <SegmentedControlItem key={value} value={value} aria-label={compact ? label : undefined}>\n {compact ? <Icon /> : label}\n </SegmentedControlItem>\n ))}\n </SegmentedControl>\n )\n}\n"],"mappings":";;;;;;AAYA,MAAM,cAAc;AACpB,MAAM,gBAAgB;AACtB,MAAM,SAA2B;CAAC;CAAU;CAAS;AAAM;;;;;;AAO3D,MAAM,4BAAY,IAAI,IAAgB;AACtC,IAAI;AAGJ,IAAI;AAEJ,SAAS,QAAQ,OAAgC;CAC/C,OAAO,OAAO,UAAU,YAAY,OAAO,SAAS,KAAc;AACpE;AAEA,SAAS,aAAoB;CAC3B,IAAI;EACF,MAAM,SAAS,aAAa,QAAQ,WAAW;EAC/C,OAAO,QAAQ,MAAM,IAAI,SAAS;CACpC,QAAQ;EAEN,OAAO;CACT;AACF;AAEA,SAAS,YAAY,OAAc;CACjC,IAAI;EACF,IAAI,UAAU,UAAU,aAAa,WAAW,WAAW;OACtD,aAAa,QAAQ,aAAa,KAAK;CAC9C,QAAQ,CAER;AACF;;;;;AAMA,SAAS,WAAW,OAAc;CAChC,MAAM,OAAO,SAAS;CAEtB,IAAI,UAAU,UAAU,OAAO,KAAK,QAAQ;MACvC,KAAK,QAAQ,QAAQ;AAC5B;;;;;;;;;AAUA,SAAS,0BAA0B;CACjC,MAAM,QAAQ,SAAS,cAAc,OAAO;CAC5C,MAAM,cACJ;CACF,SAAS,KAAK,OAAO,KAAK;CAI1B,4BAA4B,4BAA4B,MAAM,OAAO,CAAC,CAAC;AACzE;AAEA,SAAS,OAAO;CACd,KAAK,MAAM,YAAY,WAAW,SAAS;AAC7C;AAEA,SAAS,UAAU,OAAqB;CAEtC,IAAI,MAAM,QAAQ,QAAQ,MAAM,QAAQ,aAAa;CAErD,UAAU,WAAW;CACrB,wBAAwB;CACxB,WAAW,OAAO;CAClB,KAAK;AACP;AAEA,SAAS,iBAAiB;CAExB,IAAI,YAAY,UAAU,wBAAwB;AACpD;AAEA,SAAS,cAAqB;CAC5B,YAAY,WAAW;CACvB,OAAO;AACT;AAEA,SAAS,oBAA2B;CAClC,OAAO;AACT;AAEA,SAAS,UAAU,UAAsB;CACvC,IAAI,UAAU,SAAS,GAAG;EACxB,OAAO,iBAAiB,WAAW,SAAS;EAC5C,WAAW,OAAO,WAAW,aAAa;EAC1C,SAAS,iBAAiB,UAAU,cAAc;EAElD,WAAW,YAAY,CAAC;CAC1B;CAEA,UAAU,IAAI,QAAQ;CAEtB,aAAa;EACX,UAAU,OAAO,QAAQ;EACzB,IAAI,UAAU,OAAO,GAAG;EAExB,OAAO,oBAAoB,WAAW,SAAS;EAC/C,UAAU,oBAAoB,UAAU,cAAc;CACxD;AACF;AAEA,SAAS,SAAS,OAAc;CAC9B,IAAI,UAAU,SAAS;CAEvB,UAAU;CACV,YAAY,KAAK;CACjB,wBAAwB;CACxB,WAAW,KAAK;CAChB,KAAK;AACP;;;;;;;;;;;;;AAcA,SAAgB,WAA4C;CAG1D,OAAO,CAFO,qBAAqB,WAAW,aAAa,iBAE/C,GAAG,QAAQ;AACzB;AAEA,MAAM,gBAAgB;CACpB;EAAE,OAAO;EAAU,OAAO;EAAU,MAAM;CAAa;CACvD;EAAE,OAAO;EAAS,OAAO;EAAS,MAAM;CAAQ;CAChD;EAAE,OAAO;EAAQ,OAAO;EAAQ,MAAM;CAAS;AACjD;;;;;AAiBA,SAAgB,YAAY,EAAE,SAAS,GAAG,SAA2B;CACnE,MAAM,CAAC,OAAO,YAAY,SAAS;CAEnC,OACE,oBAAC,kBAAD;EACE,OAAO;EACP,MAAM,UAAU,OAAO;EACvB,cAAW;EACX,eAAe;EACf,GAAI;EAEH,UAAA,cAAc,KAAK,EAAE,OAAO,OAAO,MAAM,WACxC,oBAAC,sBAAD;GAAyC;GAAO,cAAY,UAAU,QAAQ,KAAA;GAC3E,UAAA,UAAU,oBAAC,MAAD,CAAO,CAAA,IAAI;EACF,GAFK,KAEL,CACvB;CACe,CAAA;AAEtB"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { TimeSeriesNote, TimeSeriesPoint, TimeSeriesSeries } from "../lib/time-series.js";
|
|
2
|
+
import { ComponentProps } from "react";
|
|
3
|
+
export interface TimeSeriesChartProps extends Omit<ComponentProps<"div">, "children"> {
|
|
4
|
+
data: TimeSeriesPoint[];
|
|
5
|
+
/**
|
|
6
|
+
* The series name, shown in the tooltip. Under `series` it is the chart's accessible name
|
|
7
|
+
* instead; each line carries its own label.
|
|
8
|
+
*/
|
|
9
|
+
label: string;
|
|
10
|
+
/**
|
|
11
|
+
* Series colour; one of the `--color-chart-*` tokens.
|
|
12
|
+
*/
|
|
13
|
+
color?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Multi-series mode: one line per entry, read from `point.values[key]`, all on the value
|
|
16
|
+
* axis. Draws no gradient and no `previous` line; lists every line in the tooltip, largest
|
|
17
|
+
* first, and a legend of totals above the plot. Meant for up to three lines.
|
|
18
|
+
*/
|
|
19
|
+
series?: TimeSeriesSeries[];
|
|
20
|
+
/**
|
|
21
|
+
* Whether the legend sums each line over the range. Off for a metric that does not add up
|
|
22
|
+
* across buckets (a rate, an average duration), where the legend names the lines alone.
|
|
23
|
+
*/
|
|
24
|
+
seriesTotals?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Value-axis tick, usually compact ("5.9K"). The chart builds no formatter of its own: the
|
|
27
|
+
* app supplies every reading, so the axis follows the same locale and time zone as the
|
|
28
|
+
* figures around it.
|
|
29
|
+
*/
|
|
30
|
+
formatTick: (value: number) => string;
|
|
31
|
+
/**
|
|
32
|
+
* Tooltip value, usually grouped ("5,912").
|
|
33
|
+
*/
|
|
34
|
+
formatValue: (value: number) => string;
|
|
35
|
+
/**
|
|
36
|
+
* Date-axis tick, usually short ("Sep 6").
|
|
37
|
+
*/
|
|
38
|
+
formatDate: (date: Date) => string;
|
|
39
|
+
/**
|
|
40
|
+
* A note's day in the tooltip; `formatDate` by default. Set it where `formatDate` follows
|
|
41
|
+
* the bucket size and drops the day on a monthly axis.
|
|
42
|
+
*/
|
|
43
|
+
formatNoteDate?: (date: Date) => string;
|
|
44
|
+
/**
|
|
45
|
+
* Tooltip heading, usually long ("September 6, 2026").
|
|
46
|
+
*/
|
|
47
|
+
formatTooltipDate: (date: Date) => string;
|
|
48
|
+
/**
|
|
49
|
+
* A fixed scale (a rate pinned to `[0, 100]`) instead of a rounded top over the data.
|
|
50
|
+
*/
|
|
51
|
+
domain?: [number, number];
|
|
52
|
+
/**
|
|
53
|
+
* Line shape: a smooth curve through the points by default, or straight segments between
|
|
54
|
+
* them (`"linear"`) so each bucket reads as a corner.
|
|
55
|
+
*/
|
|
56
|
+
curve?: "smooth" | "linear";
|
|
57
|
+
/**
|
|
58
|
+
* The line through `value` (default), or the `bar` series alone (`"bar"`) at full scale on
|
|
59
|
+
* the left axis: a sum per bucket, such as money, rather than a level. As the chart, a
|
|
60
|
+
* compared period (`previous`, in the bar's unit) is a hatched bar beside each one. The bar
|
|
61
|
+
* element is the same either way, so switching morphs the bars instead of redrawing them.
|
|
62
|
+
*/
|
|
63
|
+
shape?: "line" | "bar";
|
|
64
|
+
/**
|
|
65
|
+
* The bar series' name (tooltip and legend); shown when any point carries a `bar`.
|
|
66
|
+
*/
|
|
67
|
+
barLabel?: string;
|
|
68
|
+
/** The outline series' name (tooltip); shown when any point carries an `outline`. */
|
|
69
|
+
outlineLabel?: string;
|
|
70
|
+
/**
|
|
71
|
+
* Bar colour; one of the `--color-chart-*` tokens.
|
|
72
|
+
*/
|
|
73
|
+
barColor?: string;
|
|
74
|
+
/**
|
|
75
|
+
* Bar-axis tick, on the left; `formatTick` by default.
|
|
76
|
+
*/
|
|
77
|
+
formatBarTick?: (value: number) => string;
|
|
78
|
+
/**
|
|
79
|
+
* Bar tooltip value; `formatValue` by default.
|
|
80
|
+
*/
|
|
81
|
+
formatBarValue?: (value: number) => string;
|
|
82
|
+
/**
|
|
83
|
+
* Notes pinned to dates; drawn as markers on the baseline of the bucket that holds them and
|
|
84
|
+
* listed in that bucket's tooltip.
|
|
85
|
+
*/
|
|
86
|
+
notes?: TimeSeriesNote[];
|
|
87
|
+
/**
|
|
88
|
+
* Marker and tooltip colour for notes; one of the `--color-chart-*` tokens.
|
|
89
|
+
*/
|
|
90
|
+
noteColor?: string;
|
|
91
|
+
/**
|
|
92
|
+
* The exclusive end of the bucket starting at `date`. Only the trailing bucket needs it,
|
|
93
|
+
* since every other bucket ends where the next begins, and only because a month bucket's
|
|
94
|
+
* width can't be read off the series; without it the last bucket is as wide as the one
|
|
95
|
+
* before.
|
|
96
|
+
*/
|
|
97
|
+
bucketEnd?: (date: Date) => Date;
|
|
98
|
+
/**
|
|
99
|
+
* Called with the clicked bucket's date and exclusive end. The cursor turns into a pointer
|
|
100
|
+
* when set.
|
|
101
|
+
*/
|
|
102
|
+
onPointClick?: (date: Date, end: Date) => void;
|
|
103
|
+
/**
|
|
104
|
+
* What a click on the plot does, said at the foot of the tooltip; shown only with
|
|
105
|
+
* `onPointClick`.
|
|
106
|
+
*/
|
|
107
|
+
pointClickHint?: string;
|
|
108
|
+
/**
|
|
109
|
+
* Draw no value labels, on either side, and let the data run to the plot's edges. The grid
|
|
110
|
+
* stays. For a plot too narrow to give the labels their room.
|
|
111
|
+
*/
|
|
112
|
+
hideValueAxis?: boolean;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* The single time series: a smooth gradient area with a right-hand value axis on round grid
|
|
116
|
+
* lines and evenly spaced date ticks along the bottom. A compared period draws as a dashed
|
|
117
|
+
* line in the same hue. Notes pinned to dates mark their bucket on the baseline and list
|
|
118
|
+
* themselves in its tooltip. With `series` set it is several plain lines on that same axis,
|
|
119
|
+
* under a legend of totals.
|
|
120
|
+
*/
|
|
121
|
+
export declare function TimeSeriesChart({ data, label, color, series, seriesTotals, formatTick, formatValue, formatDate, formatNoteDate, formatTooltipDate, domain, curve, shape, barLabel, outlineLabel, barColor, formatBarTick, formatBarValue, notes, noteColor, bucketEnd, onPointClick, pointClickHint, hideValueAxis, className, ...props }: TimeSeriesChartProps): import("react").JSX.Element;
|
|
122
|
+
export type { TimeSeriesNote, TimeSeriesPoint, TimeSeriesSeries };
|