@kreativa/ui 0.1.0 → 0.1.2
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/dist/index.d.mts +112 -6
- package/dist/index.d.ts +112 -6
- package/dist/index.js +417 -99
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +416 -100
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -142,16 +142,18 @@ declare function FormButtonGroup({ cancelText, submitText, loadingText, isLoadin
|
|
|
142
142
|
interface TableColumn<T> {
|
|
143
143
|
/** Unique key for the column */
|
|
144
144
|
key: string;
|
|
145
|
-
/** Column header text */
|
|
146
|
-
header:
|
|
145
|
+
/** Column header text or React element */
|
|
146
|
+
header: ReactNode;
|
|
147
147
|
/** Function to render cell content */
|
|
148
148
|
render: (item: T) => ReactNode;
|
|
149
149
|
/** Whether this column is sortable */
|
|
150
150
|
sortable?: boolean;
|
|
151
151
|
/** Custom sort function */
|
|
152
152
|
sortFn?: (a: T, b: T) => number;
|
|
153
|
-
/** Column width (e.g., '200px', '20%') */
|
|
153
|
+
/** Column width (e.g., '200px', '20%') - used as initial/min width */
|
|
154
154
|
width?: string;
|
|
155
|
+
/** Minimum column width when resizing */
|
|
156
|
+
minWidth?: number;
|
|
155
157
|
/** Text alignment */
|
|
156
158
|
align?: 'left' | 'center' | 'right';
|
|
157
159
|
}
|
|
@@ -170,11 +172,115 @@ interface TableProps<T> {
|
|
|
170
172
|
emptyMessage?: string;
|
|
171
173
|
/** Additional class names for the table container */
|
|
172
174
|
className?: string;
|
|
175
|
+
/** Enable manual column resizing (default: false) */
|
|
176
|
+
resizable?: boolean;
|
|
177
|
+
/** Use fixed table layout for consistent column widths */
|
|
178
|
+
fixedLayout?: boolean;
|
|
173
179
|
}
|
|
174
180
|
/**
|
|
175
|
-
* Table component for displaying tabular data with sorting
|
|
181
|
+
* Table component for displaying tabular data with sorting and optional resizing.
|
|
182
|
+
*
|
|
183
|
+
* Features:
|
|
184
|
+
* - Responsive by default - shrinks with container
|
|
185
|
+
* - Optional column resizing with drag handles
|
|
186
|
+
* - Sortable columns
|
|
187
|
+
* - Loading and empty states
|
|
188
|
+
*/
|
|
189
|
+
declare function Table<T>({ data, columns, getRowKey, onRowClick, loading, emptyMessage, className, resizable, fixedLayout, }: TableProps<T>): react_jsx_runtime.JSX.Element;
|
|
190
|
+
|
|
191
|
+
type FilterType = 'text' | 'select' | 'multiselect' | 'boolean' | 'date' | 'none';
|
|
192
|
+
interface FilterOption {
|
|
193
|
+
value: string;
|
|
194
|
+
label: string;
|
|
195
|
+
}
|
|
196
|
+
interface DataTableColumn<T> extends Omit<TableColumn<T>, 'sortable' | 'header'> {
|
|
197
|
+
/** Column header text (must be string for filter placeholder) */
|
|
198
|
+
header: string;
|
|
199
|
+
/** Whether this column is sortable (default: true) */
|
|
200
|
+
sortable?: boolean;
|
|
201
|
+
/** Filter type for this column (default: 'text') */
|
|
202
|
+
filterType?: FilterType;
|
|
203
|
+
/** Options for select/multiselect filters */
|
|
204
|
+
filterOptions?: FilterOption[];
|
|
205
|
+
/** Function to get filterable value from item */
|
|
206
|
+
filterValue?: (item: T) => string | number | boolean | null | undefined;
|
|
207
|
+
/** Placeholder for filter input */
|
|
208
|
+
filterPlaceholder?: string;
|
|
209
|
+
}
|
|
210
|
+
interface DataTableProps<T> {
|
|
211
|
+
/** Array of data items to display */
|
|
212
|
+
data: T[];
|
|
213
|
+
/** Column definitions */
|
|
214
|
+
columns: DataTableColumn<T>[];
|
|
215
|
+
/** Function to get unique key for each row */
|
|
216
|
+
getRowKey: (item: T) => string | number;
|
|
217
|
+
/** Called when a row is clicked */
|
|
218
|
+
onRowClick?: (item: T) => void;
|
|
219
|
+
/** Whether the table is in a loading state */
|
|
220
|
+
loading?: boolean;
|
|
221
|
+
/** Message to show when data is empty */
|
|
222
|
+
emptyMessage?: string;
|
|
223
|
+
/** Additional class names for the table container */
|
|
224
|
+
className?: string;
|
|
225
|
+
/** Show filter row (default: true) */
|
|
226
|
+
showFilters?: boolean;
|
|
227
|
+
/** Initial sort column key */
|
|
228
|
+
initialSortKey?: string;
|
|
229
|
+
/** Initial sort direction */
|
|
230
|
+
initialSortDirection?: 'asc' | 'desc';
|
|
231
|
+
/** Called when filtered data changes (for external use, e.g., showing count) */
|
|
232
|
+
onFilteredDataChange?: (filteredData: T[]) => void;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* DataTable component - an enhanced Table with built-in filtering and sorting.
|
|
236
|
+
*
|
|
237
|
+
* Features:
|
|
238
|
+
* - Text, select, multiselect, and boolean filters per column
|
|
239
|
+
* - Sortable columns (default: all columns are sortable)
|
|
240
|
+
* - Filter state management
|
|
241
|
+
* - Callback when filtered data changes
|
|
242
|
+
*
|
|
243
|
+
* @example
|
|
244
|
+
* ```tsx
|
|
245
|
+
* const columns: DataTableColumn<User>[] = [
|
|
246
|
+
* {
|
|
247
|
+
* key: 'name',
|
|
248
|
+
* header: 'Name',
|
|
249
|
+
* filterType: 'text',
|
|
250
|
+
* filterValue: (user) => user.name,
|
|
251
|
+
* render: (user) => <span>{user.name}</span>,
|
|
252
|
+
* },
|
|
253
|
+
* {
|
|
254
|
+
* key: 'status',
|
|
255
|
+
* header: 'Status',
|
|
256
|
+
* filterType: 'select',
|
|
257
|
+
* filterOptions: [
|
|
258
|
+
* { value: 'active', label: 'Active' },
|
|
259
|
+
* { value: 'inactive', label: 'Inactive' },
|
|
260
|
+
* ],
|
|
261
|
+
* filterValue: (user) => user.status,
|
|
262
|
+
* render: (user) => <Badge>{user.status}</Badge>,
|
|
263
|
+
* },
|
|
264
|
+
* ]
|
|
265
|
+
*
|
|
266
|
+
* <DataTable data={users} columns={columns} getRowKey={(u) => u.id} />
|
|
267
|
+
* ```
|
|
268
|
+
*/
|
|
269
|
+
declare function DataTable<T>({ data, columns, getRowKey, onRowClick, loading, emptyMessage, className, showFilters, initialSortKey, initialSortDirection, onFilteredDataChange, }: DataTableProps<T>): react_jsx_runtime.JSX.Element;
|
|
270
|
+
/**
|
|
271
|
+
* Create filter options from data array.
|
|
272
|
+
* Extracts unique values and creates option objects.
|
|
273
|
+
*
|
|
274
|
+
* @example
|
|
275
|
+
* ```tsx
|
|
276
|
+
* const statusOptions = createFilterOptions(
|
|
277
|
+
* users,
|
|
278
|
+
* (user) => user.status,
|
|
279
|
+
* { active: 'Active', inactive: 'Inactive' }
|
|
280
|
+
* )
|
|
281
|
+
* ```
|
|
176
282
|
*/
|
|
177
|
-
declare function
|
|
283
|
+
declare function createFilterOptions<T>(data: T[], getValue: (item: T) => string | null | undefined, labelMap?: Record<string, string>): FilterOption[];
|
|
178
284
|
|
|
179
285
|
interface SelectOption<T = string> {
|
|
180
286
|
/** Unique value for the option */
|
|
@@ -313,4 +419,4 @@ declare function formatTime(totalSeconds: number): string;
|
|
|
313
419
|
*/
|
|
314
420
|
declare function Timer({ initialSeconds, onStart, onStop, onReset, onTick, showReset, size, className, isRunning: controlledIsRunning, elapsedSeconds: controlledElapsedSeconds, }: TimerProps): react_jsx_runtime.JSX.Element;
|
|
315
421
|
|
|
316
|
-
export { Button, Card, DatePicker, type DateRange, EmptyState, FormButtonGroup, FormInput, FormTextarea, Input, Layout, LoadingSpinner, Modal, Select, type SelectOption, ServiceSwitcher, Sidebar, type Tab, Table, type TableColumn, Tabs, Timer, type TimerState, formatTime };
|
|
422
|
+
export { Button, Card, DataTable, type DataTableColumn, type DataTableProps, DatePicker, type DateRange, EmptyState, type FilterOption, type FilterType, FormButtonGroup, FormInput, FormTextarea, Input, Layout, LoadingSpinner, Modal, Select, type SelectOption, ServiceSwitcher, Sidebar, type Tab, Table, type TableColumn, Tabs, Timer, type TimerState, createFilterOptions, formatTime };
|
package/dist/index.d.ts
CHANGED
|
@@ -142,16 +142,18 @@ declare function FormButtonGroup({ cancelText, submitText, loadingText, isLoadin
|
|
|
142
142
|
interface TableColumn<T> {
|
|
143
143
|
/** Unique key for the column */
|
|
144
144
|
key: string;
|
|
145
|
-
/** Column header text */
|
|
146
|
-
header:
|
|
145
|
+
/** Column header text or React element */
|
|
146
|
+
header: ReactNode;
|
|
147
147
|
/** Function to render cell content */
|
|
148
148
|
render: (item: T) => ReactNode;
|
|
149
149
|
/** Whether this column is sortable */
|
|
150
150
|
sortable?: boolean;
|
|
151
151
|
/** Custom sort function */
|
|
152
152
|
sortFn?: (a: T, b: T) => number;
|
|
153
|
-
/** Column width (e.g., '200px', '20%') */
|
|
153
|
+
/** Column width (e.g., '200px', '20%') - used as initial/min width */
|
|
154
154
|
width?: string;
|
|
155
|
+
/** Minimum column width when resizing */
|
|
156
|
+
minWidth?: number;
|
|
155
157
|
/** Text alignment */
|
|
156
158
|
align?: 'left' | 'center' | 'right';
|
|
157
159
|
}
|
|
@@ -170,11 +172,115 @@ interface TableProps<T> {
|
|
|
170
172
|
emptyMessage?: string;
|
|
171
173
|
/** Additional class names for the table container */
|
|
172
174
|
className?: string;
|
|
175
|
+
/** Enable manual column resizing (default: false) */
|
|
176
|
+
resizable?: boolean;
|
|
177
|
+
/** Use fixed table layout for consistent column widths */
|
|
178
|
+
fixedLayout?: boolean;
|
|
173
179
|
}
|
|
174
180
|
/**
|
|
175
|
-
* Table component for displaying tabular data with sorting
|
|
181
|
+
* Table component for displaying tabular data with sorting and optional resizing.
|
|
182
|
+
*
|
|
183
|
+
* Features:
|
|
184
|
+
* - Responsive by default - shrinks with container
|
|
185
|
+
* - Optional column resizing with drag handles
|
|
186
|
+
* - Sortable columns
|
|
187
|
+
* - Loading and empty states
|
|
188
|
+
*/
|
|
189
|
+
declare function Table<T>({ data, columns, getRowKey, onRowClick, loading, emptyMessage, className, resizable, fixedLayout, }: TableProps<T>): react_jsx_runtime.JSX.Element;
|
|
190
|
+
|
|
191
|
+
type FilterType = 'text' | 'select' | 'multiselect' | 'boolean' | 'date' | 'none';
|
|
192
|
+
interface FilterOption {
|
|
193
|
+
value: string;
|
|
194
|
+
label: string;
|
|
195
|
+
}
|
|
196
|
+
interface DataTableColumn<T> extends Omit<TableColumn<T>, 'sortable' | 'header'> {
|
|
197
|
+
/** Column header text (must be string for filter placeholder) */
|
|
198
|
+
header: string;
|
|
199
|
+
/** Whether this column is sortable (default: true) */
|
|
200
|
+
sortable?: boolean;
|
|
201
|
+
/** Filter type for this column (default: 'text') */
|
|
202
|
+
filterType?: FilterType;
|
|
203
|
+
/** Options for select/multiselect filters */
|
|
204
|
+
filterOptions?: FilterOption[];
|
|
205
|
+
/** Function to get filterable value from item */
|
|
206
|
+
filterValue?: (item: T) => string | number | boolean | null | undefined;
|
|
207
|
+
/** Placeholder for filter input */
|
|
208
|
+
filterPlaceholder?: string;
|
|
209
|
+
}
|
|
210
|
+
interface DataTableProps<T> {
|
|
211
|
+
/** Array of data items to display */
|
|
212
|
+
data: T[];
|
|
213
|
+
/** Column definitions */
|
|
214
|
+
columns: DataTableColumn<T>[];
|
|
215
|
+
/** Function to get unique key for each row */
|
|
216
|
+
getRowKey: (item: T) => string | number;
|
|
217
|
+
/** Called when a row is clicked */
|
|
218
|
+
onRowClick?: (item: T) => void;
|
|
219
|
+
/** Whether the table is in a loading state */
|
|
220
|
+
loading?: boolean;
|
|
221
|
+
/** Message to show when data is empty */
|
|
222
|
+
emptyMessage?: string;
|
|
223
|
+
/** Additional class names for the table container */
|
|
224
|
+
className?: string;
|
|
225
|
+
/** Show filter row (default: true) */
|
|
226
|
+
showFilters?: boolean;
|
|
227
|
+
/** Initial sort column key */
|
|
228
|
+
initialSortKey?: string;
|
|
229
|
+
/** Initial sort direction */
|
|
230
|
+
initialSortDirection?: 'asc' | 'desc';
|
|
231
|
+
/** Called when filtered data changes (for external use, e.g., showing count) */
|
|
232
|
+
onFilteredDataChange?: (filteredData: T[]) => void;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* DataTable component - an enhanced Table with built-in filtering and sorting.
|
|
236
|
+
*
|
|
237
|
+
* Features:
|
|
238
|
+
* - Text, select, multiselect, and boolean filters per column
|
|
239
|
+
* - Sortable columns (default: all columns are sortable)
|
|
240
|
+
* - Filter state management
|
|
241
|
+
* - Callback when filtered data changes
|
|
242
|
+
*
|
|
243
|
+
* @example
|
|
244
|
+
* ```tsx
|
|
245
|
+
* const columns: DataTableColumn<User>[] = [
|
|
246
|
+
* {
|
|
247
|
+
* key: 'name',
|
|
248
|
+
* header: 'Name',
|
|
249
|
+
* filterType: 'text',
|
|
250
|
+
* filterValue: (user) => user.name,
|
|
251
|
+
* render: (user) => <span>{user.name}</span>,
|
|
252
|
+
* },
|
|
253
|
+
* {
|
|
254
|
+
* key: 'status',
|
|
255
|
+
* header: 'Status',
|
|
256
|
+
* filterType: 'select',
|
|
257
|
+
* filterOptions: [
|
|
258
|
+
* { value: 'active', label: 'Active' },
|
|
259
|
+
* { value: 'inactive', label: 'Inactive' },
|
|
260
|
+
* ],
|
|
261
|
+
* filterValue: (user) => user.status,
|
|
262
|
+
* render: (user) => <Badge>{user.status}</Badge>,
|
|
263
|
+
* },
|
|
264
|
+
* ]
|
|
265
|
+
*
|
|
266
|
+
* <DataTable data={users} columns={columns} getRowKey={(u) => u.id} />
|
|
267
|
+
* ```
|
|
268
|
+
*/
|
|
269
|
+
declare function DataTable<T>({ data, columns, getRowKey, onRowClick, loading, emptyMessage, className, showFilters, initialSortKey, initialSortDirection, onFilteredDataChange, }: DataTableProps<T>): react_jsx_runtime.JSX.Element;
|
|
270
|
+
/**
|
|
271
|
+
* Create filter options from data array.
|
|
272
|
+
* Extracts unique values and creates option objects.
|
|
273
|
+
*
|
|
274
|
+
* @example
|
|
275
|
+
* ```tsx
|
|
276
|
+
* const statusOptions = createFilterOptions(
|
|
277
|
+
* users,
|
|
278
|
+
* (user) => user.status,
|
|
279
|
+
* { active: 'Active', inactive: 'Inactive' }
|
|
280
|
+
* )
|
|
281
|
+
* ```
|
|
176
282
|
*/
|
|
177
|
-
declare function
|
|
283
|
+
declare function createFilterOptions<T>(data: T[], getValue: (item: T) => string | null | undefined, labelMap?: Record<string, string>): FilterOption[];
|
|
178
284
|
|
|
179
285
|
interface SelectOption<T = string> {
|
|
180
286
|
/** Unique value for the option */
|
|
@@ -313,4 +419,4 @@ declare function formatTime(totalSeconds: number): string;
|
|
|
313
419
|
*/
|
|
314
420
|
declare function Timer({ initialSeconds, onStart, onStop, onReset, onTick, showReset, size, className, isRunning: controlledIsRunning, elapsedSeconds: controlledElapsedSeconds, }: TimerProps): react_jsx_runtime.JSX.Element;
|
|
315
421
|
|
|
316
|
-
export { Button, Card, DatePicker, type DateRange, EmptyState, FormButtonGroup, FormInput, FormTextarea, Input, Layout, LoadingSpinner, Modal, Select, type SelectOption, ServiceSwitcher, Sidebar, type Tab, Table, type TableColumn, Tabs, Timer, type TimerState, formatTime };
|
|
422
|
+
export { Button, Card, DataTable, type DataTableColumn, type DataTableProps, DatePicker, type DateRange, EmptyState, type FilterOption, type FilterType, FormButtonGroup, FormInput, FormTextarea, Input, Layout, LoadingSpinner, Modal, Select, type SelectOption, ServiceSwitcher, Sidebar, type Tab, Table, type TableColumn, Tabs, Timer, type TimerState, createFilterOptions, formatTime };
|