@underpin/ui 2.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.
@@ -1,5 +1,6 @@
1
- import { segmentedVariants } from "../lib/segmented.js";
1
+ import { SegmentedStyle, segmentedVariants } from "../lib/segmented.js";
2
2
  import { VariantProps } from "../lib/variants.js";
3
+ import { ComponentProps } from "react";
3
4
  import { Tabs as Tabs$1 } from "@base-ui/react/tabs";
4
5
  /**
5
6
  * Tabs that switch a panel: each `TabsTrigger` shows its `TabsPanel`, and a screen reader
@@ -12,7 +13,24 @@ declare const Tabs: import("react").ForwardRefExoticComponent<Omit<import("@base
12
13
  * `value` of its `TabsTrigger`.
13
14
  */
14
15
  declare const TabsPanel: import("react").ForwardRefExoticComponent<Omit<import("@base-ui/react").TabsPanelProps, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
15
- type TabsListProps = Tabs$1.List.Props & VariantProps<typeof segmentedVariants>;
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
+ };
16
21
  declare function TabsList({ className, children, variant, size, ...props }: TabsListProps): import("react").JSX.Element;
17
22
  declare const TabsTrigger: import("react").MemoExoticComponent<({ className, ...props }: Tabs$1.Tab.Props) => import("react").JSX.Element>;
18
- export { Tabs, TabsList, TabsPanel, TabsTrigger };
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 };
@@ -1,8 +1,9 @@
1
1
  "use client";
2
+ import { interactiveVariants } from "../lib/interactive.js";
2
3
  import { segmentedVariants } from "../lib/segmented.js";
3
- import { cn } from "../lib/variants.js";
4
+ import { cn, variants } from "../lib/variants.js";
4
5
  import { jsx, jsxs } from "react/jsx-runtime";
5
- import { createContext, memo, use } from "react";
6
+ import { createContext, memo, use, useEffect, useRef } from "react";
6
7
  import { Tabs as Tabs$1 } from "@base-ui/react/tabs";
7
8
  // src/components/tabs.tsx
8
9
  /**
@@ -21,27 +22,59 @@ const TabsVariantContext = createContext({
21
22
  size: "md"
22
23
  });
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
+ /**
24
40
  * Sliding highlight that tracks the active tab via Base UI's --active-tab-* CSS variables.
25
41
  * Rendered automatically by TabsList, so every tab group shares one pill.
26
42
  */
27
43
  function TabsIndicator({ className, ...props }) {
28
44
  const { variant, size } = use(TabsVariantContext);
29
45
  return /* @__PURE__ */ jsx(Tabs$1.Indicator, {
30
- className: cn(segmentedVariants({
46
+ className: cn(variant === "underline" ? UNDERLINE_CLASSES.indicator : [segmentedVariants({
31
47
  variant,
32
48
  size
33
- }).indicator(), "h-(--active-tab-height) w-(--active-tab-width) translate-x-(--active-tab-left) translate-y-(--active-tab-top)", className),
49
+ }).indicator(), "h-(--active-tab-height) w-(--active-tab-width) translate-x-(--active-tab-left) translate-y-(--active-tab-top)"], className),
34
50
  ...props
35
51
  });
36
52
  }
37
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]);
38
70
  return /* @__PURE__ */ jsx(TabsVariantContext, {
39
71
  value: {
40
72
  variant,
41
73
  size
42
74
  },
43
75
  children: /* @__PURE__ */ jsxs(Tabs$1.List, {
44
- className: cn(segmentedVariants({
76
+ ref: listRef,
77
+ className: cn(variant === "underline" ? UNDERLINE_CLASSES.root : segmentedVariants({
45
78
  variant,
46
79
  size
47
80
  }).root(), className),
@@ -53,13 +86,35 @@ function TabsList({ className, children, variant = "segmented", size = "md", ...
53
86
  const TabsTrigger = memo(function TabsTrigger({ className, ...props }) {
54
87
  const { variant, size } = use(TabsVariantContext);
55
88
  return /* @__PURE__ */ jsx(Tabs$1.Tab, {
56
- className: cn(segmentedVariants({
89
+ className: cn(variant === "underline" ? UNDERLINE_CLASSES.item : [segmentedVariants({
57
90
  variant,
58
91
  size
59
- }).item(), "not-disabled:cursor-pointer disabled:opacity-50 data-active:text-ink", className),
92
+ }).item(), "data-active:text-ink"], "not-disabled:cursor-pointer disabled:opacity-50", className),
60
93
  ...props
61
94
  });
62
95
  });
63
- export { Tabs, TabsList, TabsPanel, TabsTrigger };
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 };
64
119
 
65
120
  //# sourceMappingURL=tabs.js.map
@@ -1 +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 { createContext, memo, use } from \"react\"\nimport { type SegmentedStyle, segmentedVariants } from \"../lib/segmented\"\nimport { cn, 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\nconst TabsVariantContext = createContext<SegmentedStyle>({\n variant: \"segmented\",\n size: \"md\",\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 segmentedVariants({ variant, size }).indicator(),\n \"h-(--active-tab-height) w-(--active-tab-width) translate-x-(--active-tab-left) translate-y-(--active-tab-top)\",\n className,\n )}\n {...props}\n />\n )\n}\n\ntype TabsListProps = TabsPrimitive.List.Props & VariantProps<typeof segmentedVariants>\n\nfunction TabsList({\n className,\n children,\n variant = \"segmented\",\n size = \"md\",\n ...props\n}: TabsListProps) {\n return (\n <TabsVariantContext value={{ variant, size }}>\n <TabsPrimitive.List\n className={cn(segmentedVariants({ variant, size }).root(), className)}\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 segmentedVariants({ variant, size }).item(),\n \"not-disabled:cursor-pointer disabled:opacity-50 data-active:text-ink\",\n className,\n )}\n {...props}\n />\n )\n})\n\nexport { Tabs, TabsList, TabsPanel, TabsTrigger }\n"],"mappings":";;;;;;;;;;;;AAYA,MAAM,OAAOA,OAAc;;;;;AAM3B,MAAM,YAAYA,OAAc;AAKhC,MAAM,qBAAqB,cAA8B;CACvD,SAAS;CACT,MAAM;AACR,CAAC;;;;;AAMD,SAAS,cAAc,EAAE,WAAW,GAAG,SAAwC;CAC7E,MAAM,EAAE,SAAS,SAAS,IAAI,kBAAkB;CAEhD,OACE,oBAACA,OAAc,WAAf;EACE,WAAW,GACT,kBAAkB;GAAE;GAAS;EAAK,CAAC,CAAC,CAAC,UAAU,GAC/C,iHACA,SACF;EACA,GAAI;CACL,CAAA;AAEL;AAIA,SAAS,SAAS,EAChB,WACA,UACA,UAAU,aACV,OAAO,MACP,GAAG,SACa;CAChB,OACE,oBAAC,oBAAD;EAAoB,OAAO;GAAE;GAAS;EAAK;EACzC,UAAA,qBAACA,OAAc,MAAf;GACE,WAAW,GAAG,kBAAkB;IAAE;IAAS;GAAK,CAAC,CAAC,CAAC,KAAK,GAAG,SAAS;GACpE,GAAI;GAFN,UAAA,CAIE,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,kBAAkB;GAAE;GAAS;EAAK,CAAC,CAAC,CAAC,KAAK,GAC1C,wEACA,SACF;EACA,GAAI;CACL,CAAA;AAEL,CAAC"}
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,87 @@
1
+ import { TableColumnPriority } from "../components/table.js";
2
+ import { ColumnVisibilityState, RowData } from "@tanstack/react-table";
3
+ /**
4
+ * The model behind `DataTable`: its react-table features, the meta a column carries, and the
5
+ * state the app owns. The package never reads the URL: an app keeps `DataTableState` in its
6
+ * router's search params (TanStack Router, nuqs) and hands it back on every change.
7
+ */
8
+ /** What a column tells the table about its own head and cells. */
9
+ export interface DataTableColumnMeta {
10
+ /** Figures read from the end. */
11
+ align?: "start" | "end";
12
+ /** The column's grid track: `minmax(0,1fr)` (the default) for the name, `6rem` for a figure. */
13
+ width?: string;
14
+ /**
15
+ * Where the column gives way as the table narrows: `medium` below 672px, `low` below 896px,
16
+ * `lowest` below 1152px.
17
+ */
18
+ priority?: TableColumnPriority;
19
+ /**
20
+ * Turns the column's name into a button that sorts by it. The first click sorts ascending, or
21
+ * descending for `"descending"` (a figure, a date read newest first); the next flips it.
22
+ */
23
+ sortable?: boolean | "ascending" | "descending";
24
+ /** Whether a skeleton row draws a stand-in here. Off for an actions column. */
25
+ skeleton?: boolean;
26
+ /** The column's name in the column picker, for a column whose header is not a string. */
27
+ label?: string;
28
+ }
29
+ /** The react-table features every `DataTable` registers. */
30
+ export declare const DATA_TABLE_FEATURES: {
31
+ rowSortingFeature: import("@tanstack/react-table").TableFeature;
32
+ rowSelectionFeature: import("@tanstack/react-table").TableFeature;
33
+ columnVisibilityFeature: import("@tanstack/react-table").TableFeature;
34
+ columnMeta: DataTableColumnMeta;
35
+ };
36
+ export type DataTableFeatures = typeof DATA_TABLE_FEATURES;
37
+ /**
38
+ * The column helper for a `DataTable` of `TData` rows. A column's `cell` returns one of the
39
+ * table's cell parts (`TableCell`, `TableIdentityCell`, `TableNumberCell`…), which take the
40
+ * column's `align` and `priority` from its meta.
41
+ */
42
+ export declare function createDataTableColumnHelper<TData extends RowData>(): import("@tanstack/react-table").ColumnHelper<{
43
+ rowSortingFeature: import("@tanstack/react-table").TableFeature;
44
+ rowSelectionFeature: import("@tanstack/react-table").TableFeature;
45
+ columnVisibilityFeature: import("@tanstack/react-table").TableFeature;
46
+ columnMeta: DataTableColumnMeta;
47
+ }, TData>;
48
+ export interface DataTableSort {
49
+ /** The column's id. */
50
+ id: string;
51
+ desc: boolean;
52
+ }
53
+ /** What a table shows, owned by the app. */
54
+ export interface DataTableState {
55
+ /** 1-based. Read by a paged table, left out by one that loads as it scrolls. */
56
+ page?: number;
57
+ /** Rows on a page. Read by a paged table. */
58
+ perPage?: number;
59
+ /** Left out while the server's own order applies, so no column shows an arrow. */
60
+ sort?: DataTableSort;
61
+ search?: string;
62
+ /** The chosen values of each filtered field, by field. */
63
+ filters?: Record<string, string[]>;
64
+ }
65
+ /** The page size of a paged table whose state names none. */
66
+ export declare const DEFAULT_PER_PAGE = 25;
67
+ /**
68
+ * The state after a change, under the paging rules: a new sort, search, filter or page size
69
+ * starts over on page 1, since the page the reader was on no longer holds the same rows.
70
+ */
71
+ export declare function changeDataTableState(state: DataTableState, change: Partial<DataTableState>): DataTableState;
72
+ /** How many pages `total` rows fill. An empty table still has its one page. */
73
+ export declare function getPageCount(total: number, perPage: number): number;
74
+ /**
75
+ * The page a table shows for the one its state asks for: page 1 for a page before it, the last
76
+ * page for one past the end (a stale link, rows deleted since).
77
+ */
78
+ export declare function clampPage(page: number, pageCount: number): number;
79
+ /**
80
+ * A key that changes whenever the rows a table holds stop being the same set: a new page, sort,
81
+ * search or filter. A selection covers one such set.
82
+ */
83
+ export declare function formatRowSetKey({ page, perPage, sort, search, filters }: DataTableState): string;
84
+ /** The columns the reader hid on this table, saved in this browser. Empty when none are. */
85
+ export declare function readColumnVisibility(storageKey: string): ColumnVisibilityState;
86
+ /** Saves the columns the reader hid. A browser that blocks storage keeps them for the visit. */
87
+ export declare function writeColumnVisibility(storageKey: string, visibility: ColumnVisibilityState): void;
@@ -0,0 +1,92 @@
1
+ import { columnVisibilityFeature, createColumnHelper, metaHelper, rowSelectionFeature, rowSortingFeature, tableFeatures } from "@tanstack/react-table";
2
+ // src/lib/data-table-state.ts
3
+ /** The react-table features every `DataTable` registers. */
4
+ const DATA_TABLE_FEATURES = tableFeatures({
5
+ rowSortingFeature,
6
+ rowSelectionFeature,
7
+ columnVisibilityFeature,
8
+ columnMeta: metaHelper()
9
+ });
10
+ /**
11
+ * The column helper for a `DataTable` of `TData` rows. A column's `cell` returns one of the
12
+ * table's cell parts (`TableCell`, `TableIdentityCell`, `TableNumberCell`…), which take the
13
+ * column's `align` and `priority` from its meta.
14
+ */
15
+ function createDataTableColumnHelper() {
16
+ return createColumnHelper();
17
+ }
18
+ /** The page size of a paged table whose state names none. */
19
+ const DEFAULT_PER_PAGE = 25;
20
+ function isSameSort(one, other) {
21
+ return one?.id === other?.id && one?.desc === other?.desc;
22
+ }
23
+ function isSameFilters(one, other) {
24
+ return [.../* @__PURE__ */ new Set([...Object.keys(one ?? {}), ...Object.keys(other ?? {})])].every((key) => {
25
+ const left = one?.[key] ?? [];
26
+ const right = other?.[key] ?? [];
27
+ return left.length === right.length && left.every((value) => right.includes(value));
28
+ });
29
+ }
30
+ /**
31
+ * The state after a change, under the paging rules: a new sort, search, filter or page size
32
+ * starts over on page 1, since the page the reader was on no longer holds the same rows.
33
+ */
34
+ function changeDataTableState(state, change) {
35
+ const next = {
36
+ ...state,
37
+ ...change
38
+ };
39
+ return "sort" in change && !isSameSort(state.sort, change.sort) || "search" in change && (state.search ?? "") !== (change.search ?? "") || "filters" in change && !isSameFilters(state.filters, change.filters) || "perPage" in change && state.perPage !== change.perPage ? {
40
+ ...next,
41
+ page: 1
42
+ } : next;
43
+ }
44
+ /** How many pages `total` rows fill. An empty table still has its one page. */
45
+ function getPageCount(total, perPage) {
46
+ return Math.max(1, Math.ceil(total / perPage));
47
+ }
48
+ /**
49
+ * The page a table shows for the one its state asks for: page 1 for a page before it, the last
50
+ * page for one past the end (a stale link, rows deleted since).
51
+ */
52
+ function clampPage(page, pageCount) {
53
+ return Math.min(Math.max(1, Math.floor(page)), pageCount);
54
+ }
55
+ /**
56
+ * A key that changes whenever the rows a table holds stop being the same set: a new page, sort,
57
+ * search or filter. A selection covers one such set.
58
+ */
59
+ function formatRowSetKey({ page, perPage, sort, search, filters }) {
60
+ const filterKey = Object.entries(filters ?? {}).filter(([, values]) => values.length > 0).map(([field, values]) => [field, values.toSorted()]).toSorted(([one], [other]) => String(one).localeCompare(String(other)));
61
+ return JSON.stringify([
62
+ page,
63
+ perPage,
64
+ sort?.id,
65
+ sort?.desc,
66
+ search ?? "",
67
+ filterKey
68
+ ]);
69
+ }
70
+ function formatStorageKey(storageKey) {
71
+ return `underpin:data-table:${storageKey}:columns`;
72
+ }
73
+ /** The columns the reader hid on this table, saved in this browser. Empty when none are. */
74
+ function readColumnVisibility(storageKey) {
75
+ try {
76
+ const stored = JSON.parse(localStorage.getItem(formatStorageKey(storageKey)) ?? "{}");
77
+ if (typeof stored !== "object" || stored === null || Array.isArray(stored)) return {};
78
+ return Object.fromEntries(Object.entries(stored).filter((entry) => entry[1] === false));
79
+ } catch {
80
+ return {};
81
+ }
82
+ }
83
+ /** Saves the columns the reader hid. A browser that blocks storage keeps them for the visit. */
84
+ function writeColumnVisibility(storageKey, visibility) {
85
+ const hidden = Object.fromEntries(Object.entries(visibility).filter(([, shown]) => !shown));
86
+ try {
87
+ localStorage.setItem(formatStorageKey(storageKey), JSON.stringify(hidden));
88
+ } catch {}
89
+ }
90
+ export { DATA_TABLE_FEATURES, DEFAULT_PER_PAGE, changeDataTableState, clampPage, createDataTableColumnHelper, formatRowSetKey, getPageCount, readColumnVisibility, writeColumnVisibility };
91
+
92
+ //# sourceMappingURL=data-table-state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data-table-state.js","names":[],"sources":["../../src/lib/data-table-state.ts"],"sourcesContent":["import {\n type ColumnVisibilityState,\n columnVisibilityFeature,\n createColumnHelper,\n metaHelper,\n type RowData,\n rowSelectionFeature,\n rowSortingFeature,\n tableFeatures,\n} from \"@tanstack/react-table\"\nimport type { TableColumnPriority } from \"../components/table\"\n\n/**\n * The model behind `DataTable`: its react-table features, the meta a column carries, and the\n * state the app owns. The package never reads the URL: an app keeps `DataTableState` in its\n * router's search params (TanStack Router, nuqs) and hands it back on every change.\n */\n\n/** What a column tells the table about its own head and cells. */\nexport interface DataTableColumnMeta {\n /** Figures read from the end. */\n align?: \"start\" | \"end\"\n /** The column's grid track: `minmax(0,1fr)` (the default) for the name, `6rem` for a figure. */\n width?: string\n /**\n * Where the column gives way as the table narrows: `medium` below 672px, `low` below 896px,\n * `lowest` below 1152px.\n */\n priority?: TableColumnPriority\n /**\n * Turns the column's name into a button that sorts by it. The first click sorts ascending, or\n * descending for `\"descending\"` (a figure, a date read newest first); the next flips it.\n */\n sortable?: boolean | \"ascending\" | \"descending\"\n /** Whether a skeleton row draws a stand-in here. Off for an actions column. */\n skeleton?: boolean\n /** The column's name in the column picker, for a column whose header is not a string. */\n label?: string\n}\n\n/** The react-table features every `DataTable` registers. */\nexport const DATA_TABLE_FEATURES = tableFeatures({\n rowSortingFeature,\n rowSelectionFeature,\n columnVisibilityFeature,\n columnMeta: metaHelper<DataTableColumnMeta>(),\n})\n\nexport type DataTableFeatures = typeof DATA_TABLE_FEATURES\n\n/**\n * The column helper for a `DataTable` of `TData` rows. A column's `cell` returns one of the\n * table's cell parts (`TableCell`, `TableIdentityCell`, `TableNumberCell`…), which take the\n * column's `align` and `priority` from its meta.\n */\nexport function createDataTableColumnHelper<TData extends RowData>() {\n return createColumnHelper<DataTableFeatures, TData>()\n}\n\nexport interface DataTableSort {\n /** The column's id. */\n id: string\n desc: boolean\n}\n\n/** What a table shows, owned by the app. */\nexport interface DataTableState {\n /** 1-based. Read by a paged table, left out by one that loads as it scrolls. */\n page?: number\n /** Rows on a page. Read by a paged table. */\n perPage?: number\n /** Left out while the server's own order applies, so no column shows an arrow. */\n sort?: DataTableSort\n search?: string\n /** The chosen values of each filtered field, by field. */\n filters?: Record<string, string[]>\n}\n\n/** The page size of a paged table whose state names none. */\nexport const DEFAULT_PER_PAGE = 25\n\nfunction isSameSort(one: DataTableSort | undefined, other: DataTableSort | undefined) {\n return one?.id === other?.id && one?.desc === other?.desc\n}\n\nfunction isSameFilters(one: DataTableState[\"filters\"], other: DataTableState[\"filters\"]) {\n const keys = new Set([...Object.keys(one ?? {}), ...Object.keys(other ?? {})])\n\n return [...keys].every(key => {\n const left = one?.[key] ?? []\n const right = other?.[key] ?? []\n return left.length === right.length && left.every(value => right.includes(value))\n })\n}\n\n/**\n * The state after a change, under the paging rules: a new sort, search, filter or page size\n * starts over on page 1, since the page the reader was on no longer holds the same rows.\n */\nexport function changeDataTableState(\n state: DataTableState,\n change: Partial<DataTableState>,\n): DataTableState {\n const next = { ...state, ...change }\n const restarts =\n (\"sort\" in change && !isSameSort(state.sort, change.sort)) ||\n (\"search\" in change && (state.search ?? \"\") !== (change.search ?? \"\")) ||\n (\"filters\" in change && !isSameFilters(state.filters, change.filters)) ||\n (\"perPage\" in change && state.perPage !== change.perPage)\n\n return restarts ? { ...next, page: 1 } : next\n}\n\n/** How many pages `total` rows fill. An empty table still has its one page. */\nexport function getPageCount(total: number, perPage: number) {\n return Math.max(1, Math.ceil(total / perPage))\n}\n\n/**\n * The page a table shows for the one its state asks for: page 1 for a page before it, the last\n * page for one past the end (a stale link, rows deleted since).\n */\nexport function clampPage(page: number, pageCount: number) {\n return Math.min(Math.max(1, Math.floor(page)), pageCount)\n}\n\n/**\n * A key that changes whenever the rows a table holds stop being the same set: a new page, sort,\n * search or filter. A selection covers one such set.\n */\nexport function formatRowSetKey({ page, perPage, sort, search, filters }: DataTableState) {\n // Sorted, so the same filters in another order make the same key, as `isSameFilters` reads them.\n const filterKey = Object.entries(filters ?? {})\n .filter(([, values]) => values.length > 0)\n .map(([field, values]) => [field, values.toSorted()])\n .toSorted(([one], [other]) => String(one).localeCompare(String(other)))\n\n return JSON.stringify([page, perPage, sort?.id, sort?.desc, search ?? \"\", filterKey])\n}\n\nfunction formatStorageKey(storageKey: string) {\n return `underpin:data-table:${storageKey}:columns`\n}\n\n/** The columns the reader hid on this table, saved in this browser. Empty when none are. */\nexport function readColumnVisibility(storageKey: string): ColumnVisibilityState {\n try {\n const stored: unknown = JSON.parse(localStorage.getItem(formatStorageKey(storageKey)) ?? \"{}\")\n if (typeof stored !== \"object\" || stored === null || Array.isArray(stored)) return {}\n\n return Object.fromEntries(\n Object.entries(stored).filter((entry): entry is [string, boolean] => entry[1] === false),\n )\n } catch {\n return {}\n }\n}\n\n/** Saves the columns the reader hid. A browser that blocks storage keeps them for the visit. */\nexport function writeColumnVisibility(storageKey: string, visibility: ColumnVisibilityState) {\n const hidden = Object.fromEntries(Object.entries(visibility).filter(([, shown]) => !shown))\n\n try {\n localStorage.setItem(formatStorageKey(storageKey), JSON.stringify(hidden))\n } catch {}\n}\n"],"mappings":";;;AAyCA,MAAa,sBAAsB,cAAc;CAC/C;CACA;CACA;CACA,YAAY,WAAgC;AAC9C,CAAC;;;;;;AASD,SAAgB,8BAAqD;CACnE,OAAO,mBAA6C;AACtD;;AAsBA,MAAa,mBAAmB;AAEhC,SAAS,WAAW,KAAgC,OAAkC;CACpF,OAAO,KAAK,OAAO,OAAO,MAAM,KAAK,SAAS,OAAO;AACvD;AAEA,SAAS,cAAc,KAAgC,OAAkC;CAGvF,OAAO,CAAC,mBAAG,IAFM,IAAI,CAAC,GAAG,OAAO,KAAK,OAAO,CAAC,CAAC,GAAG,GAAG,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,CAE9D,CAAC,CAAC,CAAC,OAAM,QAAO;EAC5B,MAAM,OAAO,MAAM,QAAQ,CAAC;EAC5B,MAAM,QAAQ,QAAQ,QAAQ,CAAC;EAC/B,OAAO,KAAK,WAAW,MAAM,UAAU,KAAK,OAAM,UAAS,MAAM,SAAS,KAAK,CAAC;CAClF,CAAC;AACH;;;;;AAMA,SAAgB,qBACd,OACA,QACgB;CAChB,MAAM,OAAO;EAAE,GAAG;EAAO,GAAG;CAAO;CAOnC,OALG,UAAU,UAAU,CAAC,WAAW,MAAM,MAAM,OAAO,IAAI,KACvD,YAAY,WAAW,MAAM,UAAU,SAAS,OAAO,UAAU,OACjE,aAAa,UAAU,CAAC,cAAc,MAAM,SAAS,OAAO,OAAO,KACnE,aAAa,UAAU,MAAM,YAAY,OAAO,UAEjC;EAAE,GAAG;EAAM,MAAM;CAAE,IAAI;AAC3C;;AAGA,SAAgB,aAAa,OAAe,SAAiB;CAC3D,OAAO,KAAK,IAAI,GAAG,KAAK,KAAK,QAAQ,OAAO,CAAC;AAC/C;;;;;AAMA,SAAgB,UAAU,MAAc,WAAmB;CACzD,OAAO,KAAK,IAAI,KAAK,IAAI,GAAG,KAAK,MAAM,IAAI,CAAC,GAAG,SAAS;AAC1D;;;;;AAMA,SAAgB,gBAAgB,EAAE,MAAM,SAAS,MAAM,QAAQ,WAA2B;CAExF,MAAM,YAAY,OAAO,QAAQ,WAAW,CAAC,CAAC,CAAC,CAC5C,QAAQ,GAAG,YAAY,OAAO,SAAS,CAAC,CAAC,CACzC,KAAK,CAAC,OAAO,YAAY,CAAC,OAAO,OAAO,SAAS,CAAC,CAAC,CAAC,CACpD,UAAU,CAAC,MAAM,CAAC,WAAW,OAAO,GAAG,CAAC,CAAC,cAAc,OAAO,KAAK,CAAC,CAAC;CAExE,OAAO,KAAK,UAAU;EAAC;EAAM;EAAS,MAAM;EAAI,MAAM;EAAM,UAAU;EAAI;CAAS,CAAC;AACtF;AAEA,SAAS,iBAAiB,YAAoB;CAC5C,OAAO,uBAAuB,WAAW;AAC3C;;AAGA,SAAgB,qBAAqB,YAA2C;CAC9E,IAAI;EACF,MAAM,SAAkB,KAAK,MAAM,aAAa,QAAQ,iBAAiB,UAAU,CAAC,KAAK,IAAI;EAC7F,IAAI,OAAO,WAAW,YAAY,WAAW,QAAQ,MAAM,QAAQ,MAAM,GAAG,OAAO,CAAC;EAEpF,OAAO,OAAO,YACZ,OAAO,QAAQ,MAAM,CAAC,CAAC,QAAQ,UAAsC,MAAM,OAAO,KAAK,CACzF;CACF,QAAQ;EACN,OAAO,CAAC;CACV;AACF;;AAGA,SAAgB,sBAAsB,YAAoB,YAAmC;CAC3F,MAAM,SAAS,OAAO,YAAY,OAAO,QAAQ,UAAU,CAAC,CAAC,QAAQ,GAAG,WAAW,CAAC,KAAK,CAAC;CAE1F,IAAI;EACF,aAAa,QAAQ,iBAAiB,UAAU,GAAG,KAAK,UAAU,MAAM,CAAC;CAC3E,QAAQ,CAAC;AACX"}
package/lib/icons.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  import { IconComponent } from "./icon.js";
2
2
  export declare const AlertIcon: IconComponent;
3
3
  export declare const AlertCircleIcon: IconComponent;
4
+ export declare const ArrowDownIcon: IconComponent;
5
+ export declare const ArrowUpIcon: IconComponent;
4
6
  export declare const ArrowUpRightIcon: IconComponent;
5
7
  export declare const CalendarIcon: IconComponent;
6
8
  export declare const CancelIcon: IconComponent;
@@ -8,6 +10,8 @@ export declare const CancelCircleIcon: IconComponent;
8
10
  export declare const CheckIcon: IconComponent;
9
11
  export declare const CheckCircleIcon: IconComponent;
10
12
  export declare const ChevronDownIcon: IconComponent;
13
+ export declare const ChevronsLeftIcon: IconComponent;
14
+ export declare const ChevronsRightIcon: IconComponent;
11
15
  export declare const ChevronLeftIcon: IconComponent;
12
16
  export declare const ChevronRightIcon: IconComponent;
13
17
  export declare const ChevronUpIcon: IconComponent;
@@ -15,9 +19,11 @@ export declare const ChevronsUpDownIcon: IconComponent;
15
19
  export declare const ComputerIcon: IconComponent;
16
20
  export declare const CopyIcon: IconComponent;
17
21
  export declare const DashIcon: IconComponent;
22
+ export declare const FilterIcon: IconComponent;
18
23
  export declare const HelpIcon: IconComponent;
19
24
  export declare const InfoIcon: IconComponent;
20
25
  export declare const LoadingIcon: IconComponent;
21
26
  export declare const MoonIcon: IconComponent;
27
+ export declare const PlusCircleIcon: IconComponent;
22
28
  export declare const SearchIcon: IconComponent;
23
29
  export declare const SunIcon: IconComponent;
package/lib/icons.js CHANGED
@@ -1,8 +1,10 @@
1
1
  import { icon } from "./icon.js";
2
- import { Alert02Icon, AlertCircleIcon as AlertCircleIcon$1, ArrowDown01Icon, ArrowLeft01Icon, ArrowRight01Icon, ArrowUp01Icon, ArrowUpRight01Icon, Calendar03Icon, Cancel01Icon, CancelCircleIcon as CancelCircleIcon$1, CheckmarkCircle02Icon, ComputerIcon as ComputerIcon$1, Copy01Icon, HelpCircleIcon, InformationCircleIcon, Loading03Icon, Moon02Icon, Remove01Icon, Search01Icon, Sun03Icon, Tick02Icon, UnfoldMoreIcon } from "@hugeicons/core-free-icons";
2
+ import { Alert02Icon, AlertCircleIcon as AlertCircleIcon$1, ArrowDown01Icon, ArrowDown02Icon, ArrowLeft01Icon, ArrowLeftDoubleIcon, ArrowRight01Icon, ArrowRightDoubleIcon, ArrowUp01Icon, ArrowUp02Icon, ArrowUpRight01Icon, Calendar03Icon, Cancel01Icon, CancelCircleIcon as CancelCircleIcon$1, CheckmarkCircle02Icon, ComputerIcon as ComputerIcon$1, Copy01Icon, HelpCircleIcon, InformationCircleIcon, ListFilterIcon, Loading03Icon, Moon02Icon, PlusSignCircleIcon, Remove01Icon, Search01Icon, Sun03Icon, Tick02Icon, UnfoldMoreIcon } from "@hugeicons/core-free-icons";
3
3
  // src/lib/icons.tsx
4
4
  const AlertIcon = icon(Alert02Icon, "AlertIcon");
5
5
  const AlertCircleIcon = icon(AlertCircleIcon$1, "AlertCircleIcon");
6
+ const ArrowDownIcon = icon(ArrowDown02Icon, "ArrowDownIcon");
7
+ const ArrowUpIcon = icon(ArrowUp02Icon, "ArrowUpIcon");
6
8
  const ArrowUpRightIcon = icon(ArrowUpRight01Icon, "ArrowUpRightIcon");
7
9
  const CalendarIcon = icon(Calendar03Icon, "CalendarIcon");
8
10
  const CancelIcon = icon(Cancel01Icon, "CancelIcon");
@@ -10,6 +12,8 @@ const CancelCircleIcon = icon(CancelCircleIcon$1, "CancelCircleIcon");
10
12
  const CheckIcon = icon(Tick02Icon, "CheckIcon");
11
13
  const CheckCircleIcon = icon(CheckmarkCircle02Icon, "CheckCircleIcon");
12
14
  const ChevronDownIcon = icon(ArrowDown01Icon, "ChevronDownIcon");
15
+ const ChevronsLeftIcon = icon(ArrowLeftDoubleIcon, "ChevronsLeftIcon");
16
+ const ChevronsRightIcon = icon(ArrowRightDoubleIcon, "ChevronsRightIcon");
13
17
  const ChevronLeftIcon = icon(ArrowLeft01Icon, "ChevronLeftIcon");
14
18
  const ChevronRightIcon = icon(ArrowRight01Icon, "ChevronRightIcon");
15
19
  const ChevronUpIcon = icon(ArrowUp01Icon, "ChevronUpIcon");
@@ -17,12 +21,14 @@ const ChevronsUpDownIcon = icon(UnfoldMoreIcon, "ChevronsUpDownIcon");
17
21
  const ComputerIcon = icon(ComputerIcon$1, "ComputerIcon");
18
22
  const CopyIcon = icon(Copy01Icon, "CopyIcon");
19
23
  const DashIcon = icon(Remove01Icon, "DashIcon");
24
+ const FilterIcon = icon(ListFilterIcon, "FilterIcon");
20
25
  const HelpIcon = icon(HelpCircleIcon, "HelpIcon");
21
26
  const InfoIcon = icon(InformationCircleIcon, "InfoIcon");
22
27
  const LoadingIcon = icon(Loading03Icon, "LoadingIcon");
23
28
  const MoonIcon = icon(Moon02Icon, "MoonIcon");
29
+ const PlusCircleIcon = icon(PlusSignCircleIcon, "PlusCircleIcon");
24
30
  const SearchIcon = icon(Search01Icon, "SearchIcon");
25
31
  const SunIcon = icon(Sun03Icon, "SunIcon");
26
- export { AlertCircleIcon, AlertIcon, ArrowUpRightIcon, CalendarIcon, CancelCircleIcon, CancelIcon, CheckCircleIcon, CheckIcon, ChevronDownIcon, ChevronLeftIcon, ChevronRightIcon, ChevronUpIcon, ChevronsUpDownIcon, ComputerIcon, CopyIcon, DashIcon, HelpIcon, InfoIcon, LoadingIcon, MoonIcon, SearchIcon, SunIcon };
32
+ export { AlertCircleIcon, AlertIcon, ArrowDownIcon, ArrowUpIcon, ArrowUpRightIcon, CalendarIcon, CancelCircleIcon, CancelIcon, CheckCircleIcon, CheckIcon, ChevronDownIcon, ChevronLeftIcon, ChevronRightIcon, ChevronUpIcon, ChevronsLeftIcon, ChevronsRightIcon, ChevronsUpDownIcon, ComputerIcon, CopyIcon, DashIcon, FilterIcon, HelpIcon, InfoIcon, LoadingIcon, MoonIcon, PlusCircleIcon, SearchIcon, SunIcon };
27
33
 
28
34
  //# sourceMappingURL=icons.js.map
package/lib/icons.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"icons.js","names":["AlertCircleDef","CancelCircleDef","ComputerDef"],"sources":["../../src/lib/icons.tsx"],"sourcesContent":["import {\n Alert02Icon,\n AlertCircleIcon as AlertCircleDef,\n ArrowDown01Icon,\n ArrowLeft01Icon,\n ArrowRight01Icon,\n ArrowUp01Icon,\n ArrowUpRight01Icon,\n Calendar03Icon,\n Cancel01Icon,\n CancelCircleIcon as CancelCircleDef,\n CheckmarkCircle02Icon,\n ComputerIcon as ComputerDef,\n Copy01Icon,\n HelpCircleIcon,\n InformationCircleIcon,\n Loading03Icon,\n Moon02Icon,\n Remove01Icon,\n Search01Icon,\n Sun03Icon,\n Tick02Icon,\n UnfoldMoreIcon,\n} from \"@hugeicons/core-free-icons\"\nimport { icon } from \"./icon\"\n\n// The handful of structural glyphs the package's own components render. This file lives in\n// `lib/` rather than `components/` so the `\"./*\"` wildcard export, which maps into\n// `components/`, never exposes it.\n\nexport const AlertIcon = icon(Alert02Icon, \"AlertIcon\")\nexport const AlertCircleIcon = icon(AlertCircleDef, \"AlertCircleIcon\")\nexport const ArrowUpRightIcon = icon(ArrowUpRight01Icon, \"ArrowUpRightIcon\")\nexport const CalendarIcon = icon(Calendar03Icon, \"CalendarIcon\")\nexport const CancelIcon = icon(Cancel01Icon, \"CancelIcon\")\nexport const CancelCircleIcon = icon(CancelCircleDef, \"CancelCircleIcon\")\nexport const CheckIcon = icon(Tick02Icon, \"CheckIcon\")\nexport const CheckCircleIcon = icon(CheckmarkCircle02Icon, \"CheckCircleIcon\")\nexport const ChevronDownIcon = icon(ArrowDown01Icon, \"ChevronDownIcon\")\nexport const ChevronLeftIcon = icon(ArrowLeft01Icon, \"ChevronLeftIcon\")\nexport const ChevronRightIcon = icon(ArrowRight01Icon, \"ChevronRightIcon\")\nexport const ChevronUpIcon = icon(ArrowUp01Icon, \"ChevronUpIcon\")\nexport const ChevronsUpDownIcon = icon(UnfoldMoreIcon, \"ChevronsUpDownIcon\")\nexport const ComputerIcon = icon(ComputerDef, \"ComputerIcon\")\nexport const CopyIcon = icon(Copy01Icon, \"CopyIcon\")\nexport const DashIcon = icon(Remove01Icon, \"DashIcon\")\nexport const HelpIcon = icon(HelpCircleIcon, \"HelpIcon\")\nexport const InfoIcon = icon(InformationCircleIcon, \"InfoIcon\")\nexport const LoadingIcon = icon(Loading03Icon, \"LoadingIcon\")\nexport const MoonIcon = icon(Moon02Icon, \"MoonIcon\")\nexport const SearchIcon = icon(Search01Icon, \"SearchIcon\")\nexport const SunIcon = icon(Sun03Icon, \"SunIcon\")\n"],"mappings":";;;AA8BA,MAAa,YAAY,KAAK,aAAa,WAAW;AACtD,MAAa,kBAAkB,KAAKA,mBAAgB,iBAAiB;AACrE,MAAa,mBAAmB,KAAK,oBAAoB,kBAAkB;AAC3E,MAAa,eAAe,KAAK,gBAAgB,cAAc;AAC/D,MAAa,aAAa,KAAK,cAAc,YAAY;AACzD,MAAa,mBAAmB,KAAKC,oBAAiB,kBAAkB;AACxE,MAAa,YAAY,KAAK,YAAY,WAAW;AACrD,MAAa,kBAAkB,KAAK,uBAAuB,iBAAiB;AAC5E,MAAa,kBAAkB,KAAK,iBAAiB,iBAAiB;AACtE,MAAa,kBAAkB,KAAK,iBAAiB,iBAAiB;AACtE,MAAa,mBAAmB,KAAK,kBAAkB,kBAAkB;AACzE,MAAa,gBAAgB,KAAK,eAAe,eAAe;AAChE,MAAa,qBAAqB,KAAK,gBAAgB,oBAAoB;AAC3E,MAAa,eAAe,KAAKC,gBAAa,cAAc;AAC5D,MAAa,WAAW,KAAK,YAAY,UAAU;AACnD,MAAa,WAAW,KAAK,cAAc,UAAU;AACrD,MAAa,WAAW,KAAK,gBAAgB,UAAU;AACvD,MAAa,WAAW,KAAK,uBAAuB,UAAU;AAC9D,MAAa,cAAc,KAAK,eAAe,aAAa;AAC5D,MAAa,WAAW,KAAK,YAAY,UAAU;AACnD,MAAa,aAAa,KAAK,cAAc,YAAY;AACzD,MAAa,UAAU,KAAK,WAAW,SAAS"}
1
+ {"version":3,"file":"icons.js","names":["AlertCircleDef","CancelCircleDef","ComputerDef"],"sources":["../../src/lib/icons.tsx"],"sourcesContent":["import {\n Alert02Icon,\n AlertCircleIcon as AlertCircleDef,\n ArrowDown01Icon,\n ArrowDown02Icon,\n ArrowLeft01Icon,\n ArrowLeftDoubleIcon,\n ArrowRight01Icon,\n ArrowRightDoubleIcon,\n ArrowUp01Icon,\n ArrowUp02Icon,\n ArrowUpRight01Icon,\n Calendar03Icon,\n Cancel01Icon,\n CancelCircleIcon as CancelCircleDef,\n CheckmarkCircle02Icon,\n ListFilterIcon,\n ComputerIcon as ComputerDef,\n Copy01Icon,\n HelpCircleIcon,\n InformationCircleIcon,\n Loading03Icon,\n Moon02Icon,\n PlusSignCircleIcon,\n Remove01Icon,\n Search01Icon,\n Sun03Icon,\n Tick02Icon,\n UnfoldMoreIcon,\n} from \"@hugeicons/core-free-icons\"\nimport { icon } from \"./icon\"\n\n// The handful of structural glyphs the package's own components render. This file lives in\n// `lib/` rather than `components/` so the `\"./*\"` wildcard export, which maps into\n// `components/`, never exposes it.\n\nexport const AlertIcon = icon(Alert02Icon, \"AlertIcon\")\nexport const AlertCircleIcon = icon(AlertCircleDef, \"AlertCircleIcon\")\nexport const ArrowDownIcon = icon(ArrowDown02Icon, \"ArrowDownIcon\")\nexport const ArrowUpIcon = icon(ArrowUp02Icon, \"ArrowUpIcon\")\nexport const ArrowUpRightIcon = icon(ArrowUpRight01Icon, \"ArrowUpRightIcon\")\nexport const CalendarIcon = icon(Calendar03Icon, \"CalendarIcon\")\nexport const CancelIcon = icon(Cancel01Icon, \"CancelIcon\")\nexport const CancelCircleIcon = icon(CancelCircleDef, \"CancelCircleIcon\")\nexport const CheckIcon = icon(Tick02Icon, \"CheckIcon\")\nexport const CheckCircleIcon = icon(CheckmarkCircle02Icon, \"CheckCircleIcon\")\nexport const ChevronDownIcon = icon(ArrowDown01Icon, \"ChevronDownIcon\")\nexport const ChevronsLeftIcon = icon(ArrowLeftDoubleIcon, \"ChevronsLeftIcon\")\nexport const ChevronsRightIcon = icon(ArrowRightDoubleIcon, \"ChevronsRightIcon\")\nexport const ChevronLeftIcon = icon(ArrowLeft01Icon, \"ChevronLeftIcon\")\nexport const ChevronRightIcon = icon(ArrowRight01Icon, \"ChevronRightIcon\")\nexport const ChevronUpIcon = icon(ArrowUp01Icon, \"ChevronUpIcon\")\nexport const ChevronsUpDownIcon = icon(UnfoldMoreIcon, \"ChevronsUpDownIcon\")\nexport const ComputerIcon = icon(ComputerDef, \"ComputerIcon\")\nexport const CopyIcon = icon(Copy01Icon, \"CopyIcon\")\nexport const DashIcon = icon(Remove01Icon, \"DashIcon\")\nexport const FilterIcon = icon(ListFilterIcon, \"FilterIcon\")\nexport const HelpIcon = icon(HelpCircleIcon, \"HelpIcon\")\nexport const InfoIcon = icon(InformationCircleIcon, \"InfoIcon\")\nexport const LoadingIcon = icon(Loading03Icon, \"LoadingIcon\")\nexport const MoonIcon = icon(Moon02Icon, \"MoonIcon\")\nexport const PlusCircleIcon = icon(PlusSignCircleIcon, \"PlusCircleIcon\")\nexport const SearchIcon = icon(Search01Icon, \"SearchIcon\")\nexport const SunIcon = icon(Sun03Icon, \"SunIcon\")\n"],"mappings":";;;AAoCA,MAAa,YAAY,KAAK,aAAa,WAAW;AACtD,MAAa,kBAAkB,KAAKA,mBAAgB,iBAAiB;AACrE,MAAa,gBAAgB,KAAK,iBAAiB,eAAe;AAClE,MAAa,cAAc,KAAK,eAAe,aAAa;AAC5D,MAAa,mBAAmB,KAAK,oBAAoB,kBAAkB;AAC3E,MAAa,eAAe,KAAK,gBAAgB,cAAc;AAC/D,MAAa,aAAa,KAAK,cAAc,YAAY;AACzD,MAAa,mBAAmB,KAAKC,oBAAiB,kBAAkB;AACxE,MAAa,YAAY,KAAK,YAAY,WAAW;AACrD,MAAa,kBAAkB,KAAK,uBAAuB,iBAAiB;AAC5E,MAAa,kBAAkB,KAAK,iBAAiB,iBAAiB;AACtE,MAAa,mBAAmB,KAAK,qBAAqB,kBAAkB;AAC5E,MAAa,oBAAoB,KAAK,sBAAsB,mBAAmB;AAC/E,MAAa,kBAAkB,KAAK,iBAAiB,iBAAiB;AACtE,MAAa,mBAAmB,KAAK,kBAAkB,kBAAkB;AACzE,MAAa,gBAAgB,KAAK,eAAe,eAAe;AAChE,MAAa,qBAAqB,KAAK,gBAAgB,oBAAoB;AAC3E,MAAa,eAAe,KAAKC,gBAAa,cAAc;AAC5D,MAAa,WAAW,KAAK,YAAY,UAAU;AACnD,MAAa,WAAW,KAAK,cAAc,UAAU;AACrD,MAAa,aAAa,KAAK,gBAAgB,YAAY;AAC3D,MAAa,WAAW,KAAK,gBAAgB,UAAU;AACvD,MAAa,WAAW,KAAK,uBAAuB,UAAU;AAC9D,MAAa,cAAc,KAAK,eAAe,aAAa;AAC5D,MAAa,WAAW,KAAK,YAAY,UAAU;AACnD,MAAa,iBAAiB,KAAK,oBAAoB,gBAAgB;AACvE,MAAa,aAAa,KAAK,cAAc,YAAY;AACzD,MAAa,UAAU,KAAK,WAAW,SAAS"}
@@ -0,0 +1,14 @@
1
+ export interface LoadMoreOptions {
2
+ /** False while a page is in flight, when there is no next page, or after a failed page. */
3
+ enabled: boolean;
4
+ onLoad: () => void;
5
+ /** How far below the viewport the sentinel starts loading, in pixels. */
6
+ ahead?: number;
7
+ }
8
+ /**
9
+ * Loads the next page as `sentinel` scrolls into view. The observer is dropped while a page is
10
+ * in flight and set up again after it lands: observing fires straight away for an element
11
+ * already on screen, which is what walks a fast scroll on through page after page. Pass the
12
+ * element through a state setter (`ref={setSentinel}`), so the hook sees it once it mounts.
13
+ */
14
+ export declare function useLoadMore(sentinel: Element | null, { enabled, onLoad, ahead }: LoadMoreOptions): void;
@@ -0,0 +1,27 @@
1
+ "use client";
2
+ import { useEffect } from "react";
3
+ // src/lib/load-more.ts
4
+ /**
5
+ * Loads the next page as `sentinel` scrolls into view. The observer is dropped while a page is
6
+ * in flight and set up again after it lands: observing fires straight away for an element
7
+ * already on screen, which is what walks a fast scroll on through page after page. Pass the
8
+ * element through a state setter (`ref={setSentinel}`), so the hook sees it once it mounts.
9
+ */
10
+ function useLoadMore(sentinel, { enabled, onLoad, ahead }) {
11
+ useEffect(() => {
12
+ if (!sentinel || !enabled) return;
13
+ const observer = new IntersectionObserver((entries) => {
14
+ if (entries.some((entry) => entry.isIntersecting)) onLoad();
15
+ }, ahead === void 0 ? void 0 : { rootMargin: `0px 0px ${ahead}px 0px` });
16
+ observer.observe(sentinel);
17
+ return () => observer.disconnect();
18
+ }, [
19
+ sentinel,
20
+ enabled,
21
+ onLoad,
22
+ ahead
23
+ ]);
24
+ }
25
+ export { useLoadMore };
26
+
27
+ //# sourceMappingURL=load-more.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"load-more.js","names":[],"sources":["../../src/lib/load-more.ts"],"sourcesContent":["\"use client\"\n\nimport { useEffect } from \"react\"\n\nexport interface LoadMoreOptions {\n /** False while a page is in flight, when there is no next page, or after a failed page. */\n enabled: boolean\n onLoad: () => void\n /** How far below the viewport the sentinel starts loading, in pixels. */\n ahead?: number\n}\n\n/**\n * Loads the next page as `sentinel` scrolls into view. The observer is dropped while a page is\n * in flight and set up again after it lands: observing fires straight away for an element\n * already on screen, which is what walks a fast scroll on through page after page. Pass the\n * element through a state setter (`ref={setSentinel}`), so the hook sees it once it mounts.\n */\nexport function useLoadMore(sentinel: Element | null, { enabled, onLoad, ahead }: LoadMoreOptions) {\n useEffect(() => {\n if (!sentinel || !enabled) return\n const observer = new IntersectionObserver(\n entries => {\n if (entries.some(entry => entry.isIntersecting)) onLoad()\n },\n ahead === undefined ? undefined : { rootMargin: `0px 0px ${ahead}px 0px` },\n )\n observer.observe(sentinel)\n return () => observer.disconnect()\n }, [sentinel, enabled, onLoad, ahead])\n}\n"],"mappings":";;;;;;;;;AAkBA,SAAgB,YAAY,UAA0B,EAAE,SAAS,QAAQ,SAA0B;CACjG,gBAAgB;EACd,IAAI,CAAC,YAAY,CAAC,SAAS;EAC3B,MAAM,WAAW,IAAI,sBACnB,YAAW;GACT,IAAI,QAAQ,MAAK,UAAS,MAAM,cAAc,GAAG,OAAO;EAC1D,GACA,UAAU,KAAA,IAAY,KAAA,IAAY,EAAE,YAAY,WAAW,MAAM,QAAQ,CAC3E;EACA,SAAS,QAAQ,QAAQ;EACzB,aAAa,SAAS,WAAW;CACnC,GAAG;EAAC;EAAU;EAAS;EAAQ;CAAK,CAAC;AACvC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@underpin/ui",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "React components on Base UI and Tailwind CSS v4: controls, overlays, forms, charts and the design tokens they share.",
5
5
  "keywords": [
6
6
  "base-ui",
@@ -69,6 +69,14 @@
69
69
  "types": "./lib/media.d.ts",
70
70
  "default": "./lib/media.js"
71
71
  },
72
+ "./load-more": {
73
+ "types": "./lib/load-more.d.ts",
74
+ "default": "./lib/load-more.js"
75
+ },
76
+ "./data-table-state": {
77
+ "types": "./lib/data-table-state.d.ts",
78
+ "default": "./lib/data-table-state.js"
79
+ },
72
80
  "./time-series": {
73
81
  "types": "./lib/time-series.d.ts",
74
82
  "default": "./lib/time-series.js"
@@ -104,6 +112,7 @@
104
112
  "peerDependencies": {
105
113
  "@base-ui/react": ">=1",
106
114
  "@tanstack/react-form": ">=1",
115
+ "@tanstack/react-table": ">=9",
107
116
  "react": ">=19",
108
117
  "react-dom": ">=19",
109
118
  "tailwindcss": ">=4",
@@ -112,6 +121,9 @@
112
121
  "peerDependenciesMeta": {
113
122
  "@tanstack/react-form": {
114
123
  "optional": true
124
+ },
125
+ "@tanstack/react-table": {
126
+ "optional": true
115
127
  }
116
128
  },
117
129
  "_sideEffects": "The stylesheet is a real side effect: `false` let a bundler tree-shake away a consumer's `import \"@underpin/ui/styles.css\"` and ship an unstyled app."
package/styles.css CHANGED
@@ -20,6 +20,17 @@
20
20
  */
21
21
  @source "./";
22
22
 
23
+ /*
24
+ * `ui-pressed`: held down by a pointer or the keyboard, on a control that can run. `ui-standalone`:
25
+ * not a member of a `ButtonGroup`, whose members share their edges and stay in line, so a darker
26
+ * edge or a 1px drop would break the group's outline. Both reach every consumer's Tailwind build
27
+ * through this stylesheet, so they carry the `ui-` prefix to stay clear of a product's own names.
28
+ * `ui-pressed` takes two `:not()`s, not one with a list, to match the specificity of a hover
29
+ * written `hover:not-disabled:not-aria-disabled:`; it comes later in the output, so it wins.
30
+ */
31
+ @custom-variant ui-pressed (&:active:not(:disabled):not([aria-disabled="true"]));
32
+ @custom-variant ui-standalone (&:not([data-slot="button-group"] > *));
33
+
23
34
  /*
24
35
  * Every colour is a `light-dark()` pair, resolved by the element's `color-scheme`: unset follows
25
36
  * the OS, `[data-theme="dark"|"light"]` forces one (see the base layer below). The set has seven