@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
package/components/pagination.js
CHANGED
|
@@ -1,63 +1,212 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { ChevronLeftIcon, ChevronRightIcon } from "../lib/icons.js";
|
|
2
|
+
import { ChevronLeftIcon, ChevronRightIcon, ChevronsLeftIcon, ChevronsRightIcon } from "../lib/icons.js";
|
|
3
|
+
import { useLoadMore } from "../lib/load-more.js";
|
|
3
4
|
import { cn } from "../lib/variants.js";
|
|
4
5
|
import { Button } from "./button.js";
|
|
5
|
-
import {
|
|
6
|
+
import { ButtonGroup } from "./button-group.js";
|
|
7
|
+
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "./select.js";
|
|
8
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
+
import { useId, useState } from "react";
|
|
6
10
|
// src/components/pagination.tsx
|
|
7
11
|
/**
|
|
8
12
|
* 1-based row range shown on the current page, e.g. "26–50 of 42" → { from: 26, to: 42 }.
|
|
9
13
|
*/
|
|
10
|
-
function
|
|
14
|
+
function getPageRange(page, perPage, total) {
|
|
11
15
|
if (total === 0) return {
|
|
12
16
|
from: 0,
|
|
13
17
|
to: 0
|
|
14
18
|
};
|
|
19
|
+
const to = Math.min(page * perPage, total);
|
|
15
20
|
return {
|
|
16
|
-
from: (page - 1) * perPage + 1,
|
|
17
|
-
to
|
|
21
|
+
from: Math.min((page - 1) * perPage + 1, to),
|
|
22
|
+
to
|
|
18
23
|
};
|
|
19
24
|
}
|
|
20
25
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* params. Renders nothing when there's a single page.
|
|
26
|
+
* The band under a table's rows: a hairline above, the count at the start, the controls at the
|
|
27
|
+
* end. 48px, so the pager's 28px buttons sit 10px from each edge.
|
|
24
28
|
*/
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
29
|
+
const BAND_CLASSES = "flex h-12 shrink-0 items-center justify-between gap-4 border-t border-edge-subtle pr-3 pl-5 text-ink-muted text-xs tabular-nums";
|
|
30
|
+
/** Figures in the band are ink, the words around them muted. */
|
|
31
|
+
const FIGURE_CLASSES = "text-ink";
|
|
32
|
+
const PAGINATION_LABELS = {
|
|
33
|
+
range: ({ from, to, total }) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
34
|
+
"Showing ",
|
|
35
|
+
from,
|
|
36
|
+
"–",
|
|
37
|
+
to,
|
|
38
|
+
" of ",
|
|
39
|
+
total
|
|
40
|
+
] }),
|
|
41
|
+
rangeShort: ({ from, to, total }) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
42
|
+
from,
|
|
43
|
+
"–",
|
|
44
|
+
to,
|
|
45
|
+
" of ",
|
|
46
|
+
total
|
|
47
|
+
] }),
|
|
48
|
+
pageOf: ({ page, pageCount }) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
49
|
+
"Page ",
|
|
50
|
+
page,
|
|
51
|
+
" of ",
|
|
52
|
+
pageCount
|
|
53
|
+
] }),
|
|
54
|
+
perPage: "Per page",
|
|
55
|
+
firstPage: "First page",
|
|
56
|
+
previousPage: "Previous page",
|
|
57
|
+
nextPage: "Next page",
|
|
58
|
+
lastPage: "Last page"
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* The footer band of a paged table: "Showing 26–50 of 1,204", an optional per-page select,
|
|
62
|
+
* "Page 2 of 49" and the joined first, previous, next and last buttons. A single page keeps the
|
|
63
|
+
* count and drops the controls; an empty table has no band. On a phone the count drops
|
|
64
|
+
* "Showing", and the per-page select and the first and last buttons go. Presentational and
|
|
65
|
+
* router-agnostic: the caller wires `onPageChange` to its search params.
|
|
66
|
+
*/
|
|
67
|
+
function Pagination({ page, pageCount, total, perPage, onPageChange, perPageOptions, onPerPageChange, loading = false, format = String, labels: labelsProp, className, ...props }) {
|
|
68
|
+
const perPageLabelId = useId();
|
|
69
|
+
const labels = {
|
|
70
|
+
...PAGINATION_LABELS,
|
|
71
|
+
...labelsProp
|
|
72
|
+
};
|
|
73
|
+
if (total === 0) return null;
|
|
74
|
+
const { from, to } = getPageRange(page, perPage, total);
|
|
75
|
+
const range = {
|
|
76
|
+
from: /* @__PURE__ */ jsx("span", {
|
|
77
|
+
className: FIGURE_CLASSES,
|
|
78
|
+
children: format(from)
|
|
79
|
+
}),
|
|
80
|
+
to: /* @__PURE__ */ jsx("span", {
|
|
81
|
+
className: FIGURE_CLASSES,
|
|
82
|
+
children: format(to)
|
|
83
|
+
}),
|
|
84
|
+
total: /* @__PURE__ */ jsx("span", {
|
|
85
|
+
className: FIGURE_CLASSES,
|
|
86
|
+
children: format(total)
|
|
87
|
+
})
|
|
88
|
+
};
|
|
89
|
+
const first = page <= 1;
|
|
90
|
+
const last = page >= pageCount;
|
|
28
91
|
return /* @__PURE__ */ jsxs("div", {
|
|
29
|
-
|
|
92
|
+
"aria-busy": loading || void 0,
|
|
93
|
+
className: cn(BAND_CLASSES, className),
|
|
30
94
|
...props,
|
|
31
95
|
children: [/* @__PURE__ */ jsxs("p", {
|
|
32
|
-
className: "
|
|
96
|
+
className: "truncate",
|
|
97
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
98
|
+
className: "max-sm:hidden",
|
|
99
|
+
children: labels.range(range)
|
|
100
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
101
|
+
className: "sm:hidden",
|
|
102
|
+
children: labels.rangeShort(range)
|
|
103
|
+
})]
|
|
104
|
+
}), pageCount > 1 && /* @__PURE__ */ jsxs("div", {
|
|
105
|
+
className: "flex items-center gap-4",
|
|
33
106
|
children: [
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
107
|
+
perPageOptions && onPerPageChange && /* @__PURE__ */ jsxs("div", {
|
|
108
|
+
className: "flex items-center gap-2 max-sm:hidden",
|
|
109
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
110
|
+
id: perPageLabelId,
|
|
111
|
+
children: labels.perPage
|
|
112
|
+
}), /* @__PURE__ */ jsxs(Select, {
|
|
113
|
+
value: perPage,
|
|
114
|
+
disabled: loading,
|
|
115
|
+
onValueChange: (value) => {
|
|
116
|
+
if (value !== null) onPerPageChange(value);
|
|
117
|
+
},
|
|
118
|
+
children: [/* @__PURE__ */ jsx(SelectTrigger, {
|
|
119
|
+
size: "sm",
|
|
120
|
+
"aria-labelledby": perPageLabelId,
|
|
121
|
+
className: "w-18",
|
|
122
|
+
children: /* @__PURE__ */ jsx(SelectValue, {})
|
|
123
|
+
}), /* @__PURE__ */ jsx(SelectContent, { children: perPageOptions.map((option) => /* @__PURE__ */ jsx(SelectItem, {
|
|
124
|
+
value: option,
|
|
125
|
+
children: format(option)
|
|
126
|
+
}, option)) })]
|
|
127
|
+
})]
|
|
128
|
+
}),
|
|
129
|
+
/* @__PURE__ */ jsx("p", {
|
|
130
|
+
className: "whitespace-nowrap",
|
|
131
|
+
children: labels.pageOf({
|
|
132
|
+
page: /* @__PURE__ */ jsx("span", {
|
|
133
|
+
className: FIGURE_CLASSES,
|
|
134
|
+
children: format(page)
|
|
135
|
+
}),
|
|
136
|
+
pageCount: /* @__PURE__ */ jsx("span", {
|
|
137
|
+
className: FIGURE_CLASSES,
|
|
138
|
+
children: format(pageCount)
|
|
139
|
+
})
|
|
140
|
+
})
|
|
141
|
+
}),
|
|
142
|
+
/* @__PURE__ */ jsxs(ButtonGroup, { children: [
|
|
143
|
+
/* @__PURE__ */ jsx(Button, {
|
|
144
|
+
variant: "secondary",
|
|
145
|
+
size: "sm",
|
|
146
|
+
"aria-label": labels.firstPage,
|
|
147
|
+
prefix: /* @__PURE__ */ jsx(ChevronsLeftIcon, {}),
|
|
148
|
+
disabled: loading || first,
|
|
149
|
+
className: "max-sm:hidden",
|
|
150
|
+
onClick: () => onPageChange(1)
|
|
151
|
+
}),
|
|
152
|
+
/* @__PURE__ */ jsx(Button, {
|
|
153
|
+
variant: "secondary",
|
|
154
|
+
size: "sm",
|
|
155
|
+
"aria-label": labels.previousPage,
|
|
156
|
+
prefix: /* @__PURE__ */ jsx(ChevronLeftIcon, {}),
|
|
157
|
+
disabled: loading || first,
|
|
158
|
+
className: "max-sm:rounded-l-md! max-sm:border-l!",
|
|
159
|
+
onClick: () => onPageChange(page - 1)
|
|
160
|
+
}),
|
|
161
|
+
/* @__PURE__ */ jsx(Button, {
|
|
162
|
+
variant: "secondary",
|
|
163
|
+
size: "sm",
|
|
164
|
+
"aria-label": labels.nextPage,
|
|
165
|
+
prefix: /* @__PURE__ */ jsx(ChevronRightIcon, {}),
|
|
166
|
+
disabled: loading || last,
|
|
167
|
+
className: "max-sm:rounded-r-md!",
|
|
168
|
+
onClick: () => onPageChange(page + 1)
|
|
169
|
+
}),
|
|
170
|
+
/* @__PURE__ */ jsx(Button, {
|
|
171
|
+
variant: "secondary",
|
|
172
|
+
size: "sm",
|
|
173
|
+
"aria-label": labels.lastPage,
|
|
174
|
+
prefix: /* @__PURE__ */ jsx(ChevronsRightIcon, {}),
|
|
175
|
+
disabled: loading || last,
|
|
176
|
+
className: "max-sm:hidden",
|
|
177
|
+
onClick: () => onPageChange(pageCount)
|
|
178
|
+
})
|
|
179
|
+
] })
|
|
40
180
|
]
|
|
41
|
-
}), /* @__PURE__ */ jsxs("div", {
|
|
42
|
-
className: "flex items-center gap-2",
|
|
43
|
-
children: [/* @__PURE__ */ jsx(Button, {
|
|
44
|
-
variant: "secondary",
|
|
45
|
-
size: "sm",
|
|
46
|
-
"aria-label": "Previous page",
|
|
47
|
-
prefix: /* @__PURE__ */ jsx(ChevronLeftIcon, {}),
|
|
48
|
-
disabled: page <= 1,
|
|
49
|
-
onClick: () => onPageChange(page - 1)
|
|
50
|
-
}), /* @__PURE__ */ jsx(Button, {
|
|
51
|
-
variant: "secondary",
|
|
52
|
-
size: "sm",
|
|
53
|
-
"aria-label": "Next page",
|
|
54
|
-
prefix: /* @__PURE__ */ jsx(ChevronRightIcon, {}),
|
|
55
|
-
disabled: page >= pageCount,
|
|
56
|
-
onClick: () => onPageChange(page + 1)
|
|
57
|
-
})]
|
|
58
181
|
})]
|
|
59
182
|
});
|
|
60
183
|
}
|
|
61
|
-
|
|
184
|
+
/**
|
|
185
|
+
* The footer band of a table that loads as it scrolls: the count, then "Loading more…" while the
|
|
186
|
+
* next batch loads and "End of list" once there is none. The band itself is the trigger: the
|
|
187
|
+
* next page loads as it nears the viewport. Pass `onLoadMore` a stable callback.
|
|
188
|
+
*/
|
|
189
|
+
function PaginationInfinite({ count, hasMore, loading, onLoadMore, enabled = true, ahead, loadingLabel = "Loading more…", endLabel = "End of list", className, ...props }) {
|
|
190
|
+
const [sentinel, setSentinel] = useState(null);
|
|
191
|
+
useLoadMore(sentinel, {
|
|
192
|
+
enabled: enabled && hasMore && !loading,
|
|
193
|
+
onLoad: onLoadMore,
|
|
194
|
+
ahead
|
|
195
|
+
});
|
|
196
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
197
|
+
ref: setSentinel,
|
|
198
|
+
"aria-busy": loading || void 0,
|
|
199
|
+
className: cn(BAND_CLASSES, className),
|
|
200
|
+
...props,
|
|
201
|
+
children: [/* @__PURE__ */ jsx("p", {
|
|
202
|
+
className: "truncate",
|
|
203
|
+
children: count
|
|
204
|
+
}), /* @__PURE__ */ jsx("output", {
|
|
205
|
+
className: "whitespace-nowrap",
|
|
206
|
+
children: loading ? loadingLabel : hasMore ? null : endLabel
|
|
207
|
+
})]
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
export { Pagination, PaginationInfinite };
|
|
62
211
|
|
|
63
212
|
//# sourceMappingURL=pagination.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pagination.js","names":[],"sources":["../../src/components/pagination.tsx"],"sourcesContent":["\"use client\"\n\nimport type { ComponentProps } from \"react\"\nimport { ChevronLeftIcon, ChevronRightIcon } from \"../lib/icons\"\nimport { cn } from \"../lib/variants\"\nimport { Button } from \"./button\"\n\n/**\n * 1-based row range shown on the current page, e.g. \"26–50 of 42\" → { from: 26, to: 42 }.\n */\nfunction pageRange(page: number, perPage: number, total: number) {\n if (total === 0) return { from: 0, to: 0 }\n return { from: (page - 1) * perPage + 1, to: Math.min(page * perPage, total) }\n}\n\ntype PaginationProps = ComponentProps<\"div\"> & {\n page: number\n pageCount: number\n total: number\n perPage: number\n onPageChange: (page: number) => void\n}\n\n/**\n * Offset-pagination controls for a list: a \"Showing from–to of total\" label and prev/next\n * buttons. Presentational and router-agnostic — the caller wires `onPageChange` to its search\n * params. Renders nothing when there's a single page.\n */\nexport function Pagination({\n page,\n pageCount,\n total,\n perPage,\n onPageChange,\n className,\n ...props\n}: PaginationProps) {\n if (pageCount <= 1) return null\n\n const { from, to } = pageRange(page, perPage, total)\n\n return (\n <div className={cn(\"flex items-center justify-between gap-4 pt-1\", className)} {...props}>\n <p className=\"text-ink-muted text-xs tabular-nums\">\n Showing {from}–{to} of {total}\n </p>\n\n <div className=\"flex items-center gap-2\">\n <Button\n variant=\"secondary\"\n size=\"sm\"\n aria-label=\"Previous page\"\n prefix={<ChevronLeftIcon />}\n disabled={page <= 1}\n onClick={() => onPageChange(page - 1)}\n />\n\n <Button\n variant=\"secondary\"\n size=\"sm\"\n aria-label=\"Next page\"\n prefix={<ChevronRightIcon />}\n disabled={page >= pageCount}\n onClick={() => onPageChange(page + 1)}\n />\n </div>\n </div>\n )\n}\n"],"mappings":";;;;;;;;;AAUA,SAAS,UAAU,MAAc,SAAiB,OAAe;CAC/D,IAAI,UAAU,GAAG,OAAO;EAAE,MAAM;EAAG,IAAI;CAAE;CACzC,OAAO;EAAE,OAAO,OAAO,KAAK,UAAU;EAAG,IAAI,KAAK,IAAI,OAAO,SAAS,KAAK;CAAE;AAC/E;;;;;;AAeA,SAAgB,WAAW,EACzB,MACA,WACA,OACA,SACA,cACA,WACA,GAAG,SACe;CAClB,IAAI,aAAa,GAAG,OAAO;CAE3B,MAAM,EAAE,MAAM,OAAO,UAAU,MAAM,SAAS,KAAK;CAEnD,OACE,qBAAC,OAAD;EAAK,WAAW,GAAG,gDAAgD,SAAS;EAAG,GAAI;EAAnF,UAAA,CACE,qBAAC,KAAD;GAAG,WAAU;GAAb,UAAA;IAAmD;IACxC;IAAK;IAAE;IAAG;IAAK;GACvB;EAEH,CAAA,GAAA,qBAAC,OAAD;GAAK,WAAU;GAAf,UAAA,CACE,oBAAC,QAAD;IACE,SAAQ;IACR,MAAK;IACL,cAAW;IACX,QAAQ,oBAAC,iBAAD,CAAkB,CAAA;IAC1B,UAAU,QAAQ;IAClB,eAAe,aAAa,OAAO,CAAC;GACrC,CAAA,GAED,oBAAC,QAAD;IACE,SAAQ;IACR,MAAK;IACL,cAAW;IACX,QAAQ,oBAAC,kBAAD,CAAmB,CAAA;IAC3B,UAAU,QAAQ;IAClB,eAAe,aAAa,OAAO,CAAC;GACrC,CAAA,CACE;EACF,CAAA,CAAA;;AAET"}
|
|
1
|
+
{"version":3,"file":"pagination.js","names":[],"sources":["../../src/components/pagination.tsx"],"sourcesContent":["\"use client\"\n\nimport { type ComponentProps, type ReactNode, useId, useState } from \"react\"\nimport {\n ChevronLeftIcon,\n ChevronRightIcon,\n ChevronsLeftIcon,\n ChevronsRightIcon,\n} from \"../lib/icons\"\nimport { useLoadMore } from \"../lib/load-more\"\nimport { cn } from \"../lib/variants\"\nimport { Button } from \"./button\"\nimport { ButtonGroup } from \"./button-group\"\nimport { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from \"./select\"\n\n/**\n * 1-based row range shown on the current page, e.g. \"26–50 of 42\" → { from: 26, to: 42 }.\n */\nfunction getPageRange(page: number, perPage: number, total: number) {\n if (total === 0) return { from: 0, to: 0 }\n const to = Math.min(page * perPage, total)\n // A page past the end (a stale link, rows deleted since) reads as the last row, not \"51–50\".\n return { from: Math.min((page - 1) * perPage + 1, to), to }\n}\n\n/**\n * The band under a table's rows: a hairline above, the count at the start, the controls at the\n * end. 48px, so the pager's 28px buttons sit 10px from each edge.\n */\nconst BAND_CLASSES =\n \"flex h-12 shrink-0 items-center justify-between gap-4 border-t border-edge-subtle pr-3 pl-5 text-ink-muted text-xs tabular-nums\"\n\n/** Figures in the band are ink, the words around them muted. */\nconst FIGURE_CLASSES = \"text-ink\"\n\n/** The figures a count label places, each formatted and styled already. */\nexport interface PaginationRange {\n from: ReactNode\n to: ReactNode\n total: ReactNode\n}\n\n/** The figures of the page label. */\nexport interface PaginationPage {\n page: ReactNode\n pageCount: ReactNode\n}\n\n/**\n * The words of the paged band, each a prop so a product can translate them. A label that holds\n * figures is a function of them, so a language can put them in its own order.\n */\nexport interface PaginationLabels {\n /** The count: \"Showing 26–50 of 1,204\". */\n range: (range: PaginationRange) => ReactNode\n /** The count on a phone: \"26–50 of 1,204\". */\n rangeShort: (range: PaginationRange) => ReactNode\n /** \"Page 2 of 49\". */\n pageOf: (page: PaginationPage) => ReactNode\n perPage: string\n firstPage: string\n previousPage: string\n nextPage: string\n lastPage: string\n}\n\nconst PAGINATION_LABELS: PaginationLabels = {\n range: ({ from, to, total }) => (\n <>\n Showing {from}–{to} of {total}\n </>\n ),\n rangeShort: ({ from, to, total }) => (\n <>\n {from}–{to} of {total}\n </>\n ),\n pageOf: ({ page, pageCount }) => (\n <>\n Page {page} of {pageCount}\n </>\n ),\n perPage: \"Per page\",\n firstPage: \"First page\",\n previousPage: \"Previous page\",\n nextPage: \"Next page\",\n lastPage: \"Last page\",\n}\n\ninterface PaginationProps extends Omit<ComponentProps<\"div\">, \"children\"> {\n page: number\n pageCount: number\n total: number\n perPage: number\n onPageChange: (page: number) => void\n /** The page sizes the reader picks from. Left out, the band has no per-page select. */\n perPageOptions?: number[]\n onPerPageChange?: (perPage: number) => void\n /** While a page loads: every control is disabled, and the caller dims the old rows. */\n loading?: boolean\n /** Formats each figure in the reader's locale. */\n format?: (value: number) => string\n /** The band's words, English by default. */\n labels?: Partial<PaginationLabels>\n}\n\n/**\n * The footer band of a paged table: \"Showing 26–50 of 1,204\", an optional per-page select,\n * \"Page 2 of 49\" and the joined first, previous, next and last buttons. A single page keeps the\n * count and drops the controls; an empty table has no band. On a phone the count drops\n * \"Showing\", and the per-page select and the first and last buttons go. Presentational and\n * router-agnostic: the caller wires `onPageChange` to its search params.\n */\nexport function Pagination({\n page,\n pageCount,\n total,\n perPage,\n onPageChange,\n perPageOptions,\n onPerPageChange,\n loading = false,\n format = String,\n labels: labelsProp,\n className,\n ...props\n}: PaginationProps) {\n const perPageLabelId = useId()\n const labels = { ...PAGINATION_LABELS, ...labelsProp }\n if (total === 0) return null\n\n const { from, to } = getPageRange(page, perPage, total)\n const range = {\n from: <span className={FIGURE_CLASSES}>{format(from)}</span>,\n to: <span className={FIGURE_CLASSES}>{format(to)}</span>,\n total: <span className={FIGURE_CLASSES}>{format(total)}</span>,\n }\n const first = page <= 1\n const last = page >= pageCount\n\n return (\n <div aria-busy={loading || undefined} className={cn(BAND_CLASSES, className)} {...props}>\n <p className=\"truncate\">\n <span className=\"max-sm:hidden\">{labels.range(range)}</span>\n <span className=\"sm:hidden\">{labels.rangeShort(range)}</span>\n </p>\n\n {pageCount > 1 && (\n <div className=\"flex items-center gap-4\">\n {perPageOptions && onPerPageChange && (\n <div className=\"flex items-center gap-2 max-sm:hidden\">\n <span id={perPageLabelId}>{labels.perPage}</span>\n <Select\n value={perPage}\n disabled={loading}\n onValueChange={value => {\n if (value !== null) onPerPageChange(value)\n }}\n >\n <SelectTrigger size=\"sm\" aria-labelledby={perPageLabelId} className=\"w-18\">\n <SelectValue />\n </SelectTrigger>\n <SelectContent>\n {perPageOptions.map(option => (\n <SelectItem key={option} value={option}>\n {format(option)}\n </SelectItem>\n ))}\n </SelectContent>\n </Select>\n </div>\n )}\n\n <p className=\"whitespace-nowrap\">\n {labels.pageOf({\n page: <span className={FIGURE_CLASSES}>{format(page)}</span>,\n pageCount: <span className={FIGURE_CLASSES}>{format(pageCount)}</span>,\n })}\n </p>\n\n <ButtonGroup>\n <Button\n variant=\"secondary\"\n size=\"sm\"\n aria-label={labels.firstPage}\n prefix={<ChevronsLeftIcon />}\n disabled={loading || first}\n className=\"max-sm:hidden\"\n onClick={() => onPageChange(1)}\n />\n {/* On a phone the first and last buttons are gone, so the inner two take the\n group's ends: their outer corners and the left edge the group drops. Marked\n important, since the group's rules for its members outrank a member's own. */}\n <Button\n variant=\"secondary\"\n size=\"sm\"\n aria-label={labels.previousPage}\n prefix={<ChevronLeftIcon />}\n disabled={loading || first}\n className=\"max-sm:rounded-l-md! max-sm:border-l!\"\n onClick={() => onPageChange(page - 1)}\n />\n <Button\n variant=\"secondary\"\n size=\"sm\"\n aria-label={labels.nextPage}\n prefix={<ChevronRightIcon />}\n disabled={loading || last}\n className=\"max-sm:rounded-r-md!\"\n onClick={() => onPageChange(page + 1)}\n />\n <Button\n variant=\"secondary\"\n size=\"sm\"\n aria-label={labels.lastPage}\n prefix={<ChevronsRightIcon />}\n disabled={loading || last}\n className=\"max-sm:hidden\"\n onClick={() => onPageChange(pageCount)}\n />\n </ButtonGroup>\n </div>\n )}\n </div>\n )\n}\n\ninterface PaginationInfiniteProps extends Omit<ComponentProps<\"div\">, \"children\"> {\n /** The count at the start, formatted by the caller: \"120 of 4,300 events\". */\n count: ReactNode\n hasMore: boolean\n loading: boolean\n onLoadMore: () => void\n /** False after a failed page: a sentinel still on screen would ask for it again at once. */\n enabled?: boolean\n /** How far below the viewport the next page starts loading, in pixels. */\n ahead?: number\n loadingLabel?: ReactNode\n endLabel?: ReactNode\n}\n\n/**\n * The footer band of a table that loads as it scrolls: the count, then \"Loading more…\" while the\n * next batch loads and \"End of list\" once there is none. The band itself is the trigger: the\n * next page loads as it nears the viewport. Pass `onLoadMore` a stable callback.\n */\nexport function PaginationInfinite({\n count,\n hasMore,\n loading,\n onLoadMore,\n enabled = true,\n ahead,\n loadingLabel = \"Loading more…\",\n endLabel = \"End of list\",\n className,\n ...props\n}: PaginationInfiniteProps) {\n const [sentinel, setSentinel] = useState<HTMLDivElement | null>(null)\n\n useLoadMore(sentinel, { enabled: enabled && hasMore && !loading, onLoad: onLoadMore, ahead })\n\n return (\n <div\n ref={setSentinel}\n aria-busy={loading || undefined}\n className={cn(BAND_CLASSES, className)}\n {...props}\n >\n <p className=\"truncate\">{count}</p>\n <output className=\"whitespace-nowrap\">\n {loading ? loadingLabel : hasMore ? null : endLabel}\n </output>\n </div>\n )\n}\n"],"mappings":";;;;;;;;;;;;;AAkBA,SAAS,aAAa,MAAc,SAAiB,OAAe;CAClE,IAAI,UAAU,GAAG,OAAO;EAAE,MAAM;EAAG,IAAI;CAAE;CACzC,MAAM,KAAK,KAAK,IAAI,OAAO,SAAS,KAAK;CAEzC,OAAO;EAAE,MAAM,KAAK,KAAK,OAAO,KAAK,U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AA;MAC1B,UAAU,WAAW;MACrB,WAAU;MACV,eAAe,aAAa,OAAO,CAAC;KACrC,CAAA;KACD,oBAAC,QAAD;MACE,SAAQ;MACR,MAAK;MACL,cAAY,OAAO;MACnB,QAAQ,oBAAC,kBAAD,CAAmB,CAAA;MAC3B,UAAU,WAAW;MACrB,WAAU;MACV,eAAe,aAAa,OAAO,CAAC;KACrC,CAAA;KACD,oBAAC,QAAD;MACE,SAAQ;MACR,MAAK;MACL,cAAY,OAAO;MACnB,QAAQ,oBAAC,mBAAD,CAAoB,CAAA;MAC5B,UAAU,WAAW;MACrB,WAAU;MACV,eAAe,aAAa,SAAS;KACtC,CAAA;IACU,EAAA,CAAA;GACV;EAEJ,CAAA,CAAA;;AAET;;;;;;AAqBA,SAAgB,mBAAmB,EACjC,OACA,SACA,SACA,YACA,UAAU,MACV,OACA,eAAe,iBACf,WAAW,eACX,WACA,GAAG,SACuB;CAC1B,MAAM,CAAC,UAAU,eAAe,SAAgC,IAAI;CAEpE,YAAY,UAAU;EAAE,SAAS,WAAW,WAAW,CAAC;EAAS,QAAQ;EAAY;CAAM,CAAC;CAE5F,OACE,qBAAC,OAAD;EACE,KAAK;EACL,aAAW,WAAW,KAAA;EACtB,WAAW,GAAG,cAAc,SAAS;EACrC,GAAI;EAJN,UAAA,CAME,oBAAC,KAAD;GAAG,WAAU;GAAY,UAAA;EAAS,CAAA,GAClC,oBAAC,UAAD;GAAQ,WAAU;GACf,UAAA,UAAU,eAAe,UAAU,OAAO;EACrC,CAAA,CACL;;AAET"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { ComponentProps, ReactNode } from "react";
|
|
2
|
+
export interface TableFacetOption {
|
|
3
|
+
value: string;
|
|
4
|
+
label: ReactNode;
|
|
5
|
+
}
|
|
6
|
+
interface TableToolbarProps extends Omit<ComponentProps<"div">, "children"> {
|
|
7
|
+
/** A `SearchInput`, 200px wide; on a phone it fills its own row. */
|
|
8
|
+
search?: ReactNode;
|
|
9
|
+
/** The filters: a `TableFacetFilter` per common field, the Filter button, its chips. */
|
|
10
|
+
children?: ReactNode;
|
|
11
|
+
/** The sort picker (only for an order no column shows) and the column picker. */
|
|
12
|
+
end?: ReactNode;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The row above a table: the search, then the filters, which wrap onto a second row, then the
|
|
16
|
+
* pickers at the end. Page actions ("New site") belong in the page header, never here.
|
|
17
|
+
*/
|
|
18
|
+
export declare function TableToolbar({ search, children, end, className, ...props }: TableToolbarProps): import("react").JSX.Element;
|
|
19
|
+
interface TableFacetFilterProps {
|
|
20
|
+
/** The field: "Category", "Status". */
|
|
21
|
+
label: string;
|
|
22
|
+
options: TableFacetOption[];
|
|
23
|
+
/** The chosen values, empty while the filter is off. */
|
|
24
|
+
value: string[];
|
|
25
|
+
onValueChange: (value: string[]) => void;
|
|
26
|
+
/** What the trigger shows for several values. */
|
|
27
|
+
formatSelected?: (count: number) => string;
|
|
28
|
+
clearLabel?: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* A column filter in the toolbar, 32px like a button. Off, it is a dashed button with a plus;
|
|
32
|
+
* on, it shows the chosen value, or how many are chosen, after a divider. Its menu ticks values
|
|
33
|
+
* on and off and clears the filter. A filter with a relation (is not, contains) is a
|
|
34
|
+
* `TableFilterChip`.
|
|
35
|
+
*/
|
|
36
|
+
export declare function TableFacetFilter({ label, options, value, onValueChange, formatSelected, clearLabel }: TableFacetFilterProps): import("react").JSX.Element;
|
|
37
|
+
interface TableFilterChipProps {
|
|
38
|
+
field: ReactNode;
|
|
39
|
+
/** The relation: "is", "is not", "contains", "before". */
|
|
40
|
+
operator: ReactNode;
|
|
41
|
+
value: ReactNode;
|
|
42
|
+
/** The items of each part's menu. A part with none is plain text. */
|
|
43
|
+
fieldMenu?: ReactNode;
|
|
44
|
+
operatorMenu?: ReactNode;
|
|
45
|
+
valueMenu?: ReactNode;
|
|
46
|
+
onRemove: () => void;
|
|
47
|
+
removeLabel?: string;
|
|
48
|
+
className?: string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* One filter added from the Filter menu: the field, the relation and the value, each opening its
|
|
52
|
+
* own menu, then a cross that removes it. Chips follow the filter buttons and wrap.
|
|
53
|
+
*/
|
|
54
|
+
export declare function TableFilterChip({ field, operator, value, fieldMenu, operatorMenu, valueMenu, onRemove, removeLabel, className }: TableFilterChipProps): import("react").JSX.Element;
|
|
55
|
+
export {};
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { CancelIcon, PlusCircleIcon } from "../lib/icons.js";
|
|
3
|
+
import { interactiveVariants } from "../lib/interactive.js";
|
|
4
|
+
import { cn } from "../lib/variants.js";
|
|
5
|
+
import { Menu, MenuCheckboxItem, MenuContent, MenuItem, MenuSeparator, MenuTrigger } from "./menu.js";
|
|
6
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
// src/components/table-toolbar.tsx
|
|
8
|
+
const FACET_TRIGGER_CLASSES = cn(interactiveVariants(), "inline-flex h-control items-center gap-1.5 rounded-md border pr-3 pl-2.5 font-medium text-control text-ink", "hover:bg-fill-subtle data-popup-open:bg-fill-subtle [&_svg]:size-3.5", "border-dashed border-edge", "data-active:border-solid data-active:bg-surface data-active:pr-1.5 data-active:shadow-control");
|
|
9
|
+
const CHIP_PART_CLASSES = cn(interactiveVariants(), "inline-flex items-center px-2 outline-offset-[-2px] hover:bg-fill-subtle data-popup-open:bg-fill-subtle");
|
|
10
|
+
function ChipPart({ menu, label, className, children }) {
|
|
11
|
+
if (!menu) return /* @__PURE__ */ jsx("span", {
|
|
12
|
+
className: cn("inline-flex items-center px-2", className),
|
|
13
|
+
children
|
|
14
|
+
});
|
|
15
|
+
return /* @__PURE__ */ jsxs(Menu, { children: [/* @__PURE__ */ jsx(MenuTrigger, {
|
|
16
|
+
className: cn(CHIP_PART_CLASSES, className),
|
|
17
|
+
children
|
|
18
|
+
}), /* @__PURE__ */ jsx(MenuContent, {
|
|
19
|
+
label,
|
|
20
|
+
align: "start",
|
|
21
|
+
children: menu
|
|
22
|
+
})] });
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The row above a table: the search, then the filters, which wrap onto a second row, then the
|
|
26
|
+
* pickers at the end. Page actions ("New site") belong in the page header, never here.
|
|
27
|
+
*/
|
|
28
|
+
function TableToolbar({ search, children, end, className, ...props }) {
|
|
29
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
30
|
+
className: cn("flex flex-wrap items-center gap-2", className),
|
|
31
|
+
...props,
|
|
32
|
+
children: [
|
|
33
|
+
search && /* @__PURE__ */ jsx("div", {
|
|
34
|
+
className: "w-50 max-sm:w-full *:w-full",
|
|
35
|
+
children: search
|
|
36
|
+
}),
|
|
37
|
+
children,
|
|
38
|
+
end && /* @__PURE__ */ jsx("div", {
|
|
39
|
+
className: "ml-auto flex items-center gap-2",
|
|
40
|
+
children: end
|
|
41
|
+
})
|
|
42
|
+
]
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* A column filter in the toolbar, 32px like a button. Off, it is a dashed button with a plus;
|
|
47
|
+
* on, it shows the chosen value, or how many are chosen, after a divider. Its menu ticks values
|
|
48
|
+
* on and off and clears the filter. A filter with a relation (is not, contains) is a
|
|
49
|
+
* `TableFilterChip`.
|
|
50
|
+
*/
|
|
51
|
+
function TableFacetFilter({ label, options, value, onValueChange, formatSelected = (count) => `${count} selected`, clearLabel = "Clear filter" }) {
|
|
52
|
+
const chosen = options.filter((option) => value.includes(option.value));
|
|
53
|
+
const summary = chosen.length === 1 ? chosen[0]?.label : formatSelected(chosen.length);
|
|
54
|
+
return /* @__PURE__ */ jsxs(Menu, { children: [/* @__PURE__ */ jsxs(MenuTrigger, {
|
|
55
|
+
"data-active": chosen.length > 0 ? "" : void 0,
|
|
56
|
+
className: FACET_TRIGGER_CLASSES,
|
|
57
|
+
children: [
|
|
58
|
+
/* @__PURE__ */ jsx(PlusCircleIcon, { className: "text-ink-secondary" }),
|
|
59
|
+
label,
|
|
60
|
+
chosen.length > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", {
|
|
61
|
+
"aria-hidden": true,
|
|
62
|
+
className: "h-4 w-px bg-edge"
|
|
63
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
64
|
+
className: "inline-flex h-5 items-center rounded-sm bg-fill px-1.5 text-xs",
|
|
65
|
+
children: summary
|
|
66
|
+
})] })
|
|
67
|
+
]
|
|
68
|
+
}), /* @__PURE__ */ jsxs(MenuContent, {
|
|
69
|
+
label,
|
|
70
|
+
align: "start",
|
|
71
|
+
children: [options.map((option) => /* @__PURE__ */ jsx(MenuCheckboxItem, {
|
|
72
|
+
checked: value.includes(option.value),
|
|
73
|
+
onCheckedChange: (checked) => onValueChange(checked ? [...value, option.value] : value.filter((chosenValue) => chosenValue !== option.value)),
|
|
74
|
+
children: option.label
|
|
75
|
+
}, option.value)), chosen.length > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(MenuSeparator, {}), /* @__PURE__ */ jsx(MenuItem, {
|
|
76
|
+
onClick: () => onValueChange([]),
|
|
77
|
+
children: clearLabel
|
|
78
|
+
})] })]
|
|
79
|
+
})] });
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* One filter added from the Filter menu: the field, the relation and the value, each opening its
|
|
83
|
+
* own menu, then a cross that removes it. Chips follow the filter buttons and wrap.
|
|
84
|
+
*/
|
|
85
|
+
function TableFilterChip({ field, operator, value, fieldMenu, operatorMenu, valueMenu, onRemove, removeLabel = "Remove filter", className }) {
|
|
86
|
+
return /* @__PURE__ */ jsxs("span", {
|
|
87
|
+
className: cn("inline-flex h-control items-stretch divide-x divide-edge-subtle overflow-clip rounded-md border bg-surface text-control shadow-control", className),
|
|
88
|
+
children: [
|
|
89
|
+
/* @__PURE__ */ jsx(ChipPart, {
|
|
90
|
+
menu: fieldMenu,
|
|
91
|
+
label: "Field",
|
|
92
|
+
className: "pl-2.5 text-ink-secondary",
|
|
93
|
+
children: field
|
|
94
|
+
}),
|
|
95
|
+
/* @__PURE__ */ jsx(ChipPart, {
|
|
96
|
+
menu: operatorMenu,
|
|
97
|
+
label: "Relation",
|
|
98
|
+
className: "text-ink-muted",
|
|
99
|
+
children: operator
|
|
100
|
+
}),
|
|
101
|
+
/* @__PURE__ */ jsx(ChipPart, {
|
|
102
|
+
menu: valueMenu,
|
|
103
|
+
label: "Value",
|
|
104
|
+
className: "font-medium text-ink",
|
|
105
|
+
children: value
|
|
106
|
+
}),
|
|
107
|
+
/* @__PURE__ */ jsx("button", {
|
|
108
|
+
type: "button",
|
|
109
|
+
"aria-label": removeLabel,
|
|
110
|
+
className: cn(CHIP_PART_CLASSES, "w-7 justify-center px-0 text-ink-muted hover:text-ink"),
|
|
111
|
+
onClick: onRemove,
|
|
112
|
+
children: /* @__PURE__ */ jsx(CancelIcon, { className: "size-3" })
|
|
113
|
+
})
|
|
114
|
+
]
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
export { TableFacetFilter, TableFilterChip, TableToolbar };
|
|
118
|
+
|
|
119
|
+
//# sourceMappingURL=table-toolbar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table-toolbar.js","names":[],"sources":["../../src/components/table-toolbar.tsx"],"sourcesContent":["\"use client\"\n\nimport type { ComponentProps, ReactNode } from \"react\"\nimport { CancelIcon, PlusCircleIcon } from \"../lib/icons\"\nimport { interactiveVariants } from \"../lib/interactive\"\nimport { cn } from \"../lib/variants\"\nimport { Menu, MenuCheckboxItem, MenuContent, MenuItem, MenuSeparator, MenuTrigger } from \"./menu\"\n\nexport interface TableFacetOption {\n value: string\n label: ReactNode\n}\n\nconst FACET_TRIGGER_CLASSES = cn(\n interactiveVariants(),\n \"inline-flex h-control items-center gap-1.5 rounded-md border pr-3 pl-2.5 font-medium text-control text-ink\",\n \"hover:bg-fill-subtle data-popup-open:bg-fill-subtle [&_svg]:size-3.5\",\n // Empty, it is a dashed outline with no lift; with a value it is a raised surface.\n \"border-dashed border-edge\",\n \"data-active:border-solid data-active:bg-surface data-active:pr-1.5 data-active:shadow-control\",\n)\n\nconst CHIP_PART_CLASSES = cn(\n interactiveVariants(),\n \"inline-flex items-center px-2 outline-offset-[-2px] hover:bg-fill-subtle data-popup-open:bg-fill-subtle\",\n)\n\ninterface ChipPartProps {\n /** The menu that changes this part: `MenuItem`s. Left out, the part is plain text. */\n menu?: ReactNode\n /** Names the part's menu for a screen reader. */\n label: string\n className?: string\n children: ReactNode\n}\n\nfunction ChipPart({ menu, label, className, children }: ChipPartProps) {\n if (!menu) {\n return <span className={cn(\"inline-flex items-center px-2\", className)}>{children}</span>\n }\n\n return (\n <Menu>\n <MenuTrigger className={cn(CHIP_PART_CLASSES, className)}>{children}</MenuTrigger>\n <MenuContent label={label} align=\"start\">\n {menu}\n </MenuContent>\n </Menu>\n )\n}\n\ninterface TableToolbarProps extends Omit<ComponentProps<\"div\">, \"children\"> {\n /** A `SearchInput`, 200px wide; on a phone it fills its own row. */\n search?: ReactNode\n /** The filters: a `TableFacetFilter` per common field, the Filter button, its chips. */\n children?: ReactNode\n /** The sort picker (only for an order no column shows) and the column picker. */\n end?: ReactNode\n}\n\n/**\n * The row above a table: the search, then the filters, which wrap onto a second row, then the\n * pickers at the end. Page actions (\"New site\") belong in the page header, never here.\n */\nexport function TableToolbar({ search, children, end, className, ...props }: TableToolbarProps) {\n return (\n <div className={cn(\"flex flex-wrap items-center gap-2\", className)} {...props}>\n {search && <div className=\"w-50 max-sm:w-full *:w-full\">{search}</div>}\n {children}\n {end && <div className=\"ml-auto flex items-center gap-2\">{end}</div>}\n </div>\n )\n}\n\ninterface TableFacetFilterProps {\n /** The field: \"Category\", \"Status\". */\n label: string\n options: TableFacetOption[]\n /** The chosen values, empty while the filter is off. */\n value: string[]\n onValueChange: (value: string[]) => void\n /** What the trigger shows for several values. */\n formatSelected?: (count: number) => string\n clearLabel?: string\n}\n\n/**\n * A column filter in the toolbar, 32px like a button. Off, it is a dashed button with a plus;\n * on, it shows the chosen value, or how many are chosen, after a divider. Its menu ticks values\n * on and off and clears the filter. A filter with a relation (is not, contains) is a\n * `TableFilterChip`.\n */\nexport function TableFacetFilter({\n label,\n options,\n value,\n onValueChange,\n formatSelected = count => `${count} selected`,\n clearLabel = \"Clear filter\",\n}: TableFacetFilterProps) {\n const chosen = options.filter(option => value.includes(option.value))\n const summary = chosen.length === 1 ? chosen[0]?.label : formatSelected(chosen.length)\n\n return (\n <Menu>\n <MenuTrigger\n data-active={chosen.length > 0 ? \"\" : undefined}\n className={FACET_TRIGGER_CLASSES}\n >\n <PlusCircleIcon className=\"text-ink-secondary\" />\n {label}\n {chosen.length > 0 && (\n <>\n <span aria-hidden className=\"h-4 w-px bg-edge\" />\n <span className=\"inline-flex h-5 items-center rounded-sm bg-fill px-1.5 text-xs\">\n {summary}\n </span>\n </>\n )}\n </MenuTrigger>\n <MenuContent label={label} align=\"start\">\n {options.map(option => (\n <MenuCheckboxItem\n key={option.value}\n checked={value.includes(option.value)}\n onCheckedChange={checked =>\n onValueChange(\n checked\n ? [...value, option.value]\n : value.filter(chosenValue => chosenValue !== option.value),\n )\n }\n >\n {option.label}\n </MenuCheckboxItem>\n ))}\n {chosen.length > 0 && (\n <>\n <MenuSeparator />\n <MenuItem onClick={() => onValueChange([])}>{clearLabel}</MenuItem>\n </>\n )}\n </MenuContent>\n </Menu>\n )\n}\n\ninterface TableFilterChipProps {\n field: ReactNode\n /** The relation: \"is\", \"is not\", \"contains\", \"before\". */\n operator: ReactNode\n value: ReactNode\n /** The items of each part's menu. A part with none is plain text. */\n fieldMenu?: ReactNode\n operatorMenu?: ReactNode\n valueMenu?: ReactNode\n onRemove: () => void\n removeLabel?: string\n className?: string\n}\n\n/**\n * One filter added from the Filter menu: the field, the relation and the value, each opening its\n * own menu, then a cross that removes it. Chips follow the filter buttons and wrap.\n */\nexport function TableFilterChip({\n field,\n operator,\n value,\n fieldMenu,\n operatorMenu,\n valueMenu,\n onRemove,\n removeLabel = \"Remove filter\",\n className,\n}: TableFilterChipProps) {\n return (\n <span\n className={cn(\n \"inline-flex h-control items-stretch divide-x divide-edge-subtle overflow-clip rounded-md border bg-surface text-control shadow-control\",\n className,\n )}\n >\n <ChipPart menu={fieldMenu} label=\"Field\" className=\"pl-2.5 text-ink-secondary\">\n {field}\n </ChipPart>\n <ChipPart menu={operatorMenu} label=\"Relation\" className=\"text-ink-muted\">\n {operator}\n </ChipPart>\n <ChipPart menu={valueMenu} label=\"Value\" className=\"font-medium text-ink\">\n {value}\n </ChipPart>\n <button\n type=\"button\"\n aria-label={removeLabel}\n className={cn(CHIP_PART_CLASSES, \"w-7 justify-center px-0 text-ink-muted hover:text-ink\")}\n onClick={onRemove}\n >\n <CancelIcon className=\"size-3\" />\n </button>\n </span>\n )\n}\n"],"mappings":";;;;;;;AAaA,MAAM,wBAAwB,GAC5B,oBAAoB,GACpB,8GACA,wEAEA,6BACA,+FACF;AAEA,MAAM,oBAAoB,GACxB,oBAAoB,GACpB,yGACF;AAWA,SAAS,SAAS,EAAE,MAAM,OAAO,WAAW,YAA2B;CACrE,IAAI,CAAC,MACH,OAAO,oBAAC,QAAD;EAAM,WAAW,GAAG,iCAAiC,SAAS;EAAI;CAAe,CAAA;CAG1F,OACE,qBAAC,MAAD,EAAA,UAAA,CACE,oBAAC,aAAD;EAAa,WAAW,GAAG,mBAAmB,SAAS;EAAI;CAAsB,CAAA,GACjF,oBAAC,aAAD;EAAoB;EAAO,OAAM;EAC9B,UAAA;CACU,CAAA,CACT,EAAA,CAAA;AAEV;;;;;AAeA,SAAgB,aAAa,EAAE,QAAQ,UAAU,KAAK,WAAW,GAAG,SAA4B;CAC9F,OACE,qBAAC,OAAD;EAAK,WAAW,GAAG,qCAAqC,SAAS;EAAG,GAAI;EAAxE,UAAA;GACG,UAAU,oBAAC,OAAD;IAAK,WAAU;IAA+B,UAAA;GAAY,CAAA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