@lucasbernardosn/react-table 0.0.0-stage → 0.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/LICENSE +21 -0
- package/dist/_virtual/_rolldown/runtime.js +13 -0
- package/dist/components/column-menu/column-menu-check.d.ts +8 -0
- package/dist/components/column-menu/column-menu-check.d.ts.map +1 -0
- package/dist/components/column-menu/column-menu-check.js +17 -0
- package/dist/components/column-menu/column-menu-check.js.map +1 -0
- package/dist/components/column-menu/column-menu-hide-item.d.ts +23 -0
- package/dist/components/column-menu/column-menu-hide-item.d.ts.map +1 -0
- package/dist/components/column-menu/column-menu-hide-item.js +28 -0
- package/dist/components/column-menu/column-menu-hide-item.js.map +1 -0
- package/dist/components/column-menu/column-menu-labels.d.ts +21 -0
- package/dist/components/column-menu/column-menu-labels.d.ts.map +1 -0
- package/dist/components/column-menu/column-menu-labels.js +14 -0
- package/dist/components/column-menu/column-menu-labels.js.map +1 -0
- package/dist/components/column-menu/column-menu-pin-items.d.ts +25 -0
- package/dist/components/column-menu/column-menu-pin-items.d.ts.map +1 -0
- package/dist/components/column-menu/column-menu-pin-items.js +65 -0
- package/dist/components/column-menu/column-menu-pin-items.js.map +1 -0
- package/dist/components/column-menu/column-menu-popup.d.ts +39 -0
- package/dist/components/column-menu/column-menu-popup.d.ts.map +1 -0
- package/dist/components/column-menu/column-menu-popup.js +66 -0
- package/dist/components/column-menu/column-menu-popup.js.map +1 -0
- package/dist/components/column-menu/column-menu-root.d.ts +34 -0
- package/dist/components/column-menu/column-menu-root.d.ts.map +1 -0
- package/dist/components/column-menu/column-menu-root.js +36 -0
- package/dist/components/column-menu/column-menu-root.js.map +1 -0
- package/dist/components/column-menu/column-menu-sort-items.d.ts +29 -0
- package/dist/components/column-menu/column-menu-sort-items.d.ts.map +1 -0
- package/dist/components/column-menu/column-menu-sort-items.js +61 -0
- package/dist/components/column-menu/column-menu-sort-items.js.map +1 -0
- package/dist/components/column-menu/column-menu-trigger.d.ts +23 -0
- package/dist/components/column-menu/column-menu-trigger.d.ts.map +1 -0
- package/dist/components/column-menu/column-menu-trigger.js +38 -0
- package/dist/components/column-menu/column-menu-trigger.js.map +1 -0
- package/dist/components/column-menu/index.d.ts +2 -0
- package/dist/components/column-menu/index.js +2 -0
- package/dist/components/column-menu/index.parts.d.ts +13 -0
- package/dist/components/column-menu/index.parts.d.ts.map +1 -0
- package/dist/components/column-menu/index.parts.js +20 -0
- package/dist/components/column-menu/index.parts.js.map +1 -0
- package/dist/components/columns-panel/columns-panel-item.d.ts +31 -0
- package/dist/components/columns-panel/columns-panel-item.d.ts.map +1 -0
- package/dist/components/columns-panel/columns-panel-item.js +92 -0
- package/dist/components/columns-panel/columns-panel-item.js.map +1 -0
- package/dist/components/columns-panel/columns-panel-root.d.ts +51 -0
- package/dist/components/columns-panel/columns-panel-root.d.ts.map +1 -0
- package/dist/components/columns-panel/columns-panel-root.js +134 -0
- package/dist/components/columns-panel/columns-panel-root.js.map +1 -0
- package/dist/components/columns-panel/get-columns-panel-column-order.d.ts +16 -0
- package/dist/components/columns-panel/get-columns-panel-column-order.d.ts.map +1 -0
- package/dist/components/columns-panel/get-columns-panel-column-order.js +24 -0
- package/dist/components/columns-panel/get-columns-panel-column-order.js.map +1 -0
- package/dist/components/columns-panel/index.d.ts +2 -0
- package/dist/components/columns-panel/index.js +2 -0
- package/dist/components/columns-panel/index.parts.d.ts +8 -0
- package/dist/components/columns-panel/index.parts.d.ts.map +1 -0
- package/dist/components/columns-panel/index.parts.js +12 -0
- package/dist/components/columns-panel/index.parts.js.map +1 -0
- package/dist/components/data-table/body/data-table-body.d.ts +58 -0
- package/dist/components/data-table/body/data-table-body.d.ts.map +1 -0
- package/dist/components/data-table/body/data-table-body.js +99 -0
- package/dist/components/data-table/body/data-table-body.js.map +1 -0
- package/dist/components/data-table/body/data-table-cell.d.ts +26 -0
- package/dist/components/data-table/body/data-table-cell.d.ts.map +1 -0
- package/dist/components/data-table/body/data-table-cell.js +80 -0
- package/dist/components/data-table/body/data-table-cell.js.map +1 -0
- package/dist/components/data-table/body/data-table-empty.d.ts +38 -0
- package/dist/components/data-table/body/data-table-empty.d.ts.map +1 -0
- package/dist/components/data-table/body/data-table-empty.js +71 -0
- package/dist/components/data-table/body/data-table-empty.js.map +1 -0
- package/dist/components/data-table/body/data-table-row-focus.d.ts +32 -0
- package/dist/components/data-table/body/data-table-row-focus.d.ts.map +1 -0
- package/dist/components/data-table/body/data-table-row-focus.js +58 -0
- package/dist/components/data-table/body/data-table-row-focus.js.map +1 -0
- package/dist/components/data-table/body/data-table-row.d.ts +67 -0
- package/dist/components/data-table/body/data-table-row.d.ts.map +1 -0
- package/dist/components/data-table/body/data-table-row.js +150 -0
- package/dist/components/data-table/body/data-table-row.js.map +1 -0
- package/dist/components/data-table/body/use-data-table-row-focus-recovery.d.ts +19 -0
- package/dist/components/data-table/body/use-data-table-row-focus-recovery.d.ts.map +1 -0
- package/dist/components/data-table/body/use-data-table-row-focus-recovery.js +64 -0
- package/dist/components/data-table/body/use-data-table-row-focus-recovery.js.map +1 -0
- package/dist/components/data-table/header/data-table-header-button.d.ts +25 -0
- package/dist/components/data-table/header/data-table-header-button.d.ts.map +1 -0
- package/dist/components/data-table/header/data-table-header-button.js +57 -0
- package/dist/components/data-table/header/data-table-header-button.js.map +1 -0
- package/dist/components/data-table/header/data-table-header-cell.d.ts +34 -0
- package/dist/components/data-table/header/data-table-header-cell.d.ts.map +1 -0
- package/dist/components/data-table/header/data-table-header-cell.js +97 -0
- package/dist/components/data-table/header/data-table-header-cell.js.map +1 -0
- package/dist/components/data-table/header/data-table-header-content.d.ts +21 -0
- package/dist/components/data-table/header/data-table-header-content.d.ts.map +1 -0
- package/dist/components/data-table/header/data-table-header-content.js +37 -0
- package/dist/components/data-table/header/data-table-header-content.js.map +1 -0
- package/dist/components/data-table/header/data-table-header-row.d.ts +15 -0
- package/dist/components/data-table/header/data-table-header-row.d.ts.map +1 -0
- package/dist/components/data-table/header/data-table-header-row.js +28 -0
- package/dist/components/data-table/header/data-table-header-row.js.map +1 -0
- package/dist/components/data-table/header/data-table-header.d.ts +46 -0
- package/dist/components/data-table/header/data-table-header.d.ts.map +1 -0
- package/dist/components/data-table/header/data-table-header.js +80 -0
- package/dist/components/data-table/header/data-table-header.js.map +1 -0
- package/dist/components/data-table/index.d.ts +2 -0
- package/dist/components/data-table/index.js +2 -0
- package/dist/components/data-table/index.parts.d.ts +32 -0
- package/dist/components/data-table/index.parts.d.ts.map +1 -0
- package/dist/components/data-table/index.parts.js +60 -0
- package/dist/components/data-table/index.parts.js.map +1 -0
- package/dist/components/data-table/loading/get-data-table-loading-without-rows.d.ts +16 -0
- package/dist/components/data-table/loading/get-data-table-loading-without-rows.d.ts.map +1 -0
- package/dist/components/data-table/loading/get-data-table-loading-without-rows.js +18 -0
- package/dist/components/data-table/loading/get-data-table-loading-without-rows.js.map +1 -0
- package/dist/components/data-table/loading/use-data-table-loading-inert.d.ts +16 -0
- package/dist/components/data-table/loading/use-data-table-loading-inert.d.ts.map +1 -0
- package/dist/components/data-table/loading/use-data-table-loading-inert.js +54 -0
- package/dist/components/data-table/loading/use-data-table-loading-inert.js.map +1 -0
- package/dist/components/data-table/loading/use-data-table-loading.d.ts +13 -0
- package/dist/components/data-table/loading/use-data-table-loading.d.ts.map +1 -0
- package/dist/components/data-table/loading/use-data-table-loading.js +40 -0
- package/dist/components/data-table/loading/use-data-table-loading.js.map +1 -0
- package/dist/components/data-table/pagination/data-table-page-button.d.ts +45 -0
- package/dist/components/data-table/pagination/data-table-page-button.d.ts.map +1 -0
- package/dist/components/data-table/pagination/data-table-page-button.js +67 -0
- package/dist/components/data-table/pagination/data-table-page-button.js.map +1 -0
- package/dist/components/data-table/pagination/data-table-page-size-select.d.ts +47 -0
- package/dist/components/data-table/pagination/data-table-page-size-select.d.ts.map +1 -0
- package/dist/components/data-table/pagination/data-table-page-size-select.js +68 -0
- package/dist/components/data-table/pagination/data-table-page-size-select.js.map +1 -0
- package/dist/components/data-table/pagination/data-table-page-status.d.ts +43 -0
- package/dist/components/data-table/pagination/data-table-page-status.d.ts.map +1 -0
- package/dist/components/data-table/pagination/data-table-page-status.js +48 -0
- package/dist/components/data-table/pagination/data-table-page-status.js.map +1 -0
- package/dist/components/data-table/pagination/data-table-pagination.d.ts +38 -0
- package/dist/components/data-table/pagination/data-table-pagination.d.ts.map +1 -0
- package/dist/components/data-table/pagination/data-table-pagination.js +87 -0
- package/dist/components/data-table/pagination/data-table-pagination.js.map +1 -0
- package/dist/components/data-table/pagination/data-table-row-range.d.ts +49 -0
- package/dist/components/data-table/pagination/data-table-row-range.d.ts.map +1 -0
- package/dist/components/data-table/pagination/data-table-row-range.js +63 -0
- package/dist/components/data-table/pagination/data-table-row-range.js.map +1 -0
- package/dist/components/data-table/pagination/data-table-selected-count.d.ts +37 -0
- package/dist/components/data-table/pagination/data-table-selected-count.d.ts.map +1 -0
- package/dist/components/data-table/pagination/data-table-selected-count.js +44 -0
- package/dist/components/data-table/pagination/data-table-selected-count.js.map +1 -0
- package/dist/components/data-table/pagination/use-data-table-page-scroll-reset.d.ts +15 -0
- package/dist/components/data-table/pagination/use-data-table-page-scroll-reset.d.ts.map +1 -0
- package/dist/components/data-table/pagination/use-data-table-page-scroll-reset.js +38 -0
- package/dist/components/data-table/pagination/use-data-table-page-scroll-reset.js.map +1 -0
- package/dist/components/data-table/resize/data-table-resize-handle.d.ts +48 -0
- package/dist/components/data-table/resize/data-table-resize-handle.d.ts.map +1 -0
- package/dist/components/data-table/resize/data-table-resize-handle.js +115 -0
- package/dist/components/data-table/resize/data-table-resize-handle.js.map +1 -0
- package/dist/components/data-table/resize/use-data-table-resize-scroll.d.ts +18 -0
- package/dist/components/data-table/resize/use-data-table-resize-scroll.d.ts.map +1 -0
- package/dist/components/data-table/resize/use-data-table-resize-scroll.js +55 -0
- package/dist/components/data-table/resize/use-data-table-resize-scroll.js.map +1 -0
- package/dist/components/data-table/root/data-table-grid-classes.d.ts +10 -0
- package/dist/components/data-table/root/data-table-grid-classes.d.ts.map +1 -0
- package/dist/components/data-table/root/data-table-grid-classes.js +22 -0
- package/dist/components/data-table/root/data-table-grid-classes.js.map +1 -0
- package/dist/components/data-table/root/data-table-root.d.ts +41 -0
- package/dist/components/data-table/root/data-table-root.d.ts.map +1 -0
- package/dist/components/data-table/root/data-table-root.js +72 -0
- package/dist/components/data-table/root/data-table-root.js.map +1 -0
- package/dist/components/data-table/root/data-table-scroll-area.d.ts +21 -0
- package/dist/components/data-table/root/data-table-scroll-area.d.ts.map +1 -0
- package/dist/components/data-table/root/data-table-scroll-area.js +127 -0
- package/dist/components/data-table/root/data-table-scroll-area.js.map +1 -0
- package/dist/components/data-table/root/get-data-table-column-layout.d.ts +45 -0
- package/dist/components/data-table/root/get-data-table-column-layout.d.ts.map +1 -0
- package/dist/components/data-table/root/get-data-table-column-layout.js +55 -0
- package/dist/components/data-table/root/get-data-table-column-layout.js.map +1 -0
- package/dist/components/data-table/root/get-data-table-column-pinning.d.ts +46 -0
- package/dist/components/data-table/root/get-data-table-column-pinning.d.ts.map +1 -0
- package/dist/components/data-table/root/get-data-table-column-pinning.js +46 -0
- package/dist/components/data-table/root/get-data-table-column-pinning.js.map +1 -0
- package/dist/components/data-table/root/get-data-table-scroll-parent.d.ts +13 -0
- package/dist/components/data-table/root/get-data-table-scroll-parent.d.ts.map +1 -0
- package/dist/components/data-table/root/get-data-table-scroll-parent.js +20 -0
- package/dist/components/data-table/root/get-data-table-scroll-parent.js.map +1 -0
- package/dist/components/data-table/root/use-data-table-column-layout.d.ts +25 -0
- package/dist/components/data-table/root/use-data-table-column-layout.d.ts.map +1 -0
- package/dist/components/data-table/root/use-data-table-column-layout.js +106 -0
- package/dist/components/data-table/root/use-data-table-column-layout.js.map +1 -0
- package/dist/components/data-table/root/use-data-table-header-offset.d.ts +15 -0
- package/dist/components/data-table/root/use-data-table-header-offset.d.ts.map +1 -0
- package/dist/components/data-table/root/use-data-table-header-offset.js +35 -0
- package/dist/components/data-table/root/use-data-table-header-offset.js.map +1 -0
- package/dist/components/data-table/selection/data-table-row-checkbox.d.ts +33 -0
- package/dist/components/data-table/selection/data-table-row-checkbox.d.ts.map +1 -0
- package/dist/components/data-table/selection/data-table-row-checkbox.js +50 -0
- package/dist/components/data-table/selection/data-table-row-checkbox.js.map +1 -0
- package/dist/components/data-table/selection/data-table-select-all-checkbox.d.ts +31 -0
- package/dist/components/data-table/selection/data-table-select-all-checkbox.d.ts.map +1 -0
- package/dist/components/data-table/selection/data-table-select-all-checkbox.js +44 -0
- package/dist/components/data-table/selection/data-table-select-all-checkbox.js.map +1 -0
- package/dist/components/data-table/selection/selection-column-def.d.ts +54 -0
- package/dist/components/data-table/selection/selection-column-def.d.ts.map +1 -0
- package/dist/components/data-table/selection/selection-column-def.js +55 -0
- package/dist/components/data-table/selection/selection-column-def.js.map +1 -0
- package/dist/components/data-table/sorting/data-table-sort-indicator.d.ts +26 -0
- package/dist/components/data-table/sorting/data-table-sort-indicator.d.ts.map +1 -0
- package/dist/components/data-table/sorting/data-table-sort-indicator.js +64 -0
- package/dist/components/data-table/sorting/data-table-sort-indicator.js.map +1 -0
- package/dist/components/data-table/sorting/data-table-sort-trigger.d.ts +31 -0
- package/dist/components/data-table/sorting/data-table-sort-trigger.d.ts.map +1 -0
- package/dist/components/data-table/sorting/data-table-sort-trigger.js +46 -0
- package/dist/components/data-table/sorting/data-table-sort-trigger.js.map +1 -0
- package/dist/components/data-table/toolbar/data-table-density-select.d.ts +39 -0
- package/dist/components/data-table/toolbar/data-table-density-select.d.ts.map +1 -0
- package/dist/components/data-table/toolbar/data-table-density-select.js +60 -0
- package/dist/components/data-table/toolbar/data-table-density-select.js.map +1 -0
- package/dist/components/data-table/toolbar/data-table-sort-column-select.d.ts +47 -0
- package/dist/components/data-table/toolbar/data-table-sort-column-select.d.ts.map +1 -0
- package/dist/components/data-table/toolbar/data-table-sort-column-select.js +78 -0
- package/dist/components/data-table/toolbar/data-table-sort-column-select.js.map +1 -0
- package/dist/components/data-table/toolbar/data-table-sort-direction-select.d.ts +40 -0
- package/dist/components/data-table/toolbar/data-table-sort-direction-select.d.ts.map +1 -0
- package/dist/components/data-table/toolbar/data-table-sort-direction-select.js +66 -0
- package/dist/components/data-table/toolbar/data-table-sort-direction-select.js.map +1 -0
- package/dist/features/active-row/active-row-feature.d.ts +22 -0
- package/dist/features/active-row/active-row-feature.d.ts.map +1 -0
- package/dist/features/active-row/active-row-feature.js +55 -0
- package/dist/features/active-row/active-row-feature.js.map +1 -0
- package/dist/features/active-row/active-row-feature.types.d.ts +64 -0
- package/dist/features/active-row/active-row-feature.types.d.ts.map +1 -0
- package/dist/features/active-row/active-row-feature.types.js +0 -0
- package/dist/features/column-alignment/column-alignment-feature.d.ts +23 -0
- package/dist/features/column-alignment/column-alignment-feature.d.ts.map +1 -0
- package/dist/features/column-alignment/column-alignment-feature.js +34 -0
- package/dist/features/column-alignment/column-alignment-feature.js.map +1 -0
- package/dist/features/column-alignment/column-alignment-feature.types.d.ts +34 -0
- package/dist/features/column-alignment/column-alignment-feature.types.d.ts.map +1 -0
- package/dist/features/column-alignment/column-alignment-feature.types.js +0 -0
- package/dist/features/index.d.ts +9 -0
- package/dist/features/index.js +5 -0
- package/dist/features/loading/loading-feature.d.ts +30 -0
- package/dist/features/loading/loading-feature.d.ts.map +1 -0
- package/dist/features/loading/loading-feature.js +48 -0
- package/dist/features/loading/loading-feature.js.map +1 -0
- package/dist/features/loading/loading-feature.types.d.ts +50 -0
- package/dist/features/loading/loading-feature.types.d.ts.map +1 -0
- package/dist/features/loading/loading-feature.types.js +0 -0
- package/dist/features/row-density/row-density-feature.d.ts +26 -0
- package/dist/features/row-density/row-density-feature.d.ts.map +1 -0
- package/dist/features/row-density/row-density-feature.js +44 -0
- package/dist/features/row-density/row-density-feature.js.map +1 -0
- package/dist/features/row-density/row-density-feature.types.d.ts +53 -0
- package/dist/features/row-density/row-density-feature.types.d.ts.map +1 -0
- package/dist/features/row-density/row-density-feature.types.js +0 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.js +0 -0
- package/dist/types/table-with.d.ts +96 -0
- package/dist/types/table-with.d.ts.map +1 -0
- package/dist/types/table-with.js +0 -0
- package/dist/utils/get-default-column-label.d.ts +17 -0
- package/dist/utils/get-default-column-label.d.ts.map +1 -0
- package/dist/utils/get-default-column-label.js +18 -0
- package/dist/utils/get-default-column-label.js.map +1 -0
- package/dist/utils/has-feature.d.ts +54 -0
- package/dist/utils/has-feature.d.ts.map +1 -0
- package/dist/utils/has-feature.js +55 -0
- package/dist/utils/has-feature.js.map +1 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.js +3 -0
- package/package.json +80 -3
- package/README.md +0 -3
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useSelector } from "@tanstack/react-store";
|
|
3
|
+
import { Select } from "@lucasbernardosn/react-ui/collections/select";
|
|
4
|
+
//#region src/components/data-table/toolbar/data-table-density-select.tsx
|
|
5
|
+
const DEFAULT_LABELS = {
|
|
6
|
+
compact: "Compacta",
|
|
7
|
+
standard: "Padrão",
|
|
8
|
+
comfortable: "Confortável"
|
|
9
|
+
};
|
|
10
|
+
const DENSITIES = [
|
|
11
|
+
"compact",
|
|
12
|
+
"standard",
|
|
13
|
+
"comfortable"
|
|
14
|
+
];
|
|
15
|
+
/**
|
|
16
|
+
* O select da densidade das linhas, para a barra de ferramentas. Sem rótulo visível: o nome para
|
|
17
|
+
* o leitor de tela é "Densidade", trocável pelo `aria-label`.
|
|
18
|
+
*
|
|
19
|
+
* Renderiza o `Select` do `ui` por dentro; as props passam para o trigger.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```tsx
|
|
23
|
+
* <DataTable.DensitySelect table={table} />
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
const DataTableDensitySelect = (props) => {
|
|
27
|
+
const { table, labels, size = "sm", disabled, ...rest } = props;
|
|
28
|
+
/** Re-renderiza quando a densidade muda. */
|
|
29
|
+
const density = useSelector(table.atoms.rowDensity);
|
|
30
|
+
const items = DENSITIES.map((value) => ({
|
|
31
|
+
label: labels?.[value] ?? DEFAULT_LABELS[value],
|
|
32
|
+
value
|
|
33
|
+
}));
|
|
34
|
+
return /* @__PURE__ */ jsxs(Select.Root, {
|
|
35
|
+
size,
|
|
36
|
+
value: density,
|
|
37
|
+
items,
|
|
38
|
+
disabled,
|
|
39
|
+
onValueChange: (value) => {
|
|
40
|
+
if (value !== null) table.setRowDensity(value);
|
|
41
|
+
},
|
|
42
|
+
children: [/* @__PURE__ */ jsxs(Select.Trigger, {
|
|
43
|
+
"data-component": "DataTable.DensitySelect",
|
|
44
|
+
"aria-label": "Densidade",
|
|
45
|
+
...rest,
|
|
46
|
+
children: [/* @__PURE__ */ jsx(Select.Value, {}), /* @__PURE__ */ jsx(Select.Icon, {})]
|
|
47
|
+
}), /* @__PURE__ */ jsx(Select.Portal, { children: /* @__PURE__ */ jsx(Select.Positioner, {
|
|
48
|
+
alignItemWithTrigger: false,
|
|
49
|
+
children: /* @__PURE__ */ jsx(Select.Popup, { children: /* @__PURE__ */ jsx(Select.List, { children: items.map((item) => /* @__PURE__ */ jsxs(Select.Item, {
|
|
50
|
+
value: item.value,
|
|
51
|
+
children: [/* @__PURE__ */ jsx(Select.ItemIndicator, {}), /* @__PURE__ */ jsx(Select.ItemText, { children: item.label })]
|
|
52
|
+
}, item.value)) }) })
|
|
53
|
+
}) })]
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
DataTableDensitySelect.displayName = "DataTable.DensitySelect";
|
|
57
|
+
//#endregion
|
|
58
|
+
export { DataTableDensitySelect };
|
|
59
|
+
|
|
60
|
+
//# sourceMappingURL=data-table-density-select.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-table-density-select.js","names":[],"sources":["../../../../src/components/data-table/toolbar/data-table-density-select.tsx"],"sourcesContent":["import { Select } from '@lucasbernardosn/react-ui/collections/select';\nimport type { MergeOverride } from '@lucasbernardosn/utils';\nimport { useSelector } from '@tanstack/react-store';\nimport type { RowData, TableFeatures } from '@tanstack/react-table';\nimport type { RowDensity } from '../../../features';\nimport type { TableWith } from '../../../types';\n\nexport type DataTableDensitySelectProps<\n TFeatures extends TableFeatures,\n TData extends RowData,\n> = MergeOverride<\n Select.TriggerProps,\n {\n /** A tabela. Exige `rowDensityFeature`. */\n table: TableWith<TFeatures, TData, 'rowDensityFeature'>;\n /**\n * O nome de cada densidade.\n * @default { compact: 'Compacta', standard: 'Padrão', comfortable: 'Confortável' }\n */\n labels?: Partial<Record<RowDensity, string>>;\n /**\n * O tamanho do select.\n * @default 'sm'\n */\n size?: Select.RootProps<RowDensity>['size'];\n }\n>;\n\nconst DEFAULT_LABELS: Record<RowDensity, string> = {\n compact: 'Compacta',\n standard: 'Padrão',\n comfortable: 'Confortável',\n};\n\nconst DENSITIES: RowDensity[] = ['compact', 'standard', 'comfortable'];\n\n/**\n * O select da densidade das linhas, para a barra de ferramentas. Sem rótulo visível: o nome para\n * o leitor de tela é \"Densidade\", trocável pelo `aria-label`.\n *\n * Renderiza o `Select` do `ui` por dentro; as props passam para o trigger.\n *\n * @example\n * ```tsx\n * <DataTable.DensitySelect table={table} />\n * ```\n */\nexport const DataTableDensitySelect = <\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n props: DataTableDensitySelectProps<TFeatures, TData>,\n) => {\n const { table, labels, size = 'sm', disabled, ...rest } = props;\n\n /** Re-renderiza quando a densidade muda. */\n const density = useSelector(table.atoms.rowDensity);\n\n const items = DENSITIES.map((value) => ({\n label: labels?.[value] ?? DEFAULT_LABELS[value],\n value,\n }));\n\n return (\n <Select.Root<RowDensity>\n size={size}\n value={density}\n items={items}\n disabled={disabled}\n onValueChange={(value) => {\n if (value !== null) {\n table.setRowDensity(value);\n }\n }}\n >\n <Select.Trigger\n data-component=\"DataTable.DensitySelect\"\n aria-label=\"Densidade\"\n {...rest}\n >\n <Select.Value />\n <Select.Icon />\n </Select.Trigger>\n\n <Select.Portal>\n <Select.Positioner alignItemWithTrigger={false}>\n <Select.Popup>\n <Select.List>\n {items.map((item) => (\n <Select.Item\n key={item.value}\n value={item.value}\n >\n <Select.ItemIndicator />\n <Select.ItemText>{item.label}</Select.ItemText>\n </Select.Item>\n ))}\n </Select.List>\n </Select.Popup>\n </Select.Positioner>\n </Select.Portal>\n </Select.Root>\n );\n};\n\nDataTableDensitySelect.displayName = 'DataTable.DensitySelect';\n"],"mappings":";;;;AA4BA,MAAM,iBAA6C;CACjD,SAAS;CACT,UAAU;CACV,aAAa;AACf;AAEA,MAAM,YAA0B;CAAC;CAAW;CAAY;AAAa;;;;;;;;;;;;AAarE,MAAa,0BAIX,UACG;CACH,MAAM,EAAE,OAAO,QAAQ,OAAO,MAAM,UAAU,GAAG,SAAS;;CAG1D,MAAM,UAAU,YAAY,MAAM,MAAM,UAAU;CAElD,MAAM,QAAQ,UAAU,KAAK,WAAW;EACtC,OAAO,SAAS,UAAU,eAAe;EACzC;CACF,EAAE;CAEF,OACE,qBAAC,OAAO,MAAR;EACQ;EACN,OAAO;EACA;EACG;EACV,gBAAgB,UAAU;GACxB,IAAI,UAAU,MACZ,MAAM,cAAc,KAAK;EAE7B;EATF,UAAA,CAWE,qBAAC,OAAO,SAAR;GACE,kBAAe;GACf,cAAW;GACX,GAAI;GAHN,UAAA,CAKE,oBAAC,OAAO,OAAR,CAAe,CAAA,GACf,oBAAC,OAAO,MAAR,CAAc,CAAA,CACA;EAEhB,CAAA,GAAA,oBAAC,OAAO,QAAR,EAAA,UACE,oBAAC,OAAO,YAAR;GAAmB,sBAAsB;GACvC,UAAA,oBAAC,OAAO,OAAR,EAAA,UACE,oBAAC,OAAO,MAAR,EAAA,UACG,MAAM,KAAK,SACV,qBAAC,OAAO,MAAR;IAEE,OAAO,KAAK;IAFd,UAAA,CAIE,oBAAC,OAAO,eAAR,CAAuB,CAAA,GACvB,oBAAC,OAAO,UAAR,EAAA,UAAkB,KAAK,MAAuB,CAAA,CACnC;GALN,GAAA,KAAK,KAKC,CACd,EACU,CAAA,EACD,CAAA;EACG,CAAA,EACN,CAAA,CACJ;;AAEjB;AAEA,uBAAuB,cAAc"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { TableWith } from "../../../types/table-with.js";
|
|
2
|
+
import "../../../types/index.js";
|
|
3
|
+
import { Column, RowData, TableFeatures } from "@tanstack/react-table";
|
|
4
|
+
import { Select } from "@lucasbernardosn/react-ui/collections/select";
|
|
5
|
+
import { MergeOverride } from "@lucasbernardosn/utils";
|
|
6
|
+
//#region src/components/data-table/toolbar/data-table-sort-column-select.d.ts
|
|
7
|
+
export type DataTableSortColumnSelectProps<TFeatures extends TableFeatures, TData extends RowData> = MergeOverride<Select.TriggerProps, {
|
|
8
|
+
/** A tabela. Exige `rowSortingFeature`. */
|
|
9
|
+
table: TableWith<TFeatures, TData, 'rowSortingFeature'>;
|
|
10
|
+
/**
|
|
11
|
+
* O nome de uma coluna.
|
|
12
|
+
* @default getDefaultColumnLabel: o `header` quando é texto, e o id quando não é
|
|
13
|
+
*/
|
|
14
|
+
getLabel?: (column: Column<TFeatures, TData>) => string;
|
|
15
|
+
/**
|
|
16
|
+
* O nome da opção que tira a ordenação.
|
|
17
|
+
* @default 'Sem ordenação'
|
|
18
|
+
*/
|
|
19
|
+
noSortingLabel?: string;
|
|
20
|
+
/**
|
|
21
|
+
* O tamanho do select.
|
|
22
|
+
* @default 'sm'
|
|
23
|
+
*/
|
|
24
|
+
size?: Select.RootProps<string>['size'];
|
|
25
|
+
}>;
|
|
26
|
+
/**
|
|
27
|
+
* O select da coluna da ordenação, para onde o cabeçalho não serve de controle, como no celular.
|
|
28
|
+
* Lista as colunas visíveis que ordenam, e "Sem ordenação" no topo; a coluna da ordenação atual
|
|
29
|
+
* entra no fim mesmo escondida. Escolher uma coluna troca a
|
|
30
|
+
* ordenação inteira por ela, na direção atual, ou na primeira da coluna sem ordenação antes. Com
|
|
31
|
+
* a ordenação por várias colunas, mostra a primeira.
|
|
32
|
+
*
|
|
33
|
+
* Vai junto com o `DataTable.SortDirectionSelect`. Quando aparecem é do app, pela `className`
|
|
34
|
+
* (ex.: `sm:hidden`). Renderiza o `Select` do `ui` por dentro; as props passam para o trigger.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```tsx
|
|
38
|
+
* <DataTable.SortColumnSelect table={table} className="sm:hidden" />
|
|
39
|
+
* <DataTable.SortDirectionSelect table={table} className="sm:hidden" />
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare const DataTableSortColumnSelect: {
|
|
43
|
+
<TFeatures extends TableFeatures, TData extends RowData>(props: DataTableSortColumnSelectProps<TFeatures, TData>): import("react").JSX.Element;
|
|
44
|
+
displayName: string;
|
|
45
|
+
};
|
|
46
|
+
//#endregion
|
|
47
|
+
//# sourceMappingURL=data-table-sort-column-select.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-table-sort-column-select.d.ts","names":[],"sources":["../../../../src/components/data-table/toolbar/data-table-sort-column-select.tsx"],"mappings":";;;;;;YAWY,+BACV,kBAAkB,eAClB,cAAc,WACZ,cACF,OAAO;;EAGL,OAAO,UAAU,WAAW;;;;;EAK5B,YAAY,QAAQ,OAAO,WAAW;;;;;EAKtC;;;;;EAKA,OAAO,OAAO;;;;;;;;;;;;;;;;;;qBAuBL;GACX,kBAAkB,eAClB,cAAc,SAAO,OAEd,+BAA+B,WAAW,yBAAM,IAAA"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { getDefaultColumnLabel } from "../../../utils/get-default-column-label.js";
|
|
2
|
+
import { hasColumnFeature, hasTableFeature } from "../../../utils/has-feature.js";
|
|
3
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
import { useSelector } from "@tanstack/react-store";
|
|
5
|
+
import { Select } from "@lucasbernardosn/react-ui/collections/select";
|
|
6
|
+
//#region src/components/data-table/toolbar/data-table-sort-column-select.tsx
|
|
7
|
+
/** O valor da opção que tira a ordenação. Um id de coluna nunca é vazio. */
|
|
8
|
+
const NO_SORTING = "";
|
|
9
|
+
/**
|
|
10
|
+
* O select da coluna da ordenação, para onde o cabeçalho não serve de controle, como no celular.
|
|
11
|
+
* Lista as colunas visíveis que ordenam, e "Sem ordenação" no topo; a coluna da ordenação atual
|
|
12
|
+
* entra no fim mesmo escondida. Escolher uma coluna troca a
|
|
13
|
+
* ordenação inteira por ela, na direção atual, ou na primeira da coluna sem ordenação antes. Com
|
|
14
|
+
* a ordenação por várias colunas, mostra a primeira.
|
|
15
|
+
*
|
|
16
|
+
* Vai junto com o `DataTable.SortDirectionSelect`. Quando aparecem é do app, pela `className`
|
|
17
|
+
* (ex.: `sm:hidden`). Renderiza o `Select` do `ui` por dentro; as props passam para o trigger.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```tsx
|
|
21
|
+
* <DataTable.SortColumnSelect table={table} className="sm:hidden" />
|
|
22
|
+
* <DataTable.SortDirectionSelect table={table} className="sm:hidden" />
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
const DataTableSortColumnSelect = (props) => {
|
|
26
|
+
const { table, getLabel = getDefaultColumnLabel, noSortingLabel = "Sem ordenação", size = "sm", disabled, ...rest } = props;
|
|
27
|
+
/** Re-renderiza quando a primeira coluna da ordenação muda. */
|
|
28
|
+
const sortedColumnId = useSelector(table.atoms.sorting, (sorting) => sorting[0]?.id ?? NO_SORTING);
|
|
29
|
+
const sortableColumns = useSelector(table.store, () => hasTableFeature(table, "columnVisibilityFeature") ? table.getVisibleLeafColumns() : table.getAllLeafColumns()).filter((column) => hasColumnFeature(column, "rowSortingFeature") && column.getCanSort());
|
|
30
|
+
/**
|
|
31
|
+
* A coluna da ordenação entra no fim mesmo fora da lista: escondida, ou sem a ordenação pelo
|
|
32
|
+
* usuário mas ordenada pelo código. Sem ela, o trigger mostraria o id.
|
|
33
|
+
*/
|
|
34
|
+
const sortedColumn = sortedColumnId === NO_SORTING || sortableColumns.some((column) => column.id === sortedColumnId) ? void 0 : table.getColumn(sortedColumnId);
|
|
35
|
+
const items = [{
|
|
36
|
+
label: noSortingLabel,
|
|
37
|
+
value: NO_SORTING
|
|
38
|
+
}, ...[...sortableColumns, ...sortedColumn ? [sortedColumn] : []].map((column) => ({
|
|
39
|
+
label: getLabel(column),
|
|
40
|
+
value: column.id
|
|
41
|
+
}))];
|
|
42
|
+
const handleValueChange = (columnId) => {
|
|
43
|
+
if (columnId === null || columnId === NO_SORTING) {
|
|
44
|
+
table.resetSorting(true);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const column = table.getColumn(columnId);
|
|
48
|
+
if (!(column && hasColumnFeature(column, "rowSortingFeature"))) return;
|
|
49
|
+
table.setSorting((sorting) => [{
|
|
50
|
+
id: columnId,
|
|
51
|
+
desc: sorting[0]?.desc ?? column.getFirstSortDir() === "desc"
|
|
52
|
+
}]);
|
|
53
|
+
};
|
|
54
|
+
return /* @__PURE__ */ jsxs(Select.Root, {
|
|
55
|
+
size,
|
|
56
|
+
value: sortedColumnId,
|
|
57
|
+
items,
|
|
58
|
+
disabled,
|
|
59
|
+
onValueChange: handleValueChange,
|
|
60
|
+
children: [/* @__PURE__ */ jsxs(Select.Trigger, {
|
|
61
|
+
"data-component": "DataTable.SortColumnSelect",
|
|
62
|
+
"aria-label": "Ordenar por",
|
|
63
|
+
...rest,
|
|
64
|
+
children: [/* @__PURE__ */ jsx(Select.Value, {}), /* @__PURE__ */ jsx(Select.Icon, {})]
|
|
65
|
+
}), /* @__PURE__ */ jsx(Select.Portal, { children: /* @__PURE__ */ jsx(Select.Positioner, {
|
|
66
|
+
alignItemWithTrigger: false,
|
|
67
|
+
children: /* @__PURE__ */ jsx(Select.Popup, { children: /* @__PURE__ */ jsx(Select.List, { children: items.map((item) => /* @__PURE__ */ jsxs(Select.Item, {
|
|
68
|
+
value: item.value,
|
|
69
|
+
children: [/* @__PURE__ */ jsx(Select.ItemIndicator, {}), /* @__PURE__ */ jsx(Select.ItemText, { children: item.label })]
|
|
70
|
+
}, item.value)) }) })
|
|
71
|
+
}) })]
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
DataTableSortColumnSelect.displayName = "DataTable.SortColumnSelect";
|
|
75
|
+
//#endregion
|
|
76
|
+
export { DataTableSortColumnSelect };
|
|
77
|
+
|
|
78
|
+
//# sourceMappingURL=data-table-sort-column-select.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-table-sort-column-select.js","names":[],"sources":["../../../../src/components/data-table/toolbar/data-table-sort-column-select.tsx"],"sourcesContent":["import { Select } from '@lucasbernardosn/react-ui/collections/select';\nimport type { MergeOverride } from '@lucasbernardosn/utils';\nimport { useSelector } from '@tanstack/react-store';\nimport type { Column, RowData, TableFeatures } from '@tanstack/react-table';\nimport type { TableWith } from '../../../types';\nimport {\n getDefaultColumnLabel,\n hasColumnFeature,\n hasTableFeature,\n} from '../../../utils';\n\nexport type DataTableSortColumnSelectProps<\n TFeatures extends TableFeatures,\n TData extends RowData,\n> = MergeOverride<\n Select.TriggerProps,\n {\n /** A tabela. Exige `rowSortingFeature`. */\n table: TableWith<TFeatures, TData, 'rowSortingFeature'>;\n /**\n * O nome de uma coluna.\n * @default getDefaultColumnLabel: o `header` quando é texto, e o id quando não é\n */\n getLabel?: (column: Column<TFeatures, TData>) => string;\n /**\n * O nome da opção que tira a ordenação.\n * @default 'Sem ordenação'\n */\n noSortingLabel?: string;\n /**\n * O tamanho do select.\n * @default 'sm'\n */\n size?: Select.RootProps<string>['size'];\n }\n>;\n\n/** O valor da opção que tira a ordenação. Um id de coluna nunca é vazio. */\nconst NO_SORTING = '';\n\n/**\n * O select da coluna da ordenação, para onde o cabeçalho não serve de controle, como no celular.\n * Lista as colunas visíveis que ordenam, e \"Sem ordenação\" no topo; a coluna da ordenação atual\n * entra no fim mesmo escondida. Escolher uma coluna troca a\n * ordenação inteira por ela, na direção atual, ou na primeira da coluna sem ordenação antes. Com\n * a ordenação por várias colunas, mostra a primeira.\n *\n * Vai junto com o `DataTable.SortDirectionSelect`. Quando aparecem é do app, pela `className`\n * (ex.: `sm:hidden`). Renderiza o `Select` do `ui` por dentro; as props passam para o trigger.\n *\n * @example\n * ```tsx\n * <DataTable.SortColumnSelect table={table} className=\"sm:hidden\" />\n * <DataTable.SortDirectionSelect table={table} className=\"sm:hidden\" />\n * ```\n */\nexport const DataTableSortColumnSelect = <\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n props: DataTableSortColumnSelectProps<TFeatures, TData>,\n) => {\n const {\n table,\n getLabel = getDefaultColumnLabel,\n noSortingLabel = 'Sem ordenação',\n size = 'sm',\n disabled,\n ...rest\n } = props;\n\n /** Re-renderiza quando a primeira coluna da ordenação muda. */\n const sortedColumnId = useSelector(\n table.atoms.sorting,\n (sorting) => sorting[0]?.id ?? NO_SORTING,\n );\n\n /**\n * As colunas, que o TanStack memoiza: re-renderiza quando a ordem ou a visibilidade mudam. A\n * visibilidade é opcional, então assina o store.\n */\n const columns = useSelector(table.store, () =>\n hasTableFeature(table, 'columnVisibilityFeature')\n ? table.getVisibleLeafColumns()\n : table.getAllLeafColumns(),\n );\n\n const sortableColumns = columns.filter(\n (column) =>\n hasColumnFeature(column, 'rowSortingFeature') && column.getCanSort(),\n );\n\n /**\n * A coluna da ordenação entra no fim mesmo fora da lista: escondida, ou sem a ordenação pelo\n * usuário mas ordenada pelo código. Sem ela, o trigger mostraria o id.\n */\n const sortedColumn =\n sortedColumnId === NO_SORTING ||\n sortableColumns.some((column) => column.id === sortedColumnId)\n ? undefined\n : table.getColumn(sortedColumnId);\n\n const items = [\n { label: noSortingLabel, value: NO_SORTING },\n ...[...sortableColumns, ...(sortedColumn ? [sortedColumn] : [])].map(\n (column) => ({ label: getLabel(column), value: column.id }),\n ),\n ];\n\n const handleValueChange = (columnId: string | null) => {\n if (columnId === null || columnId === NO_SORTING) {\n table.resetSorting(true);\n\n return;\n }\n\n const column = table.getColumn(columnId);\n\n if (!(column && hasColumnFeature(column, 'rowSortingFeature'))) {\n return;\n }\n\n table.setSorting((sorting) => [\n {\n id: columnId,\n desc: sorting[0]?.desc ?? column.getFirstSortDir() === 'desc',\n },\n ]);\n };\n\n return (\n <Select.Root<string>\n size={size}\n value={sortedColumnId}\n items={items}\n disabled={disabled}\n onValueChange={handleValueChange}\n >\n <Select.Trigger\n data-component=\"DataTable.SortColumnSelect\"\n aria-label=\"Ordenar por\"\n {...rest}\n >\n <Select.Value />\n <Select.Icon />\n </Select.Trigger>\n\n <Select.Portal>\n <Select.Positioner alignItemWithTrigger={false}>\n <Select.Popup>\n <Select.List>\n {items.map((item) => (\n <Select.Item\n key={item.value}\n value={item.value}\n >\n <Select.ItemIndicator />\n <Select.ItemText>{item.label}</Select.ItemText>\n </Select.Item>\n ))}\n </Select.List>\n </Select.Popup>\n </Select.Positioner>\n </Select.Portal>\n </Select.Root>\n );\n};\n\nDataTableSortColumnSelect.displayName = 'DataTable.SortColumnSelect';\n"],"mappings":";;;;;;;AAsCA,MAAM,aAAa;;;;;;;;;;;;;;;;;AAkBnB,MAAa,6BAIX,UACG;CACH,MAAM,EACJ,OACA,WAAW,uBACX,iBAAiB,iBACjB,OAAO,MACP,UACA,GAAG,SACD;;CAGJ,MAAM,iBAAiB,YACrB,MAAM,MAAM,UACX,YAAY,QAAQ,EAAE,EAAE,MAAM,UACjC;CAYA,MAAM,kBANU,YAAY,MAAM,aAChC,gBAAgB,OAAO,yBAAyB,IAC5C,MAAM,sBAAsB,IAC5B,MAAM,kBAAkB,CAGA,CAAC,CAAC,QAC7B,WACC,iBAAiB,QAAQ,mBAAmB,KAAK,OAAO,WAAW,CACvE;;;;;CAMA,MAAM,eACJ,mBAAmB,cACnB,gBAAgB,MAAM,WAAW,OAAO,OAAO,cAAc,IACzD,KAAA,IACA,MAAM,UAAU,cAAc;CAEpC,MAAM,QAAQ,CACZ;EAAE,OAAO;EAAgB,OAAO;CAAW,GAC3C,GAAG,CAAC,GAAG,iBAAiB,GAAI,eAAe,CAAC,YAAY,IAAI,CAAC,CAAE,CAAC,CAAC,KAC9D,YAAY;EAAE,OAAO,SAAS,MAAM;EAAG,OAAO,OAAO;CAAG,EAC3D,CACF;CAEA,MAAM,qBAAqB,aAA4B;EACrD,IAAI,aAAa,QAAQ,aAAa,YAAY;GAChD,MAAM,aAAa,IAAI;GAEvB;EACF;EAEA,MAAM,SAAS,MAAM,UAAU,QAAQ;EAEvC,IAAI,EAAE,UAAU,iBAAiB,QAAQ,mBAAmB,IAC1D;EAGF,MAAM,YAAY,YAAY,CAC5B;GACE,IAAI;GACJ,MAAM,QAAQ,EAAE,EAAE,QAAQ,OAAO,gBAAgB,MAAM;EACzD,CACF,CAAC;CACH;CAEA,OACE,qBAAC,OAAO,MAAR;EACQ;EACN,OAAO;EACA;EACG;EACV,eAAe;EALjB,UAAA,CAOE,qBAAC,OAAO,SAAR;GACE,kBAAe;GACf,cAAW;GACX,GAAI;GAHN,UAAA,CAKE,oBAAC,OAAO,OAAR,CAAe,CAAA,GACf,oBAAC,OAAO,MAAR,CAAc,CAAA,CACA;EAEhB,CAAA,GAAA,oBAAC,OAAO,QAAR,EAAA,UACE,oBAAC,OAAO,YAAR;GAAmB,sBAAsB;GACvC,UAAA,oBAAC,OAAO,OAAR,EAAA,UACE,oBAAC,OAAO,MAAR,EAAA,UACG,MAAM,KAAK,SACV,qBAAC,OAAO,MAAR;IAEE,OAAO,KAAK;IAFd,UAAA,CAIE,oBAAC,OAAO,eAAR,CAAuB,CAAA,GACvB,oBAAC,OAAO,UAAR,EAAA,UAAkB,KAAK,MAAuB,CAAA,CACnC;GALN,GAAA,KAAK,KAKC,CACd,EACU,CAAA,EACD,CAAA;EACG,CAAA,EACN,CAAA,CACJ;;AAEjB;AAEA,0BAA0B,cAAc"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { TableWith } from "../../../types/table-with.js";
|
|
2
|
+
import "../../../types/index.js";
|
|
3
|
+
import { RowData, SortDirection, TableFeatures } from "@tanstack/react-table";
|
|
4
|
+
import { Select } from "@lucasbernardosn/react-ui/collections/select";
|
|
5
|
+
import { MergeOverride } from "@lucasbernardosn/utils";
|
|
6
|
+
//#region src/components/data-table/toolbar/data-table-sort-direction-select.d.ts
|
|
7
|
+
export type DataTableSortDirectionSelectProps<TFeatures extends TableFeatures, TData extends RowData> = MergeOverride<Select.TriggerProps, {
|
|
8
|
+
/** A tabela. Exige `rowSortingFeature`. */
|
|
9
|
+
table: TableWith<TFeatures, TData, 'rowSortingFeature'>;
|
|
10
|
+
/**
|
|
11
|
+
* O nome de cada direção.
|
|
12
|
+
* @default { asc: 'Crescente', desc: 'Decrescente' }
|
|
13
|
+
*/
|
|
14
|
+
labels?: Partial<Record<SortDirection, string>>;
|
|
15
|
+
/**
|
|
16
|
+
* O tamanho do select.
|
|
17
|
+
* @default 'sm'
|
|
18
|
+
*/
|
|
19
|
+
size?: Select.RootProps<SortDirection>['size'];
|
|
20
|
+
}>;
|
|
21
|
+
/**
|
|
22
|
+
* O select da direção da ordenação, para ir junto com o `DataTable.SortColumnSelect`. Troca a
|
|
23
|
+
* direção da primeira coluna da ordenação; sem ordenação, fica desabilitado.
|
|
24
|
+
*
|
|
25
|
+
* Renderiza o `Select` do `ui` por dentro; as props passam para o trigger.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```tsx
|
|
29
|
+
* <DataTable.SortDirectionSelect
|
|
30
|
+
* table={table}
|
|
31
|
+
* labels={{ asc: 'A–Z', desc: 'Z–A' }}
|
|
32
|
+
* />
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare const DataTableSortDirectionSelect: {
|
|
36
|
+
<TFeatures extends TableFeatures, TData extends RowData>(props: DataTableSortDirectionSelectProps<TFeatures, TData>): import("react").JSX.Element;
|
|
37
|
+
displayName: string;
|
|
38
|
+
};
|
|
39
|
+
//#endregion
|
|
40
|
+
//# sourceMappingURL=data-table-sort-direction-select.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-table-sort-direction-select.d.ts","names":[],"sources":["../../../../src/components/data-table/toolbar/data-table-sort-direction-select.tsx"],"mappings":";;;;;;YAUY,kCACV,kBAAkB,eAClB,cAAc,WACZ,cACF,OAAO;;EAGL,OAAO,UAAU,WAAW;;;;;EAK5B,SAAS,QAAQ,OAAO;;;;;EAKxB,OAAO,OAAO,UAAU;;;;;;;;;;;;;;;;qBAyBf;GACX,kBAAkB,eAClB,cAAc,SAAO,OAEd,kCAAkC,WAAW,yBAAM,IAAA"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useSelector } from "@tanstack/react-store";
|
|
3
|
+
import { Select } from "@lucasbernardosn/react-ui/collections/select";
|
|
4
|
+
//#region src/components/data-table/toolbar/data-table-sort-direction-select.tsx
|
|
5
|
+
const DEFAULT_LABELS = {
|
|
6
|
+
asc: "Crescente",
|
|
7
|
+
desc: "Decrescente"
|
|
8
|
+
};
|
|
9
|
+
const DIRECTIONS = ["asc", "desc"];
|
|
10
|
+
/**
|
|
11
|
+
* O select da direção da ordenação, para ir junto com o `DataTable.SortColumnSelect`. Troca a
|
|
12
|
+
* direção da primeira coluna da ordenação; sem ordenação, fica desabilitado.
|
|
13
|
+
*
|
|
14
|
+
* Renderiza o `Select` do `ui` por dentro; as props passam para o trigger.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```tsx
|
|
18
|
+
* <DataTable.SortDirectionSelect
|
|
19
|
+
* table={table}
|
|
20
|
+
* labels={{ asc: 'A–Z', desc: 'Z–A' }}
|
|
21
|
+
* />
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
const DataTableSortDirectionSelect = (props) => {
|
|
25
|
+
const { table, labels, size = "sm", disabled, ...rest } = props;
|
|
26
|
+
/**
|
|
27
|
+
* A direção da primeira coluna da ordenação, ou `null` sem ordenação. Re-renderiza quando
|
|
28
|
+
* muda.
|
|
29
|
+
*/
|
|
30
|
+
const direction = useSelector(table.atoms.sorting, (sorting) => sorting[0] ? sorting[0].desc ? "desc" : "asc" : null);
|
|
31
|
+
const items = DIRECTIONS.map((value) => ({
|
|
32
|
+
label: labels?.[value] ?? DEFAULT_LABELS[value],
|
|
33
|
+
value
|
|
34
|
+
}));
|
|
35
|
+
/** Sem ordenação, o trigger mostra a crescente, desabilitado, para não ficar vazio. */
|
|
36
|
+
const placeholder = labels?.asc ?? DEFAULT_LABELS.asc;
|
|
37
|
+
return /* @__PURE__ */ jsxs(Select.Root, {
|
|
38
|
+
size,
|
|
39
|
+
value: direction,
|
|
40
|
+
items,
|
|
41
|
+
disabled: disabled || direction === null,
|
|
42
|
+
onValueChange: (value) => {
|
|
43
|
+
if (value !== null) table.setSorting(([first, ...others]) => first ? [{
|
|
44
|
+
...first,
|
|
45
|
+
desc: value === "desc"
|
|
46
|
+
}, ...others] : []);
|
|
47
|
+
},
|
|
48
|
+
children: [/* @__PURE__ */ jsxs(Select.Trigger, {
|
|
49
|
+
"data-component": "DataTable.SortDirectionSelect",
|
|
50
|
+
"aria-label": "Direção da ordenação",
|
|
51
|
+
...rest,
|
|
52
|
+
children: [/* @__PURE__ */ jsx(Select.Value, { placeholder }), /* @__PURE__ */ jsx(Select.Icon, {})]
|
|
53
|
+
}), /* @__PURE__ */ jsx(Select.Portal, { children: /* @__PURE__ */ jsx(Select.Positioner, {
|
|
54
|
+
alignItemWithTrigger: false,
|
|
55
|
+
children: /* @__PURE__ */ jsx(Select.Popup, { children: /* @__PURE__ */ jsx(Select.List, { children: items.map((item) => /* @__PURE__ */ jsxs(Select.Item, {
|
|
56
|
+
value: item.value,
|
|
57
|
+
children: [/* @__PURE__ */ jsx(Select.ItemIndicator, {}), /* @__PURE__ */ jsx(Select.ItemText, { children: item.label })]
|
|
58
|
+
}, item.value)) }) })
|
|
59
|
+
}) })]
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
DataTableSortDirectionSelect.displayName = "DataTable.SortDirectionSelect";
|
|
63
|
+
//#endregion
|
|
64
|
+
export { DataTableSortDirectionSelect };
|
|
65
|
+
|
|
66
|
+
//# sourceMappingURL=data-table-sort-direction-select.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-table-sort-direction-select.js","names":[],"sources":["../../../../src/components/data-table/toolbar/data-table-sort-direction-select.tsx"],"sourcesContent":["import { Select } from '@lucasbernardosn/react-ui/collections/select';\nimport type { MergeOverride } from '@lucasbernardosn/utils';\nimport { useSelector } from '@tanstack/react-store';\nimport type {\n RowData,\n SortDirection,\n TableFeatures,\n} from '@tanstack/react-table';\nimport type { TableWith } from '../../../types';\n\nexport type DataTableSortDirectionSelectProps<\n TFeatures extends TableFeatures,\n TData extends RowData,\n> = MergeOverride<\n Select.TriggerProps,\n {\n /** A tabela. Exige `rowSortingFeature`. */\n table: TableWith<TFeatures, TData, 'rowSortingFeature'>;\n /**\n * O nome de cada direção.\n * @default { asc: 'Crescente', desc: 'Decrescente' }\n */\n labels?: Partial<Record<SortDirection, string>>;\n /**\n * O tamanho do select.\n * @default 'sm'\n */\n size?: Select.RootProps<SortDirection>['size'];\n }\n>;\n\nconst DEFAULT_LABELS: Record<SortDirection, string> = {\n asc: 'Crescente',\n desc: 'Decrescente',\n};\n\nconst DIRECTIONS: SortDirection[] = ['asc', 'desc'];\n\n/**\n * O select da direção da ordenação, para ir junto com o `DataTable.SortColumnSelect`. Troca a\n * direção da primeira coluna da ordenação; sem ordenação, fica desabilitado.\n *\n * Renderiza o `Select` do `ui` por dentro; as props passam para o trigger.\n *\n * @example\n * ```tsx\n * <DataTable.SortDirectionSelect\n * table={table}\n * labels={{ asc: 'A–Z', desc: 'Z–A' }}\n * />\n * ```\n */\nexport const DataTableSortDirectionSelect = <\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n props: DataTableSortDirectionSelectProps<TFeatures, TData>,\n) => {\n const { table, labels, size = 'sm', disabled, ...rest } = props;\n\n /**\n * A direção da primeira coluna da ordenação, ou `null` sem ordenação. Re-renderiza quando\n * muda.\n */\n const direction = useSelector(\n table.atoms.sorting,\n (sorting): SortDirection | null =>\n sorting[0] ? (sorting[0].desc ? 'desc' : 'asc') : null,\n );\n\n const items = DIRECTIONS.map((value) => ({\n label: labels?.[value] ?? DEFAULT_LABELS[value],\n value,\n }));\n\n /** Sem ordenação, o trigger mostra a crescente, desabilitado, para não ficar vazio. */\n const placeholder = labels?.asc ?? DEFAULT_LABELS.asc;\n\n return (\n <Select.Root<SortDirection>\n size={size}\n value={direction}\n items={items}\n disabled={disabled || direction === null}\n onValueChange={(value) => {\n if (value !== null) {\n table.setSorting(([first, ...others]) =>\n first ? [{ ...first, desc: value === 'desc' }, ...others] : [],\n );\n }\n }}\n >\n <Select.Trigger\n data-component=\"DataTable.SortDirectionSelect\"\n aria-label=\"Direção da ordenação\"\n {...rest}\n >\n <Select.Value placeholder={placeholder} />\n <Select.Icon />\n </Select.Trigger>\n\n <Select.Portal>\n <Select.Positioner alignItemWithTrigger={false}>\n <Select.Popup>\n <Select.List>\n {items.map((item) => (\n <Select.Item\n key={item.value}\n value={item.value}\n >\n <Select.ItemIndicator />\n <Select.ItemText>{item.label}</Select.ItemText>\n </Select.Item>\n ))}\n </Select.List>\n </Select.Popup>\n </Select.Positioner>\n </Select.Portal>\n </Select.Root>\n );\n};\n\nDataTableSortDirectionSelect.displayName = 'DataTable.SortDirectionSelect';\n"],"mappings":";;;;AA+BA,MAAM,iBAAgD;CACpD,KAAK;CACL,MAAM;AACR;AAEA,MAAM,aAA8B,CAAC,OAAO,MAAM;;;;;;;;;;;;;;;AAgBlD,MAAa,gCAIX,UACG;CACH,MAAM,EAAE,OAAO,QAAQ,OAAO,MAAM,UAAU,GAAG,SAAS;;;;;CAM1D,MAAM,YAAY,YAChB,MAAM,MAAM,UACX,YACC,QAAQ,KAAM,QAAQ,EAAE,CAAC,OAAO,SAAS,QAAS,IACtD;CAEA,MAAM,QAAQ,WAAW,KAAK,WAAW;EACvC,OAAO,SAAS,UAAU,eAAe;EACzC;CACF,EAAE;;CAGF,MAAM,cAAc,QAAQ,OAAO,eAAe;CAElD,OACE,qBAAC,OAAO,MAAR;EACQ;EACN,OAAO;EACA;EACP,UAAU,YAAY,cAAc;EACpC,gBAAgB,UAAU;GACxB,IAAI,UAAU,MACZ,MAAM,YAAY,CAAC,OAAO,GAAG,YAC3B,QAAQ,CAAC;IAAE,GAAG;IAAO,MAAM,UAAU;GAAO,GAAG,GAAG,MAAM,IAAI,CAAC,CAC/D;EAEJ;EAXF,UAAA,CAaE,qBAAC,OAAO,SAAR;GACE,kBAAe;GACf,cAAW;GACX,GAAI;GAHN,UAAA,CAKE,oBAAC,OAAO,OAAR,EAA2B,YAAc,CAAA,GACzC,oBAAC,OAAO,MAAR,CAAc,CAAA,CACA;EAEhB,CAAA,GAAA,oBAAC,OAAO,QAAR,EAAA,UACE,oBAAC,OAAO,YAAR;GAAmB,sBAAsB;GACvC,UAAA,oBAAC,OAAO,OAAR,EAAA,UACE,oBAAC,OAAO,MAAR,EAAA,UACG,MAAM,KAAK,SACV,qBAAC,OAAO,MAAR;IAEE,OAAO,KAAK;IAFd,UAAA,CAIE,oBAAC,OAAO,eAAR,CAAuB,CAAA,GACvB,oBAAC,OAAO,UAAR,EAAA,UAAkB,KAAK,MAAuB,CAAA,CACnC;GALN,GAAA,KAAK,KAKC,CACd,EACU,CAAA,EACD,CAAA;EACG,CAAA,EACN,CAAA,CACJ;;AAEjB;AAEA,6BAA6B,cAAc"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { TableFeature } from "@tanstack/react-table";
|
|
2
|
+
//#region src/features/active-row/active-row-feature.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Feature do TanStack Table para a linha ativa, a do teclado. Registre com essa chave:
|
|
5
|
+
* `tableFeatures({ activeRowFeature })`.
|
|
6
|
+
*
|
|
7
|
+
* Guarda o id da linha ativa. Com ela, o `DataTable.Root` vira `role="grid"`, e as setas andam
|
|
8
|
+
* entre as `DataTable.Row`, que gravam a linha que recebe o foco, do teclado ou do clique. A
|
|
9
|
+
* linha ativa é separada da seleção.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* const features = tableFeatures({ columnSizingFeature, activeRowFeature });
|
|
14
|
+
*
|
|
15
|
+
* const table = useTable({ features, columns, data });
|
|
16
|
+
*
|
|
17
|
+
* table.getActiveRow()?.original;
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare const activeRowFeature: TableFeature;
|
|
21
|
+
//#endregion
|
|
22
|
+
//# sourceMappingURL=active-row-feature.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"active-row-feature.d.ts","names":[],"sources":["../../../src/features/active-row/active-row-feature.ts"],"mappings":";;;;;;;;;;;;;;;;;;;qBAmCa,kBAAkB"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { hasRowFeature, hasTableFeature } from "../../utils/has-feature.js";
|
|
2
|
+
import { assignPrototypeAPIs, assignTableAPIs, makeStateUpdater, setStateSlice } from "@tanstack/react-table";
|
|
3
|
+
//#region src/features/active-row/active-row-feature.ts
|
|
4
|
+
/** A linha ativa de um estado inicial, ou nenhuma quando ele não traz. */
|
|
5
|
+
const getInitialActiveRowId = (initialState) => initialState.activeRowId ?? null;
|
|
6
|
+
/**
|
|
7
|
+
* Feature do TanStack Table para a linha ativa, a do teclado. Registre com essa chave:
|
|
8
|
+
* `tableFeatures({ activeRowFeature })`.
|
|
9
|
+
*
|
|
10
|
+
* Guarda o id da linha ativa. Com ela, o `DataTable.Root` vira `role="grid"`, e as setas andam
|
|
11
|
+
* entre as `DataTable.Row`, que gravam a linha que recebe o foco, do teclado ou do clique. A
|
|
12
|
+
* linha ativa é separada da seleção.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* const features = tableFeatures({ columnSizingFeature, activeRowFeature });
|
|
17
|
+
*
|
|
18
|
+
* const table = useTable({ features, columns, data });
|
|
19
|
+
*
|
|
20
|
+
* table.getActiveRow()?.original;
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
const activeRowFeature = {
|
|
24
|
+
getInitialState: (initialState) => ({
|
|
25
|
+
activeRowId: null,
|
|
26
|
+
...initialState
|
|
27
|
+
}),
|
|
28
|
+
getDefaultTableOptions: (table) => ({ onActiveRowIdChange: makeStateUpdater("activeRowId", table) }),
|
|
29
|
+
constructTableAPIs: (table) => {
|
|
30
|
+
assignTableAPIs("activeRowFeature", table, {
|
|
31
|
+
table_setActiveRowId: { fn: (updater) => setStateSlice(table, "activeRowId", updater) },
|
|
32
|
+
table_resetActiveRowId: { fn: (defaultState) => setStateSlice(table, "activeRowId", defaultState ? null : getInitialActiveRowId(table.initialState)) },
|
|
33
|
+
table_getActiveRow: {
|
|
34
|
+
/**
|
|
35
|
+
* O guard só tipa os atoms da tabela: com a feature registrada, ele sempre passa.
|
|
36
|
+
*/
|
|
37
|
+
fn: () => {
|
|
38
|
+
const activeRowId = hasTableFeature(table, "activeRowFeature") ? table.atoms.activeRowId.get() : null;
|
|
39
|
+
return activeRowId === null ? void 0 : table.getRowModel().rowsById[activeRowId];
|
|
40
|
+
} }
|
|
41
|
+
});
|
|
42
|
+
},
|
|
43
|
+
assignRowPrototype: (prototype, table) => {
|
|
44
|
+
assignPrototypeAPIs("activeRowFeature", prototype, table, { row_getIsActive: {
|
|
45
|
+
/**
|
|
46
|
+
* O TanStack chama com a linha de uma tabela qualquer; o guard tipa o atom, e com a
|
|
47
|
+
* feature registrada sempre passa.
|
|
48
|
+
*/
|
|
49
|
+
fn: (row) => hasRowFeature(row, "activeRowFeature") && row.table.atoms.activeRowId.get() === row.id } });
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
//#endregion
|
|
53
|
+
export { activeRowFeature };
|
|
54
|
+
|
|
55
|
+
//# sourceMappingURL=active-row-feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"active-row-feature.js","names":[],"sources":["../../../src/features/active-row/active-row-feature.ts"],"sourcesContent":["import {\n assignPrototypeAPIs,\n assignTableAPIs,\n makeStateUpdater,\n type Row,\n type RowData,\n setStateSlice,\n type TableFeature,\n type TableFeatures,\n type TableState_All,\n type Updater,\n} from '@tanstack/react-table';\nimport { hasRowFeature, hasTableFeature } from '../../utils';\n\n/** A linha ativa de um estado inicial, ou nenhuma quando ele não traz. */\nconst getInitialActiveRowId = (initialState: Partial<TableState_All>) =>\n initialState.activeRowId ?? null;\n\n/**\n * Feature do TanStack Table para a linha ativa, a do teclado. Registre com essa chave:\n * `tableFeatures({ activeRowFeature })`.\n *\n * Guarda o id da linha ativa. Com ela, o `DataTable.Root` vira `role=\"grid\"`, e as setas andam\n * entre as `DataTable.Row`, que gravam a linha que recebe o foco, do teclado ou do clique. A\n * linha ativa é separada da seleção.\n *\n * @example\n * ```ts\n * const features = tableFeatures({ columnSizingFeature, activeRowFeature });\n *\n * const table = useTable({ features, columns, data });\n *\n * table.getActiveRow()?.original;\n * ```\n */\nexport const activeRowFeature: TableFeature = {\n getInitialState: (initialState) => ({\n activeRowId: null,\n ...initialState,\n }),\n\n getDefaultTableOptions: (table) => ({\n onActiveRowIdChange: makeStateUpdater('activeRowId', table),\n }),\n\n constructTableAPIs: (table) => {\n assignTableAPIs('activeRowFeature', table, {\n table_setActiveRowId: {\n fn: (updater: Updater<string | null>) =>\n setStateSlice(table, 'activeRowId', updater),\n },\n table_resetActiveRowId: {\n fn: (defaultState?: boolean) =>\n setStateSlice(\n table,\n 'activeRowId',\n defaultState ? null : getInitialActiveRowId(table.initialState),\n ),\n },\n table_getActiveRow: {\n /**\n * O guard só tipa os atoms da tabela: com a feature registrada, ele sempre passa.\n */\n fn: () => {\n const activeRowId = hasTableFeature(table, 'activeRowFeature')\n ? table.atoms.activeRowId.get()\n : null;\n\n return activeRowId === null\n ? undefined\n : table.getRowModel().rowsById[activeRowId];\n },\n },\n });\n },\n\n assignRowPrototype: (prototype, table) => {\n assignPrototypeAPIs('activeRowFeature', prototype, table, {\n row_getIsActive: {\n /**\n * O TanStack chama com a linha de uma tabela qualquer; o guard tipa o atom, e com a\n * feature registrada sempre passa.\n */\n fn: (row: Row<TableFeatures, RowData>) =>\n hasRowFeature(row, 'activeRowFeature') &&\n row.table.atoms.activeRowId.get() === row.id,\n },\n });\n },\n};\n"],"mappings":";;;;AAeA,MAAM,yBAAyB,iBAC7B,aAAa,eAAe;;;;;;;;;;;;;;;;;;AAmB9B,MAAa,mBAAiC;CAC5C,kBAAkB,kBAAkB;EAClC,aAAa;EACb,GAAG;CACL;CAEA,yBAAyB,WAAW,EAClC,qBAAqB,iBAAiB,eAAe,KAAK,EAC5D;CAEA,qBAAqB,UAAU;EAC7B,gBAAgB,oBAAoB,OAAO;GACzC,sBAAsB,EACpB,KAAK,YACH,cAAc,OAAO,eAAe,OAAO,EAC/C;GACA,wBAAwB,EACtB,KAAK,iBACH,cACE,OACA,eACA,eAAe,OAAO,sBAAsB,MAAM,YAAY,CAChE,EACJ;GACA,oBAAoB;;;;AAIlB,UAAU;IACR,MAAM,cAAc,gBAAgB,OAAO,kBAAkB,IACzD,MAAM,MAAM,YAAY,IAAI,IAC5B;IAEJ,OAAO,gBAAgB,OACnB,KAAA,IACA,MAAM,YAAY,CAAC,CAAC,SAAS;GACnC,EACF;EACF,CAAC;CACH;CAEA,qBAAqB,WAAW,UAAU;EACxC,oBAAoB,oBAAoB,WAAW,OAAO,EACxD,iBAAiB;;;;;AAKf,KAAK,QACH,cAAc,KAAK,kBAAkB,KACrC,IAAI,MAAM,MAAM,YAAY,IAAI,MAAM,IAAI,GAC9C,EACF,CAAC;CACH;AACF"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { OnChangeFn, Row, RowData, TableFeature, TableFeatures, Updater } from "@tanstack/react-table";
|
|
2
|
+
//#region src/features/active-row/active-row-feature.types.d.ts
|
|
3
|
+
/** O estado da feature. */
|
|
4
|
+
export type TableState_ActiveRow = {
|
|
5
|
+
/**
|
|
6
|
+
* O id da linha ativa, a do teclado: a que tem o ponto de Tab e recebe as teclas. Separada da
|
|
7
|
+
* seleção, que é a do checkbox.
|
|
8
|
+
* @default null
|
|
9
|
+
*/
|
|
10
|
+
activeRowId: string | null;
|
|
11
|
+
};
|
|
12
|
+
/** As opções da feature. */
|
|
13
|
+
export type TableOptions_ActiveRow = {
|
|
14
|
+
/**
|
|
15
|
+
* Chamada a cada troca da linha ativa, com o updater. Sem ela, a tabela guarda a linha ativa
|
|
16
|
+
* sozinha. Para controlar o estado, passe esta função e `state.activeRowId`.
|
|
17
|
+
*/
|
|
18
|
+
onActiveRowIdChange?: OnChangeFn<string | null>;
|
|
19
|
+
};
|
|
20
|
+
/** As APIs da feature na tabela. */
|
|
21
|
+
export type Table_ActiveRow<TFeatures extends TableFeatures, TData extends RowData> = {
|
|
22
|
+
/** Troca a linha ativa, com um id, `null` ou um updater. */
|
|
23
|
+
setActiveRowId: (updater: Updater<string | null>) => void;
|
|
24
|
+
/**
|
|
25
|
+
* Volta a linha ativa à do `initialState`. Com `defaultState`, volta ao padrão da feature,
|
|
26
|
+
* `null`.
|
|
27
|
+
*/
|
|
28
|
+
resetActiveRowId: (defaultState?: boolean) => void;
|
|
29
|
+
/**
|
|
30
|
+
* A linha ativa, se ela está no row model atual. Fora dele, como numa linha apagada ou de
|
|
31
|
+
* outra página, `undefined`.
|
|
32
|
+
*/
|
|
33
|
+
getActiveRow: () => Row<TFeatures, TData> | undefined;
|
|
34
|
+
};
|
|
35
|
+
/** As APIs da feature na linha. */
|
|
36
|
+
export type Row_ActiveRow = {
|
|
37
|
+
/** Se esta é a linha ativa. */
|
|
38
|
+
getIsActive: () => boolean;
|
|
39
|
+
};
|
|
40
|
+
declare module '@tanstack/react-table' {
|
|
41
|
+
interface Plugins {
|
|
42
|
+
activeRowFeature: TableFeature;
|
|
43
|
+
}
|
|
44
|
+
interface TableState_FeatureMap {
|
|
45
|
+
activeRowFeature: TableState_ActiveRow;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* O `TableState_All` não junta os plugins sozinho. Sem a chave aqui, o `setStateSlice` e a
|
|
49
|
+
* leitura do `initialState` dentro da feature não a conhecem. Opcional, como as chaves do
|
|
50
|
+
* TanStack.
|
|
51
|
+
*/
|
|
52
|
+
interface TableState_All extends Partial<TableState_ActiveRow> {}
|
|
53
|
+
interface TableOptions_FeatureMap<TFeatures extends TableFeatures, TData extends RowData> {
|
|
54
|
+
activeRowFeature: TableOptions_ActiveRow;
|
|
55
|
+
}
|
|
56
|
+
interface Table_FeatureMap<TFeatures extends TableFeatures, TData extends RowData> {
|
|
57
|
+
activeRowFeature: Table_ActiveRow<TFeatures, TData>;
|
|
58
|
+
}
|
|
59
|
+
interface Row_FeatureMap<TFeatures extends TableFeatures, TData extends RowData> {
|
|
60
|
+
activeRowFeature: Row_ActiveRow;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
//#endregion
|
|
64
|
+
//# sourceMappingURL=active-row-feature.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"active-row-feature.types.d.ts","names":[],"sources":["../../../src/features/active-row/active-row-feature.types.ts"],"mappings":";;;YAWY;;;;;;EAMV;;;YAIU;;;;;EAKV,sBAAsB;;;YAIZ,gBACV,kBAAkB,eAClB,cAAc;;EAGd,iBAAiB,SAAS;;;;;EAK1B,mBAAmB;;;;;EAKnB,oBAAoB,IAAI,WAAW;;;YAIzB;;EAEV;;;YASU;IACR,kBAAkB;;YAGV;IACR,kBAAkB;;;;;;;YAQV,uBAAuB,QAAQ;YAE/B,wBACR,kBAAkB,eAClB,cAAc;IAEd,kBAAkB;;YAGV,iBACR,kBAAkB,eAClB,cAAc;IAEd,kBAAkB,gBAAgB,WAAW;;YAGrC,eACR,kBAAkB,eAClB,cAAc;IAEd,kBAAkB"}
|
|
File without changes
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { TableFeature } from "@tanstack/react-table";
|
|
2
|
+
//#region src/features/column-alignment/column-alignment-feature.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Feature do TanStack Table para o alinhamento por coluna. Registre com essa chave:
|
|
5
|
+
* `tableFeatures({ columnAlignmentFeature })`.
|
|
6
|
+
*
|
|
7
|
+
* Não tem estado: o alinhamento vem do `align` da definição da coluna, e não muda em runtime. A
|
|
8
|
+
* `DataTable.Cell` e a `DataTable.HeaderCell` o leem por `column.getAlign()` e o marcam em
|
|
9
|
+
* `data-align`.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* const features = tableFeatures({ columnSizingFeature, columnAlignmentFeature });
|
|
14
|
+
*
|
|
15
|
+
* const columns = columnHelper.columns([
|
|
16
|
+
* columnHelper.accessor('name', { header: 'Nome' }),
|
|
17
|
+
* columnHelper.accessor('total', { header: 'Total', align: 'end' }),
|
|
18
|
+
* ]);
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare const columnAlignmentFeature: TableFeature;
|
|
22
|
+
//#endregion
|
|
23
|
+
//# sourceMappingURL=column-alignment-feature.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"column-alignment-feature.d.ts","names":[],"sources":["../../../src/features/column-alignment/column-alignment-feature.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;qBA8Ba,wBAAwB"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { assignPrototypeAPIs } from "@tanstack/react-table";
|
|
2
|
+
//#region src/features/column-alignment/column-alignment-feature.ts
|
|
3
|
+
/** O alinhamento de uma coluna sem `align` na definição. */
|
|
4
|
+
const DEFAULT_COLUMN_ALIGN = "start";
|
|
5
|
+
/**
|
|
6
|
+
* Feature do TanStack Table para o alinhamento por coluna. Registre com essa chave:
|
|
7
|
+
* `tableFeatures({ columnAlignmentFeature })`.
|
|
8
|
+
*
|
|
9
|
+
* Não tem estado: o alinhamento vem do `align` da definição da coluna, e não muda em runtime. A
|
|
10
|
+
* `DataTable.Cell` e a `DataTable.HeaderCell` o leem por `column.getAlign()` e o marcam em
|
|
11
|
+
* `data-align`.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* const features = tableFeatures({ columnSizingFeature, columnAlignmentFeature });
|
|
16
|
+
*
|
|
17
|
+
* const columns = columnHelper.columns([
|
|
18
|
+
* columnHelper.accessor('name', { header: 'Nome' }),
|
|
19
|
+
* columnHelper.accessor('total', { header: 'Total', align: 'end' }),
|
|
20
|
+
* ]);
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
const columnAlignmentFeature = { assignColumnPrototype: (prototype, table) => {
|
|
24
|
+
assignPrototypeAPIs("columnAlignmentFeature", prototype, table, { column_getAlign: {
|
|
25
|
+
/**
|
|
26
|
+
* O TanStack chama com a coluna de uma tabela qualquer: o tipo com todas as features é o
|
|
27
|
+
* que conhece o `align`.
|
|
28
|
+
*/
|
|
29
|
+
fn: (column) => column.columnDef.align ?? DEFAULT_COLUMN_ALIGN } });
|
|
30
|
+
} };
|
|
31
|
+
//#endregion
|
|
32
|
+
export { columnAlignmentFeature };
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=column-alignment-feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"column-alignment-feature.js","names":[],"sources":["../../../src/features/column-alignment/column-alignment-feature.ts"],"sourcesContent":["import {\n assignPrototypeAPIs,\n type Column,\n type RowData,\n type TableFeature,\n type TableFeatures,\n} from '@tanstack/react-table';\nimport type { ColumnAlign } from './column-alignment-feature.types';\n\n/** O alinhamento de uma coluna sem `align` na definição. */\nconst DEFAULT_COLUMN_ALIGN: ColumnAlign = 'start';\n\n/**\n * Feature do TanStack Table para o alinhamento por coluna. Registre com essa chave:\n * `tableFeatures({ columnAlignmentFeature })`.\n *\n * Não tem estado: o alinhamento vem do `align` da definição da coluna, e não muda em runtime. A\n * `DataTable.Cell` e a `DataTable.HeaderCell` o leem por `column.getAlign()` e o marcam em\n * `data-align`.\n *\n * @example\n * ```ts\n * const features = tableFeatures({ columnSizingFeature, columnAlignmentFeature });\n *\n * const columns = columnHelper.columns([\n * columnHelper.accessor('name', { header: 'Nome' }),\n * columnHelper.accessor('total', { header: 'Total', align: 'end' }),\n * ]);\n * ```\n */\nexport const columnAlignmentFeature: TableFeature = {\n assignColumnPrototype: (prototype, table) => {\n assignPrototypeAPIs('columnAlignmentFeature', prototype, table, {\n column_getAlign: {\n /**\n * O TanStack chama com a coluna de uma tabela qualquer: o tipo com todas as features é o\n * que conhece o `align`.\n */\n fn: (column: Column<TableFeatures, RowData>) =>\n column.columnDef.align ?? DEFAULT_COLUMN_ALIGN,\n },\n });\n },\n};\n"],"mappings":";;;AAUA,MAAM,uBAAoC;;;;;;;;;;;;;;;;;;;AAoB1C,MAAa,yBAAuC,EAClD,wBAAwB,WAAW,UAAU;CAC3C,oBAAoB,0BAA0B,WAAW,OAAO,EAC9D,iBAAiB;;;;;AAKf,KAAK,WACH,OAAO,UAAU,SAAS,qBAC9B,EACF,CAAC;AACH,EACF"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { CellData, RowData, TableFeature, TableFeatures } from "@tanstack/react-table";
|
|
2
|
+
//#region src/features/column-alignment/column-alignment-feature.types.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* O alinhamento do conteúdo de uma coluna. Em direção lógica: `start` e `end` seguem a direção
|
|
5
|
+
* do texto, à esquerda e à direita num idioma LTR.
|
|
6
|
+
*/
|
|
7
|
+
export type ColumnAlign = 'start' | 'center' | 'end';
|
|
8
|
+
/** As opções da feature na definição da coluna. */
|
|
9
|
+
export type ColumnDef_ColumnAlignment = {
|
|
10
|
+
/**
|
|
11
|
+
* O alinhamento do conteúdo das células e do header da coluna. Para mudar o padrão da tabela
|
|
12
|
+
* inteira, passe no `defaultColumn`.
|
|
13
|
+
* @default 'start'
|
|
14
|
+
*/
|
|
15
|
+
align?: ColumnAlign;
|
|
16
|
+
};
|
|
17
|
+
/** As APIs da feature na coluna. */
|
|
18
|
+
export type Column_ColumnAlignment = {
|
|
19
|
+
/** O alinhamento da coluna: o `align` da definição, ou `'start'`. */
|
|
20
|
+
getAlign: () => ColumnAlign;
|
|
21
|
+
};
|
|
22
|
+
declare module '@tanstack/react-table' {
|
|
23
|
+
interface Plugins {
|
|
24
|
+
columnAlignmentFeature: TableFeature;
|
|
25
|
+
}
|
|
26
|
+
interface ColumnDef_FeatureMap<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData> {
|
|
27
|
+
columnAlignmentFeature: ColumnDef_ColumnAlignment;
|
|
28
|
+
}
|
|
29
|
+
interface Column_FeatureMap<TFeatures extends TableFeatures, TData extends RowData> {
|
|
30
|
+
columnAlignmentFeature: Column_ColumnAlignment;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
34
|
+
//# sourceMappingURL=column-alignment-feature.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"column-alignment-feature.types.d.ts","names":[],"sources":["../../../src/features/column-alignment/column-alignment-feature.types.ts"],"mappings":";;;;;;YAYY;;YAGA;;;;;;EAMV,QAAQ;;;YAIE;;EAEV,gBAAgB;;;YASN;IACR,wBAAwB;;YAGhB,qBACR,kBAAkB,eAClB,cAAc,SACd,eAAe;IAEf,wBAAwB;;YAGhB,kBACR,kBAAkB,eAClB,cAAc;IAEd,wBAAwB"}
|
|
File without changes
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { activeRowFeature } from "./active-row/active-row-feature.js";
|
|
2
|
+
import { Row_ActiveRow, TableOptions_ActiveRow, TableState_ActiveRow, Table_ActiveRow } from "./active-row/active-row-feature.types.js";
|
|
3
|
+
import { columnAlignmentFeature } from "./column-alignment/column-alignment-feature.js";
|
|
4
|
+
import { ColumnAlign, ColumnDef_ColumnAlignment, Column_ColumnAlignment } from "./column-alignment/column-alignment-feature.types.js";
|
|
5
|
+
import { loadingFeature } from "./loading/loading-feature.js";
|
|
6
|
+
import { TableOptions_Loading, TableState_Loading, Table_Loading } from "./loading/loading-feature.types.js";
|
|
7
|
+
import { rowDensityFeature } from "./row-density/row-density-feature.js";
|
|
8
|
+
import { RowDensity, TableOptions_RowDensity, TableState_RowDensity, Table_RowDensity } from "./row-density/row-density-feature.types.js";
|
|
9
|
+
export { type ColumnAlign, type ColumnDef_ColumnAlignment, type Column_ColumnAlignment, type RowDensity, type Row_ActiveRow, type TableOptions_ActiveRow, type TableOptions_Loading, type TableOptions_RowDensity, type TableState_ActiveRow, type TableState_Loading, type TableState_RowDensity, type Table_ActiveRow, type Table_Loading, type Table_RowDensity, activeRowFeature, columnAlignmentFeature, loadingFeature, rowDensityFeature };
|