danielgm-ui 0.4.0 → 0.4.1
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/dist/data-table.d.ts +8 -2
- package/dist/data-table.js +21 -4
- package/dist/styles.css +57 -2
- package/package.json +1 -1
package/dist/data-table.d.ts
CHANGED
|
@@ -10,7 +10,8 @@ export interface DataColumn<T extends object> {
|
|
|
10
10
|
sortable?: boolean;
|
|
11
11
|
/** Participa en el buscador global. @defaultValue true */
|
|
12
12
|
searchable?: boolean;
|
|
13
|
-
|
|
13
|
+
/** Alineación compartida por cabecera y celdas. @defaultValue 'start' */
|
|
14
|
+
align?: 'start' | 'center' | 'end';
|
|
14
15
|
/** Ancho estable CSS (px si es número); las columnas sin ancho reparten el espacio restante. */
|
|
15
16
|
width?: CSSProperties['width'];
|
|
16
17
|
}
|
|
@@ -27,7 +28,12 @@ export interface DataTableProps<T extends object> {
|
|
|
27
28
|
caption: string;
|
|
28
29
|
/** Orden controlado. Usa [] para quitarlo. */
|
|
29
30
|
sorting?: DataTableSort[];
|
|
31
|
+
/** Orden base: conserva aria-sort pero no muestra flecha. */
|
|
30
32
|
defaultSorting?: DataTableSort[];
|
|
33
|
+
/** Habilita las cabeceras ordenables; cada columna puede desactivarlas. @defaultValue true */
|
|
34
|
+
sortable?: boolean;
|
|
35
|
+
/** Delega la ordenación al consumidor sin reordenar data. @defaultValue false */
|
|
36
|
+
manualSorting?: boolean;
|
|
31
37
|
onSortingChange?: (sorting: DataTableSort[]) => void;
|
|
32
38
|
/** Buscador de todas las columnas habilitadas. @defaultValue true */
|
|
33
39
|
searchable?: boolean;
|
|
@@ -50,4 +56,4 @@ export interface DataTableProps<T extends object> {
|
|
|
50
56
|
className?: string;
|
|
51
57
|
}
|
|
52
58
|
/** Paginación y selección conservan IDs reales. El filtrado devuelve a la primera página. */
|
|
53
|
-
export declare function DataTable<T extends object>({ data, columns, getRowId, caption, sorting, defaultSorting, onSortingChange, searchable, searchPlaceholder, pageSize, page, onPageChange, selectable, selection, defaultSelection, onSelectionChange, loading, emptyMessage, locale, className, }: DataTableProps<T>): ReactElement;
|
|
59
|
+
export declare function DataTable<T extends object>({ data, columns, getRowId, caption, sorting, sortable, manualSorting, defaultSorting, onSortingChange, searchable, searchPlaceholder, pageSize, page, onPageChange, selectable, selection, defaultSelection, onSelectionChange, loading, emptyMessage, locale, className, }: DataTableProps<T>): ReactElement;
|
package/dist/data-table.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
/** Tabla HTML con operaciones locales. TanStack calcula filas filtradas y ordenadas sin mutar data. */
|
|
4
|
-
import { ArrowUpIcon, ArrowDownIcon
|
|
4
|
+
import { ArrowUpIcon, ArrowDownIcon } from './internal/icons.js';
|
|
5
5
|
import { useEffect, useMemo, useRef, useState, } from 'react';
|
|
6
6
|
import { useTable, tableFeatures, rowSortingFeature, columnFilteringFeature, globalFilteringFeature, createSortedRowModel, createFilteredRowModel, filterFn_includesString, functionalUpdate, } from '@tanstack/react-table';
|
|
7
7
|
import { Button } from './button.js';
|
|
@@ -20,7 +20,7 @@ const features = tableFeatures({
|
|
|
20
20
|
filterFns: { includesString: filterFn_includesString },
|
|
21
21
|
});
|
|
22
22
|
/** Paginación y selección conservan IDs reales. El filtrado devuelve a la primera página. */
|
|
23
|
-
export function DataTable({ data, columns, getRowId, caption, sorting, defaultSorting = [], onSortingChange, searchable = true, searchPlaceholder, pageSize = 10, page, onPageChange, selectable = false, selection, defaultSelection = [], onSelectionChange, loading = false, emptyMessage, locale = 'en', className, }) {
|
|
23
|
+
export function DataTable({ data, columns, getRowId, caption, sorting, sortable = true, manualSorting = false, defaultSorting = [], onSortingChange, searchable = true, searchPlaceholder, pageSize = 10, page, onPageChange, selectable = false, selection, defaultSelection = [], onSelectionChange, loading = false, emptyMessage, locale = 'en', className, }) {
|
|
24
24
|
const [sort, changeSort] = useControllable(sorting, defaultSorting, onSortingChange);
|
|
25
25
|
const [currentPage, changePage] = useControllable(page, 1, onPageChange);
|
|
26
26
|
const [selected, changeSelection] = useControllable(selection, defaultSelection, onSelectionChange ? (next) => onSelectionChange([...next]) : undefined);
|
|
@@ -55,6 +55,7 @@ export function DataTable({ data, columns, getRowId, caption, sorting, defaultSo
|
|
|
55
55
|
changeSort(functionalUpdate(updater, sort));
|
|
56
56
|
changePage(1);
|
|
57
57
|
},
|
|
58
|
+
manualSorting,
|
|
58
59
|
globalFilterFn: 'includesString',
|
|
59
60
|
enableMultiSort: false,
|
|
60
61
|
});
|
|
@@ -89,11 +90,27 @@ export function DataTable({ data, columns, getRowId, caption, sorting, defaultSo
|
|
|
89
90
|
} }) })), columns.map((column) => {
|
|
90
91
|
const instance = table.getColumn(column.id);
|
|
91
92
|
const direction = instance.getIsSorted();
|
|
92
|
-
|
|
93
|
+
const baseline = defaultSorting.find((item) => item.id === column.id);
|
|
94
|
+
const showArrow = Boolean(direction && !(baseline && baseline.desc === (direction === 'desc')));
|
|
95
|
+
return (_jsx("th", { scope: "col", "data-align": column.align ?? 'start', style: { textAlign: column.align ?? 'start' }, "aria-sort": direction === 'asc'
|
|
93
96
|
? 'ascending'
|
|
94
97
|
: direction === 'desc'
|
|
95
98
|
? 'descending'
|
|
96
|
-
: undefined, children:
|
|
99
|
+
: undefined, children: sortable && instance.getCanSort() ? (_jsxs(Button, { variant: "ghost", size: "sm", className: "dgm-table-sort", "data-sorted": showArrow || undefined, disabled: loading, onClick: () => {
|
|
100
|
+
// El orden base alterna siempre con su inverso, también en números.
|
|
101
|
+
if (baseline) {
|
|
102
|
+
changeSort([
|
|
103
|
+
{
|
|
104
|
+
id: column.id,
|
|
105
|
+
desc: direction ? direction !== 'desc' : !baseline.desc,
|
|
106
|
+
},
|
|
107
|
+
]);
|
|
108
|
+
changePage(1);
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
instance.toggleSorting();
|
|
112
|
+
}
|
|
113
|
+
}, children: [_jsx("span", { className: "dgm-table-sort-label", children: column.header }), _jsx("span", { className: "dgm-table-sort-icon", "aria-hidden": "true", children: direction === 'desc' ? _jsx(ArrowDownIcon, {}) : _jsx(ArrowUpIcon, {}) })] })) : (column.header) }, column.id));
|
|
97
114
|
})] }) }), _jsx("tbody", { children: loading ? (Array.from({ length: Math.min(size, 5) }, (_, index) => (_jsx("tr", { children: _jsx("td", { colSpan: columns.length + (selectable ? 1 : 0), children: _jsx(Skeleton, { height: "1.5rem" }) }) }, index)))) : visible.length ? (visible.map((row) => (_jsxs("tr", { "data-selected": selectedIds.has(row.id) || undefined, children: [selectable && (_jsx("td", { children: _jsx(Checkbox, { checked: selectedIds.has(row.id), label: _jsxs("span", { className: "dgm-visually-hidden", children: [es ? 'Seleccionar fila' : 'Select row', " ", row.id] }), onChange: (event) => changeSelection(event.target.checked
|
|
98
115
|
? [...new Set([...selected, row.id])]
|
|
99
116
|
: selected.filter((id) => id !== row.id)) }) })), columns.map((column) => (_jsx("td", { style: { textAlign: column.align ?? 'start' }, children: column.cell ? column.cell(row.original) : column.accessor(row.original) }, column.id)))] }, row.id)))) : (_jsx("tr", { children: _jsx("td", { colSpan: columns.length + (selectable ? 1 : 0), className: "dgm-table-empty", children: emptyMessage ?? (es ? 'No hay resultados.' : 'No results.') }) })) })] }) }), _jsxs("div", { className: "dgm-table-footer", children: [_jsx("p", { role: "status", children: loading
|
package/dist/styles.css
CHANGED
|
@@ -2759,8 +2759,63 @@ button.dgm-step:hover:not(:disabled),
|
|
|
2759
2759
|
font-weight: var(--dgm-font-weight-semibold);
|
|
2760
2760
|
background: var(--dgm-subtle);
|
|
2761
2761
|
}
|
|
2762
|
-
.dgm-data-table th .dgm-
|
|
2763
|
-
|
|
2762
|
+
.dgm-data-table th .dgm-table-sort {
|
|
2763
|
+
--dgm-table-sort-space: 1.125rem;
|
|
2764
|
+
display: inline-block;
|
|
2765
|
+
position: relative;
|
|
2766
|
+
max-width: 100%;
|
|
2767
|
+
padding-inline: var(--dgm-table-sort-space);
|
|
2768
|
+
text-align: inherit;
|
|
2769
|
+
white-space: normal;
|
|
2770
|
+
}
|
|
2771
|
+
.dgm-table-sort-label {
|
|
2772
|
+
position: relative;
|
|
2773
|
+
display: inline-block;
|
|
2774
|
+
transition: transform 240ms ease;
|
|
2775
|
+
}
|
|
2776
|
+
.dgm-table-sort-icon {
|
|
2777
|
+
position: absolute;
|
|
2778
|
+
inset-inline-end: 0;
|
|
2779
|
+
top: 50%;
|
|
2780
|
+
width: 0.875rem;
|
|
2781
|
+
height: 0.875rem;
|
|
2782
|
+
opacity: 0;
|
|
2783
|
+
transform: translateY(-50%) scale(0.5);
|
|
2784
|
+
transition:
|
|
2785
|
+
opacity 240ms ease,
|
|
2786
|
+
transform 240ms ease;
|
|
2787
|
+
}
|
|
2788
|
+
.dgm-table-sort-icon svg {
|
|
2789
|
+
width: 100%;
|
|
2790
|
+
height: 100%;
|
|
2791
|
+
}
|
|
2792
|
+
.dgm-table-sort[data-sorted] .dgm-table-sort-icon {
|
|
2793
|
+
opacity: 1;
|
|
2794
|
+
transform: translateY(-50%) scale(1);
|
|
2795
|
+
}
|
|
2796
|
+
.dgm-data-table th[data-align='center'] .dgm-table-sort[data-sorted] .dgm-table-sort-label,
|
|
2797
|
+
.dgm-data-table th[data-align='end'] .dgm-table-sort[data-sorted] .dgm-table-sort-label {
|
|
2798
|
+
transform: translateX(-0.5625rem);
|
|
2799
|
+
}
|
|
2800
|
+
.dgm-data-table th[data-align='center'] .dgm-table-sort-icon,
|
|
2801
|
+
.dgm-data-table th[data-align='end'] .dgm-table-sort-icon {
|
|
2802
|
+
inset-inline-end: 0.5625rem;
|
|
2803
|
+
}
|
|
2804
|
+
.dgm-data-table th[data-align='start'] .dgm-table-sort {
|
|
2805
|
+
margin-inline-start: calc(-1 * var(--dgm-table-sort-space));
|
|
2806
|
+
}
|
|
2807
|
+
[dir='rtl']
|
|
2808
|
+
.dgm-data-table
|
|
2809
|
+
th:not([data-align='start'])
|
|
2810
|
+
.dgm-table-sort[data-sorted]
|
|
2811
|
+
.dgm-table-sort-label {
|
|
2812
|
+
transform: translateX(0.5625rem);
|
|
2813
|
+
}
|
|
2814
|
+
@media (prefers-reduced-motion: reduce) {
|
|
2815
|
+
.dgm-table-sort-label,
|
|
2816
|
+
.dgm-table-sort-icon {
|
|
2817
|
+
transition: none;
|
|
2818
|
+
}
|
|
2764
2819
|
}
|
|
2765
2820
|
.dgm-data-table tr[data-selected] {
|
|
2766
2821
|
background: var(--dgm-subtle);
|