@dynostack/react-grid 0.2.0 → 0.3.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/dist/index.d.cts CHANGED
@@ -1,5 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { RowData, ColumnDef, SortingState, ColumnFiltersState, ColumnPinningState, VisibilityState, Column, Table, CellContext, FilterFn } from '@tanstack/react-table';
2
+ import { Column, RowData, ColumnDef, SortingState, ColumnFiltersState, ColumnPinningState, VisibilityState, Table, CellContext, FilterFn } from '@tanstack/react-table';
3
+ import * as React$1 from 'react';
3
4
  import { CSSProperties } from 'react';
4
5
 
5
6
  type RowActionId = "view" | "edit" | "duplicate" | "delete" | string;
@@ -140,6 +141,57 @@ type DataTableThemeName = keyof typeof themePresets;
140
141
  declare const ISOLATE_LIGHT_TOKENS: DataTableTokens;
141
142
  declare const ISOLATE_DARK_TOKENS: DataTableTokens;
142
143
 
144
+ type SheetSide = "right" | "left" | "top" | "bottom";
145
+
146
+ type ViewSheetDensity = "compact" | "relaxed" | "comfy";
147
+ type ViewSheetLabels = {
148
+ title?: (row: any) => React.ReactNode;
149
+ description?: (row: any) => React.ReactNode;
150
+ emptyValue?: string;
151
+ density?: {
152
+ compact?: string;
153
+ relaxed?: string;
154
+ comfy?: string;
155
+ };
156
+ };
157
+ type ViewSheetConfig<TData> = {
158
+ /** Side of the screen to slide in from. Defaults to "right". */
159
+ side?: SheetSide;
160
+ /** Initial column count. Defaults to "compact" (1 column). */
161
+ defaultDensity?: ViewSheetDensity;
162
+ /** Hide the density tabs entirely if you want a fixed layout. */
163
+ hideDensityTabs?: boolean;
164
+ /** Override how a field's value is rendered. */
165
+ renderField?: (args: {
166
+ column: Column<TData, unknown>;
167
+ value: unknown;
168
+ row: TData;
169
+ }) => React.ReactNode;
170
+ /** Custom header for the sheet. */
171
+ renderHeader?: (row: TData) => React.ReactNode;
172
+ /** Filter / reorder which columns appear. Defaults to all visible columns. */
173
+ fields?: string[];
174
+ /** Override label / placeholder strings. */
175
+ labels?: ViewSheetLabels;
176
+ };
177
+
178
+ type ConfirmDeleteContext<TData> = {
179
+ /** The rows being deleted. Single-row delete passes one row; bulk passes many. */
180
+ rows: TData[];
181
+ /** "single" when triggered from the row actions menu; "bulk" from the toolbar. */
182
+ source: "single" | "bulk";
183
+ };
184
+ type ConfirmDeleteConfig<TData> = {
185
+ /** Modal title. Receives the same context the resolver receives. */
186
+ title?: (ctx: ConfirmDeleteContext<TData>) => React.ReactNode;
187
+ /** Modal description / body. */
188
+ description?: (ctx: ConfirmDeleteContext<TData>) => React.ReactNode;
189
+ /** Confirm button label. Defaults to "Delete". */
190
+ confirmLabel?: string;
191
+ /** Cancel button label. Defaults to "Cancel". */
192
+ cancelLabel?: string;
193
+ };
194
+
143
195
  type CellEditorType = "text" | "number" | "currency" | "date" | "select" | "switch" | "checkbox";
144
196
  type FilterType = "text" | "number" | "select" | "multi-select" | "boolean" | "date";
145
197
  type SelectOption = {
@@ -269,6 +321,30 @@ type DataTableProps<TData extends {
269
321
  rowActions?: ("view" | "edit" | "duplicate" | "delete")[];
270
322
  customRowActions?: CustomRowAction<TData>[];
271
323
  onRowAction?: (action: RowActionId, row: TData) => void;
324
+ /**
325
+ * Handler for the built-in "View" action. If omitted, the grid still opens
326
+ * the View sheet (unless `viewSheet={false}`). Use this to also log,
327
+ * navigate, or fetch detail data when a user opens View.
328
+ */
329
+ onView?: (row: TData) => void;
330
+ /**
331
+ * Handler for the built-in "Delete" action. Fires *after* the user confirms
332
+ * in the delete modal (or immediately if `confirmDelete={false}`).
333
+ * If omitted, the grid only emits via `onRowAction("delete", row)`.
334
+ */
335
+ onDelete?: (row: TData) => void;
336
+ /**
337
+ * Configure the built-in View sheet — side, density, custom renderers.
338
+ * Pass `false` to disable; clicking "View" will then only fire
339
+ * `onView` / `onRowAction` without opening a sheet.
340
+ */
341
+ viewSheet?: ViewSheetConfig<TData> | false;
342
+ /**
343
+ * Configure the delete confirmation modal. Pass `false` to disable it and
344
+ * fire delete handlers immediately. Pass an object to customize title,
345
+ * description, and button labels. Defaults to enabled with built-in copy.
346
+ */
347
+ confirmDelete?: ConfirmDeleteConfig<TData> | boolean;
272
348
  /** Commit a single edited cell. Receives the row, column id and new value. */
273
349
  onCellEdit?: (row: TData, columnId: string, value: unknown) => void;
274
350
  /** Commit an entire row in row-edit mode. */
@@ -320,7 +396,31 @@ type DataTableProps<TData extends {
320
396
  };
321
397
  declare function DataTable<TData extends {
322
398
  id: string | number;
323
- }>({ data, columns, dataSource, isLoading, isFetching, onRefresh, totalRecords, exportFileName, enableSelection, renderSubRow, getSubRows, rowActions, customRowActions, onRowAction, onCellEdit, onRowSave, onAddRow, onBulkDelete, initialPageSize, pageSizeOptions, initialColumnPinning, initialColumnVisibility, globalFilter: globalFilterProp, onGlobalFilterChange, className, toolbarSlot, features, labels: labelsProp, density, theme, isolate, }: DataTableProps<TData>): react_jsx_runtime.JSX.Element;
399
+ }>({ data, columns, dataSource, isLoading, isFetching, onRefresh, totalRecords, exportFileName, enableSelection, renderSubRow, getSubRows, rowActions, customRowActions, onRowAction, onCellEdit, onRowSave, onAddRow, onBulkDelete, initialPageSize, pageSizeOptions, initialColumnPinning, initialColumnVisibility, globalFilter: globalFilterProp, onGlobalFilterChange, className, toolbarSlot, features, labels: labelsProp, density, theme, isolate, onView, onDelete, viewSheet, confirmDelete, }: DataTableProps<TData>): react_jsx_runtime.JSX.Element;
400
+
401
+ /**
402
+ * Shared portal container for every overlay inside a DataTable (popover,
403
+ * dropdown, select, sheet, alert-dialog, …).
404
+ *
405
+ * `<DataTable>` provides a ref pointing to a `<div>` rendered *inside* the
406
+ * themed grid root. When the value is non-null, every overlay primitive
407
+ * mounts its portal into that div instead of `document.body`.
408
+ *
409
+ * Why this matters
410
+ * ----------------
411
+ * CSS variables cascade only down the DOM tree. The grid's `theme` prop
412
+ * applies inline tokens to the grid root — if a popover portals to
413
+ * `document.body` (Radix default), those tokens never reach the popover and
414
+ * its `bg-primary` / `bg-popover` / `border` etc. resolve from `:root`
415
+ * instead. That's why a `theme={themePresets.rose}` table can show a black
416
+ * "Apply" button on a white popover surrounded by a rose grid.
417
+ *
418
+ * Mounting overlays inside the themed root fixes this cleanly with no global
419
+ * CSS pollution.
420
+ */
421
+ declare const PortalContainerContext: React$1.Context<HTMLElement | null>;
422
+ /** Read the current grid's portal container, or `null` when outside a DataTable. */
423
+ declare function usePortalContainer(): HTMLElement | null;
324
424
 
325
425
  type Props$2<TData, TValue> = {
326
426
  column: Column<TData, TValue>;
@@ -412,4 +512,4 @@ declare function ColumnFilterPanel<TData, TValue>(props: CommonProps<TData, TVal
412
512
  declare function exportToCsv<TData>(table: Table<TData>, fileName?: string): void;
413
513
  declare function exportToExcel<TData>(table: Table<TData>, fileName?: string): void;
414
514
 
415
- export { type AdvFilter, type CellEditorType, ColumnFilterPanel, type Combine, type Condition, type CustomRowAction, DataTable, type DataTableColumn, DataTableColumnHeader, type DataTableDataSource, type DataTableDataSourceResult, type DataTableDensity, type DataTableErrorContext, type DataTableFeatures, type DataTableFetchParams, type DataTableLabels, type DataTableModedTheme, DataTablePagination, type DataTableProps, DataTableRowActions, type DataTableRowActionsProps, type DataTableTheme, type DataTableThemeName, type DataTableTokens, DataTableToolbar, type DateOp, EditableCell, type FilterType, ISOLATE_DARK_TOKENS, ISOLATE_LIGHT_TOKENS, type NumberOp, type RowAction, type RowActionId, type SelectOption, type SetFilter, type TextOp, booleanFilterFn, buildPreset, dateFilterFn, exportToCsv, exportToExcel, isFilterActive, numberFilterFn, setFilterFn, splitTheme, textFilterFn, themePresets, themeToStyle, tokensToCssBlock, tokensToStyle };
515
+ export { type AdvFilter, type CellEditorType, ColumnFilterPanel, type Combine, type Condition, type ConfirmDeleteConfig, type ConfirmDeleteContext, type CustomRowAction, DataTable, type DataTableColumn, DataTableColumnHeader, type DataTableDataSource, type DataTableDataSourceResult, type DataTableDensity, type DataTableErrorContext, type DataTableFeatures, type DataTableFetchParams, type DataTableLabels, type DataTableModedTheme, DataTablePagination, type DataTableProps, DataTableRowActions, type DataTableRowActionsProps, type DataTableTheme, type DataTableThemeName, type DataTableTokens, DataTableToolbar, type DateOp, EditableCell, type FilterType, ISOLATE_DARK_TOKENS, ISOLATE_LIGHT_TOKENS, type NumberOp, PortalContainerContext, type RowAction, type RowActionId, type SelectOption, type SetFilter, type TextOp, type ViewSheetConfig, type ViewSheetDensity, type ViewSheetLabels, booleanFilterFn, buildPreset, dateFilterFn, exportToCsv, exportToExcel, isFilterActive, numberFilterFn, setFilterFn, splitTheme, textFilterFn, themePresets, themeToStyle, tokensToCssBlock, tokensToStyle, usePortalContainer };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { RowData, ColumnDef, SortingState, ColumnFiltersState, ColumnPinningState, VisibilityState, Column, Table, CellContext, FilterFn } from '@tanstack/react-table';
2
+ import { Column, RowData, ColumnDef, SortingState, ColumnFiltersState, ColumnPinningState, VisibilityState, Table, CellContext, FilterFn } from '@tanstack/react-table';
3
+ import * as React$1 from 'react';
3
4
  import { CSSProperties } from 'react';
4
5
 
5
6
  type RowActionId = "view" | "edit" | "duplicate" | "delete" | string;
@@ -140,6 +141,57 @@ type DataTableThemeName = keyof typeof themePresets;
140
141
  declare const ISOLATE_LIGHT_TOKENS: DataTableTokens;
141
142
  declare const ISOLATE_DARK_TOKENS: DataTableTokens;
142
143
 
144
+ type SheetSide = "right" | "left" | "top" | "bottom";
145
+
146
+ type ViewSheetDensity = "compact" | "relaxed" | "comfy";
147
+ type ViewSheetLabels = {
148
+ title?: (row: any) => React.ReactNode;
149
+ description?: (row: any) => React.ReactNode;
150
+ emptyValue?: string;
151
+ density?: {
152
+ compact?: string;
153
+ relaxed?: string;
154
+ comfy?: string;
155
+ };
156
+ };
157
+ type ViewSheetConfig<TData> = {
158
+ /** Side of the screen to slide in from. Defaults to "right". */
159
+ side?: SheetSide;
160
+ /** Initial column count. Defaults to "compact" (1 column). */
161
+ defaultDensity?: ViewSheetDensity;
162
+ /** Hide the density tabs entirely if you want a fixed layout. */
163
+ hideDensityTabs?: boolean;
164
+ /** Override how a field's value is rendered. */
165
+ renderField?: (args: {
166
+ column: Column<TData, unknown>;
167
+ value: unknown;
168
+ row: TData;
169
+ }) => React.ReactNode;
170
+ /** Custom header for the sheet. */
171
+ renderHeader?: (row: TData) => React.ReactNode;
172
+ /** Filter / reorder which columns appear. Defaults to all visible columns. */
173
+ fields?: string[];
174
+ /** Override label / placeholder strings. */
175
+ labels?: ViewSheetLabels;
176
+ };
177
+
178
+ type ConfirmDeleteContext<TData> = {
179
+ /** The rows being deleted. Single-row delete passes one row; bulk passes many. */
180
+ rows: TData[];
181
+ /** "single" when triggered from the row actions menu; "bulk" from the toolbar. */
182
+ source: "single" | "bulk";
183
+ };
184
+ type ConfirmDeleteConfig<TData> = {
185
+ /** Modal title. Receives the same context the resolver receives. */
186
+ title?: (ctx: ConfirmDeleteContext<TData>) => React.ReactNode;
187
+ /** Modal description / body. */
188
+ description?: (ctx: ConfirmDeleteContext<TData>) => React.ReactNode;
189
+ /** Confirm button label. Defaults to "Delete". */
190
+ confirmLabel?: string;
191
+ /** Cancel button label. Defaults to "Cancel". */
192
+ cancelLabel?: string;
193
+ };
194
+
143
195
  type CellEditorType = "text" | "number" | "currency" | "date" | "select" | "switch" | "checkbox";
144
196
  type FilterType = "text" | "number" | "select" | "multi-select" | "boolean" | "date";
145
197
  type SelectOption = {
@@ -269,6 +321,30 @@ type DataTableProps<TData extends {
269
321
  rowActions?: ("view" | "edit" | "duplicate" | "delete")[];
270
322
  customRowActions?: CustomRowAction<TData>[];
271
323
  onRowAction?: (action: RowActionId, row: TData) => void;
324
+ /**
325
+ * Handler for the built-in "View" action. If omitted, the grid still opens
326
+ * the View sheet (unless `viewSheet={false}`). Use this to also log,
327
+ * navigate, or fetch detail data when a user opens View.
328
+ */
329
+ onView?: (row: TData) => void;
330
+ /**
331
+ * Handler for the built-in "Delete" action. Fires *after* the user confirms
332
+ * in the delete modal (or immediately if `confirmDelete={false}`).
333
+ * If omitted, the grid only emits via `onRowAction("delete", row)`.
334
+ */
335
+ onDelete?: (row: TData) => void;
336
+ /**
337
+ * Configure the built-in View sheet — side, density, custom renderers.
338
+ * Pass `false` to disable; clicking "View" will then only fire
339
+ * `onView` / `onRowAction` without opening a sheet.
340
+ */
341
+ viewSheet?: ViewSheetConfig<TData> | false;
342
+ /**
343
+ * Configure the delete confirmation modal. Pass `false` to disable it and
344
+ * fire delete handlers immediately. Pass an object to customize title,
345
+ * description, and button labels. Defaults to enabled with built-in copy.
346
+ */
347
+ confirmDelete?: ConfirmDeleteConfig<TData> | boolean;
272
348
  /** Commit a single edited cell. Receives the row, column id and new value. */
273
349
  onCellEdit?: (row: TData, columnId: string, value: unknown) => void;
274
350
  /** Commit an entire row in row-edit mode. */
@@ -320,7 +396,31 @@ type DataTableProps<TData extends {
320
396
  };
321
397
  declare function DataTable<TData extends {
322
398
  id: string | number;
323
- }>({ data, columns, dataSource, isLoading, isFetching, onRefresh, totalRecords, exportFileName, enableSelection, renderSubRow, getSubRows, rowActions, customRowActions, onRowAction, onCellEdit, onRowSave, onAddRow, onBulkDelete, initialPageSize, pageSizeOptions, initialColumnPinning, initialColumnVisibility, globalFilter: globalFilterProp, onGlobalFilterChange, className, toolbarSlot, features, labels: labelsProp, density, theme, isolate, }: DataTableProps<TData>): react_jsx_runtime.JSX.Element;
399
+ }>({ data, columns, dataSource, isLoading, isFetching, onRefresh, totalRecords, exportFileName, enableSelection, renderSubRow, getSubRows, rowActions, customRowActions, onRowAction, onCellEdit, onRowSave, onAddRow, onBulkDelete, initialPageSize, pageSizeOptions, initialColumnPinning, initialColumnVisibility, globalFilter: globalFilterProp, onGlobalFilterChange, className, toolbarSlot, features, labels: labelsProp, density, theme, isolate, onView, onDelete, viewSheet, confirmDelete, }: DataTableProps<TData>): react_jsx_runtime.JSX.Element;
400
+
401
+ /**
402
+ * Shared portal container for every overlay inside a DataTable (popover,
403
+ * dropdown, select, sheet, alert-dialog, …).
404
+ *
405
+ * `<DataTable>` provides a ref pointing to a `<div>` rendered *inside* the
406
+ * themed grid root. When the value is non-null, every overlay primitive
407
+ * mounts its portal into that div instead of `document.body`.
408
+ *
409
+ * Why this matters
410
+ * ----------------
411
+ * CSS variables cascade only down the DOM tree. The grid's `theme` prop
412
+ * applies inline tokens to the grid root — if a popover portals to
413
+ * `document.body` (Radix default), those tokens never reach the popover and
414
+ * its `bg-primary` / `bg-popover` / `border` etc. resolve from `:root`
415
+ * instead. That's why a `theme={themePresets.rose}` table can show a black
416
+ * "Apply" button on a white popover surrounded by a rose grid.
417
+ *
418
+ * Mounting overlays inside the themed root fixes this cleanly with no global
419
+ * CSS pollution.
420
+ */
421
+ declare const PortalContainerContext: React$1.Context<HTMLElement | null>;
422
+ /** Read the current grid's portal container, or `null` when outside a DataTable. */
423
+ declare function usePortalContainer(): HTMLElement | null;
324
424
 
325
425
  type Props$2<TData, TValue> = {
326
426
  column: Column<TData, TValue>;
@@ -412,4 +512,4 @@ declare function ColumnFilterPanel<TData, TValue>(props: CommonProps<TData, TVal
412
512
  declare function exportToCsv<TData>(table: Table<TData>, fileName?: string): void;
413
513
  declare function exportToExcel<TData>(table: Table<TData>, fileName?: string): void;
414
514
 
415
- export { type AdvFilter, type CellEditorType, ColumnFilterPanel, type Combine, type Condition, type CustomRowAction, DataTable, type DataTableColumn, DataTableColumnHeader, type DataTableDataSource, type DataTableDataSourceResult, type DataTableDensity, type DataTableErrorContext, type DataTableFeatures, type DataTableFetchParams, type DataTableLabels, type DataTableModedTheme, DataTablePagination, type DataTableProps, DataTableRowActions, type DataTableRowActionsProps, type DataTableTheme, type DataTableThemeName, type DataTableTokens, DataTableToolbar, type DateOp, EditableCell, type FilterType, ISOLATE_DARK_TOKENS, ISOLATE_LIGHT_TOKENS, type NumberOp, type RowAction, type RowActionId, type SelectOption, type SetFilter, type TextOp, booleanFilterFn, buildPreset, dateFilterFn, exportToCsv, exportToExcel, isFilterActive, numberFilterFn, setFilterFn, splitTheme, textFilterFn, themePresets, themeToStyle, tokensToCssBlock, tokensToStyle };
515
+ export { type AdvFilter, type CellEditorType, ColumnFilterPanel, type Combine, type Condition, type ConfirmDeleteConfig, type ConfirmDeleteContext, type CustomRowAction, DataTable, type DataTableColumn, DataTableColumnHeader, type DataTableDataSource, type DataTableDataSourceResult, type DataTableDensity, type DataTableErrorContext, type DataTableFeatures, type DataTableFetchParams, type DataTableLabels, type DataTableModedTheme, DataTablePagination, type DataTableProps, DataTableRowActions, type DataTableRowActionsProps, type DataTableTheme, type DataTableThemeName, type DataTableTokens, DataTableToolbar, type DateOp, EditableCell, type FilterType, ISOLATE_DARK_TOKENS, ISOLATE_LIGHT_TOKENS, type NumberOp, PortalContainerContext, type RowAction, type RowActionId, type SelectOption, type SetFilter, type TextOp, type ViewSheetConfig, type ViewSheetDensity, type ViewSheetLabels, booleanFilterFn, buildPreset, dateFilterFn, exportToCsv, exportToExcel, isFilterActive, numberFilterFn, setFilterFn, splitTheme, textFilterFn, themePresets, themeToStyle, tokensToCssBlock, tokensToStyle, usePortalContainer };