pallote-react 0.16.7 → 0.16.9

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.
@@ -1,14 +1,21 @@
1
1
  import { ReactNode, HTMLAttributes } from 'react';
2
+ import { type TableCellKind } from './TableCell';
2
3
  export type DataTableFilterType = 'text' | 'select';
4
+ /** Option value for filtering; label is shown in the dropdown. Use when row values are raw (e.g. in_progress) but you want formatted labels (e.g. In progress). */
5
+ export type DataTableFilterOption = string | {
6
+ value: string;
7
+ label: string;
8
+ };
3
9
  export interface DataTableColumnDef<TData> {
4
10
  accessorKey: keyof TData & string;
5
11
  header: string;
6
12
  enableSorting?: boolean;
7
13
  enableFiltering?: boolean;
8
14
  filterType?: DataTableFilterType;
9
- filterOptions?: string[];
15
+ filterOptions?: DataTableFilterOption[];
10
16
  cell?: (value: TData[keyof TData & string], row: TData) => ReactNode;
11
17
  className?: string;
18
+ kind?: TableCellKind;
12
19
  }
13
20
  export interface DataTableProps<TData> extends Omit<HTMLAttributes<HTMLDivElement>, 'children'> {
14
21
  data: TData[];
@@ -22,5 +29,6 @@ export interface DataTableProps<TData> extends Omit<HTMLAttributes<HTMLDivElemen
22
29
  dense?: boolean;
23
30
  border?: boolean;
24
31
  className?: string;
32
+ kind?: TableCellKind;
25
33
  }
26
- export declare function DataTable<TData extends Record<string, unknown>>({ data, columns: columnDefs, enableSearch, searchPlaceholder, pageSize: initialPageSize, pageSizeOptions, striped, hasHover, dense, border, className, ...props }: DataTableProps<TData>): import("react/jsx-runtime").JSX.Element;
34
+ export declare function DataTable<TData extends Record<string, unknown>>({ data, columns: columnDefs, enableSearch, searchPlaceholder, pageSize: initialPageSize, pageSizeOptions, striped, hasHover, dense, border, kind: defaultKind, className, ...props }: DataTableProps<TData>): import("react/jsx-runtime").JSX.Element;
@@ -1,9 +1,8 @@
1
1
  import { TdHTMLAttributes, ReactNode } from 'react';
2
- type TableCellKind = 'default' | 'number' | 'action';
2
+ export type TableCellKind = 'default' | 'number' | 'action';
3
3
  export interface TableCellProps extends TdHTMLAttributes<HTMLTableCellElement> {
4
4
  kind?: TableCellKind;
5
5
  className?: string;
6
6
  children?: ReactNode;
7
7
  }
8
8
  export declare const TableCell: ({ kind, className, children, ...props }: TableCellProps) => import("react/jsx-runtime").JSX.Element;
9
- export {};
package/dist/index.d.ts CHANGED
@@ -68,7 +68,7 @@ export type { CardMediaProps } from './components/CardMedia';
68
68
  export type { CheckboxProps } from './components/Checkbox';
69
69
  export type { CheckboxesProps } from './components/Checkboxes';
70
70
  export type { ChipProps } from './components/Chip';
71
- export type { DataTableProps, DataTableColumnDef, DataTableFilterType } from './components/DataTable';
71
+ export type { DataTableProps, DataTableColumnDef, DataTableFilterType, DataTableFilterOption } from './components/DataTable';
72
72
  export type { DividerProps } from './components/Divider';
73
73
  export type { InputProps } from './components/Input';
74
74
  export type { InputLabelProps } from './components/InputLabel';
@@ -92,7 +92,7 @@ export type { SwitchProps } from './components/Switch';
92
92
  export type { TabProps } from './components/Tab';
93
93
  export type { TableProps } from './components/Table';
94
94
  export type { TableBodyProps } from './components/TableBody';
95
- export type { TableCellProps } from './components/TableCell';
95
+ export type { TableCellProps, TableCellKind } from './components/TableCell';
96
96
  export type { TablePaginationProps } from './components/TablePagination';
97
97
  export type { TableHeadProps } from './components/TableHead';
98
98
  export type { TableRowProps } from './components/TableRow';
package/dist/index.js CHANGED
@@ -790,17 +790,21 @@ const Input = ({ onChange, type = 'text', id, placeholder, label = 'Input', icon
790
790
  : null), ...props })] }));
791
791
  };
792
792
 
793
+ function normalizeFilterOption(opt) {
794
+ return typeof opt === 'string' ? { value: opt, label: opt } : opt;
795
+ }
793
796
  function ColumnFilter({ header }) {
794
797
  const columnDef = header.column.columnDef.meta;
795
798
  const filterType = columnDef?.filterType ?? 'text';
796
799
  const filterOptions = columnDef?.filterOptions ?? [];
797
800
  const filterValue = header.column.getFilterValue() ?? '';
798
801
  if (filterType === 'select') {
799
- return (jsxs(Select, { dense: true, id: `filter-${header.id}`, label: `Filter ${header.column.columnDef.header}`, hideLabel: true, className: "datatable_filter", value: filterValue, onChange: (e) => header.column.setFilterValue(e.target.value || undefined), children: [jsx("option", { value: "", children: "All" }), filterOptions.map(opt => (jsx("option", { value: opt, children: opt }, opt)))] }));
802
+ const options = filterOptions.map(normalizeFilterOption);
803
+ return (jsxs(Select, { dense: true, id: `filter-${header.id}`, label: `Filter ${header.column.columnDef.header}`, hideLabel: true, className: "datatable_filter", value: filterValue, onChange: (e) => header.column.setFilterValue(e.target.value || undefined), children: [jsx("option", { value: "", children: "All" }), options.map(({ value, label }) => (jsx("option", { value: value, children: label }, value)))] }));
800
804
  }
801
805
  return (jsx(Input, { dense: true, id: `filter-${header.id}`, label: `Filter ${header.column.columnDef.header}`, hideLabel: true, placeholder: "Filter...", className: "datatable_filter", value: filterValue, onChange: (e) => header.column.setFilterValue(e.target.value || undefined) }));
802
806
  }
803
- function DataTable({ data, columns: columnDefs, enableSearch, searchPlaceholder = 'Search...', pageSize: initialPageSize = 10, pageSizeOptions = [10, 25, 50, 100], striped, hasHover = true, dense, border, className, ...props }) {
807
+ function DataTable({ data, columns: columnDefs, enableSearch, searchPlaceholder = 'Search...', pageSize: initialPageSize = 10, pageSizeOptions = [10, 25, 50, 100], striped, hasHover = true, dense, border, kind: defaultKind, className, ...props }) {
804
808
  const [sorting, setSorting] = useState([]);
805
809
  const [columnFilters, setColumnFilters] = useState([]);
806
810
  const [globalFilter, setGlobalFilter] = useState('');
@@ -816,6 +820,7 @@ function DataTable({ data, columns: columnDefs, enableSearch, searchPlaceholder
816
820
  filterType: col.filterType ?? 'text',
817
821
  filterOptions: col.filterOptions,
818
822
  className: col.className,
823
+ kind: col.kind,
819
824
  },
820
825
  })), [columnDefs]);
821
826
  const table = useReactTable({
@@ -836,17 +841,20 @@ function DataTable({ data, columns: columnDefs, enableSearch, searchPlaceholder
836
841
  const hasFilters = columnDefs.some(col => col.enableFiltering === true);
837
842
  return (jsxs("div", { className: classnames('datatable', className), ...props, children: [enableSearch && (jsx("div", { className: "datatable_search", children: jsx(Input, { id: "datatable-search", label: "Search", hideLabel: true, placeholder: searchPlaceholder, icon: jsx(MagnifyingGlassIcon, {}), value: globalFilter, onChange: (e) => setGlobalFilter(e.target.value) }) })), jsxs(Table, { striped: striped, hasHover: hasHover, dense: dense, border: border, children: [jsxs(TableHead, { children: [table.getHeaderGroups().map(headerGroup => (jsx(TableRow, { children: headerGroup.headers.map(header => {
838
843
  const meta = header.column.columnDef.meta;
839
- return (jsx(TableCell, { className: classnames(meta?.className, {
844
+ const cellKind = meta?.kind ?? defaultKind ?? 'default';
845
+ return (jsx(TableCell, { kind: cellKind, className: classnames(meta?.className, {
840
846
  'datatable_sortable': header.column.getCanSort()
841
847
  }), onClick: header.column.getToggleSortingHandler(), "aria-sort": header.column.getIsSorted() === 'asc' ? 'ascending'
842
848
  : header.column.getIsSorted() === 'desc' ? 'descending'
843
849
  : undefined, children: jsxs("span", { className: "datatable_headerContent", children: [flexRender(header.column.columnDef.header, header.getContext()), header.column.getCanSort() && (jsx("span", { className: "datatable_sortIcon", "aria-hidden": "true", children: header.column.getIsSorted() === 'asc' ? (jsx(CaretDownIcon, { size: 12 })) : header.column.getIsSorted() === 'desc' ? (jsx(CaretUpIcon, { size: 12 })) : (jsx(CaretDownIcon, { size: 12, className: "datatable_sortIcon-inactive" })) }))] }) }, header.id));
844
850
  }) }, headerGroup.id))), hasFilters && (jsx(TableRow, { className: "datatable_filterRow", children: table.getHeaderGroups()[0].headers.map(header => {
845
851
  const meta = header.column.columnDef.meta;
846
- return (jsx(TableCell, { className: meta?.className, children: header.column.getCanFilter() ? (jsx(ColumnFilter, { header: header })) : null }, `filter-${header.id}`));
852
+ const cellKind = meta?.kind ?? defaultKind ?? 'default';
853
+ return (jsx(TableCell, { kind: cellKind, className: meta?.className, children: header.column.getCanFilter() ? (jsx(ColumnFilter, { header: header })) : null }, `filter-${header.id}`));
847
854
  }) }))] }), jsx(TableBody, { children: table.getRowModel().rows.length === 0 ? (jsx(TableRow, { children: jsx(TableCell, { colSpan: columnDefs.length, className: "datatable_empty", children: "No results found" }) })) : (table.getRowModel().rows.map(row => (jsx(TableRow, { children: row.getVisibleCells().map(cell => {
848
855
  const meta = cell.column.columnDef.meta;
849
- return (jsx(TableCell, { className: meta?.className, children: flexRender(cell.column.columnDef.cell, cell.getContext()) }, cell.id));
856
+ const cellKind = meta?.kind ?? defaultKind ?? 'default';
857
+ return (jsx(TableCell, { kind: cellKind, className: meta?.className, children: flexRender(cell.column.columnDef.cell, cell.getContext()) }, cell.id));
850
858
  }) }, row.id)))) })] }), jsx(TablePagination, { pageIndex: table.getState().pagination.pageIndex, pageCount: table.getPageCount(), pageSize: table.getState().pagination.pageSize, pageSizeOptions: pageSizeOptions, totalRows: table.getFilteredRowModel().rows.length, onPageChange: (page) => table.setPageIndex(page), onPageSizeChange: (size) => table.setPageSize(size) })] }));
851
859
  }
852
860
 
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pallote-react",
3
- "version": "0.16.7",
3
+ "version": "0.16.9",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pallote-react",
3
- "version": "0.16.7",
3
+ "version": "0.16.9",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",