@kreativa/ui 0.1.0 → 0.1.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.
- package/dist/index.d.mts +93 -1
- package/dist/index.d.ts +93 -1
- package/dist/index.js +303 -60
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +295 -54
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -176,6 +176,98 @@ interface TableProps<T> {
|
|
|
176
176
|
*/
|
|
177
177
|
declare function Table<T>({ data, columns, getRowKey, onRowClick, loading, emptyMessage, className, }: TableProps<T>): react_jsx_runtime.JSX.Element;
|
|
178
178
|
|
|
179
|
+
type FilterType = 'text' | 'select' | 'multiselect' | 'boolean' | 'date' | 'none';
|
|
180
|
+
interface FilterOption {
|
|
181
|
+
value: string;
|
|
182
|
+
label: string;
|
|
183
|
+
}
|
|
184
|
+
interface DataTableColumn<T> extends Omit<TableColumn<T>, 'sortable'> {
|
|
185
|
+
/** Whether this column is sortable (default: true) */
|
|
186
|
+
sortable?: boolean;
|
|
187
|
+
/** Filter type for this column (default: 'text') */
|
|
188
|
+
filterType?: FilterType;
|
|
189
|
+
/** Options for select/multiselect filters */
|
|
190
|
+
filterOptions?: FilterOption[];
|
|
191
|
+
/** Function to get filterable value from item */
|
|
192
|
+
filterValue?: (item: T) => string | number | boolean | null | undefined;
|
|
193
|
+
/** Placeholder for filter input */
|
|
194
|
+
filterPlaceholder?: string;
|
|
195
|
+
}
|
|
196
|
+
interface DataTableProps<T> {
|
|
197
|
+
/** Array of data items to display */
|
|
198
|
+
data: T[];
|
|
199
|
+
/** Column definitions */
|
|
200
|
+
columns: DataTableColumn<T>[];
|
|
201
|
+
/** Function to get unique key for each row */
|
|
202
|
+
getRowKey: (item: T) => string | number;
|
|
203
|
+
/** Called when a row is clicked */
|
|
204
|
+
onRowClick?: (item: T) => void;
|
|
205
|
+
/** Whether the table is in a loading state */
|
|
206
|
+
loading?: boolean;
|
|
207
|
+
/** Message to show when data is empty */
|
|
208
|
+
emptyMessage?: string;
|
|
209
|
+
/** Additional class names for the table container */
|
|
210
|
+
className?: string;
|
|
211
|
+
/** Show filter row (default: true) */
|
|
212
|
+
showFilters?: boolean;
|
|
213
|
+
/** Initial sort column key */
|
|
214
|
+
initialSortKey?: string;
|
|
215
|
+
/** Initial sort direction */
|
|
216
|
+
initialSortDirection?: 'asc' | 'desc';
|
|
217
|
+
/** Called when filtered data changes (for external use, e.g., showing count) */
|
|
218
|
+
onFilteredDataChange?: (filteredData: T[]) => void;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* DataTable component - an enhanced Table with built-in filtering and sorting.
|
|
222
|
+
*
|
|
223
|
+
* Features:
|
|
224
|
+
* - Text, select, multiselect, and boolean filters per column
|
|
225
|
+
* - Sortable columns (default: all columns are sortable)
|
|
226
|
+
* - Filter state management
|
|
227
|
+
* - Callback when filtered data changes
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* ```tsx
|
|
231
|
+
* const columns: DataTableColumn<User>[] = [
|
|
232
|
+
* {
|
|
233
|
+
* key: 'name',
|
|
234
|
+
* header: 'Name',
|
|
235
|
+
* filterType: 'text',
|
|
236
|
+
* filterValue: (user) => user.name,
|
|
237
|
+
* render: (user) => <span>{user.name}</span>,
|
|
238
|
+
* },
|
|
239
|
+
* {
|
|
240
|
+
* key: 'status',
|
|
241
|
+
* header: 'Status',
|
|
242
|
+
* filterType: 'select',
|
|
243
|
+
* filterOptions: [
|
|
244
|
+
* { value: 'active', label: 'Active' },
|
|
245
|
+
* { value: 'inactive', label: 'Inactive' },
|
|
246
|
+
* ],
|
|
247
|
+
* filterValue: (user) => user.status,
|
|
248
|
+
* render: (user) => <Badge>{user.status}</Badge>,
|
|
249
|
+
* },
|
|
250
|
+
* ]
|
|
251
|
+
*
|
|
252
|
+
* <DataTable data={users} columns={columns} getRowKey={(u) => u.id} />
|
|
253
|
+
* ```
|
|
254
|
+
*/
|
|
255
|
+
declare function DataTable<T>({ data, columns, getRowKey, onRowClick, loading, emptyMessage, className, showFilters, initialSortKey, initialSortDirection, onFilteredDataChange, }: DataTableProps<T>): react_jsx_runtime.JSX.Element;
|
|
256
|
+
/**
|
|
257
|
+
* Create filter options from data array.
|
|
258
|
+
* Extracts unique values and creates option objects.
|
|
259
|
+
*
|
|
260
|
+
* @example
|
|
261
|
+
* ```tsx
|
|
262
|
+
* const statusOptions = createFilterOptions(
|
|
263
|
+
* users,
|
|
264
|
+
* (user) => user.status,
|
|
265
|
+
* { active: 'Active', inactive: 'Inactive' }
|
|
266
|
+
* )
|
|
267
|
+
* ```
|
|
268
|
+
*/
|
|
269
|
+
declare function createFilterOptions<T>(data: T[], getValue: (item: T) => string | null | undefined, labelMap?: Record<string, string>): FilterOption[];
|
|
270
|
+
|
|
179
271
|
interface SelectOption<T = string> {
|
|
180
272
|
/** Unique value for the option */
|
|
181
273
|
value: T;
|
|
@@ -313,4 +405,4 @@ declare function formatTime(totalSeconds: number): string;
|
|
|
313
405
|
*/
|
|
314
406
|
declare function Timer({ initialSeconds, onStart, onStop, onReset, onTick, showReset, size, className, isRunning: controlledIsRunning, elapsedSeconds: controlledElapsedSeconds, }: TimerProps): react_jsx_runtime.JSX.Element;
|
|
315
407
|
|
|
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 };
|
|
408
|
+
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
|
@@ -176,6 +176,98 @@ interface TableProps<T> {
|
|
|
176
176
|
*/
|
|
177
177
|
declare function Table<T>({ data, columns, getRowKey, onRowClick, loading, emptyMessage, className, }: TableProps<T>): react_jsx_runtime.JSX.Element;
|
|
178
178
|
|
|
179
|
+
type FilterType = 'text' | 'select' | 'multiselect' | 'boolean' | 'date' | 'none';
|
|
180
|
+
interface FilterOption {
|
|
181
|
+
value: string;
|
|
182
|
+
label: string;
|
|
183
|
+
}
|
|
184
|
+
interface DataTableColumn<T> extends Omit<TableColumn<T>, 'sortable'> {
|
|
185
|
+
/** Whether this column is sortable (default: true) */
|
|
186
|
+
sortable?: boolean;
|
|
187
|
+
/** Filter type for this column (default: 'text') */
|
|
188
|
+
filterType?: FilterType;
|
|
189
|
+
/** Options for select/multiselect filters */
|
|
190
|
+
filterOptions?: FilterOption[];
|
|
191
|
+
/** Function to get filterable value from item */
|
|
192
|
+
filterValue?: (item: T) => string | number | boolean | null | undefined;
|
|
193
|
+
/** Placeholder for filter input */
|
|
194
|
+
filterPlaceholder?: string;
|
|
195
|
+
}
|
|
196
|
+
interface DataTableProps<T> {
|
|
197
|
+
/** Array of data items to display */
|
|
198
|
+
data: T[];
|
|
199
|
+
/** Column definitions */
|
|
200
|
+
columns: DataTableColumn<T>[];
|
|
201
|
+
/** Function to get unique key for each row */
|
|
202
|
+
getRowKey: (item: T) => string | number;
|
|
203
|
+
/** Called when a row is clicked */
|
|
204
|
+
onRowClick?: (item: T) => void;
|
|
205
|
+
/** Whether the table is in a loading state */
|
|
206
|
+
loading?: boolean;
|
|
207
|
+
/** Message to show when data is empty */
|
|
208
|
+
emptyMessage?: string;
|
|
209
|
+
/** Additional class names for the table container */
|
|
210
|
+
className?: string;
|
|
211
|
+
/** Show filter row (default: true) */
|
|
212
|
+
showFilters?: boolean;
|
|
213
|
+
/** Initial sort column key */
|
|
214
|
+
initialSortKey?: string;
|
|
215
|
+
/** Initial sort direction */
|
|
216
|
+
initialSortDirection?: 'asc' | 'desc';
|
|
217
|
+
/** Called when filtered data changes (for external use, e.g., showing count) */
|
|
218
|
+
onFilteredDataChange?: (filteredData: T[]) => void;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* DataTable component - an enhanced Table with built-in filtering and sorting.
|
|
222
|
+
*
|
|
223
|
+
* Features:
|
|
224
|
+
* - Text, select, multiselect, and boolean filters per column
|
|
225
|
+
* - Sortable columns (default: all columns are sortable)
|
|
226
|
+
* - Filter state management
|
|
227
|
+
* - Callback when filtered data changes
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* ```tsx
|
|
231
|
+
* const columns: DataTableColumn<User>[] = [
|
|
232
|
+
* {
|
|
233
|
+
* key: 'name',
|
|
234
|
+
* header: 'Name',
|
|
235
|
+
* filterType: 'text',
|
|
236
|
+
* filterValue: (user) => user.name,
|
|
237
|
+
* render: (user) => <span>{user.name}</span>,
|
|
238
|
+
* },
|
|
239
|
+
* {
|
|
240
|
+
* key: 'status',
|
|
241
|
+
* header: 'Status',
|
|
242
|
+
* filterType: 'select',
|
|
243
|
+
* filterOptions: [
|
|
244
|
+
* { value: 'active', label: 'Active' },
|
|
245
|
+
* { value: 'inactive', label: 'Inactive' },
|
|
246
|
+
* ],
|
|
247
|
+
* filterValue: (user) => user.status,
|
|
248
|
+
* render: (user) => <Badge>{user.status}</Badge>,
|
|
249
|
+
* },
|
|
250
|
+
* ]
|
|
251
|
+
*
|
|
252
|
+
* <DataTable data={users} columns={columns} getRowKey={(u) => u.id} />
|
|
253
|
+
* ```
|
|
254
|
+
*/
|
|
255
|
+
declare function DataTable<T>({ data, columns, getRowKey, onRowClick, loading, emptyMessage, className, showFilters, initialSortKey, initialSortDirection, onFilteredDataChange, }: DataTableProps<T>): react_jsx_runtime.JSX.Element;
|
|
256
|
+
/**
|
|
257
|
+
* Create filter options from data array.
|
|
258
|
+
* Extracts unique values and creates option objects.
|
|
259
|
+
*
|
|
260
|
+
* @example
|
|
261
|
+
* ```tsx
|
|
262
|
+
* const statusOptions = createFilterOptions(
|
|
263
|
+
* users,
|
|
264
|
+
* (user) => user.status,
|
|
265
|
+
* { active: 'Active', inactive: 'Inactive' }
|
|
266
|
+
* )
|
|
267
|
+
* ```
|
|
268
|
+
*/
|
|
269
|
+
declare function createFilterOptions<T>(data: T[], getValue: (item: T) => string | null | undefined, labelMap?: Record<string, string>): FilterOption[];
|
|
270
|
+
|
|
179
271
|
interface SelectOption<T = string> {
|
|
180
272
|
/** Unique value for the option */
|
|
181
273
|
value: T;
|
|
@@ -313,4 +405,4 @@ declare function formatTime(totalSeconds: number): string;
|
|
|
313
405
|
*/
|
|
314
406
|
declare function Timer({ initialSeconds, onStart, onStop, onReset, onTick, showReset, size, className, isRunning: controlledIsRunning, elapsedSeconds: controlledElapsedSeconds, }: TimerProps): react_jsx_runtime.JSX.Element;
|
|
315
407
|
|
|
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 };
|
|
408
|
+
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 };
|