@ciridae/ui 0.5.0 → 0.6.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.
|
@@ -4,6 +4,8 @@ import { flexRender, } from "@tanstack/react-table";
|
|
|
4
4
|
import { cn } from "../../lib/utils";
|
|
5
5
|
import { Button } from "./button";
|
|
6
6
|
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "./table";
|
|
7
|
+
/** Font taken from the enclosing `TableHead`; see `DataTableHeaderCell`. */
|
|
8
|
+
const inheritType = { fontSize: "inherit", fontWeight: "inherit", lineHeight: "inherit" };
|
|
7
9
|
function DataTableGrid({ empty, getRowClassName, onRowClick, rows, table, }) {
|
|
8
10
|
// One scroller, owned by `data-table-content` outside this: nesting an
|
|
9
11
|
// `overflow-x-auto` inside it would give the sticky header a scrollport that
|
|
@@ -20,10 +22,13 @@ function DataTableHeaderCell({ header }) {
|
|
|
20
22
|
const Icon = sorted === "asc" ? ArrowUpIcon : sorted === "desc" ? ArrowDownIcon : ChevronsUpDownIcon;
|
|
21
23
|
if (!header.column.getCanSort())
|
|
22
24
|
return flexRender(header.column.columnDef.header, header.getContext());
|
|
23
|
-
return (_jsxs(Button, { "aria-pressed": Boolean(sorted),
|
|
24
|
-
//
|
|
25
|
-
//
|
|
26
|
-
//
|
|
27
|
-
|
|
25
|
+
return (_jsxs(Button, { "aria-pressed": Boolean(sorted), className: "-ml-2 h-auto px-2 py-0 text-muted-foreground hover:bg-transparent hover:text-foreground",
|
|
26
|
+
// Type taken from the `<th>` this sits in, whatever that turns out to be,
|
|
27
|
+
// so a caller restyling its headers moves the sortable ones with them.
|
|
28
|
+
// Inline because Tailwind has no font-size or font-weight `inherit`
|
|
29
|
+
// utility, and an arbitrary-value one would be a second utility in the
|
|
30
|
+
// same group as the Button recipe's own -- decided by stylesheet order
|
|
31
|
+
// rather than by this file.
|
|
32
|
+
style: inheritType, onClick: header.column.getToggleSortingHandler(), size: "sm", type: "button", variant: "ghost", children: [_jsx("span", { children: flexRender(header.column.columnDef.header, header.getContext()) }), _jsx(Icon, {})] }));
|
|
28
33
|
}
|
|
29
34
|
export { DataTableGrid };
|
|
@@ -20,12 +20,16 @@ function DataTableEmpty({ className, ...props }) {
|
|
|
20
20
|
function DataTableSkeleton({ className, ...props }) {
|
|
21
21
|
return (_jsx(DataTableContent, { className: "border-t-0", children: _jsx(TableSkeleton, { className: cn("rounded-none border-x-0 border-b-0", className), ...props }) }));
|
|
22
22
|
}
|
|
23
|
+
/** Font taken from the enclosing `TableHead`; see `SortableTableHead`. */
|
|
24
|
+
const inheritType = { fontSize: "inherit", fontWeight: "inherit", lineHeight: "inherit" };
|
|
23
25
|
function SortableTableHead({ active = false, children, className, direction = "asc", onSort, align = "left", ...props }) {
|
|
24
26
|
const Icon = active ? (direction === "asc" ? ArrowUpIcon : ArrowDownIcon) : ArrowUpDownIcon;
|
|
25
|
-
return (_jsx(TableHead, { "aria-sort": active ? (direction === "asc" ? "ascending" : "descending") : "none", className: cn(align === "right" && "text-right", className), ...props, children: _jsxs(Button, { "aria-pressed": active, className: cn(
|
|
26
|
-
//
|
|
27
|
-
//
|
|
28
|
-
//
|
|
29
|
-
|
|
27
|
+
return (_jsx(TableHead, { "aria-sort": active ? (direction === "asc" ? "ascending" : "descending") : "none", className: cn(align === "right" && "text-right", className), ...props, children: _jsxs(Button, { "aria-pressed": active, className: cn("h-auto px-0 py-0 text-muted-foreground hover:bg-transparent hover:text-foreground", align === "right" ? "ml-auto justify-end" : "justify-start"), onClick: onSort, size: "sm",
|
|
28
|
+
// Type taken from the `<th>`, including a `className` the caller put
|
|
29
|
+
// there, so a restyled header row stays one typeface. Inline rather
|
|
30
|
+
// than a utility: Tailwind has no font-size or font-weight `inherit`,
|
|
31
|
+
// and an arbitrary-value one would compete with the Button recipe's
|
|
32
|
+
// own on stylesheet order.
|
|
33
|
+
style: inheritType, type: "button", variant: "ghost", children: [_jsx("span", { children: children }), _jsx(Icon, {})] }) }));
|
|
30
34
|
}
|
|
31
35
|
export { DataTable, DataTableToolbar, DataTableContent, DataTableEmpty, DataTableSkeleton, TanStackDataTable, SortableTableHead, };
|
|
@@ -18,11 +18,12 @@ function TableRow({ className, ...props }) {
|
|
|
18
18
|
}
|
|
19
19
|
function TableHead({ className, ...props }) {
|
|
20
20
|
return (_jsx("th", { "data-slot": "table-head", className: cn(
|
|
21
|
-
// A
|
|
22
|
-
//
|
|
23
|
-
//
|
|
24
|
-
// not two typefaces
|
|
25
|
-
|
|
21
|
+
// A step down from the rows and a step up in weight, so the header
|
|
22
|
+
// reads as the label of the column rather than as its first entry.
|
|
23
|
+
// It lives here rather than on the sort button so that a table mixing
|
|
24
|
+
// sortable and plain columns draws one header row, not two typefaces
|
|
25
|
+
// side by side -- the sort buttons restate this pair to match.
|
|
26
|
+
"h-(--table-row-height) px-(--table-cell-padding-x) py-(--table-cell-padding-y) text-left align-middle text-xs font-medium tracking-normal whitespace-nowrap text-table-header-foreground normal-case [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]", className), ...props }));
|
|
26
27
|
}
|
|
27
28
|
function TableCell({ className, ...props }) {
|
|
28
29
|
return (_jsx("td", { "data-slot": "table-cell", className: cn("px-(--table-cell-padding-x) py-(--table-cell-padding-y) align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]", className), ...props }));
|