@ethanhann/mantine-dataview 0.5.0 → 0.7.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/README.md CHANGED
@@ -426,6 +426,24 @@ col.accessor("revenue", {
426
426
  });
427
427
  ```
428
428
 
429
+ ## View mode in cell renderers
430
+
431
+ Cell renderers can check whether they're rendering in table or card view using `getViewMode`:
432
+
433
+ ```tsx
434
+ import { getViewMode } from "@ethanhann/mantine-dataview";
435
+
436
+ col.accessor("name", {
437
+ cell: (ctx) => {
438
+ const mode = getViewMode(ctx); // "table" | "cards"
439
+ return mode === "cards" ? <Text>{ctx.getValue()}</Text> : <Anchor>{ctx.getValue()}</Anchor>;
440
+ },
441
+ });
442
+ ```
443
+
444
+ `getViewMode` accepts a cell context, header context, or table instance. It updates
445
+ automatically when the user toggles the view.
446
+
429
447
  ## CSV export
430
448
 
431
449
  Export the current page's visible columns as a CSV file:
@@ -0,0 +1,4 @@
1
+ import { CellContext, HeaderContext, Table } from '@tanstack/react-table';
2
+ import { ViewMode } from '../types/state';
3
+ /** Get the current view mode from a cell context. */
4
+ export declare function getViewMode<TData>(ctx: CellContext<TData, unknown> | HeaderContext<TData, unknown> | Table<TData>): ViewMode;
package/dist/index.d.ts CHANGED
@@ -10,6 +10,7 @@ export type { CardSlotContext, DataViewSlots, EmptySlotContext, ErrorSlotContext
10
10
  export { type CardField, type CardLayout, type CardLayoutRole, type ComposeCardOptions, composeCardLayout, resolveColumnLabel, } from './core/cardComposition';
11
11
  export { type ColOptions, ColumnBuilder, col } from './core/colBuilder';
12
12
  export { type ExportCsvOptions, exportCsv } from './core/exportCsv';
13
+ export { getViewMode } from './core/getViewMode';
13
14
  export { useDataView } from './core/useDataView';
14
15
  export { type UseDataViewFetcherOptions, useDataViewFetcher, } from './core/useDataViewFetcher';
15
16
  export type { CardFieldMeta, CardRole, ColumnAlign, ColumnDataType, ColumnFilterMeta, ColumnFormatOption, CustomFilterComponentProps, DataColumnDef, DateFormatOptions, FilterOption, FilterVariant, NumberFormatOptions, } from './types/column';