pallote-react 0.16.7 → 0.16.8
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,4 +1,5 @@
|
|
|
1
1
|
import { ReactNode, HTMLAttributes } from 'react';
|
|
2
|
+
import { type TableCellKind } from './TableCell';
|
|
2
3
|
export type DataTableFilterType = 'text' | 'select';
|
|
3
4
|
export interface DataTableColumnDef<TData> {
|
|
4
5
|
accessorKey: keyof TData & string;
|
|
@@ -9,6 +10,7 @@ export interface DataTableColumnDef<TData> {
|
|
|
9
10
|
filterOptions?: string[];
|
|
10
11
|
cell?: (value: TData[keyof TData & string], row: TData) => ReactNode;
|
|
11
12
|
className?: string;
|
|
13
|
+
kind?: TableCellKind;
|
|
12
14
|
}
|
|
13
15
|
export interface DataTableProps<TData> extends Omit<HTMLAttributes<HTMLDivElement>, 'children'> {
|
|
14
16
|
data: TData[];
|
|
@@ -22,5 +24,6 @@ export interface DataTableProps<TData> extends Omit<HTMLAttributes<HTMLDivElemen
|
|
|
22
24
|
dense?: boolean;
|
|
23
25
|
border?: boolean;
|
|
24
26
|
className?: string;
|
|
27
|
+
kind?: TableCellKind;
|
|
25
28
|
}
|
|
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;
|
|
29
|
+
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
|
@@ -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
|
@@ -800,7 +800,7 @@ function ColumnFilter({ header }) {
|
|
|
800
800
|
}
|
|
801
801
|
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
802
|
}
|
|
803
|
-
function DataTable({ data, columns: columnDefs, enableSearch, searchPlaceholder = 'Search...', pageSize: initialPageSize = 10, pageSizeOptions = [10, 25, 50, 100], striped, hasHover = true, dense, border, className, ...props }) {
|
|
803
|
+
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
804
|
const [sorting, setSorting] = useState([]);
|
|
805
805
|
const [columnFilters, setColumnFilters] = useState([]);
|
|
806
806
|
const [globalFilter, setGlobalFilter] = useState('');
|
|
@@ -816,6 +816,7 @@ function DataTable({ data, columns: columnDefs, enableSearch, searchPlaceholder
|
|
|
816
816
|
filterType: col.filterType ?? 'text',
|
|
817
817
|
filterOptions: col.filterOptions,
|
|
818
818
|
className: col.className,
|
|
819
|
+
kind: col.kind,
|
|
819
820
|
},
|
|
820
821
|
})), [columnDefs]);
|
|
821
822
|
const table = useReactTable({
|
|
@@ -836,17 +837,20 @@ function DataTable({ data, columns: columnDefs, enableSearch, searchPlaceholder
|
|
|
836
837
|
const hasFilters = columnDefs.some(col => col.enableFiltering === true);
|
|
837
838
|
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
839
|
const meta = header.column.columnDef.meta;
|
|
839
|
-
|
|
840
|
+
const cellKind = meta?.kind ?? defaultKind ?? 'default';
|
|
841
|
+
return (jsx(TableCell, { kind: cellKind, className: classnames(meta?.className, {
|
|
840
842
|
'datatable_sortable': header.column.getCanSort()
|
|
841
843
|
}), onClick: header.column.getToggleSortingHandler(), "aria-sort": header.column.getIsSorted() === 'asc' ? 'ascending'
|
|
842
844
|
: header.column.getIsSorted() === 'desc' ? 'descending'
|
|
843
845
|
: 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
846
|
}) }, headerGroup.id))), hasFilters && (jsx(TableRow, { className: "datatable_filterRow", children: table.getHeaderGroups()[0].headers.map(header => {
|
|
845
847
|
const meta = header.column.columnDef.meta;
|
|
846
|
-
|
|
848
|
+
const cellKind = meta?.kind ?? defaultKind ?? 'default';
|
|
849
|
+
return (jsx(TableCell, { kind: cellKind, className: meta?.className, children: header.column.getCanFilter() ? (jsx(ColumnFilter, { header: header })) : null }, `filter-${header.id}`));
|
|
847
850
|
}) }))] }), 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
851
|
const meta = cell.column.columnDef.meta;
|
|
849
|
-
|
|
852
|
+
const cellKind = meta?.kind ?? defaultKind ?? 'default';
|
|
853
|
+
return (jsx(TableCell, { kind: cellKind, className: meta?.className, children: flexRender(cell.column.columnDef.cell, cell.getContext()) }, cell.id));
|
|
850
854
|
}) }, 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
855
|
}
|
|
852
856
|
|
package/dist/package.json
CHANGED