@gridcore/react-smart-table 0.1.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 ADDED
@@ -0,0 +1,139 @@
1
+ # React Smart Table
2
+
3
+ A customizable, feature-rich table component for React with TypeScript support. Inspired by enterprise-grade table implementations.
4
+
5
+ ## Features
6
+
7
+ - ✅ **Sorting** - Click column headers to sort
8
+ - ✅ **Row Selection** - Checkbox support with bulk selection
9
+ - ✅ **Custom Rendering** - Full control over cell rendering
10
+ - ✅ **Actions** - Built-in edit/delete actions
11
+ - ✅ **Loading States** - Skeleton loading UI
12
+ - ✅ **TypeScript** - Full type safety with generics
13
+ - ✅ **Responsive** - Mobile-friendly design
14
+ - ✅ **Customizable** - Tailwind CSS styling
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ npm install react-smart-table
20
+ ```
21
+
22
+ ## Basic Usage
23
+
24
+ ```tsx
25
+ import { SmartTable } from 'react-smart-table';
26
+
27
+ interface User {
28
+ id: number;
29
+ name: string;
30
+ email: string;
31
+ status: string;
32
+ }
33
+
34
+ const users: User[] = [
35
+ { id: 1, name: 'John Doe', email: 'john@example.com', status: 'Active' },
36
+ { id: 2, name: 'Jane Smith', email: 'jane@example.com', status: 'Inactive' }
37
+ ];
38
+
39
+ function App() {
40
+ return (
41
+ <SmartTable
42
+ data={users}
43
+ columns={[
44
+ { key: 'id', title: 'ID', sortable: true },
45
+ { key: 'name', title: 'Name', sortable: true },
46
+ { key: 'email', title: 'Email' },
47
+ {
48
+ key: 'status',
49
+ title: 'Status',
50
+ render: (value) => (
51
+ <span className={value === 'Active' ? 'text-green-600' : 'text-red-600'}>
52
+ {value}
53
+ </span>
54
+ )
55
+ }
56
+ ]}
57
+ />
58
+ );
59
+ }
60
+ ```
61
+
62
+ ## Advanced Usage
63
+
64
+ ### With Actions and Selection
65
+
66
+ ```tsx
67
+ const [selectedRows, setSelectedRows] = useState<string[]>([]);
68
+
69
+ <SmartTable
70
+ data={users}
71
+ columns={columns}
72
+ showCheckbox={true}
73
+ showActions={true}
74
+ selectedRows={selectedRows}
75
+ onSelectionChange={setSelectedRows}
76
+ onEdit={(row) => console.log('Edit:', row)}
77
+ onDelete={(row) => console.log('Delete:', row)}
78
+ onRowClick={(row) => console.log('Clicked:', row)}
79
+ rowKey="id"
80
+ />
81
+ ```
82
+
83
+ ### With Loading State
84
+
85
+ ```tsx
86
+ <SmartTable
87
+ data={users}
88
+ columns={columns}
89
+ loading={isLoading}
90
+ emptyMessage="No users found"
91
+ />
92
+ ```
93
+
94
+ ## API Reference
95
+
96
+ ### Props
97
+
98
+ | Prop | Type | Default | Description |
99
+ |------|------|---------|-------------|
100
+ | `data` | `T[]` | **required** | Array of data objects |
101
+ | `columns` | `Column<T>[]` | **required** | Column definitions |
102
+ | `className` | `string` | `''` | Additional CSS classes |
103
+ | `showCheckbox` | `boolean` | `false` | Show row selection checkboxes |
104
+ | `showActions` | `boolean` | `false` | Show actions column |
105
+ | `onEdit` | `(row: T) => void` | - | Edit button handler |
106
+ | `onDelete` | `(row: T) => void` | - | Delete button handler |
107
+ | `onRowClick` | `(row: T) => void` | - | Row click handler |
108
+ | `loading` | `boolean` | `false` | Show loading skeleton |
109
+ | `emptyMessage` | `string` | `'No data available'` | Empty state message |
110
+ | `selectedRows` | `string[]` | `[]` | Selected row keys |
111
+ | `onSelectionChange` | `(selected: string[]) => void` | - | Selection change handler |
112
+ | `rowKey` | `keyof T` | `'id'` | Unique row identifier |
113
+
114
+ ### Column Definition
115
+
116
+ ```typescript
117
+ interface Column<T> {
118
+ key: keyof T; // Data key
119
+ title: string; // Column header
120
+ sortable?: boolean; // Enable sorting
121
+ render?: (value: any, row: T) => React.ReactNode; // Custom cell renderer
122
+ }
123
+ ```
124
+
125
+ ## Build
126
+
127
+ ```bash
128
+ npm run build
129
+ ```
130
+
131
+ ## Development
132
+
133
+ ```bash
134
+ npm run dev
135
+ ```
136
+
137
+ ## License
138
+
139
+ MIT
@@ -0,0 +1,149 @@
1
+ import React from 'react';
2
+ import * as react_jsx_runtime from 'react/jsx-runtime';
3
+ import * as LucideIcons from 'lucide-react';
4
+
5
+ interface Column<T> {
6
+ key: keyof T;
7
+ title: string;
8
+ sortable?: boolean;
9
+ render?: (value: any, row: T) => React.ReactNode;
10
+ }
11
+ interface BulkAction {
12
+ label: string;
13
+ icon?: React.ReactNode;
14
+ onClick: (selectedRows: string[]) => void;
15
+ color?: 'red' | 'green' | 'yellow' | 'blue';
16
+ }
17
+ interface SidebarAction {
18
+ icon: React.ReactNode;
19
+ label: string;
20
+ onClick: () => void;
21
+ }
22
+ type SidebarPosition = 'left' | 'right' | 'top' | 'bottom';
23
+ interface TableStyles {
24
+ container?: string;
25
+ table?: string;
26
+ header?: string;
27
+ headerRow?: string;
28
+ headerCell?: string;
29
+ body?: string;
30
+ row?: string;
31
+ rowHover?: string;
32
+ cell?: string;
33
+ sidebar?: string;
34
+ sidebarButton?: string;
35
+ sidebarButtonHover?: string;
36
+ checkbox?: string;
37
+ checkboxChecked?: string;
38
+ }
39
+ interface SmartTableProps<T> {
40
+ data: T[];
41
+ columns: Column<T>[];
42
+ className?: string;
43
+ showCheckbox?: boolean;
44
+ showActions?: boolean;
45
+ onEdit?: (row: T) => void;
46
+ onDelete?: (row: T) => void;
47
+ onRowClick?: (row: T) => void;
48
+ loading?: boolean;
49
+ emptyMessage?: string;
50
+ selectedRows?: string[];
51
+ onSelectionChange?: (selected: string[]) => void;
52
+ rowKey?: keyof T;
53
+ bulkActions?: BulkAction[];
54
+ onSearch?: (value: string) => void;
55
+ searchPlaceholder?: string;
56
+ sidebarActions?: SidebarAction[];
57
+ sidebarPosition?: SidebarPosition;
58
+ tableHeight?: string;
59
+ styles?: TableStyles;
60
+ primaryColor?: string;
61
+ pagination?: {
62
+ currentPage: number;
63
+ totalPages: number;
64
+ pageSize: number;
65
+ totalItems: number;
66
+ onPageChange: (page: number) => void;
67
+ onPageSizeChange?: (size: number) => void;
68
+ pageSizeOptions?: number[];
69
+ };
70
+ }
71
+
72
+ interface SmartTablePropsExtended<T> extends Omit<SmartTableProps<T>, 'pagination'> {
73
+ onAdd?: () => void;
74
+ onRefresh?: () => void;
75
+ onExport?: () => void;
76
+ onPrint?: () => void;
77
+ onSettings?: () => void;
78
+ showAdd?: boolean;
79
+ showRefresh?: boolean;
80
+ showExport?: boolean;
81
+ showPrint?: boolean;
82
+ showSettings?: boolean;
83
+ showColumnSelector?: boolean;
84
+ columnSelectorLabel?: string;
85
+ visibleColumns?: string[];
86
+ onColumnVisibilityChange?: (columns: string[]) => void;
87
+ minVisibleColumns?: number;
88
+ maxVisibleColumns?: number;
89
+ maxHeight?: string;
90
+ skeletonRows?: number;
91
+ pagination?: {
92
+ currentPage: number;
93
+ totalPages: number;
94
+ pageSize: number;
95
+ totalItems: number;
96
+ onPageChange: (page: number) => void;
97
+ onPageSizeChange?: (size: number) => void;
98
+ pageSizeOptions?: number[];
99
+ };
100
+ }
101
+ declare function SmartTable<T extends Record<string, any>>({ data, columns, className, showCheckbox, showActions, onEdit, onDelete, onRowClick, loading, emptyMessage, selectedRows, onSelectionChange, rowKey, bulkActions, onSearch, searchPlaceholder, sidebarActions, sidebarPosition, onAdd, onRefresh, onExport, onPrint, onSettings, showAdd, showRefresh, showExport, showPrint, showSettings, tableHeight, styles, primaryColor, pagination, showColumnSelector, columnSelectorLabel, visibleColumns, onColumnVisibilityChange, minVisibleColumns, maxVisibleColumns, maxHeight, skeletonRows }: SmartTablePropsExtended<T>): JSX.Element;
102
+
103
+ interface TooltipProps {
104
+ children: React.ReactNode;
105
+ text: string;
106
+ position?: 'left' | 'right' | 'top' | 'bottom';
107
+ }
108
+ declare const Tooltip: React.FC<TooltipProps>;
109
+
110
+ interface PaginationProps {
111
+ currentPage: number;
112
+ totalPages: number;
113
+ onPageChange: (page: number) => void;
114
+ pageSize: number;
115
+ totalItems: number;
116
+ onPageSizeChange?: (size: number) => void;
117
+ pageSizeOptions?: number[];
118
+ primaryColor?: string;
119
+ }
120
+ declare const Pagination: React.FC<PaginationProps>;
121
+
122
+ interface ColumnSelectorProps {
123
+ columns: {
124
+ key: string;
125
+ title: string;
126
+ }[];
127
+ visibleColumns: string[];
128
+ onColumnToggle: (columnKey: string) => void;
129
+ onReset?: () => void;
130
+ primaryColor?: string;
131
+ minColumns?: number;
132
+ maxColumns?: number;
133
+ label?: string;
134
+ position?: 'left' | 'right';
135
+ }
136
+ declare const ColumnSelector: React.FC<ColumnSelectorProps>;
137
+
138
+ type IconName = keyof typeof LucideIcons;
139
+ interface IconProps {
140
+ name: IconName;
141
+ className?: string;
142
+ size?: number;
143
+ strokeWidth?: number;
144
+ style?: React.CSSProperties;
145
+ }
146
+ declare const Icon: React.FC<IconProps>;
147
+ declare const getIcon: (name: IconName, props?: Omit<IconProps, "name">) => react_jsx_runtime.JSX.Element;
148
+
149
+ export { type BulkAction, type Column, ColumnSelector, Icon, type IconName, Pagination, type SidebarAction, type SidebarPosition, SmartTable, type SmartTableProps, type TableStyles, Tooltip, getIcon };
@@ -0,0 +1,149 @@
1
+ import React from 'react';
2
+ import * as react_jsx_runtime from 'react/jsx-runtime';
3
+ import * as LucideIcons from 'lucide-react';
4
+
5
+ interface Column<T> {
6
+ key: keyof T;
7
+ title: string;
8
+ sortable?: boolean;
9
+ render?: (value: any, row: T) => React.ReactNode;
10
+ }
11
+ interface BulkAction {
12
+ label: string;
13
+ icon?: React.ReactNode;
14
+ onClick: (selectedRows: string[]) => void;
15
+ color?: 'red' | 'green' | 'yellow' | 'blue';
16
+ }
17
+ interface SidebarAction {
18
+ icon: React.ReactNode;
19
+ label: string;
20
+ onClick: () => void;
21
+ }
22
+ type SidebarPosition = 'left' | 'right' | 'top' | 'bottom';
23
+ interface TableStyles {
24
+ container?: string;
25
+ table?: string;
26
+ header?: string;
27
+ headerRow?: string;
28
+ headerCell?: string;
29
+ body?: string;
30
+ row?: string;
31
+ rowHover?: string;
32
+ cell?: string;
33
+ sidebar?: string;
34
+ sidebarButton?: string;
35
+ sidebarButtonHover?: string;
36
+ checkbox?: string;
37
+ checkboxChecked?: string;
38
+ }
39
+ interface SmartTableProps<T> {
40
+ data: T[];
41
+ columns: Column<T>[];
42
+ className?: string;
43
+ showCheckbox?: boolean;
44
+ showActions?: boolean;
45
+ onEdit?: (row: T) => void;
46
+ onDelete?: (row: T) => void;
47
+ onRowClick?: (row: T) => void;
48
+ loading?: boolean;
49
+ emptyMessage?: string;
50
+ selectedRows?: string[];
51
+ onSelectionChange?: (selected: string[]) => void;
52
+ rowKey?: keyof T;
53
+ bulkActions?: BulkAction[];
54
+ onSearch?: (value: string) => void;
55
+ searchPlaceholder?: string;
56
+ sidebarActions?: SidebarAction[];
57
+ sidebarPosition?: SidebarPosition;
58
+ tableHeight?: string;
59
+ styles?: TableStyles;
60
+ primaryColor?: string;
61
+ pagination?: {
62
+ currentPage: number;
63
+ totalPages: number;
64
+ pageSize: number;
65
+ totalItems: number;
66
+ onPageChange: (page: number) => void;
67
+ onPageSizeChange?: (size: number) => void;
68
+ pageSizeOptions?: number[];
69
+ };
70
+ }
71
+
72
+ interface SmartTablePropsExtended<T> extends Omit<SmartTableProps<T>, 'pagination'> {
73
+ onAdd?: () => void;
74
+ onRefresh?: () => void;
75
+ onExport?: () => void;
76
+ onPrint?: () => void;
77
+ onSettings?: () => void;
78
+ showAdd?: boolean;
79
+ showRefresh?: boolean;
80
+ showExport?: boolean;
81
+ showPrint?: boolean;
82
+ showSettings?: boolean;
83
+ showColumnSelector?: boolean;
84
+ columnSelectorLabel?: string;
85
+ visibleColumns?: string[];
86
+ onColumnVisibilityChange?: (columns: string[]) => void;
87
+ minVisibleColumns?: number;
88
+ maxVisibleColumns?: number;
89
+ maxHeight?: string;
90
+ skeletonRows?: number;
91
+ pagination?: {
92
+ currentPage: number;
93
+ totalPages: number;
94
+ pageSize: number;
95
+ totalItems: number;
96
+ onPageChange: (page: number) => void;
97
+ onPageSizeChange?: (size: number) => void;
98
+ pageSizeOptions?: number[];
99
+ };
100
+ }
101
+ declare function SmartTable<T extends Record<string, any>>({ data, columns, className, showCheckbox, showActions, onEdit, onDelete, onRowClick, loading, emptyMessage, selectedRows, onSelectionChange, rowKey, bulkActions, onSearch, searchPlaceholder, sidebarActions, sidebarPosition, onAdd, onRefresh, onExport, onPrint, onSettings, showAdd, showRefresh, showExport, showPrint, showSettings, tableHeight, styles, primaryColor, pagination, showColumnSelector, columnSelectorLabel, visibleColumns, onColumnVisibilityChange, minVisibleColumns, maxVisibleColumns, maxHeight, skeletonRows }: SmartTablePropsExtended<T>): JSX.Element;
102
+
103
+ interface TooltipProps {
104
+ children: React.ReactNode;
105
+ text: string;
106
+ position?: 'left' | 'right' | 'top' | 'bottom';
107
+ }
108
+ declare const Tooltip: React.FC<TooltipProps>;
109
+
110
+ interface PaginationProps {
111
+ currentPage: number;
112
+ totalPages: number;
113
+ onPageChange: (page: number) => void;
114
+ pageSize: number;
115
+ totalItems: number;
116
+ onPageSizeChange?: (size: number) => void;
117
+ pageSizeOptions?: number[];
118
+ primaryColor?: string;
119
+ }
120
+ declare const Pagination: React.FC<PaginationProps>;
121
+
122
+ interface ColumnSelectorProps {
123
+ columns: {
124
+ key: string;
125
+ title: string;
126
+ }[];
127
+ visibleColumns: string[];
128
+ onColumnToggle: (columnKey: string) => void;
129
+ onReset?: () => void;
130
+ primaryColor?: string;
131
+ minColumns?: number;
132
+ maxColumns?: number;
133
+ label?: string;
134
+ position?: 'left' | 'right';
135
+ }
136
+ declare const ColumnSelector: React.FC<ColumnSelectorProps>;
137
+
138
+ type IconName = keyof typeof LucideIcons;
139
+ interface IconProps {
140
+ name: IconName;
141
+ className?: string;
142
+ size?: number;
143
+ strokeWidth?: number;
144
+ style?: React.CSSProperties;
145
+ }
146
+ declare const Icon: React.FC<IconProps>;
147
+ declare const getIcon: (name: IconName, props?: Omit<IconProps, "name">) => react_jsx_runtime.JSX.Element;
148
+
149
+ export { type BulkAction, type Column, ColumnSelector, Icon, type IconName, Pagination, type SidebarAction, type SidebarPosition, SmartTable, type SmartTableProps, type TableStyles, Tooltip, getIcon };