@pk-design/react-tailwind 1.3.0 → 1.4.1

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,5 +1,5 @@
1
1
  export type BannerType = 'info' | 'error' | 'success' | 'warning';
2
- export type IconSize = 5 | 6 | 7 | 8 | 9 | 10;
2
+ export type IconSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
3
3
  export interface BannerProps {
4
4
  /**
5
5
  * Defines banner type
@@ -9,6 +9,7 @@ export interface BannerProps {
9
9
  children: any;
10
10
  /**
11
11
  * Controls the icon size
12
+ * @default "sm"
12
13
  */
13
14
  iconSize?: IconSize;
14
15
  }
@@ -1,2 +1,5 @@
1
1
  import type { DataTableProps } from './DataTable.types';
2
- export declare const DataTable: React.FC<DataTableProps>;
2
+ export declare function DataTable<T extends Record<string, any> = Record<string, any>>({ items, columns, sorting, onSort, loading, pagination, setPagination, emptyMessage, containerClass, wrapperClass, tableClass, headClass, footerRow, rowKey, onRowClick, rowClass, density, striped, layout, }: DataTableProps<T>): import("react/jsx-runtime").JSX.Element;
3
+ export declare namespace DataTable {
4
+ var displayName: string;
5
+ }
@@ -1,8 +1,8 @@
1
1
  import type { ReactNode } from 'react';
2
2
  import type { TPagination } from '../Pagination';
3
3
  /**
4
- * Allowed column value data types
5
- * Used only to influence sorting logic
4
+ * Allowed column value data types.
5
+ * Used only to influence sorting logic.
6
6
  */
7
7
  export type DataValueType = 'string' | 'number' | 'date';
8
8
  /**
@@ -13,9 +13,15 @@ export type Sorting = 'asc' | 'desc' | '1' | '-1';
13
13
  export type SortIconKey = Extract<Sorting, 'asc' | 'desc' | '1' | '-1'>;
14
14
  export type SortQuery = Record<string, Sorting>;
15
15
  /**
16
- * Column definition for DataTable
16
+ * Cell padding preset.
17
+ * @default 'default'
17
18
  */
18
- export interface DataTableColumn {
19
+ export type DataTableDensity = 'compact' | 'default' | 'spacious';
20
+ /**
21
+ * Column definition for DataTable.
22
+ * @template T Shape of each data row
23
+ */
24
+ export interface DataTableColumn<T = any> {
19
25
  /** Unique key used to extract column data (supports nested paths) */
20
26
  name: string;
21
27
  /** Display label for the header */
@@ -25,39 +31,85 @@ export interface DataTableColumn {
25
31
  /** Text alignment for body cells */
26
32
  align?: 'left' | 'center' | 'right';
27
33
  /** Custom cell renderer (highest priority) */
28
- render?: (item: any) => ReactNode;
34
+ render?: (item: T) => ReactNode;
29
35
  /** Optional fixed width (px, %, rem) */
30
36
  width?: string | number;
31
37
  /** Enables sorting when true */
32
38
  sortable?: boolean;
33
- /** Type of cell value helps sorting logic */
39
+ /** Type of cell value — influences sort logic */
34
40
  type?: DataValueType;
35
- /** Sticks cell to right side */
41
+ /** Sticks cell to the given side on horizontal scroll */
36
42
  sticky?: 'left' | 'right';
43
+ /** Extra classes applied to the header cell (`<th>`) for this column */
44
+ headerClass?: string;
45
+ /**
46
+ * Extra classes applied to each body cell (`<td>`) for this column.
47
+ * Pass a function to vary styles per row value.
48
+ * @example cellClass={(item) => item.status === 'error' ? 'text-red-600' : ''}
49
+ */
50
+ cellClass?: string | ((item: T) => string);
37
51
  }
38
52
  /**
39
53
  * DataTable props
54
+ * @template T Shape of each data row
40
55
  */
41
- export interface DataTableProps {
56
+ export interface DataTableProps<T = any> {
42
57
  /** Array of data items */
43
- items: any[];
58
+ items: T[];
44
59
  /** Column definitions */
45
- columns: DataTableColumn[];
60
+ columns: DataTableColumn<T>[];
46
61
  /** Sorting state, keyed by column name */
47
62
  sorting?: Record<string, Sorting>;
48
- /** Loading state (shows skeleton rows) */
63
+ /** Loading state — shows skeleton rows instead of data */
49
64
  loading?: boolean;
50
65
  /** Pagination config */
51
66
  pagination?: TPagination;
52
- /** Empty message to show when no results */
67
+ /** Message or node shown when the items array is empty */
53
68
  emptyMessage?: ReactNode;
54
- /** External sorting handler */
55
- onSort?: (column: DataTableColumn) => void;
69
+ /** External sorting handler. When omitted, DataTable auto-sorts internally. */
70
+ onSort?: (column: DataTableColumn<T>) => void;
56
71
  /** Pagination setter */
57
72
  setPagination?: (pagination: Partial<TPagination>) => void;
58
- /** Layout of table cells */
73
+ /** Table layout algorithm */
59
74
  layout?: 'fixed' | 'auto';
60
- /** Optional wrapper styles */
75
+ /**
76
+ * Determines the stable React key for each row.
77
+ * Pass a field name string or a function returning a unique value.
78
+ * @default 'id'
79
+ */
80
+ rowKey?: string | ((item: T) => string | number);
81
+ /**
82
+ * Callback fired when a row is clicked.
83
+ * Rows become visually interactive (pointer cursor) when this is set.
84
+ */
85
+ onRowClick?: (item: T, index: number) => void;
86
+ /**
87
+ * Extra class(es) applied to each `<tr>` in the body.
88
+ * Pass a function to vary classes per row.
89
+ * @example rowClass={(item, i) => item.active ? 'font-semibold' : ''}
90
+ */
91
+ rowClass?: string | ((item: T, index: number) => string);
92
+ /**
93
+ * Cell padding preset.
94
+ * @default 'default'
95
+ */
96
+ density?: DataTableDensity;
97
+ /**
98
+ * Applies an alternating background to odd-indexed rows.
99
+ * @default false
100
+ */
101
+ striped?: boolean;
102
+ /**
103
+ * Node(s) rendered inside `<tfoot><tr>` as a summary or totals row.
104
+ * Should be a set of `<td>` elements matching the column count.
105
+ */
106
+ footerRow?: ReactNode;
107
+ /** Optional classes applied to the outer container div */
61
108
  containerClass?: string;
109
+ /** Optional classes applied to the scroll wrapper div */
62
110
  wrapperClass?: string;
111
+ /** Optional classes applied directly to the `<table>` element */
112
+ tableClass?: string;
113
+ /** Optional classes applied to the `<thead>` element */
114
+ headClass?: string;
63
115
  }
@@ -1,4 +1,4 @@
1
- import type { HTMLAttributes, ReactNode, TdHTMLAttributes, ThHTMLAttributes } from 'react';
1
+ import type { HTMLAttributes, ReactNode, TdHTMLAttributes } from 'react';
2
2
  /**
3
3
  * Root <Table /> props.
4
4
  */
@@ -11,6 +11,8 @@ export interface TableProps {
11
11
  className?: string;
12
12
  /** Table content (Head + Body + Foot) */
13
13
  children: ReactNode;
14
+ /** Accessible caption rendered as a <caption> element above the header */
15
+ caption?: ReactNode;
14
16
  }
15
17
  /**
16
18
  * <TableHead /> — table header section
@@ -29,12 +31,12 @@ export interface TableBodyProps {
29
31
  className?: string;
30
32
  /** Show loading shimmer (overrides children) */
31
33
  loading?: boolean;
32
- /** Number of columns — needed for shimmer loader layout */
33
- colSize: number;
34
+ /** Number of columns — needed for shimmer loader layout. Defaults to 1 when not provided. */
35
+ colSize?: number;
34
36
  /** Number of shimmer rows to show when loading */
35
37
  rowSize?: number;
36
38
  /** Actual table rows */
37
- children: ReactNode;
39
+ children?: ReactNode;
38
40
  }
39
41
  /**
40
42
  * <TableFoot /> — table footer
@@ -67,7 +69,7 @@ export interface TableCellProps extends TdHTMLAttributes<HTMLTableCellElement> {
67
69
  /**
68
70
  * <TableRow /> — regular row
69
71
  */
70
- export interface TableRowProps extends ThHTMLAttributes<HTMLTableRowElement> {
72
+ export interface TableRowProps extends HTMLAttributes<HTMLTableRowElement> {
71
73
  /** Whether the row highlights on hover */
72
74
  hoverable?: boolean;
73
75
  }
@@ -1,3 +1,2 @@
1
- import React from 'react';
2
- import { VirtualizedDataTableProps } from './VirtualizedDataTable.types';
3
- export declare const VirtualizedDataTable: React.FC<VirtualizedDataTableProps>;
1
+ import type { VirtualizedDataTableProps } from './VirtualizedDataTable.types';
2
+ export declare function VirtualizedDataTable<T extends Record<string, any> = Record<string, any>>({ items, columns, sorting, onSort, loading, emptyMessage, containerClass, wrapperClass, onRowClick, rowClass, density, striped, rowHeight, maxHeight, overscanCount, }: VirtualizedDataTableProps<T>): import("react/jsx-runtime").JSX.Element;
@@ -1,18 +1,42 @@
1
- import { DataTableColumn, DataTableProps } from '../DataTable';
1
+ import type { DataTableColumn, DataTableDensity, DataTableProps } from '../DataTable';
2
2
  /**
3
- * Props for VirtualizedDataTable
3
+ * Props shared with DataTable but not applicable to virtualized tables are omitted:
4
+ * pagination, setPagination, layout, footerRow, rowKey, tableClass, headClass.
4
5
  */
5
- export interface VirtualizedDataTableProps extends DataTableProps {
6
- /** Height of each row in pixels (required for virtualization) */
6
+ type VirtualizedBase<T = any> = Omit<DataTableProps<T>, 'pagination' | 'setPagination' | 'layout' | 'footerRow' | 'rowKey' | 'tableClass' | 'headClass'>;
7
+ /**
8
+ * Props for VirtualizedDataTable.
9
+ * @template T Shape of each data row
10
+ */
11
+ export interface VirtualizedDataTableProps<T = any> extends VirtualizedBase<T> {
12
+ /** Height of each row in pixels. Required for react-window's fixed-size virtualization.
13
+ * @default 48
14
+ */
7
15
  rowHeight?: number;
8
- /** Max height (px) the table body can take. AutoSizer will size to available space. */
16
+ /** Maximum height of the scrollable body in pixels.
17
+ * @default 400
18
+ */
9
19
  maxHeight?: number;
20
+ /**
21
+ * Number of extra rows rendered outside the visible area.
22
+ * Higher values reduce blank flicker during fast scrolling at the cost of more DOM nodes.
23
+ * Maps directly to react-window's overscanCount.
24
+ * @default 3
25
+ */
26
+ overscanCount?: number;
10
27
  }
11
28
  /**
12
- * Row props passed to the custom rowComponent API of react-window.
13
- * react-window will also pass index, style, and aria attributes.
29
+ * Data object passed to each virtualized row via react-window's itemData.
30
+ * Items and columns use any internally because react-window's generic inference
31
+ * does not flow through to ComponentType children.
14
32
  */
15
33
  export type VirtualizedRowProps = {
16
34
  items: any[];
17
35
  columns: DataTableColumn[];
36
+ gridTemplate: string;
37
+ onRowClick?: (item: any, index: number) => void;
38
+ rowClass?: string | ((item: any, index: number) => string);
39
+ density?: DataTableDensity;
40
+ striped?: boolean;
18
41
  };
42
+ export {};
@@ -1,7 +1,3 @@
1
1
  import { ListChildComponentProps } from 'react-window';
2
- import { VirtualizedRowProps } from './VirtualizedDataTable.types';
3
- interface RowData extends VirtualizedRowProps {
4
- gridTemplate: string;
5
- }
6
- export declare const VirtualizedRow: ({ index, style, data }: ListChildComponentProps<RowData>) => import("react/jsx-runtime").JSX.Element;
7
- export {};
2
+ import type { VirtualizedRowProps } from './VirtualizedDataTable.types';
3
+ export declare const VirtualizedRow: ({ index, style, data, }: ListChildComponentProps<VirtualizedRowProps>) => import("react/jsx-runtime").JSX.Element;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pk-design/react-tailwind",
3
- "version": "1.3.0",
3
+ "version": "1.4.1",
4
4
  "main": "dist/react-tailwind.cjs.js",
5
5
  "module": "dist/react-tailwind.es.js",
6
6
  "types": "dist/types/index.d.ts",