@aic-kits/react 0.35.2 → 0.35.4

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.
Files changed (47) hide show
  1. package/dist/components/Button/StyledButton.d.ts +15 -10
  2. package/dist/components/Grid/StyledGrid.d.ts +13 -4
  3. package/dist/components/Grid/__tests__/index.test.d.ts +1 -0
  4. package/dist/components/Grid/__tests__/utils.test.d.ts +1 -0
  5. package/dist/components/Grid/types.d.ts +2 -1
  6. package/dist/components/Grid/utils.d.ts +2 -1
  7. package/dist/components/Input/StyledInput.d.ts +2 -1
  8. package/dist/components/Input/types.d.ts +6 -1
  9. package/dist/components/Radio/Radio.d.ts +3 -0
  10. package/dist/components/Radio/RadioButton.d.ts +3 -0
  11. package/dist/components/Radio/RadioContext.d.ts +3 -0
  12. package/dist/components/Radio/RadioGroup.d.ts +3 -0
  13. package/dist/components/Radio/index.d.ts +10 -0
  14. package/dist/components/Radio/types.d.ts +147 -0
  15. package/dist/components/Select/Select.d.ts +1 -1
  16. package/dist/components/Select/types.d.ts +10 -1
  17. package/dist/components/Switch/StyledSwitch.d.ts +6 -0
  18. package/dist/components/Switch/Switch.d.ts +3 -0
  19. package/dist/components/Switch/__tests__/index.test.d.ts +1 -0
  20. package/dist/components/Switch/index.d.ts +2 -0
  21. package/dist/components/Switch/types.d.ts +44 -0
  22. package/dist/components/Table/AccordionRow.d.ts +5 -0
  23. package/dist/components/Table/AccordionRowContent.d.ts +20 -0
  24. package/dist/components/Table/AccordionRowHeader.d.ts +16 -0
  25. package/dist/components/Table/AddForm.d.ts +5 -0
  26. package/dist/components/Table/DeleteDialog.d.ts +3 -0
  27. package/dist/components/Table/Filters.d.ts +3 -0
  28. package/dist/components/Table/FormFields.d.ts +24 -0
  29. package/dist/components/Table/InlineMultiSelect.d.ts +3 -0
  30. package/dist/components/Table/InlinePairSelect.d.ts +3 -0
  31. package/dist/components/Table/StyledTable.d.ts +29 -0
  32. package/dist/components/Table/Table.d.ts +5 -0
  33. package/dist/components/Table/TableHeaderRow.d.ts +10 -0
  34. package/dist/components/Table/TablePagination.d.ts +11 -0
  35. package/dist/components/Table/ValidationDialog.d.ts +7 -0
  36. package/dist/components/Table/hooks.d.ts +34 -0
  37. package/dist/components/Table/index.d.ts +12 -0
  38. package/dist/components/Table/types.d.ts +374 -0
  39. package/dist/components/Table/utils.d.ts +83 -0
  40. package/dist/components/index.d.ts +3 -0
  41. package/dist/index.cjs +486 -370
  42. package/dist/index.js +13162 -9559
  43. package/dist/theme/components/index.d.ts +10 -1
  44. package/dist/theme/components/radio.d.ts +42 -0
  45. package/dist/theme/components/switch.d.ts +27 -0
  46. package/dist/theme/components/table.d.ts +34 -0
  47. package/package.json +2 -2
@@ -0,0 +1,12 @@
1
+ export { Table } from './Table';
2
+ export { AccordionRow } from './AccordionRow';
3
+ export { AddForm } from './AddForm';
4
+ export { DeleteDialog } from './DeleteDialog';
5
+ export { FormFields } from './FormFields';
6
+ export { Filters } from './Filters';
7
+ export { InlineMultiSelect } from './InlineMultiSelect';
8
+ export { InlinePairSelect } from './InlinePairSelect';
9
+ export { useTable, useLocalStateAdapter } from './hooks';
10
+ export { applyFilters, PAGINATION_PARAMS, createNonFilterParams, filtersToSearchParams, parseFiltersFromParams, } from './utils';
11
+ export type { FormFieldsProps } from './FormFields';
12
+ export type { RecordWithId, FilterOperator, FilterCondition, FilterFn, InlinePairSelectOption, InlinePairSelectValue, InlinePairSelectConfig, InlineMultiSelectOption, InlineMultiSelectGroupOption, ColumnType, FilterType, Column, PaginationParams, PaginatedResponse, TableProps, AccordionRowProps, AddFormProps, FiltersProps, DeleteDialogProps, InlineMultiSelectProps, InlinePairSelectProps, UseTableConfig, TableStateAdapter, UseTableReturn, UseLocalStateAdapterConfig, } from './types';
@@ -0,0 +1,374 @@
1
+ import { ReactNode } from 'react';
2
+ import { Color, Radius } from '../../theme';
3
+ /**
4
+ * Base type for records with an id field
5
+ */
6
+ export type RecordWithId = {
7
+ id: string | number;
8
+ [key: string]: unknown;
9
+ };
10
+ /**
11
+ * Filter operators for table filtering
12
+ */
13
+ export type FilterOperator = 'equals' | 'contains' | 'starts_with' | 'ends_with' | 'greater_than' | 'less_than' | 'greater_equal' | 'less_equal' | 'not_equals' | 'is_empty' | 'is_not_empty';
14
+ /**
15
+ * Filter condition for a column
16
+ */
17
+ export interface FilterCondition<T> {
18
+ id: string;
19
+ column: keyof T;
20
+ operator: FilterOperator;
21
+ value: string;
22
+ valueEnd?: string;
23
+ relation?: string;
24
+ }
25
+ /**
26
+ * Custom filter function type
27
+ */
28
+ export type FilterFn<T> = (data: T[], filters: FilterCondition<T>[]) => T[];
29
+ /**
30
+ * Option for inline pair select
31
+ */
32
+ export interface InlinePairSelectOption {
33
+ value: string;
34
+ label: string;
35
+ icon?: ReactNode;
36
+ }
37
+ /**
38
+ * Value type for inline pair select
39
+ */
40
+ export type InlinePairSelectValue = Record<string, string>;
41
+ /**
42
+ * Configuration for inline pair select
43
+ */
44
+ export interface InlinePairSelectConfig {
45
+ primaryLabel?: string;
46
+ secondaryLabel?: string;
47
+ primaryPlaceholder?: string;
48
+ secondaryPlaceholder?: string;
49
+ emptyStateText?: string;
50
+ valueKeys?: {
51
+ primary: string;
52
+ secondary: string;
53
+ };
54
+ primaryOptions: InlinePairSelectOption[];
55
+ secondaryOptions: InlinePairSelectOption[];
56
+ getSecondaryOptions?: (primaryValue: string) => InlinePairSelectOption[];
57
+ }
58
+ /**
59
+ * Option for inline multi select
60
+ */
61
+ export interface InlineMultiSelectOption {
62
+ value: string;
63
+ label: string;
64
+ }
65
+ /**
66
+ * Group option for inline multi select
67
+ */
68
+ export interface InlineMultiSelectGroupOption {
69
+ values: string[];
70
+ label: string;
71
+ }
72
+ /**
73
+ * Column type definitions
74
+ */
75
+ export type ColumnType = 'text' | 'number' | 'email' | 'date' | 'select' | 'link' | 'checkboxes' | 'inlinemultiselect' | 'inlinepairselect' | 'boolean';
76
+ /**
77
+ * Filter type definitions
78
+ */
79
+ export type FilterType = 'text' | 'number' | 'date' | 'select' | 'checkboxes' | 'boolean' | 'none' | 'inlinemultiselect' | 'inlinepairselect';
80
+ /**
81
+ * Column definition for table
82
+ */
83
+ export interface Column<T> {
84
+ key: keyof T | 'select';
85
+ header: string;
86
+ sortable?: boolean;
87
+ render?: (value: unknown, item: T) => ReactNode;
88
+ renderEditField?: (value: unknown, item: T, onChange: (value: unknown) => void) => ReactNode;
89
+ editable?: boolean;
90
+ required?: boolean;
91
+ multiline?: boolean;
92
+ type?: ColumnType;
93
+ filterType?: FilterType;
94
+ /** For inlinemultiselect filter: 'option' filters by individual options, 'group' filters by groupOptions */
95
+ filterBy?: 'option' | 'group';
96
+ options?: {
97
+ value: string;
98
+ label: string;
99
+ }[];
100
+ filterOptions?: {
101
+ value: string;
102
+ label: string;
103
+ }[];
104
+ groupOptions?: {
105
+ values: string[];
106
+ label: string;
107
+ }[];
108
+ pairOptions?: InlinePairSelectConfig;
109
+ flex?: number | string;
110
+ truncate?: boolean;
111
+ href?: (item: T) => string;
112
+ hiddenInHeader?: boolean;
113
+ hiddenInContent?: boolean;
114
+ headerEditable?: boolean;
115
+ filterKey?: string;
116
+ filterRelation?: string;
117
+ tagColor?: Color;
118
+ defaultValue?: unknown;
119
+ }
120
+ /**
121
+ * Pagination parameters
122
+ */
123
+ export interface PaginationParams {
124
+ page: number;
125
+ pageSize: number;
126
+ sortBy?: string;
127
+ sortDirection?: 'asc' | 'desc';
128
+ search?: string;
129
+ }
130
+ /**
131
+ * Paginated response type
132
+ */
133
+ export interface PaginatedResponse<T> {
134
+ data: T[];
135
+ total: number;
136
+ page: number;
137
+ pageSize: number;
138
+ }
139
+ /**
140
+ * Table component props
141
+ */
142
+ export interface TableProps<T extends {
143
+ id: string | number;
144
+ }> {
145
+ data: T[];
146
+ columns: Column<T>[];
147
+ onAdd?: (item: Omit<T, 'id'>) => void | Promise<void>;
148
+ onEdit?: (id: string | number, item: Partial<T>) => void | Promise<void>;
149
+ onDelete?: (id: string | number) => void | Promise<void>;
150
+ onView?: (id: string | number) => Promise<unknown>;
151
+ renderExpandedRow?: (item: T, detailedData: unknown) => ReactNode;
152
+ onSelectedItemChange?: (item: T | null) => void | Promise<void>;
153
+ title?: string;
154
+ addButtonText?: string;
155
+ editButtonText?: string;
156
+ deleteButtonText?: string;
157
+ viewButtonText?: string;
158
+ confirmDeleteMessage?: string;
159
+ noDataMessage?: string;
160
+ total: number;
161
+ currentPage: number;
162
+ pageSize: number;
163
+ pageSizeOptions?: number[];
164
+ sortBy?: string;
165
+ sortDirection?: 'asc' | 'desc';
166
+ onPaginationChange: (params: PaginationParams) => void;
167
+ isLoading?: boolean;
168
+ filters?: FilterCondition<T>[];
169
+ onFiltersChange?: (filters: FilterCondition<T>[]) => void;
170
+ showFilterBuilder?: boolean;
171
+ onFieldChange?: (updates: Partial<T>, key: keyof T, value: unknown) => Partial<T>;
172
+ expandable?: boolean;
173
+ /** Error message displayed as a banner above the table */
174
+ error?: string | null;
175
+ }
176
+ /**
177
+ * AccordionRow component props
178
+ */
179
+ export interface AccordionRowProps<T extends {
180
+ id: string | number;
181
+ }> {
182
+ item: T;
183
+ columns: Column<T>[];
184
+ allColumns: Column<T>[];
185
+ expandedRows: Set<string | number>;
186
+ editFormData: Record<string | number, Partial<T>>;
187
+ loadingDetails: Set<string | number>;
188
+ isFormLoading: boolean;
189
+ isEditable?: boolean;
190
+ isExpandAccordion?: boolean;
191
+ isSelected?: boolean;
192
+ onToggleExpanded: (item: T) => void;
193
+ onEditFormChange: (itemId: string | number, key: keyof T, value: unknown) => void;
194
+ onSave: (item: T) => void;
195
+ onDelete?: (item: T) => void;
196
+ onQuickEdit?: (item: T, key: keyof T, value: unknown) => void;
197
+ }
198
+ /**
199
+ * AddForm component props
200
+ */
201
+ export interface AddFormProps<T extends {
202
+ id: string | number;
203
+ }> {
204
+ columns: Column<T>[];
205
+ formData: Partial<T>;
206
+ isLoading: boolean;
207
+ onInputChange: (key: keyof T, value: unknown) => void;
208
+ onSubmit: () => void;
209
+ onCancel: () => void;
210
+ }
211
+ /**
212
+ * Filters component props
213
+ */
214
+ export interface FiltersProps<T> {
215
+ columns: Column<T>[];
216
+ filters: FilterCondition<T>[];
217
+ onFiltersChange: (filters: FilterCondition<T>[]) => void;
218
+ /**
219
+ * Border radius for Input, Select, and DatePicker components
220
+ * @default 'md'
221
+ */
222
+ borderRadius?: Radius;
223
+ }
224
+ /**
225
+ * DeleteDialog component props
226
+ */
227
+ export interface DeleteDialogProps {
228
+ open: boolean;
229
+ onOpenChange: (open: boolean) => void;
230
+ onConfirm: () => void;
231
+ isLoading?: boolean;
232
+ message?: string;
233
+ deleteButtonText?: string;
234
+ }
235
+ /**
236
+ * InlineMultiSelect component props
237
+ */
238
+ export interface InlineMultiSelectProps {
239
+ options: InlineMultiSelectOption[];
240
+ groupOptions: InlineMultiSelectGroupOption[];
241
+ value: string[];
242
+ onChange: (next: string[]) => void;
243
+ placeholder?: string;
244
+ max?: number;
245
+ limit?: number;
246
+ }
247
+ /**
248
+ * InlinePairSelect component props
249
+ */
250
+ export interface InlinePairSelectProps {
251
+ primaryOptions: InlinePairSelectOption[];
252
+ secondaryOptions: InlinePairSelectOption[];
253
+ getSecondaryOptions?: (primaryValue: string) => InlinePairSelectOption[];
254
+ value: InlinePairSelectValue[];
255
+ onChange: (next: InlinePairSelectValue[]) => void;
256
+ primaryLabel?: string;
257
+ secondaryLabel?: string;
258
+ primaryPlaceholder?: string;
259
+ secondaryPlaceholder?: string;
260
+ emptyStateText?: string;
261
+ valueKeys?: {
262
+ primary: string;
263
+ secondary: string;
264
+ };
265
+ disabled?: boolean;
266
+ /**
267
+ * Border radius for Select components
268
+ * @default 'md'
269
+ */
270
+ borderRadius?: Radius;
271
+ }
272
+ /**
273
+ * Configuration for useTable hook defaults
274
+ */
275
+ export interface UseTableConfig {
276
+ defaultPageSize: number;
277
+ defaultSortBy: string;
278
+ defaultSortDirection: 'asc' | 'desc';
279
+ }
280
+ /**
281
+ * Adapter interface for reading and writing table UI state
282
+ * Enables useTable to work with different state backends (URL params, local state, etc.)
283
+ */
284
+ export interface TableStateAdapter<T = unknown> {
285
+ getCurrentPage: () => number;
286
+ getPageSize: () => number;
287
+ getSortBy: () => string;
288
+ getSortDirection: () => 'asc' | 'desc';
289
+ getFilters: () => FilterCondition<T>[];
290
+ setPagination: (params: PaginationParams) => void;
291
+ setFilters: (filters: FilterCondition<T>[]) => void;
292
+ }
293
+ /**
294
+ * Return type for useTable hook
295
+ */
296
+ export interface UseTableReturn<T = unknown> {
297
+ currentPage: number;
298
+ pageSize: number;
299
+ sortBy: string;
300
+ sortDirection: 'asc' | 'desc';
301
+ filters: FilterCondition<T>[];
302
+ onPaginationChange: (params: PaginationParams) => void;
303
+ onFiltersChange: (filters: FilterCondition<T>[]) => void;
304
+ }
305
+ /**
306
+ * Configuration for useLocalStateAdapter hook
307
+ */
308
+ export interface UseLocalStateAdapterConfig {
309
+ defaultPageSize?: number;
310
+ defaultSortBy?: string;
311
+ defaultSortDirection?: 'asc' | 'desc';
312
+ }
313
+ /**
314
+ * Props for useTableState hook
315
+ */
316
+ export interface UseTableStateProps<T extends {
317
+ id: string | number;
318
+ }> {
319
+ data: T[];
320
+ columns: Column<T>[];
321
+ currentPage: number;
322
+ pageSize: number;
323
+ total: number;
324
+ sortBy?: string;
325
+ sortDirection: 'asc' | 'desc';
326
+ onPaginationChange: (params: PaginationParams) => void;
327
+ onAdd?: (item: Omit<T, 'id'>) => void | Promise<void>;
328
+ onEdit?: (id: string | number, item: Partial<T>) => void | Promise<void>;
329
+ onDelete?: (id: string | number) => void | Promise<void>;
330
+ onView?: (id: string | number) => Promise<unknown>;
331
+ onSelectedItemChange?: (item: T | null) => void | Promise<void>;
332
+ onFieldChange?: (formData: Partial<T>, changedKey: keyof T, newValue: unknown) => Partial<T>;
333
+ renderExpandedRow?: (item: T, detailedData: unknown) => ReactNode;
334
+ }
335
+ /**
336
+ * Return type for useTableState hook
337
+ */
338
+ export interface UseTableStateReturn<T extends {
339
+ id: string | number;
340
+ }> {
341
+ visibleColumns: Column<T>[];
342
+ displayData: T[];
343
+ totalPages: number;
344
+ totalFlex: number;
345
+ defaults: Partial<T>;
346
+ isAddFormOpen: boolean;
347
+ setIsAddFormOpen: (open: boolean) => void;
348
+ isDeleteDialogOpen: boolean;
349
+ setIsDeleteDialogOpen: (open: boolean) => void;
350
+ validationErrors: string[];
351
+ setValidationErrors: (errors: string[]) => void;
352
+ isFilterBuilderOpen: boolean;
353
+ setIsFilterBuilderOpen: (open: boolean) => void;
354
+ isFormLoading: boolean;
355
+ selectedItem: T | null;
356
+ setSelectedItem: (item: T | null) => void;
357
+ addFormData: Partial<T>;
358
+ setAddFormData: (data: Partial<T>) => void;
359
+ editFormData: Record<string | number, Partial<T>>;
360
+ expandedRows: Set<string | number>;
361
+ loadingDetails: Set<string | number>;
362
+ detailedData: Record<string | number, unknown>;
363
+ handleSort: (key: keyof T) => void;
364
+ handlePageChange: (page: number) => void;
365
+ handlePageSizeChange: (newPageSize: number) => void;
366
+ handleAddFormInputChange: (key: keyof T, value: unknown) => void;
367
+ handleAdd: () => Promise<void>;
368
+ handleDelete: () => Promise<void>;
369
+ openDeleteDialog: (item: T) => void;
370
+ toggleExpandedRow: (item: T) => Promise<void>;
371
+ handleInlineEditFormChange: (itemId: string | number, key: keyof T, value: unknown) => void;
372
+ handleInlineSave: (item: T) => void;
373
+ handleQuickEdit: (row: T, key: keyof T, value: unknown) => void;
374
+ }
@@ -0,0 +1,83 @@
1
+ import { FilterCondition } from './types';
2
+ /**
3
+ * Format a date value for display in table cells.
4
+ * Uses DD/MM/YYYY format to match editable inputs (Filters, AddForm, AccordionRow).
5
+ */
6
+ export declare function formatCellDate(value: unknown): string;
7
+ /**
8
+ * Format a cell value for display, handling complex types like arrays and objects.
9
+ * Resolves labels from column options for select/multiselect/pairselect types.
10
+ */
11
+ export declare function formatCellValue(value: unknown, column: {
12
+ type?: string;
13
+ options?: {
14
+ value: string;
15
+ label: string;
16
+ }[];
17
+ pairOptions?: {
18
+ primaryOptions: {
19
+ value: string;
20
+ label: string;
21
+ }[];
22
+ secondaryOptions: {
23
+ value: string;
24
+ label: string;
25
+ }[];
26
+ valueKeys?: {
27
+ primary: string;
28
+ secondary: string;
29
+ };
30
+ };
31
+ }): string;
32
+ /**
33
+ * Common pagination and sorting parameters that should NOT be treated as filters
34
+ */
35
+ export declare const PAGINATION_PARAMS: Set<string>;
36
+ /**
37
+ * Create a set of known non-filter params by combining pagination params with custom params
38
+ *
39
+ * @param additionalParams - Additional parameter names to exclude from filtering
40
+ * @returns Set of all non-filter parameter names
41
+ */
42
+ export declare function createNonFilterParams(...additionalParams: string[]): Set<string>;
43
+ /**
44
+ * Convert filter conditions to URL search params
45
+ *
46
+ * Converts FilterCondition objects into individual URL parameters with optional table prefix:
47
+ * - Simple filters: { column: 'name', value: 'john' } → ?name=john or ?experts_name=john
48
+ * - Range filters: { column: 'count', value: '5', valueEnd: '10' } → ?count_min=5&count_max=10
49
+ *
50
+ * @param searchParams - Current URLSearchParams to update
51
+ * @param filters - Array of FilterCondition objects to convert
52
+ * @param knownNonFilterParams - Set of parameter names that should NOT be removed
53
+ * @param pageParam - Name of the page parameter to reset (e.g., 'page', 'staffPage')
54
+ * @param tablePrefix - Optional prefix for filter params (e.g., 'experts') to avoid conflicts between tables
55
+ * @returns Updated URLSearchParams with filter parameters
56
+ */
57
+ export declare function filtersToSearchParams<T>(searchParams: URLSearchParams, filters: FilterCondition<T>[], knownNonFilterParams: Set<string>, pageParam?: string, tablePrefix?: string): URLSearchParams;
58
+ /**
59
+ * Parse filter conditions from URL search params
60
+ *
61
+ * Converts individual URL parameters into FilterCondition objects:
62
+ * - Simple filters: ?name=john → { column: 'name', operator: 'contains', value: 'john' }
63
+ * - Range filters: ?count_min=5&count_max=10 → { column: 'count', operator: 'greater_equal', value: '5', valueEnd: '10' }
64
+ *
65
+ * The operator for simple filters is derived from `columnTypes` when provided:
66
+ * - 'boolean' | 'select' | 'checkboxes' → 'equals'
67
+ * - 'number' | 'date' → 'greater_equal'
68
+ * - default (text etc.) → 'contains'
69
+ *
70
+ * @param searchParams - URLSearchParams to parse
71
+ * @param knownNonFilterParams - Set of parameter names that should NOT be treated as filters
72
+ * @param tablePrefix - Optional prefix for filter params (e.g., 'experts') to only parse this table's filters
73
+ * @param columnTypes - Optional map of column name → filter type for correct operator inference
74
+ * @returns Array of FilterCondition objects
75
+ */
76
+ export declare function parseFiltersFromParams<T>(searchParams: URLSearchParams, knownNonFilterParams: Set<string>, tablePrefix?: string, columnTypes?: Record<string, string>): FilterCondition<T>[];
77
+ /**
78
+ * Apply filters to data array based on filter conditions.
79
+ * Handles all filter operators including range filters with valueEnd.
80
+ */
81
+ export declare function applyFilters<T extends {
82
+ id: string | number;
83
+ }>(data: T[], filters: FilterCondition<T>[]): T[];
@@ -16,11 +16,14 @@ export * from './Carousel';
16
16
  export * from './Accordion';
17
17
  export * from './Tag';
18
18
  export * from './Checkbox';
19
+ export * from './Radio';
19
20
  export * from './Select';
21
+ export * from './Switch';
20
22
  export * from './Grid';
21
23
  export * from './Pagination';
22
24
  export * from './Progress';
23
25
  export * from './Modal';
26
+ export * from './Table';
24
27
  export * from './Tooltip';
25
28
  export * from './BarChart';
26
29
  export * from './PieChart';