@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.
- 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 +11 -7
- package/components/button-group.js +13 -8
- package/components/button-group.js.map +1 -1
- package/components/button.d.ts +1 -1
- package/components/button.js +29 -12
- package/components/button.js.map +1 -1
- 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/pagination.d.ts +65 -7
- package/components/pagination.js +186 -37
- package/components/pagination.js.map +1 -1
- 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 +21 -3
- package/components/tabs.js +63 -8
- package/components/tabs.js.map +1 -1
- 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/icons.d.ts +6 -0
- package/lib/icons.js +8 -2
- package/lib/icons.js.map +1 -1
- package/lib/load-more.d.ts +14 -0
- package/lib/load-more.js +27 -0
- package/lib/load-more.js.map +1 -0
- package/package.json +13 -1
- package/styles.css +11 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ComponentProps, ReactNode } from "react";
|
|
2
|
+
interface BulkActionBarProps extends Omit<ComponentProps<"section">, "children"> {
|
|
3
|
+
/** How many rows are selected. The bar shows while there is at least one. */
|
|
4
|
+
count: number;
|
|
5
|
+
/** The selection as text, formatted by the caller. */
|
|
6
|
+
label?: ReactNode;
|
|
7
|
+
onClear: () => void;
|
|
8
|
+
clearLabel?: string;
|
|
9
|
+
/**
|
|
10
|
+
* The actions for the selection: small ghost buttons, the destructive one last with
|
|
11
|
+
* `tone="danger"`.
|
|
12
|
+
*/
|
|
13
|
+
children: ReactNode;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Floats at the bottom centre of the page while rows are selected: "N selected" with a cross
|
|
17
|
+
* that clears the selection, then the actions for it. It owns the selection count, so the
|
|
18
|
+
* footer band never shows one. A selection covers the current page only.
|
|
19
|
+
*/
|
|
20
|
+
export declare function BulkActionBar({ count, label, onClear, clearLabel, "aria-label": ariaLabel, className, children, ...props }: BulkActionBarProps): import("react").JSX.Element;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { CancelIcon } from "../lib/icons.js";
|
|
3
|
+
import { cn } from "../lib/variants.js";
|
|
4
|
+
import { Button } from "./button.js";
|
|
5
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
// src/components/bulk-action-bar.tsx
|
|
7
|
+
/**
|
|
8
|
+
* Floats at the bottom centre of the page while rows are selected: "N selected" with a cross
|
|
9
|
+
* that clears the selection, then the actions for it. It owns the selection count, so the
|
|
10
|
+
* footer band never shows one. A selection covers the current page only.
|
|
11
|
+
*/
|
|
12
|
+
function BulkActionBar({ count, label = `${count} selected`, onClear, clearLabel = "Clear selection", "aria-label": ariaLabel = "Selection", className, children, ...props }) {
|
|
13
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", {
|
|
14
|
+
"aria-live": "polite",
|
|
15
|
+
className: "sr-only",
|
|
16
|
+
children: count > 0 ? label : ""
|
|
17
|
+
}), count > 0 && /* @__PURE__ */ jsxs("section", {
|
|
18
|
+
"aria-label": ariaLabel,
|
|
19
|
+
className: cn("fixed bottom-6 left-1/2 z-40 flex max-w-[calc(100vw-2rem)] -translate-x-1/2 items-center gap-2 rounded-xl border border-edge-float bg-overlay p-1.5 shadow-popup", "fade-in-0 slide-in-from-bottom-2 animate-in duration-150 ease-out-expo", className),
|
|
20
|
+
...props,
|
|
21
|
+
children: [/* @__PURE__ */ jsxs("span", {
|
|
22
|
+
className: "flex h-7 shrink-0 items-center gap-1 rounded-md border border-edge border-dashed pr-0.5 pl-2.5 font-medium text-control text-ink tabular-nums",
|
|
23
|
+
children: [label, /* @__PURE__ */ jsx(Button, {
|
|
24
|
+
variant: "ghost",
|
|
25
|
+
size: "xs",
|
|
26
|
+
"aria-label": clearLabel,
|
|
27
|
+
prefix: /* @__PURE__ */ jsx(CancelIcon, {}),
|
|
28
|
+
onClick: onClear
|
|
29
|
+
})]
|
|
30
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
31
|
+
className: "flex min-w-0 items-center gap-0.5 overflow-x-auto",
|
|
32
|
+
children
|
|
33
|
+
})]
|
|
34
|
+
})] });
|
|
35
|
+
}
|
|
36
|
+
export { BulkActionBar };
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=bulk-action-bar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bulk-action-bar.js","names":[],"sources":["../../src/components/bulk-action-bar.tsx"],"sourcesContent":["\"use client\"\n\nimport type { ComponentProps, ReactNode } from \"react\"\nimport { CancelIcon } from \"../lib/icons\"\nimport { cn } from \"../lib/variants\"\nimport { Button } from \"./button\"\n\ninterface BulkActionBarProps extends Omit<ComponentProps<\"section\">, \"children\"> {\n /** How many rows are selected. The bar shows while there is at least one. */\n count: number\n /** The selection as text, formatted by the caller. */\n label?: ReactNode\n onClear: () => void\n clearLabel?: string\n /**\n * The actions for the selection: small ghost buttons, the destructive one last with\n * `tone=\"danger\"`.\n */\n children: ReactNode\n}\n\n/**\n * Floats at the bottom centre of the page while rows are selected: \"N selected\" with a cross\n * that clears the selection, then the actions for it. It owns the selection count, so the\n * footer band never shows one. A selection covers the current page only.\n */\nexport function BulkActionBar({\n count,\n label = `${count} selected`,\n onClear,\n clearLabel = \"Clear selection\",\n \"aria-label\": ariaLabel = \"Selection\",\n className,\n children,\n ...props\n}: BulkActionBarProps) {\n return (\n <>\n {/* Mounted while nothing is selected too: a screen reader skips the text a live region\n is born with, so the first selection would go unannounced. */}\n <span aria-live=\"polite\" className=\"sr-only\">\n {count > 0 ? label : \"\"}\n </span>\n {count > 0 && (\n <section\n aria-label={ariaLabel}\n className={cn(\n \"fixed bottom-6 left-1/2 z-40 flex max-w-[calc(100vw-2rem)] -translate-x-1/2 items-center gap-2 rounded-xl border border-edge-float bg-overlay p-1.5 shadow-popup\",\n \"fade-in-0 slide-in-from-bottom-2 animate-in duration-150 ease-out-expo\",\n className,\n )}\n {...props}\n >\n <span className=\"flex h-7 shrink-0 items-center gap-1 rounded-md border border-edge border-dashed pr-0.5 pl-2.5 font-medium text-control text-ink tabular-nums\">\n {label}\n <Button\n variant=\"ghost\"\n size=\"xs\"\n aria-label={clearLabel}\n prefix={<CancelIcon />}\n onClick={onClear}\n />\n </span>\n <div className=\"flex min-w-0 items-center gap-0.5 overflow-x-auto\">{children}</div>\n </section>\n )}\n </>\n )\n}\n"],"mappings":";;;;;;;;;;;AA0BA,SAAgB,cAAc,EAC5B,OACA,QAAQ,GAAG,MAAM,YACjB,SACA,aAAa,mBACb,cAAc,YAAY,aAC1B,WACA,UACA,GAAG,SACkB;CACrB,OACE,qBAAA,UAAA,EAAA,UAAA,CAGE,oBAAC,QAAD;EAAM,aAAU;EAAS,WAAU;EAChC,UAAA,QAAQ,IAAI,QAAQ;CACjB,CAAA,GACL,QAAQ,KACP,qBAAC,WAAD;EACE,cAAY;EACZ,WAAW,GACT,oKACA,0EACA,SACF;EACA,GAAI;EAPN,UAAA,CASE,qBAAC,QAAD;GAAM,WAAU;GAAhB,UAAA,CACG,OACD,oBAAC,QAAD;IACE,SAAQ;IACR,MAAK;IACL,cAAY;IACZ,QAAQ,oBAAC,YAAD,CAAa,CAAA;IACrB,SAAS;GACV,CAAA,CACG;EACN,CAAA,GAAA,oBAAC,OAAD;GAAK,WAAU;GAAqD;EAAc,CAAA,CAC3E;CAEX,CAAA,CAAA,EAAA,CAAA;AAEN"}
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { ComponentProps } from "react";
|
|
2
2
|
/**
|
|
3
|
-
* Buttons joined into one control
|
|
4
|
-
*
|
|
5
|
-
* is the divider. Edges are translucent, so two
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
3
|
+
* Buttons joined into one control, meant for bordered (`secondary`) buttons. The group only
|
|
4
|
+
* shapes its members: every member after the first drops its left border, so the edge of the one
|
|
5
|
+
* before it is the divider, and the inner corners square off. Edges are translucent, so two
|
|
6
|
+
* borders laid over each other would draw a darker seam. Each member paints its fill inside its
|
|
7
|
+
* border, over the group's surface, so every edge lies on the same colour, and a hovered or
|
|
8
|
+
* pressed fill cannot darken three of a member's edges and not the fourth, which its neighbour
|
|
9
|
+
* draws. The group's corners are a medium button's.
|
|
10
|
+
*
|
|
11
|
+
* Each member's states stay its own, and `Button` keeps them inside its box when it sits in a
|
|
12
|
+
* group (the `ui-standalone` variant in `styles.css`): no darker edge on hover, no drop on press,
|
|
13
|
+
* a disabled member keeps its edge.
|
|
10
14
|
*
|
|
11
15
|
* The ends are found among the members, not the children: an open popup trigger gets
|
|
12
16
|
* focus-guard and `aria-owns` spans rendered beside it, a member under `DisabledReason` a
|
|
@@ -2,13 +2,17 @@ import { cn } from "../lib/variants.js";
|
|
|
2
2
|
import { jsx } from "react/jsx-runtime";
|
|
3
3
|
// src/components/button-group.tsx
|
|
4
4
|
/**
|
|
5
|
-
* Buttons joined into one control
|
|
6
|
-
*
|
|
7
|
-
* is the divider. Edges are translucent, so two
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
5
|
+
* Buttons joined into one control, meant for bordered (`secondary`) buttons. The group only
|
|
6
|
+
* shapes its members: every member after the first drops its left border, so the edge of the one
|
|
7
|
+
* before it is the divider, and the inner corners square off. Edges are translucent, so two
|
|
8
|
+
* borders laid over each other would draw a darker seam. Each member paints its fill inside its
|
|
9
|
+
* border, over the group's surface, so every edge lies on the same colour, and a hovered or
|
|
10
|
+
* pressed fill cannot darken three of a member's edges and not the fourth, which its neighbour
|
|
11
|
+
* draws. The group's corners are a medium button's.
|
|
12
|
+
*
|
|
13
|
+
* Each member's states stay its own, and `Button` keeps them inside its box when it sits in a
|
|
14
|
+
* group (the `ui-standalone` variant in `styles.css`): no darker edge on hover, no drop on press,
|
|
15
|
+
* a disabled member keeps its edge.
|
|
12
16
|
*
|
|
13
17
|
* The ends are found among the members, not the children: an open popup trigger gets
|
|
14
18
|
* focus-guard and `aria-owns` spans rendered beside it, a member under `DisabledReason` a
|
|
@@ -18,7 +22,8 @@ import { jsx } from "react/jsx-runtime";
|
|
|
18
22
|
*/
|
|
19
23
|
function ButtonGroup({ className, ...props }) {
|
|
20
24
|
return /* @__PURE__ */ jsx("div", {
|
|
21
|
-
|
|
25
|
+
"data-slot": "button-group",
|
|
26
|
+
className: cn("inline-flex rounded-md bg-surface [&>*]:bg-clip-padding", "[&>:not(:nth-child(1_of_:not([data-base-ui-focus-guard]):not([aria-owns]):not([hidden])))]:rounded-l-none", "[&>:not(:nth-child(1_of_:not([data-base-ui-focus-guard]):not([aria-owns]):not([hidden])))]:border-l-0", "[&>:not(:nth-last-child(1_of_:not([data-base-ui-focus-guard]):not([aria-owns]):not([hidden])))]:rounded-r-none", className),
|
|
22
27
|
...props
|
|
23
28
|
});
|
|
24
29
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"button-group.js","names":[],"sources":["../../src/components/button-group.tsx"],"sourcesContent":["import type { ComponentProps } from \"react\"\nimport { cn } from \"../lib/variants\"\n\n/**\n * Buttons joined into one control
|
|
1
|
+
{"version":3,"file":"button-group.js","names":[],"sources":["../../src/components/button-group.tsx"],"sourcesContent":["import type { ComponentProps } from \"react\"\nimport { cn } from \"../lib/variants\"\n\n/**\n * Buttons joined into one control, meant for bordered (`secondary`) buttons. The group only\n * shapes its members: every member after the first drops its left border, so the edge of the one\n * before it is the divider, and the inner corners square off. Edges are translucent, so two\n * borders laid over each other would draw a darker seam. Each member paints its fill inside its\n * border, over the group's surface, so every edge lies on the same colour, and a hovered or\n * pressed fill cannot darken three of a member's edges and not the fourth, which its neighbour\n * draws. The group's corners are a medium button's.\n *\n * Each member's states stay its own, and `Button` keeps them inside its box when it sits in a\n * group (the `ui-standalone` variant in `styles.css`): no darker edge on hover, no drop on press,\n * a disabled member keeps its edge.\n *\n * The ends are found among the members, not the children: an open popup trigger gets\n * focus-guard and `aria-owns` spans rendered beside it, a member under `DisabledReason` a\n * `hidden` reason, and `:first-child` would move off the button onto one of those. A guard is\n * matched by its `data-base-ui-focus-guard` attribute, not `aria-hidden`: in Safari, Base UI\n * gives it `role=\"button\"` in place of `aria-hidden`, for VoiceOver.\n */\nexport function ButtonGroup({ className, ...props }: ComponentProps<\"div\">) {\n return (\n <div\n data-slot=\"button-group\"\n className={cn(\n \"inline-flex rounded-md bg-surface [&>*]:bg-clip-padding\",\n \"[&>:not(:nth-child(1_of_:not([data-base-ui-focus-guard]):not([aria-owns]):not([hidden])))]:rounded-l-none\",\n \"[&>:not(:nth-child(1_of_:not([data-base-ui-focus-guard]):not([aria-owns]):not([hidden])))]:border-l-0\",\n \"[&>:not(:nth-last-child(1_of_:not([data-base-ui-focus-guard]):not([aria-owns]):not([hidden])))]:rounded-r-none\",\n className,\n )}\n {...props}\n />\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAgB,YAAY,EAAE,WAAW,GAAG,SAAgC;CAC1E,OACE,oBAAC,OAAD;EACE,aAAU;EACV,WAAW,GACT,2DACA,6GACA,yGACA,kHACA,SACF;EACA,GAAI;CACL,CAAA;AAEL"}
|
package/components/button.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ declare const buttonVariants: import("tailwind-variants").TVReturnType<{
|
|
|
22
22
|
lg: string;
|
|
23
23
|
};
|
|
24
24
|
interactive: {
|
|
25
|
-
true: string;
|
|
25
|
+
true: string[];
|
|
26
26
|
};
|
|
27
27
|
}, undefined, string[], undefined, undefined, undefined>;
|
|
28
28
|
export type ButtonProps = Omit<useRender.ComponentProps<"button">, "size" | "prefix"> & VariantProps<typeof buttonVariants> & {
|
package/components/button.js
CHANGED
|
@@ -11,10 +11,9 @@ const buttonInteractiveClasses = interactiveVariants({ interactive: false });
|
|
|
11
11
|
const buttonVariants = variants({
|
|
12
12
|
base: [
|
|
13
13
|
buttonInteractiveClasses,
|
|
14
|
-
"group/button inline-flex items-center justify-center font-medium text-start rounded-md hover:z-10",
|
|
14
|
+
"group/button inline-flex items-center justify-center font-medium text-start rounded-md hover:z-10 focus-visible:z-10",
|
|
15
15
|
"text-control",
|
|
16
|
-
"
|
|
17
|
-
"relative transition-[color,background-color,border-color,box-shadow,opacity,translate] duration-150 ease-out-expo"
|
|
16
|
+
"relative transition-[color,background-color,border-color,box-shadow,translate] duration-150 ease-out-expo"
|
|
18
17
|
],
|
|
19
18
|
variants: {
|
|
20
19
|
variant: {
|
|
@@ -27,44 +26,62 @@ const buttonVariants = variants({
|
|
|
27
26
|
neutral: "",
|
|
28
27
|
danger: ""
|
|
29
28
|
},
|
|
30
|
-
bordered: { true: "border border-edge-strong shadow-control aria-expanded:border-edge-solid aria-expanded:shadow-none" },
|
|
29
|
+
bordered: { true: "border border-edge-strong shadow-control aria-expanded:ui-standalone:border-edge-solid aria-expanded:ui-standalone:shadow-none" },
|
|
31
30
|
size: {
|
|
32
31
|
xs: "h-6 px-2 gap-1 text-xs rounded",
|
|
33
32
|
sm: "h-7 px-2 gap-1.5",
|
|
34
33
|
md: "h-control px-3 gap-1.5",
|
|
35
34
|
lg: "h-9 px-3.5 gap-2 text-sm rounded-lg"
|
|
36
35
|
},
|
|
37
|
-
interactive: { true:
|
|
36
|
+
interactive: { true: [
|
|
37
|
+
"not-disabled:not-aria-disabled:cursor-pointer aria-disabled:cursor-not-allowed",
|
|
38
|
+
"ui-pressed:duration-75 ui-pressed:ui-standalone:shadow-none ui-pressed:ui-standalone:translate-y-px",
|
|
39
|
+
"ui-pressed:ui-standalone:after:absolute ui-pressed:ui-standalone:after:inset-x-0 ui-pressed:ui-standalone:after:-top-0.5 ui-pressed:ui-standalone:after:h-0.5"
|
|
40
|
+
] }
|
|
38
41
|
},
|
|
39
42
|
compoundVariants: [
|
|
43
|
+
{
|
|
44
|
+
variant: [
|
|
45
|
+
"secondary",
|
|
46
|
+
"soft",
|
|
47
|
+
"ghost"
|
|
48
|
+
],
|
|
49
|
+
class: ["not-data-pending:disabled:*:opacity-50 not-data-pending:disabled:ui-standalone:shadow-none", "aria-disabled:*:opacity-50 aria-disabled:ui-standalone:shadow-none"]
|
|
50
|
+
},
|
|
40
51
|
{
|
|
41
52
|
variant: "primary",
|
|
42
|
-
class: ["not-data-pending:disabled:bg-fill not-data-pending:disabled:text-ink-muted not-data-pending:disabled:shadow-none
|
|
53
|
+
class: ["not-data-pending:disabled:bg-fill not-data-pending:disabled:text-ink-muted not-data-pending:disabled:shadow-none", "aria-disabled:bg-fill aria-disabled:text-ink-muted aria-disabled:shadow-none"]
|
|
43
54
|
},
|
|
44
55
|
{
|
|
45
56
|
variant: "primary",
|
|
46
57
|
interactive: true,
|
|
47
|
-
class: "hover:not-aria-disabled:bg-ink/90"
|
|
58
|
+
class: "hover:not-disabled:not-aria-disabled:bg-ink/90 ui-pressed:bg-ink/80"
|
|
48
59
|
},
|
|
49
60
|
{
|
|
50
61
|
variant: ["secondary", "ghost"],
|
|
51
62
|
interactive: true,
|
|
52
|
-
class: "hover:not-aria-disabled:bg-fill-subtle hover:not-aria-disabled:text-ink"
|
|
63
|
+
class: "hover:not-disabled:not-aria-disabled:bg-fill-subtle hover:not-disabled:not-aria-disabled:text-ink ui-pressed:bg-fill"
|
|
53
64
|
},
|
|
54
65
|
{
|
|
55
66
|
bordered: true,
|
|
56
67
|
interactive: true,
|
|
57
|
-
class: "hover:not-aria-disabled:border-edge-solid"
|
|
68
|
+
class: "hover:ui-standalone:not-disabled:not-aria-disabled:border-edge-solid"
|
|
58
69
|
},
|
|
59
70
|
{
|
|
60
71
|
variant: "soft",
|
|
61
72
|
interactive: true,
|
|
62
|
-
class: "hover:not-aria-disabled:bg-fill-strong hover:not-aria-disabled:text-ink"
|
|
73
|
+
class: "hover:not-disabled:not-aria-disabled:bg-fill-strong hover:not-disabled:not-aria-disabled:text-ink ui-pressed:bg-fill-strong"
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
variant: "primary",
|
|
77
|
+
tone: "danger",
|
|
78
|
+
class: "bg-danger text-danger-on hover:not-disabled:not-aria-disabled:bg-danger/90 aria-expanded:bg-danger/90"
|
|
63
79
|
},
|
|
64
80
|
{
|
|
65
81
|
variant: "primary",
|
|
66
82
|
tone: "danger",
|
|
67
|
-
|
|
83
|
+
interactive: true,
|
|
84
|
+
class: "ui-pressed:bg-danger/80"
|
|
68
85
|
},
|
|
69
86
|
{
|
|
70
87
|
variant: [
|
|
@@ -73,7 +90,7 @@ const buttonVariants = variants({
|
|
|
73
90
|
"ghost"
|
|
74
91
|
],
|
|
75
92
|
tone: "danger",
|
|
76
|
-
class: "text-danger-ink hover:not-aria-disabled:text-danger-ink aria-expanded:text-danger-ink"
|
|
93
|
+
class: "text-danger-ink hover:not-disabled:not-aria-disabled:text-danger-ink aria-expanded:text-danger-ink"
|
|
77
94
|
}
|
|
78
95
|
],
|
|
79
96
|
defaultVariants: {
|
package/components/button.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"button.js","names":[],"sources":["../../src/components/button.tsx"],"sourcesContent":["import { mergeProps } from \"@base-ui/react\"\nimport { useRender } from \"@base-ui/react/use-render\"\nimport { Children, isValidElement, type ReactNode } from \"react\"\nimport { LoadingIcon } from \"../lib/icons\"\nimport { interactiveVariants } from \"../lib/interactive\"\nimport { slot } from \"../lib/slot\"\nimport { cn, variants, type VariantProps } from \"../lib/variants\"\n\n// The shared chrome without its edge or cursor, which the button gates on its own variants.\nconst buttonInteractiveClasses = interactiveVariants({ interactive: false })\n\nconst buttonVariants = variants({\n base: [\n buttonInteractiveClasses,\n \"group/button inline-flex items-center justify-center font-medium text-start rounded-md hover:z-10\",\n \"text-control\",\n \"disabled:opacity-50 aria-disabled:opacity-50 data-pending:disabled:opacity-100\",\n \"relative transition-[color,background-color,border-color,box-shadow,opacity,translate] duration-150 ease-out-expo\",\n ],\n\n variants: {\n variant: {\n // The open look holds while the button's menu or popover is open (Base UI sets the\n // trigger's `aria-expanded`), so the trigger reads as the thing that opened it. Not\n // `data-popup-open`: a tooltip sets that too, and a button would look open under its tooltip.\n // The same look on hover rides `interactive`, below.\n primary:\n \"bg-ink text-ink-inverse shadow-control aria-expanded:bg-ink/90 aria-expanded:shadow-none\",\n secondary:\n \"bg-surface text-ink-secondary aria-expanded:bg-fill-subtle aria-expanded:text-ink\",\n soft: \"bg-fill text-ink-secondary aria-expanded:bg-fill-strong aria-expanded:text-ink\",\n ghost: \"text-ink-secondary aria-expanded:bg-fill-subtle aria-expanded:text-ink\",\n },\n // What the action means, apart from how loud it is. Danger is for a loss: a primary danger\n // button confirms one, a secondary danger button starts one from a page.\n tone: {\n neutral: \"\",\n danger: \"\",\n },\n bordered: {\n true: \"border border-edge-strong shadow-control aria-expanded:border-edge-solid aria-expanded:shadow-none\",\n },\n // A fixed height and no vertical padding, so a button lines up with the inputs, pickers\n // and triggers beside it whatever it holds: the control scale in `styles.css`.\n size: {\n xs: \"h-6 px-2 gap-1 text-xs rounded\",\n sm: \"h-7 px-2 gap-1.5\",\n md: \"h-control px-3 gap-1.5\",\n lg: \"h-9 px-3.5 gap-2 text-sm rounded-lg\",\n },\n interactive: {\n // A press sets the button down: it drops 1px and loses its shadow, as a card does. A fixed\n // 1px, so a wide button moves as far as a small one, and a move rather than a scale, which\n // would re-rasterise the label on every frame. It goes down at twice the speed it comes\n // back. The `::after` strip stays over the row the button left, or a press on its top pixel\n // would release outside it and lose the click. Rides `interactive`: a disabled control does\n // not answer.\n true: \"not-disabled:not-aria-disabled:cursor-pointer aria-disabled:cursor-not-allowed active:not-disabled:not-aria-disabled:translate-y-px active:not-disabled:not-aria-disabled:shadow-none active:not-disabled:not-aria-disabled:duration-75 active:not-disabled:not-aria-disabled:after:absolute active:not-disabled:not-aria-disabled:after:inset-x-0 active:not-disabled:not-aria-disabled:after:-top-0.5 active:not-disabled:not-aria-disabled:after:h-0.5\",\n },\n },\n\n compoundVariants: [\n // A disabled primary button goes flat and grey rather than fading: ink at half strength\n // reads as a dimmed slab, while the fill reads as a button that is not ready yet. A pending\n // one keeps its colour, since it is busy rather than unavailable.\n {\n variant: \"primary\",\n class: [\n \"not-data-pending:disabled:bg-fill not-data-pending:disabled:text-ink-muted not-data-pending:disabled:shadow-none not-data-pending:disabled:opacity-100\",\n \"aria-disabled:bg-fill aria-disabled:text-ink-muted aria-disabled:shadow-none aria-disabled:opacity-100\",\n ],\n },\n // Only a button that does something answers the pointer. A reading drawn as a button, with\n // `interactive` off, keeps its resting look under the cursor.\n {\n variant: \"primary\",\n interactive: true,\n class: \"hover:not-aria-disabled:bg-ink/90\",\n },\n {\n variant: [\"secondary\", \"ghost\"],\n interactive: true,\n class: \"hover:not-aria-disabled:bg-fill-subtle hover:not-aria-disabled:text-ink\",\n },\n // A bordered button's edge darkens under the pointer, as a field's and a checkbox's do.\n {\n bordered: true,\n interactive: true,\n class: \"hover:not-aria-disabled:border-edge-solid\",\n },\n {\n variant: \"soft\",\n interactive: true,\n class: \"hover:not-aria-disabled:bg-fill-strong hover:not-aria-disabled:text-ink\",\n },\n {\n variant: \"primary\",\n tone: \"danger\",\n class:\n \"bg-danger text-danger-on hover:not-aria-disabled:bg-danger/90 aria-expanded:bg-danger/90\",\n },\n {\n variant: [\"secondary\", \"soft\", \"ghost\"],\n tone: \"danger\",\n class:\n \"text-danger-ink hover:not-aria-disabled:text-danger-ink aria-expanded:text-danger-ink\",\n },\n ],\n\n defaultVariants: {\n variant: \"primary\",\n tone: \"neutral\",\n size: \"md\",\n interactive: true,\n },\n})\n\n// A 14px icon, drawn 2px closer to the edge than the text is.\nconst buttonAffixClasses = \"shrink-0 first:-ml-0.5 last:-mr-0.5 [svg]:size-3.5\"\n// Nothing but an icon: a square of the button's height, the icon centred in it.\nconst buttonSquareClasses = \"px-0 aspect-square\"\nconst buttonSquareAffixClasses = \"shrink-0 [svg]:size-3.5\"\n\n/**\n * Hidden while a button with no leading icon is pending, so only the spinner reads as content. A\n * button with one keeps its label, since the spinner takes the icon's place.\n */\nconst buttonPendingClasses = \"group-data-pending/button:text-transparent\"\n\nexport type ButtonProps = Omit<useRender.ComponentProps<\"button\">, \"size\" | \"prefix\"> &\n VariantProps<typeof buttonVariants> & {\n /**\n * If set to `true`, the button will be rendered in the pending state.\n */\n isPending?: boolean\n\n /** The slot to be rendered before the label. */\n prefix?: ReactNode\n\n /** The slot to be rendered after the label. */\n suffix?: ReactNode\n }\n\nfunction Button({\n children,\n className,\n disabled = false,\n render,\n isPending,\n prefix,\n suffix,\n variant,\n tone,\n size,\n interactive = true,\n bordered,\n ...rest\n}: ButtonProps) {\n // `toArray` drops `false` and `null`, so a label hidden with `{wide && \"Label\"}` leaves an\n // icon-only button, square and with nothing beside its icon.\n const square = Children.toArray(children).length === 0\n const affixClasses = square ? buttonSquareAffixClasses : buttonAffixClasses\n const props = mergeProps<\"button\">(\n {\n disabled: disabled || isPending,\n \"aria-busy\": isPending ? true : undefined,\n className: buttonVariants({\n variant,\n tone,\n size,\n interactive,\n bordered: bordered ?? variant === \"secondary\",\n className: cn(square && buttonSquareClasses, className),\n }),\n children: (\n <>\n {slot(prefix && isPending ? <LoadingIcon className=\"animate-spin\" /> : prefix, {\n className: affixClasses,\n })}\n\n {/* Beside an affix the label fills the row and pushes the suffix to the end. Alone it\n keeps its own width, so the button's `justify-*` places it: centred by default,\n at the start for a `justify-start` row. */}\n {!square &&\n slot(isValidElement(children) ? children : <span>{children}</span>, {\n className: cn(\n \"flex-1 truncate only:flex-initial has-[div]:contents\",\n !prefix && buttonPendingClasses,\n ),\n })}\n\n {slot(suffix, { className: cn(affixClasses, buttonPendingClasses) })}\n\n {!prefix && !!isPending && (\n <LoadingIcon className=\"absolute size-[1.25em] animate-spin\" />\n )}\n </>\n ),\n },\n rest,\n )\n\n // `data-pending` drives the label and suffix fade; it sits outside `mergeProps`, whose\n // button props type has no room for a custom data attribute.\n //\n // `type` defaults to \"button\", not HTML's \"submit\": a Button inside a <form> that never\n // meant to submit it (a dialog's X, a search field's clear) otherwise does. Callers that\n // want a submit still say so: `props` spreads last and wins. Only applied when the\n // element really is a <button>, since `type` means something else on an <a> or a <label>.\n const isButton = !render\n\n return useRender({\n defaultTagName: \"button\",\n render,\n props: {\n \"data-pending\": isPending ? true : undefined,\n \"data-pressable\": interactive ? \"\" : undefined,\n ...(isButton && { type: \"button\" }),\n ...props,\n },\n })\n}\n\nexport { Button, buttonVariants }\n"],"mappings":";;;;;;;;;AASA,MAAM,2BAA2B,oBAAoB,EAAE,aAAa,MAAM,CAAC;AAE3E,MAAM,iBAAiB,SAAS;CAC9B,MAAM;EACJ;EACA;EACA;EACA;EACA;CACF;CAEA,UAAU;EACR,SAAS;GAKP,SACE;GACF,WACE;GACF,MAAM;GACN,OAAO;EACT;EAGA,MAAM;GACJ,SAAS;GACT,QAAQ;EACV;EACA,UAAU,EACR,MAAM,qGACR;EAGA,MAAM;GACJ,IAAI;GACJ,IAAI;GACJ,IAAI;GACJ,IAAI;EACN;EACA,aAAa,EAOX,MAAM,4bACR;CACF;CAEA,kBAAkB;EAIhB;GACE,SAAS;GACT,OAAO,CACL,0JACA,wGACF;EACF;EAGA;GACE,SAAS;GACT,aAAa;GACb,OAAO;EACT;EACA;GACE,SAAS,CAAC,aAAa,OAAO;GAC9B,aAAa;GACb,OAAO;EACT;EAEA;GACE,UAAU;GACV,aAAa;GACb,OAAO;EACT;EACA;GACE,SAAS;GACT,aAAa;GACb,OAAO;EACT;EACA;GACE,SAAS;GACT,MAAM;GACN,OACE;EACJ;EACA;GACE,SAAS;IAAC;IAAa;IAAQ;GAAO;GACtC,MAAM;GACN,OACE;EACJ;CACF;CAEA,iBAAiB;EACf,SAAS;EACT,MAAM;EACN,MAAM;EACN,aAAa;CACf;AACF,CAAC;AAGD,MAAM,qBAAqB;AAE3B,MAAM,sBAAsB;AAC5B,MAAM,2BAA2B;;;;;AAMjC,MAAM,uBAAuB;AAgB7B,SAAS,OAAO,EACd,UACA,WACA,WAAW,OACX,QACA,WACA,QACA,QACA,SACA,MACA,MACA,cAAc,MACd,UACA,GAAG,QACW;CAGd,MAAM,SAAS,SAAS,QAAQ,QAAQ,CAAC,CAAC,WAAW;CACrD,MAAM,eAAe,SAAS,2BAA2B;CACzD,MAAM,QAAQ,WACZ;EACE,UAAU,YAAY;EACtB,aAAa,YAAY,OAAO,KAAA;EAChC,WAAW,eAAe;GACxB;GACA;GACA;GACA;GACA,UAAU,YAAY,YAAY;GAClC,WAAW,GAAG,UAAU,qBAAqB,SAAS;EACxD,CAAC;EACD,UACE,qBAAA,UAAA,EAAA,UAAA;GACG,KAAK,UAAU,YAAY,oBAAC,aAAD,EAAa,WAAU,eAAgB,CAAA,IAAI,QAAQ,EAC7E,WAAW,aACb,CAAC;GAKA,CAAC,UACA,KAAK,eAAe,QAAQ,IAAI,WAAW,oBAAC,QAAD,EAAO,SAAe,CAAA,GAAG,EAClE,WAAW,GACT,wDACA,CAAC,UAAU,oBACb,EACF,CAAC;GAEF,KAAK,QAAQ,EAAE,WAAW,GAAG,cAAc,oBAAoB,EAAE,CAAC;GAElE,CAAC,UAAU,CAAC,CAAC,aACZ,oBAAC,aAAD,EAAa,WAAU,sCAAuC,CAAA;EAEhE,EAAA,CAAA;CAEN,GACA,IACF;CAWA,OAAO,UAAU;EACf,gBAAgB;EAChB;EACA,OAAO;GACL,gBAAgB,YAAY,OAAO,KAAA;GACnC,kBAAkB,cAAc,KAAK,KAAA;GACrC,GAAI,CARU,UAQE,EAAE,MAAM,SAAS;GACjC,GAAG;EACL;CACF,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"button.js","names":[],"sources":["../../src/components/button.tsx"],"sourcesContent":["import { mergeProps } from \"@base-ui/react\"\nimport { useRender } from \"@base-ui/react/use-render\"\nimport { Children, isValidElement, type ReactNode } from \"react\"\nimport { LoadingIcon } from \"../lib/icons\"\nimport { interactiveVariants } from \"../lib/interactive\"\nimport { slot } from \"../lib/slot\"\nimport { cn, variants, type VariantProps } from \"../lib/variants\"\n\n// The shared chrome without its edge or cursor, which the button gates on its own variants.\nconst buttonInteractiveClasses = interactiveVariants({ interactive: false })\n\nconst buttonVariants = variants({\n base: [\n buttonInteractiveClasses,\n // Lifted while hovered or focused, so its focus outline runs over a neighbour's edge in a\n // `ButtonGroup` or a toolbar.\n \"group/button inline-flex items-center justify-center font-medium text-start rounded-md hover:z-10 focus-visible:z-10\",\n \"text-control\",\n \"relative transition-[color,background-color,border-color,box-shadow,translate] duration-150 ease-out-expo\",\n ],\n\n variants: {\n variant: {\n // The open look holds while the button's menu or popover is open (Base UI sets the\n // trigger's `aria-expanded`), so the trigger reads as the thing that opened it. Not\n // `data-popup-open`: a tooltip sets that too, and a button would look open under its tooltip.\n // The same look on hover rides `interactive`, below.\n primary:\n \"bg-ink text-ink-inverse shadow-control aria-expanded:bg-ink/90 aria-expanded:shadow-none\",\n secondary:\n \"bg-surface text-ink-secondary aria-expanded:bg-fill-subtle aria-expanded:text-ink\",\n soft: \"bg-fill text-ink-secondary aria-expanded:bg-fill-strong aria-expanded:text-ink\",\n ghost: \"text-ink-secondary aria-expanded:bg-fill-subtle aria-expanded:text-ink\",\n },\n // What the action means, apart from how loud it is. Danger is for a loss: a primary danger\n // button confirms one, a secondary danger button starts one from a page.\n tone: {\n neutral: \"\",\n danger: \"\",\n },\n bordered: {\n true: \"border border-edge-strong shadow-control aria-expanded:ui-standalone:border-edge-solid aria-expanded:ui-standalone:shadow-none\",\n },\n // A fixed height and no vertical padding, so a button lines up with the inputs, pickers\n // and triggers beside it whatever it holds: the control scale in `styles.css`.\n size: {\n xs: \"h-6 px-2 gap-1 text-xs rounded\",\n sm: \"h-7 px-2 gap-1.5\",\n md: \"h-control px-3 gap-1.5\",\n lg: \"h-9 px-3.5 gap-2 text-sm rounded-lg\",\n },\n interactive: {\n // A press sets the button down: it loses its shadow and drops 1px, as a card does. A fixed\n // 1px, so a wide button moves as far as a small one, and a move rather than a scale, which\n // would re-rasterise the label on every frame. It goes down at twice the speed it comes\n // back. The `::after` strip stays over the row the button left, or a press on its top pixel\n // would release outside it and lose the click. A member of a `ButtonGroup` stays in line with\n // its shadow, since either would step it out of the group's outline. Rides `interactive`: a\n // disabled control does not answer.\n true: [\n \"not-disabled:not-aria-disabled:cursor-pointer aria-disabled:cursor-not-allowed\",\n \"ui-pressed:duration-75 ui-pressed:ui-standalone:shadow-none ui-pressed:ui-standalone:translate-y-px\",\n \"ui-pressed:ui-standalone:after:absolute ui-pressed:ui-standalone:after:inset-x-0 ui-pressed:ui-standalone:after:-top-0.5 ui-pressed:ui-standalone:after:h-0.5\",\n ],\n },\n },\n\n compoundVariants: [\n // A disabled button fades its label and icons to half strength but keeps its fill and edge, so\n // a disabled member of a `ButtonGroup` still draws its part of the outline. On its own it also\n // goes flat. A pending button keeps its colour, since it is busy rather than unavailable.\n {\n variant: [\"secondary\", \"soft\", \"ghost\"],\n class: [\n \"not-data-pending:disabled:*:opacity-50 not-data-pending:disabled:ui-standalone:shadow-none\",\n \"aria-disabled:*:opacity-50 aria-disabled:ui-standalone:shadow-none\",\n ],\n },\n // A disabled primary button goes flat and grey instead: ink at half strength reads as a\n // dimmed slab, while the fill reads as a button that is not ready yet.\n {\n variant: \"primary\",\n class: [\n \"not-data-pending:disabled:bg-fill not-data-pending:disabled:text-ink-muted not-data-pending:disabled:shadow-none\",\n \"aria-disabled:bg-fill aria-disabled:text-ink-muted aria-disabled:shadow-none\",\n ],\n },\n // Only a button that does something answers the pointer. A reading drawn as a button, with\n // `interactive` off, keeps its resting look under the cursor. Each variant darkens one step\n // past its hover when pressed, which is the whole press of a `ButtonGroup` member.\n {\n variant: \"primary\",\n interactive: true,\n class: \"hover:not-disabled:not-aria-disabled:bg-ink/90 ui-pressed:bg-ink/80\",\n },\n {\n variant: [\"secondary\", \"ghost\"],\n interactive: true,\n class:\n \"hover:not-disabled:not-aria-disabled:bg-fill-subtle hover:not-disabled:not-aria-disabled:text-ink ui-pressed:bg-fill\",\n },\n // A bordered button's edge darkens under the pointer, as a field's and a checkbox's do. Not in\n // a `ButtonGroup`, where a member shares its left edge with the one before it, so a darker\n // edge would stop short on that side: a member answers with its fill alone.\n {\n bordered: true,\n interactive: true,\n class: \"hover:ui-standalone:not-disabled:not-aria-disabled:border-edge-solid\",\n },\n {\n variant: \"soft\",\n interactive: true,\n // The fill has no step past `fill-strong`, so a pressed soft button keeps its hover fill.\n class:\n \"hover:not-disabled:not-aria-disabled:bg-fill-strong hover:not-disabled:not-aria-disabled:text-ink ui-pressed:bg-fill-strong\",\n },\n {\n variant: \"primary\",\n tone: \"danger\",\n class:\n \"bg-danger text-danger-on hover:not-disabled:not-aria-disabled:bg-danger/90 aria-expanded:bg-danger/90\",\n },\n {\n variant: \"primary\",\n tone: \"danger\",\n interactive: true,\n class: \"ui-pressed:bg-danger/80\",\n },\n {\n variant: [\"secondary\", \"soft\", \"ghost\"],\n tone: \"danger\",\n class:\n \"text-danger-ink hover:not-disabled:not-aria-disabled:text-danger-ink aria-expanded:text-danger-ink\",\n },\n ],\n\n defaultVariants: {\n variant: \"primary\",\n tone: \"neutral\",\n size: \"md\",\n interactive: true,\n },\n})\n\n// A 14px icon, drawn 2px closer to the edge than the text is.\nconst buttonAffixClasses = \"shrink-0 first:-ml-0.5 last:-mr-0.5 [svg]:size-3.5\"\n// Nothing but an icon: a square of the button's height, the icon centred in it.\nconst buttonSquareClasses = \"px-0 aspect-square\"\nconst buttonSquareAffixClasses = \"shrink-0 [svg]:size-3.5\"\n\n/**\n * Hidden while a button with no leading icon is pending, so only the spinner reads as content. A\n * button with one keeps its label, since the spinner takes the icon's place.\n */\nconst buttonPendingClasses = \"group-data-pending/button:text-transparent\"\n\nexport type ButtonProps = Omit<useRender.ComponentProps<\"button\">, \"size\" | \"prefix\"> &\n VariantProps<typeof buttonVariants> & {\n /**\n * If set to `true`, the button will be rendered in the pending state.\n */\n isPending?: boolean\n\n /** The slot to be rendered before the label. */\n prefix?: ReactNode\n\n /** The slot to be rendered after the label. */\n suffix?: ReactNode\n }\n\nfunction Button({\n children,\n className,\n disabled = false,\n render,\n isPending,\n prefix,\n suffix,\n variant,\n tone,\n size,\n interactive = true,\n bordered,\n ...rest\n}: ButtonProps) {\n // `toArray` drops `false` and `null`, so a label hidden with `{wide && \"Label\"}` leaves an\n // icon-only button, square and with nothing beside its icon.\n const square = Children.toArray(children).length === 0\n const affixClasses = square ? buttonSquareAffixClasses : buttonAffixClasses\n const props = mergeProps<\"button\">(\n {\n disabled: disabled || isPending,\n \"aria-busy\": isPending ? true : undefined,\n className: buttonVariants({\n variant,\n tone,\n size,\n interactive,\n bordered: bordered ?? variant === \"secondary\",\n className: cn(square && buttonSquareClasses, className),\n }),\n children: (\n <>\n {slot(prefix && isPending ? <LoadingIcon className=\"animate-spin\" /> : prefix, {\n className: affixClasses,\n })}\n\n {/* Beside an affix the label fills the row and pushes the suffix to the end. Alone it\n keeps its own width, so the button's `justify-*` places it: centred by default,\n at the start for a `justify-start` row. */}\n {!square &&\n slot(isValidElement(children) ? children : <span>{children}</span>, {\n className: cn(\n \"flex-1 truncate only:flex-initial has-[div]:contents\",\n !prefix && buttonPendingClasses,\n ),\n })}\n\n {slot(suffix, { className: cn(affixClasses, buttonPendingClasses) })}\n\n {!prefix && !!isPending && (\n <LoadingIcon className=\"absolute size-[1.25em] animate-spin\" />\n )}\n </>\n ),\n },\n rest,\n )\n\n // `data-pending` drives the label and suffix fade; it sits outside `mergeProps`, whose\n // button props type has no room for a custom data attribute.\n //\n // `type` defaults to \"button\", not HTML's \"submit\": a Button inside a <form> that never\n // meant to submit it (a dialog's X, a search field's clear) otherwise does. Callers that\n // want a submit still say so: `props` spreads last and wins. Only applied when the\n // element really is a <button>, since `type` means something else on an <a> or a <label>.\n const isButton = !render\n\n return useRender({\n defaultTagName: \"button\",\n render,\n props: {\n \"data-pending\": isPending ? true : undefined,\n \"data-pressable\": interactive ? \"\" : undefined,\n ...(isButton && { type: \"button\" }),\n ...props,\n },\n })\n}\n\nexport { Button, buttonVariants }\n"],"mappings":";;;;;;;;;AASA,MAAM,2BAA2B,oBAAoB,EAAE,aAAa,MAAM,CAAC;AAE3E,MAAM,iBAAiB,SAAS;CAC9B,MAAM;EACJ;EAGA;EACA;EACA;CACF;CAEA,UAAU;EACR,SAAS;GAKP,SACE;GACF,WACE;GACF,MAAM;GACN,OAAO;EACT;EAGA,MAAM;GACJ,SAAS;GACT,QAAQ;EACV;EACA,UAAU,EACR,MAAM,iIACR;EAGA,MAAM;GACJ,IAAI;GACJ,IAAI;GACJ,IAAI;GACJ,IAAI;EACN;EACA,aAAa,EAQX,MAAM;GACJ;GACA;GACA;EACF,EACF;CACF;CAEA,kBAAkB;EAIhB;GACE,SAAS;IAAC;IAAa;IAAQ;GAAO;GACtC,OAAO,CACL,8FACA,oEACF;EACF;EAGA;GACE,SAAS;GACT,OAAO,CACL,oHACA,8EACF;EACF;EAIA;GACE,SAAS;GACT,aAAa;GACb,OAAO;EACT;EACA;GACE,SAAS,CAAC,aAAa,OAAO;GAC9B,aAAa;GACb,OACE;EACJ;EAIA;GACE,UAAU;GACV,aAAa;GACb,OAAO;EACT;EACA;GACE,SAAS;GACT,aAAa;GAEb,OACE;EACJ;EACA;GACE,SAAS;GACT,MAAM;GACN,OACE;EACJ;EACA;GACE,SAAS;GACT,MAAM;GACN,aAAa;GACb,OAAO;EACT;EACA;GACE,SAAS;IAAC;IAAa;IAAQ;GAAO;GACtC,MAAM;GACN,OACE;EACJ;CACF;CAEA,iBAAiB;EACf,SAAS;EACT,MAAM;EACN,MAAM;EACN,aAAa;CACf;AACF,CAAC;AAGD,MAAM,qBAAqB;AAE3B,MAAM,sBAAsB;AAC5B,MAAM,2BAA2B;;;;;AAMjC,MAAM,uBAAuB;AAgB7B,SAAS,OAAO,EACd,UACA,WACA,WAAW,OACX,QACA,WACA,QACA,QACA,SACA,MACA,MACA,cAAc,MACd,UACA,GAAG,QACW;CAGd,MAAM,SAAS,SAAS,QAAQ,QAAQ,CAAC,CAAC,WAAW;CACrD,MAAM,eAAe,SAAS,2BAA2B;CACzD,MAAM,QAAQ,WACZ;EACE,UAAU,YAAY;EACtB,aAAa,YAAY,OAAO,KAAA;EAChC,WAAW,eAAe;GACxB;GACA;GACA;GACA;GACA,UAAU,YAAY,YAAY;GAClC,WAAW,GAAG,UAAU,qBAAqB,SAAS;EACxD,CAAC;EACD,UACE,qBAAA,UAAA,EAAA,UAAA;GACG,KAAK,UAAU,YAAY,oBAAC,aAAD,EAAa,WAAU,eAAgB,CAAA,IAAI,QAAQ,EAC7E,WAAW,aACb,CAAC;GAKA,CAAC,UACA,KAAK,eAAe,QAAQ,IAAI,WAAW,oBAAC,QAAD,EAAO,SAAe,CAAA,GAAG,EAClE,WAAW,GACT,wDACA,CAAC,UAAU,oBACb,EACF,CAAC;GAEF,KAAK,QAAQ,EAAE,WAAW,GAAG,cAAc,oBAAoB,EAAE,CAAC;GAElE,CAAC,UAAU,CAAC,CAAC,aACZ,oBAAC,aAAD,EAAa,WAAU,sCAAuC,CAAA;EAEhE,EAAA,CAAA;CAEN,GACA,IACF;CAWA,OAAO,UAAU;EACf,gBAAgB;EAChB;EACA,OAAO;GACL,gBAAgB,YAAY,OAAO,KAAA;GACnC,kBAAkB,cAAc,KAAK,KAAA;GACrC,GAAI,CARU,UAQE,EAAE,MAAM,SAAS;GACjC,GAAG;EACL;CACF,CAAC;AACH"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { DataTableFeatures, DataTableState } from "../lib/data-table-state.js";
|
|
2
|
+
import { PaginationLabels } from "./pagination.js";
|
|
3
|
+
import { TableProps, TableRowProps } from "./table.js";
|
|
4
|
+
import { useRender } from "@base-ui/react/use-render";
|
|
5
|
+
import { ReactNode } from "react";
|
|
6
|
+
import { RowData, TableOptions } from "@tanstack/react-table";
|
|
7
|
+
/** The words of a `DataTable`, each a prop with an English default. */
|
|
8
|
+
export interface DataTableLabels {
|
|
9
|
+
selectAll: string;
|
|
10
|
+
/** The checkbox of one row, named by `getRowLabel`. */
|
|
11
|
+
selectRow: (name: string) => string;
|
|
12
|
+
/** The column picker's button. */
|
|
13
|
+
columns: string;
|
|
14
|
+
/** The count of an infinite table's band, from the formatted number of loaded rows. */
|
|
15
|
+
rowCount: (count: string) => ReactNode;
|
|
16
|
+
/** The bulk action bar's count, from the formatted number of selected rows. */
|
|
17
|
+
selected: (count: string) => ReactNode;
|
|
18
|
+
/** Names the bulk action bar for a screen reader. */
|
|
19
|
+
selection: string;
|
|
20
|
+
clearSelection: string;
|
|
21
|
+
loadingMore: ReactNode;
|
|
22
|
+
endOfList: ReactNode;
|
|
23
|
+
/** The paged band's words. */
|
|
24
|
+
pagination?: Partial<PaginationLabels>;
|
|
25
|
+
}
|
|
26
|
+
/** The footer of a table whose rows come a page at a time. Page and page size live in `state`. */
|
|
27
|
+
interface DataTablePages {
|
|
28
|
+
type: "pages";
|
|
29
|
+
/** Every row the query matches, across all pages. */
|
|
30
|
+
total: number;
|
|
31
|
+
/** The page sizes the reader picks from. Left out, the band has no per-page select. */
|
|
32
|
+
perPageOptions?: number[];
|
|
33
|
+
}
|
|
34
|
+
/** The footer of a table that loads the next batch as its end scrolls into view. */
|
|
35
|
+
interface DataTableInfinite {
|
|
36
|
+
type: "infinite";
|
|
37
|
+
hasMore: boolean;
|
|
38
|
+
isLoadingMore: boolean;
|
|
39
|
+
/** Asks for the next batch. Pass a stable callback. */
|
|
40
|
+
onLoadMore: () => void;
|
|
41
|
+
/** False after a failed batch, so the band does not ask for it again at once. */
|
|
42
|
+
enabled?: boolean;
|
|
43
|
+
/** The count at the start of the band. Left out, it is the number of loaded rows. */
|
|
44
|
+
count?: ReactNode;
|
|
45
|
+
}
|
|
46
|
+
export type DataTablePagination = DataTablePages | DataTableInfinite;
|
|
47
|
+
export interface DataTableChangeOptions {
|
|
48
|
+
/**
|
|
49
|
+
* True when the table corrects the state itself (a page past the end), so a router adapter
|
|
50
|
+
* replaces the history entry rather than adding one the reader would land back on.
|
|
51
|
+
*/
|
|
52
|
+
replace: boolean;
|
|
53
|
+
}
|
|
54
|
+
/** What the toolbar render prop receives. */
|
|
55
|
+
export interface DataTableToolbarContext {
|
|
56
|
+
state: DataTableState;
|
|
57
|
+
/** Changes part of the state under the paging rules: a new search or filter goes to page 1. */
|
|
58
|
+
setState: (change: Partial<DataTableState>) => void;
|
|
59
|
+
/** A menu that shows and hides the columns that allow it, for the toolbar's `end`. */
|
|
60
|
+
columnPicker: ReactNode;
|
|
61
|
+
}
|
|
62
|
+
export interface DataTableProps<TData extends RowData> extends Pick<TableProps, "variant" | "layout" | "className" | "containerClassName"> {
|
|
63
|
+
/** Built with `createDataTableColumnHelper`. Keep the array stable between renders. */
|
|
64
|
+
columns: TableOptions<DataTableFeatures, TData>["columns"];
|
|
65
|
+
/** The rows to show: this page's, or every batch loaded so far. Keep it stable too. */
|
|
66
|
+
data: TData[];
|
|
67
|
+
/** A stable id per row, which a selection is kept by. */
|
|
68
|
+
getRowId: (row: TData) => string;
|
|
69
|
+
/** Names a row for a screen reader: its checkbox reads "Select <name>". Defaults to its id. */
|
|
70
|
+
getRowLabel?: (row: TData) => string;
|
|
71
|
+
"aria-label": string;
|
|
72
|
+
state: DataTableState;
|
|
73
|
+
onStateChange: (state: DataTableState, options: DataTableChangeOptions) => void;
|
|
74
|
+
pagination?: DataTablePagination;
|
|
75
|
+
/**
|
|
76
|
+
* A request is in flight. With no rows yet the table shows skeleton rows; with rows, it keeps
|
|
77
|
+
* them and dims them until the new ones land.
|
|
78
|
+
*/
|
|
79
|
+
loading?: boolean;
|
|
80
|
+
/** Stands in for the rows when there are none: a `TableMessage` (empty, filtered, error). */
|
|
81
|
+
message?: ReactNode;
|
|
82
|
+
/** The row's link. A row with one opens from anywhere on it, through `DataTableRowLink`. */
|
|
83
|
+
getRowHref?: (row: TData) => string | undefined;
|
|
84
|
+
/** Renders the row link through a router's link component; it receives the `href`. */
|
|
85
|
+
renderRowLink?: useRender.ComponentProps<"a">["render"];
|
|
86
|
+
/** Fades a row whose record is archived or blocked, all but its menu and checkbox. */
|
|
87
|
+
isRowInactive?: (row: TData) => boolean;
|
|
88
|
+
/** Adds a checkbox column. A function disables the box of each row it returns false for. */
|
|
89
|
+
enableRowSelection?: boolean | ((row: TData) => boolean);
|
|
90
|
+
/** The bulk action bar's buttons for the selected rows, shown while any are selected. */
|
|
91
|
+
bulkActions?: (rows: TData[], clear: () => void) => ReactNode;
|
|
92
|
+
/** Saves the columns the reader hides, per table, in `localStorage`. */
|
|
93
|
+
storageKey?: string;
|
|
94
|
+
/** The row above the table: a `TableToolbar`. */
|
|
95
|
+
toolbar?: (context: DataTableToolbarContext) => ReactNode;
|
|
96
|
+
size?: TableRowProps["size"];
|
|
97
|
+
/** Formats each figure in the reader's locale. */
|
|
98
|
+
format?: (value: number) => string;
|
|
99
|
+
labels?: Partial<DataTableLabels>;
|
|
100
|
+
}
|
|
101
|
+
interface DataTableRowLinkProps {
|
|
102
|
+
className?: string;
|
|
103
|
+
children: ReactNode;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* The record's name, inside a `DataTable` column's cell: a link over the whole row when the
|
|
107
|
+
* table has `getRowHref`, plain text when it has none or the row returns none.
|
|
108
|
+
*/
|
|
109
|
+
export declare function DataTableRowLink({ className, children }: DataTableRowLinkProps): import("react").JSX.Element;
|
|
110
|
+
/**
|
|
111
|
+
* A table drawn from react-table column definitions: the app writes columns, the wrapper draws
|
|
112
|
+
* the head, the rows, the footer band, the checkbox column and the bulk action bar. Its state
|
|
113
|
+
* (page, page size, sort, search, filters) is controlled and never read from the URL, so each
|
|
114
|
+
* app keeps it in its own router. The server sorts, filters and pages: `data` is the rows to
|
|
115
|
+
* show, in order. Paging follows one set of rules: the page is 1-based, a page past the end
|
|
116
|
+
* shows the last one, a change of sort, search, filter or page size goes back to page 1, and
|
|
117
|
+
* the old rows stay dimmed while the next ones load.
|
|
118
|
+
*/
|
|
119
|
+
export declare function DataTable<TData extends RowData>({ columns, data, getRowId, getRowLabel, "aria-label": ariaLabel, state, onStateChange, pagination, loading, message, getRowHref, renderRowLink, isRowInactive, enableRowSelection, bulkActions, storageKey, toolbar, size, format, labels: labelsProp, variant, layout, className, containerClassName }: DataTableProps<TData>): import("react").JSX.Element;
|
|
120
|
+
export {};
|