@kivacore/ui-pro-shared 0.0.9 → 0.0.11

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 (145) hide show
  1. package/package.json +167 -1
  2. package/src/.kiva/config.json +27 -0
  3. package/src/components/avatar-group.tsx +222 -0
  4. package/src/components/kiva/bulk-update-dialog/bulk-update-dialog.tsx +240 -0
  5. package/src/components/kiva/bulk-update-dialog/index.tsx +6 -0
  6. package/src/components/kiva/bulk-update-dialog/types.ts +33 -0
  7. package/src/components/kiva/calendar/animations.ts +40 -0
  8. package/src/components/kiva/calendar/calendar-body.tsx +106 -0
  9. package/src/components/kiva/calendar/calendar-sidebar.tsx +103 -0
  10. package/src/components/kiva/calendar/calendar.tsx +243 -0
  11. package/src/components/kiva/calendar/constants.ts +12 -0
  12. package/src/components/kiva/calendar/contexts/calendar-context.tsx +696 -0
  13. package/src/components/kiva/calendar/contexts/dnd-context.tsx +173 -0
  14. package/src/components/kiva/calendar/dialogs/add-edit-event-dialog.tsx +287 -0
  15. package/src/components/kiva/calendar/dialogs/delete-event-dialog.tsx +73 -0
  16. package/src/components/kiva/calendar/dialogs/event-details-dialog.tsx +163 -0
  17. package/src/components/kiva/calendar/dialogs/events-list-dialog.tsx +122 -0
  18. package/src/components/kiva/calendar/dnd/draggable-event.tsx +66 -0
  19. package/src/components/kiva/calendar/dnd/droppable-area.tsx +53 -0
  20. package/src/components/kiva/calendar/dnd/resizable-event.tsx +190 -0
  21. package/src/components/kiva/calendar/header/calendar-header.tsx +84 -0
  22. package/src/components/kiva/calendar/header/date-navigator.tsx +188 -0
  23. package/src/components/kiva/calendar/header/filter.tsx +80 -0
  24. package/src/components/kiva/calendar/header/today-button.tsx +49 -0
  25. package/src/components/kiva/calendar/header/user-select.tsx +111 -0
  26. package/src/components/kiva/calendar/header/view-tabs.tsx +144 -0
  27. package/src/components/kiva/calendar/helpers.ts +617 -0
  28. package/src/components/kiva/calendar/hooks/use-disclosure.ts +19 -0
  29. package/src/components/kiva/calendar/hooks/use-local-storage.ts +40 -0
  30. package/src/components/kiva/calendar/hooks/use-media-query.ts +25 -0
  31. package/src/components/kiva/calendar/hooks.ts +5 -0
  32. package/src/components/kiva/calendar/index.tsx +27 -0
  33. package/src/components/kiva/calendar/interfaces.ts +35 -0
  34. package/src/components/kiva/calendar/schemas.ts +20 -0
  35. package/src/components/kiva/calendar/settings/settings.tsx +116 -0
  36. package/src/components/kiva/calendar/skeletons/calendar-header-skeleton.tsx +27 -0
  37. package/src/components/kiva/calendar/skeletons/calendar-skeleton.tsx +19 -0
  38. package/src/components/kiva/calendar/skeletons/day-view-skeleton.tsx +40 -0
  39. package/src/components/kiva/calendar/skeletons/month-view-skeleton.tsx +36 -0
  40. package/src/components/kiva/calendar/skeletons/week-view-skeleton.tsx +48 -0
  41. package/src/components/kiva/calendar/skeletons/year-view-skeleton.tsx +42 -0
  42. package/src/components/kiva/calendar/types.ts +25 -0
  43. package/src/components/kiva/calendar/views/agenda-view/agenda-events.tsx +150 -0
  44. package/src/components/kiva/calendar/views/month-view/calendar-month-view.tsx +82 -0
  45. package/src/components/kiva/calendar/views/month-view/day-cell.tsx +218 -0
  46. package/src/components/kiva/calendar/views/month-view/event-bullet.tsx +46 -0
  47. package/src/components/kiva/calendar/views/month-view/month-event-badge.tsx +154 -0
  48. package/src/components/kiva/calendar/views/timeline/calendar-timeline-view.tsx +100 -0
  49. package/src/components/kiva/calendar/views/timeline/lib/timeline-layout.ts +130 -0
  50. package/src/components/kiva/calendar/views/timeline/lib/timeline-model.ts +504 -0
  51. package/src/components/kiva/calendar/views/timeline/timeline-event-bar.tsx +68 -0
  52. package/src/components/kiva/calendar/views/timeline/timeline-grid-header.tsx +125 -0
  53. package/src/components/kiva/calendar/views/timeline/timeline-row.tsx +159 -0
  54. package/src/components/kiva/calendar/views/timeline/timeline-section.tsx +61 -0
  55. package/src/components/kiva/calendar/views/timeline/use-timeline-sections.ts +278 -0
  56. package/src/components/kiva/calendar/views/week-and-day-view/calendar-day-view.tsx +277 -0
  57. package/src/components/kiva/calendar/views/week-and-day-view/calendar-time-line.tsx +47 -0
  58. package/src/components/kiva/calendar/views/week-and-day-view/calendar-week-view.tsx +229 -0
  59. package/src/components/kiva/calendar/views/week-and-day-view/day-view-multi-day-events-row.tsx +79 -0
  60. package/src/components/kiva/calendar/views/week-and-day-view/event-block.tsx +116 -0
  61. package/src/components/kiva/calendar/views/week-and-day-view/render-grouped-events.tsx +54 -0
  62. package/src/components/kiva/calendar/views/week-and-day-view/week-view-multi-day-events-row.tsx +159 -0
  63. package/src/components/kiva/calendar/views/year-view/calendar-year-view.tsx +159 -0
  64. package/src/components/kiva/data-table-side-filters/components/side-filter-active-chips.tsx +137 -0
  65. package/src/components/kiva/data-table-side-filters/components/side-filter-clear.tsx +34 -0
  66. package/src/components/kiva/data-table-side-filters/components/side-filter-search.tsx +67 -0
  67. package/src/components/kiva/data-table-side-filters/components/side-filter-section.tsx +77 -0
  68. package/src/components/kiva/data-table-side-filters/controllers/side-filter-async-options.tsx +354 -0
  69. package/src/components/kiva/data-table-side-filters/controllers/side-filter-boolean.tsx +66 -0
  70. package/src/components/kiva/data-table-side-filters/controllers/side-filter-checkbox-list.tsx +137 -0
  71. package/src/components/kiva/data-table-side-filters/controllers/side-filter-date-range.tsx +204 -0
  72. package/src/components/kiva/data-table-side-filters/controllers/side-filter-numeric-range.tsx +162 -0
  73. package/src/components/kiva/data-table-side-filters/controllers/side-filter-options-dropdown.tsx +191 -0
  74. package/src/components/kiva/data-table-side-filters/controllers/side-filter-text.tsx +53 -0
  75. package/src/components/kiva/data-table-side-filters/core/query-translator.ts +367 -0
  76. package/src/components/kiva/data-table-side-filters/core/types.ts +81 -0
  77. package/src/components/kiva/data-table-side-filters/data-table-side-filters.tsx +483 -0
  78. package/src/components/kiva/data-table-side-filters/hooks/use-data-table-side-filters.tsx +160 -0
  79. package/src/components/kiva/data-table-side-filters/hooks/use-show-more.tsx +62 -0
  80. package/src/components/kiva/data-table-side-filters/index.tsx +44 -0
  81. package/src/components/kiva/data-table-side-filters/lib/render-mode.ts +62 -0
  82. package/src/components/kiva/date-time-picker.tsx +163 -0
  83. package/src/components/kiva/editable-record-detail.tsx +809 -0
  84. package/src/components/kiva/enum-option-editor/enum-option-editor.tsx +891 -0
  85. package/src/components/kiva/enum-option-editor/index.tsx +26 -0
  86. package/src/components/kiva/enum-option-editor/kiva-enum-option-editor.tsx +320 -0
  87. package/src/components/kiva/enum-option-editor/types.ts +90 -0
  88. package/src/components/kiva/kanban.tsx +1376 -0
  89. package/src/components/kiva/kiva-data-export-menu.tsx +543 -0
  90. package/src/components/kiva/map.tsx +1631 -0
  91. package/src/components/kiva/pivot-calendar/components/group-sidebar.tsx +95 -0
  92. package/src/components/kiva/pivot-calendar/components/pivot-calendar-toolbar.tsx +113 -0
  93. package/src/components/kiva/pivot-calendar/components/stats-cell.tsx +126 -0
  94. package/src/components/kiva/pivot-calendar/helpers.ts +374 -0
  95. package/src/components/kiva/pivot-calendar/hooks/use-pivot-calendar.ts +222 -0
  96. package/src/components/kiva/pivot-calendar/index.tsx +32 -0
  97. package/src/components/kiva/pivot-calendar/pivot-calendar.tsx +107 -0
  98. package/src/components/kiva/pivot-calendar/types.ts +154 -0
  99. package/src/components/kiva/pivot-calendar/views/days-of-month-view.tsx +37 -0
  100. package/src/components/kiva/pivot-calendar/views/days-of-week-view.tsx +37 -0
  101. package/src/components/kiva/pivot-calendar/views/month-calendar-view.tsx +154 -0
  102. package/src/components/kiva/pivot-calendar/views/months-of-year-view.tsx +40 -0
  103. package/src/components/kiva/pivot-calendar/views/pivot-grid-view.tsx +251 -0
  104. package/src/components/kiva/pivot-filter/index.tsx +9 -0
  105. package/src/components/kiva/pivot-filter/pivot-filter-item.tsx +159 -0
  106. package/src/components/kiva/pivot-filter/pivot-filter-settings.tsx +161 -0
  107. package/src/components/kiva/pivot-filter/pivot-filter.tsx +187 -0
  108. package/src/components/kiva/pivot-filter/types.ts +82 -0
  109. package/src/components/kiva/pivot-grid/hooks/use-pivot-grid.ts +683 -0
  110. package/src/components/kiva/pivot-grid/index.tsx +23 -0
  111. package/src/components/kiva/pivot-grid/lib/pivot-grid-color-rules.ts +98 -0
  112. package/src/components/kiva/pivot-grid/lib/pivot-grid-export.ts +265 -0
  113. package/src/components/kiva/pivot-grid/lib/pivot-grid-model.ts +1110 -0
  114. package/src/components/kiva/pivot-grid/pivot-grid-demo-data.ts +200 -0
  115. package/src/components/kiva/pivot-grid/pivot-grid-export-menu.tsx +66 -0
  116. package/src/components/kiva/pivot-grid/pivot-grid-toolbar.tsx +85 -0
  117. package/src/components/kiva/pivot-grid/pivot-grid.tsx +601 -0
  118. package/src/components/kiva/pivot-grid/types.ts +195 -0
  119. package/src/components/kiva/place-autocomplete.tsx +484 -0
  120. package/src/components/kiva/record-delete-confirm-dialog/index.tsx +10 -0
  121. package/src/components/kiva/record-delete-confirm-dialog/record-delete-confirm-dialog.tsx +266 -0
  122. package/src/components/kiva/record-delete-confirm-dialog/types.ts +25 -0
  123. package/src/hooks/kiva/_internal/autonumber-setting.ts +112 -0
  124. package/src/hooks/kiva/_internal/form-layout-to-view.ts +665 -0
  125. package/src/hooks/kiva/_internal/kiva-hook-utils.ts +143 -0
  126. package/src/hooks/kiva/_internal/use-computed-field-evaluator.tsx +310 -0
  127. package/src/hooks/kiva/_internal/use-field-actions-evaluator.tsx +398 -0
  128. package/src/hooks/kiva/_internal/use-form-actions-evaluator.tsx +363 -0
  129. package/src/hooks/kiva/_internal/use-form-view-engine.tsx +2200 -0
  130. package/src/hooks/kiva/_internal/use-kiva-form-view-fields.tsx +190 -0
  131. package/src/hooks/kiva/_internal/use-kiva-kanban-cards.tsx +311 -0
  132. package/src/hooks/kiva/use-data-export.tsx +265 -0
  133. package/src/hooks/kiva/use-kiva-calendar.tsx +992 -0
  134. package/src/hooks/kiva/use-kiva-data-export.tsx +173 -0
  135. package/src/hooks/kiva/use-kiva-data-grid.tsx +4750 -0
  136. package/src/hooks/kiva/use-kiva-data-view-select.tsx +1273 -0
  137. package/src/hooks/kiva/use-kiva-form-view.tsx +1581 -0
  138. package/src/hooks/kiva/use-kiva-inventory.tsx +184 -0
  139. package/src/hooks/kiva/use-kiva-kanban.tsx +1750 -0
  140. package/src/hooks/kiva/use-kiva-map-view.tsx +2255 -0
  141. package/src/hooks/kiva/use-kiva-pivot-calendar.tsx +759 -0
  142. package/src/hooks/kiva/use-kiva-pivot-filter.tsx +1523 -0
  143. package/src/hooks/kiva/use-kiva-pivot-grid.tsx +543 -0
  144. package/src/hooks/kiva/use-kiva-tenant.tsx +313 -0
  145. package/src/hooks/kiva/use-parameter-persistence.ts +191 -0
@@ -0,0 +1,483 @@
1
+ 'use client';
2
+
3
+ // @ts-nocheck
4
+ /* eslint-disable */
5
+ import {
6
+ type CSSProperties,
7
+ isValidElement,
8
+ type ReactNode,
9
+ useCallback,
10
+ useMemo,
11
+ useState
12
+ } from 'react';
13
+
14
+ import { type VariantProps, cva } from 'class-variance-authority';
15
+ import { PanelLeftClose, PanelLeftOpen } from 'lucide-react';
16
+
17
+ import { Button } from '@kivacore/ui-pro-shared/components/button';
18
+ import { cn } from '@kivacore/ui-pro-shared/lib/utils';
19
+ import {
20
+ type Column,
21
+ type DataTableFilterActions,
22
+ type FilterModel,
23
+ type FilterStrategy,
24
+ type FiltersState,
25
+ type OptionBasedColumnDataType
26
+ } from '@kivacore/ui-pro-shared/components/kiva/data-table-filter/core/types';
27
+ import { type Locale } from '@kivacore/ui-pro-shared/components/kiva/data-table-filter/lib/i18n';
28
+
29
+ import { SideFilterActiveChips } from './components/side-filter-active-chips';
30
+ import { SideFilterClear } from './components/side-filter-clear';
31
+ import { SideFilterSearch } from './components/side-filter-search';
32
+ import { SideFilterSection } from './components/side-filter-section';
33
+ import { SideFilterAsyncOptions } from './controllers/side-filter-async-options';
34
+ import { SideFilterBoolean } from './controllers/side-filter-boolean';
35
+ import { SideFilterCheckboxList } from './controllers/side-filter-checkbox-list';
36
+ import { SideFilterDateRange } from './controllers/side-filter-date-range';
37
+ import { SideFilterNumericRange } from './controllers/side-filter-numeric-range';
38
+ import { SideFilterOptionsDropdown } from './controllers/side-filter-options-dropdown';
39
+ import { SideFilterText } from './controllers/side-filter-text';
40
+ import {
41
+ type SideFilterDefaults,
42
+ type SideFilterSectionGroup
43
+ } from './core/types';
44
+ import { resolveSideFilterRenderMode } from './lib/render-mode';
45
+ export interface DataTableSideFiltersProps<TData>
46
+ extends VariantProps<typeof dataTableSideFiltersVariants> {
47
+ columns: Array<Column<TData>>;
48
+ filters: FiltersState;
49
+ actions: DataTableFilterActions;
50
+ strategy: FilterStrategy;
51
+ defaults?: SideFilterDefaults;
52
+ sections?: ReadonlyArray<SideFilterSectionGroup>;
53
+ locale?: Locale;
54
+ className?: string;
55
+ /** Inline style applied to the root container (panel or rail). */
56
+ style?: CSSProperties;
57
+ /** Header title. Pass `null` to hide. */
58
+ title?: ReactNode;
59
+ /** Show the active-filter chip strip below the header. Default true. */
60
+ showActiveChips?: boolean;
61
+ /** Show "Clear all" button next to the title when any filter is active. Default true. */
62
+ showClearAll?: boolean;
63
+ /**
64
+ * When `true`, renders a search input above the sections that drives the
65
+ * first `text`-typed column. Pass a column id to drive a specific one.
66
+ */
67
+ searchable?: boolean | string;
68
+ /** Optional override for "Clear all" text. */
69
+ clearAllLabel?: string;
70
+ /** Optional override for per-section "Clear" text. */
71
+ clearLabel?: string;
72
+ /**
73
+ * When `true`, the panel can be toggled between expanded and collapsed.
74
+ * In collapsed mode it renders a thin vertical rail with a 90°-rotated
75
+ * label that re-expands the panel; the expanded state shows a panel-close
76
+ * icon at the top right. Default `false`.
77
+ */
78
+ collapsible?: boolean;
79
+ /** Controlled expanded state. Pair with `onExpandedChange`. */
80
+ expanded?: boolean;
81
+ /** Uncontrolled initial expanded state. Default `true`. */
82
+ defaultExpanded?: boolean;
83
+ /** Called when the user toggles the collapse/expand control. */
84
+ onExpandedChange?: (expanded: boolean) => void;
85
+ /** Width of the collapsed rail (number → px). Default `36`. */
86
+ collapsedWidth?: number | string;
87
+ /** Label rendered (rotated 90°) on the collapsed rail. Defaults to `title`, then `'Filters'`. */
88
+ expandLabel?: ReactNode;
89
+ /** Override for the collapse-button accessible label. Default `'Collapse filters'`. */
90
+ collapseAriaLabel?: string;
91
+ /** Override for the expand-button accessible label. Default `'Expand filters'`. */
92
+ expandAriaLabel?: string;
93
+ }
94
+
95
+ interface RenderControllerArgs<TData> {
96
+ column: Column<TData>;
97
+ filter: FilterModel | undefined;
98
+ actions: DataTableFilterActions;
99
+ defaults: SideFilterDefaults | undefined;
100
+ locale: Locale;
101
+ }
102
+
103
+ function renderController<TData>({
104
+ column, filter, actions, defaults, locale
105
+ }: RenderControllerArgs<TData>): ReactNode {
106
+ const columnDefaults = defaults?.[column.id];
107
+ const mode = resolveSideFilterRenderMode(column, {
108
+ defaults: columnDefaults
109
+ });
110
+
111
+ switch (mode) {
112
+ case 'text-input':
113
+ return (
114
+ <SideFilterText
115
+ column={column as Column<TData, 'text'>}
116
+ filter={filter as FilterModel<'text'> | undefined}
117
+ actions={actions}
118
+ locale={locale} />
119
+ );
120
+
121
+ case 'boolean':
122
+ return (
123
+ <SideFilterBoolean
124
+ column={column as Column<TData, 'boolean'>}
125
+ filter={filter as FilterModel<'boolean'> | undefined}
126
+ actions={actions}
127
+ locale={locale} />
128
+ );
129
+
130
+ case 'numeric-range':
131
+ return (
132
+ <SideFilterNumericRange
133
+ column={column as Column<TData, 'number'>}
134
+ filter={filter as FilterModel<'number'> | undefined}
135
+ actions={actions}
136
+ locale={locale} />
137
+ );
138
+
139
+ case 'date':
140
+
141
+ case 'date-range':
142
+ return (
143
+ <SideFilterDateRange
144
+ column={column as Column<TData, 'date'>}
145
+ filter={filter as FilterModel<'date'> | undefined}
146
+ actions={actions}
147
+ locale={locale} />
148
+ );
149
+
150
+ case 'inline-checkbox':
151
+ return (
152
+ <SideFilterCheckboxList
153
+ column={column as Column<TData, OptionBasedColumnDataType>}
154
+ filter={filter as FilterModel<OptionBasedColumnDataType> | undefined}
155
+ actions={actions}
156
+ locale={locale}
157
+ threshold={columnDefaults?.showMoreThreshold} />
158
+ );
159
+
160
+ case 'dropdown-chips': {
161
+ const optColumn = column as Column<TData, OptionBasedColumnDataType>;
162
+
163
+ if (optColumn.asyncOptions) {
164
+ return (
165
+ <SideFilterAsyncOptions
166
+ column={optColumn}
167
+ filter={filter as FilterModel<OptionBasedColumnDataType> | undefined}
168
+ actions={actions}
169
+ locale={locale} />
170
+ );
171
+ }
172
+
173
+ return (
174
+ <SideFilterOptionsDropdown
175
+ column={optColumn}
176
+ filter={filter as FilterModel<OptionBasedColumnDataType> | undefined}
177
+ actions={actions}
178
+ locale={locale} />
179
+ );
180
+ }
181
+
182
+ default:
183
+ return null;
184
+ }
185
+ }
186
+
187
+ function activeCountFor(filter: FilterModel | undefined): number {
188
+ if (!filter) return 0;
189
+ if (filter.values.length === 0) {
190
+ return filter.operator === 'is empty' || filter.operator === 'is not empty' ? 1 : 0;
191
+ }
192
+ if (filter.type === 'option' || filter.type === 'multiOption') {
193
+ return filter.values.length;
194
+ }
195
+
196
+ return 1;
197
+ }
198
+
199
+ interface BuiltSection<TData> {
200
+ id: string;
201
+ title: ReactNode;
202
+ withDivider?: boolean;
203
+ columns: Array<Column<TData>>;
204
+ }
205
+
206
+ function buildSections<TData>(
207
+ columns: Array<Column<TData>>,
208
+ defaults: SideFilterDefaults | undefined,
209
+ sections: ReadonlyArray<SideFilterSectionGroup> | undefined
210
+ ): Array<BuiltSection<TData>> {
211
+ const visible = columns.filter((c) => {
212
+ const colDef = defaults?.[c.id];
213
+
214
+ return !colDef?.hidden;
215
+ });
216
+
217
+ const stickyIds = new Set(
218
+ visible
219
+ .filter(c => defaults?.[c.id]?.sticky)
220
+ .map(c => c.id)
221
+ );
222
+
223
+ if (!sections || sections.length === 0) {
224
+ const sticky = visible.filter(c => stickyIds.has(c.id));
225
+ const rest = visible.filter(c => !stickyIds.has(c.id));
226
+
227
+ return [
228
+ ...(sticky.length > 0 ? [
229
+ {
230
+ id: '__sticky', title: null, columns: sticky, withDivider: false
231
+ } as BuiltSection<TData>
232
+ ] : []),
233
+ { id: '__main', title: null, columns: rest }
234
+ ];
235
+ }
236
+
237
+ const byId = new Map(visible.map(c => [c.id, c]));
238
+ const used = new Set<string>();
239
+ const grouped: Array<BuiltSection<TData>> = [];
240
+
241
+ for (const group of sections) {
242
+ const cols: Array<Column<TData>> = [];
243
+
244
+ for (const id of group.columnIds) {
245
+ const col = byId.get(id);
246
+
247
+ if (!col) continue;
248
+ cols.push(col);
249
+ used.add(id);
250
+ }
251
+
252
+ if (cols.length === 0) continue;
253
+ grouped.push({
254
+ id: group.id,
255
+ title: group.title,
256
+ columns: cols,
257
+ withDivider: group.withDivider !== false
258
+ });
259
+ }
260
+
261
+ const leftovers = visible.filter(c => !used.has(c.id));
262
+
263
+ if (leftovers.length > 0) {
264
+ grouped.push({ id: '__other', title: 'Other', columns: leftovers });
265
+ }
266
+
267
+ return grouped;
268
+ }
269
+
270
+ export function DataTableSideFilters<TData>({
271
+ columns,
272
+ filters,
273
+ actions,
274
+ strategy: _strategy,
275
+ defaults,
276
+ sections,
277
+ locale = 'en',
278
+ className,
279
+ style,
280
+ variant,
281
+ title = 'Filters',
282
+ showActiveChips = true,
283
+ showClearAll = true,
284
+ searchable = false,
285
+ clearAllLabel = 'Clear all',
286
+ clearLabel = 'Clear',
287
+ collapsible = false,
288
+ expanded,
289
+ defaultExpanded = true,
290
+ onExpandedChange,
291
+ collapsedWidth = 36,
292
+ expandLabel,
293
+ collapseAriaLabel = 'Collapse filters',
294
+ expandAriaLabel = 'Expand filters'
295
+ }: DataTableSideFiltersProps<TData>) {
296
+ const filterByColumn = useMemo(() => {
297
+ const map = new Map<string, FilterModel>();
298
+
299
+ for (const f of filters) map.set(f.columnId, f);
300
+
301
+ return map;
302
+ }, [filters]);
303
+
304
+ const built = useMemo(
305
+ () => buildSections(columns, defaults, sections),
306
+ [columns, defaults, sections]
307
+ );
308
+
309
+ const searchColumnId = useMemo<string | null>(() => {
310
+ if (!searchable) return null;
311
+ if (typeof searchable === 'string') return searchable;
312
+
313
+ return columns.find(c => c.type === 'text')?.id ?? null;
314
+ }, [searchable, columns]);
315
+
316
+ const removeColumnFilter = useCallback(
317
+ (columnId: string) => actions.removeFilter(columnId),
318
+ [actions]
319
+ );
320
+
321
+ const activeFilterCount = filters.filter(f => activeCountFor(f) > 0).length;
322
+
323
+ const [internalExpanded, setInternalExpanded] = useState<boolean>(defaultExpanded);
324
+ const isControlled = expanded !== undefined;
325
+ const isExpanded = collapsible ? (isControlled ? expanded : internalExpanded) : true;
326
+
327
+ const setExpanded = useCallback((next: boolean) => {
328
+ if (!isControlled) setInternalExpanded(next);
329
+ onExpandedChange?.(next);
330
+ }, [isControlled, onExpandedChange]);
331
+
332
+ if (collapsible && !isExpanded) {
333
+ const railWidth = typeof collapsedWidth === 'number' ? `${collapsedWidth}px` : collapsedWidth;
334
+ const railLabel = expandLabel ?? (typeof title === 'string' ? title : null) ?? 'Filters';
335
+
336
+ return (
337
+ <aside
338
+ data-slot="kiva-side-filters-rail"
339
+ className={cn(
340
+ 'flex h-full flex-col items-center border-r bg-card',
341
+ className
342
+ )}
343
+ style={{ ...style, width: railWidth }}>
344
+ <Button
345
+ type="button"
346
+ variant="ghost"
347
+ size="icon"
348
+ aria-label={expandAriaLabel}
349
+ onClick={() => setExpanded(true)}
350
+ className="mt-2 size-7 shrink-0">
351
+ <PanelLeftOpen className="size-4" />
352
+ </Button>
353
+ <button
354
+ type="button"
355
+ aria-label={expandAriaLabel}
356
+ onClick={() => setExpanded(true)}
357
+ className="mt-2 flex flex-1 items-center justify-center text-xs font-medium tracking-wide text-muted-foreground hover:text-foreground"
358
+ style={{ writingMode: 'vertical-rl', transform: 'rotate(180deg)' }}>
359
+ <span className="px-1 py-2 select-none">
360
+ {railLabel}
361
+ {activeFilterCount > 0 ? ` · ${activeFilterCount}` : ''}
362
+ </span>
363
+ </button>
364
+ </aside>
365
+ );
366
+ }
367
+
368
+ return (
369
+ <aside className={cn(dataTableSideFiltersVariants({ variant }), className)} style={style}>
370
+ {(title || (showClearAll && activeFilterCount > 0) || collapsible) && (
371
+ <header className="mb-2 flex items-center justify-between gap-2">
372
+ {title && (
373
+ <h3 className="text-sm font-semibold tracking-tight">{title}</h3>
374
+ )}
375
+ <div className="flex items-center gap-1">
376
+ {showClearAll && (
377
+ <SideFilterClear
378
+ count={activeFilterCount}
379
+ onClick={actions.removeAllFilters}
380
+ label={clearAllLabel} />
381
+ )}
382
+ {collapsible && (
383
+ <Button
384
+ type="button"
385
+ variant="ghost"
386
+ size="icon"
387
+ aria-label={collapseAriaLabel}
388
+ onClick={() => setExpanded(false)}
389
+ className="size-7 shrink-0 text-muted-foreground hover:text-foreground">
390
+ <PanelLeftClose className="size-4" />
391
+ </Button>
392
+ )}
393
+ </div>
394
+ </header>
395
+ )}
396
+
397
+ {searchColumnId && (
398
+ <div className="mb-3">
399
+ <SideFilterSearch
400
+ columnId={searchColumnId}
401
+ columns={columns}
402
+ filters={filters}
403
+ actions={actions}
404
+ locale={locale} />
405
+ </div>
406
+ )}
407
+
408
+ {showActiveChips && activeFilterCount > 0 && (
409
+ <div className="mb-3">
410
+ <SideFilterActiveChips
411
+ filters={filters}
412
+ columns={columns}
413
+ actions={actions}
414
+ clearAllLabel={clearAllLabel} />
415
+ </div>
416
+ )}
417
+
418
+ <div className="flex flex-col">
419
+ {built.map(section => (
420
+ <div
421
+ key={section.id}
422
+ className={cn(
423
+ section.title !== null && section.withDivider !== false && 'mt-2 border-t border-border/60 pt-2'
424
+ )}>
425
+ {section.title !== null && (
426
+ <h4 className="mb-1 text-xs font-semibold uppercase tracking-wider text-muted-foreground">
427
+ {section.title}
428
+ </h4>
429
+ )}
430
+ {section.columns.map((column) => {
431
+ if (column.id === searchColumnId) return null;
432
+ const colDef = defaults?.[column.id];
433
+ const filter = filterByColumn.get(column.id);
434
+ const Icon = column.icon;
435
+ const sectionTitle = colDef?.title ?? column.displayName;
436
+ const iconNode = Icon ? (
437
+ isValidElement(Icon) ? Icon : <Icon className="size-4" />
438
+ ) : null;
439
+
440
+ return (
441
+ <SideFilterSection
442
+ key={column.id}
443
+ id={column.id}
444
+ title={sectionTitle}
445
+ icon={iconNode}
446
+ activeCount={activeCountFor(filter)}
447
+ defaultCollapsed={colDef?.collapsed ?? false}
448
+ onClear={() => removeColumnFilter(column.id)}
449
+ clearLabel={clearLabel}>
450
+ {renderController({
451
+ column,
452
+ filter,
453
+ actions,
454
+ defaults,
455
+ locale
456
+ })}
457
+ </SideFilterSection>
458
+ );
459
+ })}
460
+ </div>
461
+ ))}
462
+ </div>
463
+ </aside>
464
+ );
465
+ }
466
+
467
+ DataTableSideFilters.displayName = 'DataTableSideFilters';
468
+
469
+ export const dataTableSideFiltersVariants = cva(
470
+ 'flex w-full flex-col text-sm',
471
+ {
472
+ variants: {
473
+ variant: {
474
+ default: '',
475
+ bordered: 'rounded-lg border bg-card p-4 shadow-sm',
476
+ compact: 'gap-1 text-xs'
477
+ }
478
+ },
479
+ defaultVariants: {
480
+ variant: 'default'
481
+ }
482
+ }
483
+ );
@@ -0,0 +1,160 @@
1
+ 'use client';
2
+
3
+ // @ts-nocheck
4
+ /* eslint-disable */
5
+ import {
6
+ useCallback, useEffect, useMemo, useRef, useState
7
+ } from 'react';
8
+
9
+ import { type RuleGroupType } from 'react-querybuilder';
10
+
11
+ import {
12
+ type DataTableFiltersOptions,
13
+ useDataTableFilters
14
+ } from '@kivacore/ui-pro-shared/components/kiva/data-table-filter/hooks/use-data-table-filters';
15
+ import {
16
+ type ColumnConfig,
17
+ type FilterStrategy,
18
+ type FiltersState
19
+ } from '@kivacore/ui-pro-shared/components/kiva/data-table-filter/core/types';
20
+
21
+ import {
22
+ DEFAULT_OPERATOR_MAP,
23
+ filtersStateToRuleGroup,
24
+ ruleGroupToFiltersState
25
+ } from '../core/query-translator';
26
+ import {
27
+ type SideFilterCombinator,
28
+ type SideFilterDefaults,
29
+ type SideFilterOperatorMap,
30
+ type SideFilterSectionGroup
31
+ } from '../core/types';
32
+
33
+ export interface DataTableSideFiltersOptions<
34
+ TData,
35
+ TColumns extends ReadonlyArray<ColumnConfig<TData, any, any, any>>,
36
+ TStrategy extends FilterStrategy
37
+ > extends Omit<
38
+ DataTableFiltersOptions<TData, TColumns, TStrategy>,
39
+ 'defaultFilters' | 'filters' | 'onFiltersChange'
40
+ > {
41
+ /** Uncontrolled initial query. Translated to internal FiltersState on mount. */
42
+ defaultQuery?: RuleGroupType;
43
+ /** Controlled query. Pair with `onQueryChange`. */
44
+ query?: RuleGroupType;
45
+ onQueryChange?: (query: RuleGroupType) => void;
46
+ /** Top-level combinator for the emitted RuleGroupType. Default `'and'`. */
47
+ combinator?: SideFilterCombinator;
48
+ /** Override the DTF→QB operator vocabulary. */
49
+ operatorMap?: SideFilterOperatorMap;
50
+ /** Per-column UI hints (collapsed / mode / threshold / etc.). */
51
+ defaults?: SideFilterDefaults;
52
+ /** Optional grouping of filter sections into named blocks. */
53
+ sections?: ReadonlyArray<SideFilterSectionGroup>;
54
+ }
55
+
56
+ function rulesEqual(a: RuleGroupType, b: RuleGroupType): boolean {
57
+ if (a === b) return true;
58
+ if (a.combinator !== b.combinator) return false;
59
+ if (a.rules.length !== b.rules.length) return false;
60
+ try {
61
+ return JSON.stringify(a.rules) === JSON.stringify(b.rules);
62
+ } catch {
63
+ return false;
64
+ }
65
+ }
66
+
67
+ export function useDataTableSideFilters<
68
+ TData,
69
+ TColumns extends ReadonlyArray<ColumnConfig<TData, any, any, any>>,
70
+ TStrategy extends FilterStrategy
71
+ >(options: DataTableSideFiltersOptions<TData, TColumns, TStrategy>) {
72
+ const {
73
+ defaultQuery,
74
+ query,
75
+ onQueryChange,
76
+ combinator = 'and',
77
+ operatorMap = DEFAULT_OPERATOR_MAP,
78
+ defaults,
79
+ sections,
80
+ columnsConfig,
81
+ ...rest
82
+ } = options;
83
+
84
+ const [filters, setFilters] = useState<FiltersState>(() => {
85
+ if (!defaultQuery) return [];
86
+
87
+ return ruleGroupToFiltersState(
88
+ defaultQuery,
89
+ columnsConfig as ReadonlyArray<ColumnConfig<unknown>>,
90
+ operatorMap
91
+ );
92
+ });
93
+
94
+ const lastEmittedRef = useRef<RuleGroupType | null>(null);
95
+
96
+ useEffect(() => {
97
+ if (!query) return;
98
+ if (lastEmittedRef.current && rulesEqual(query, lastEmittedRef.current)) return;
99
+ const next = ruleGroupToFiltersState(
100
+ query,
101
+ columnsConfig as ReadonlyArray<ColumnConfig<unknown>>,
102
+ operatorMap
103
+ );
104
+
105
+ queueMicrotask(() => setFilters(next));
106
+ }, [query, columnsConfig, operatorMap]);
107
+
108
+ const dtf = useDataTableFilters<TData, TColumns, TStrategy>({
109
+ ...rest,
110
+ columnsConfig,
111
+ filters,
112
+ onFiltersChange: setFilters
113
+ });
114
+
115
+ useEffect(() => {
116
+ if (!onQueryChange) return;
117
+ const ruleGroup = filtersStateToRuleGroup(
118
+ filters,
119
+ combinator,
120
+ operatorMap,
121
+ columnsConfig as ReadonlyArray<ColumnConfig<unknown>>
122
+ );
123
+
124
+ lastEmittedRef.current = ruleGroup;
125
+ onQueryChange(ruleGroup);
126
+ }, [
127
+ filters,
128
+ combinator,
129
+ operatorMap,
130
+ onQueryChange,
131
+ columnsConfig
132
+ ]);
133
+
134
+ const ruleGroup = useMemo(
135
+ () => filtersStateToRuleGroup(
136
+ filters,
137
+ combinator,
138
+ operatorMap,
139
+ columnsConfig as ReadonlyArray<ColumnConfig<unknown>>
140
+ ),
141
+ [
142
+ filters,
143
+ combinator,
144
+ operatorMap,
145
+ columnsConfig
146
+ ]
147
+ );
148
+
149
+ const reset = useCallback(() => setFilters([]), []);
150
+
151
+ return {
152
+ ...dtf,
153
+ query: ruleGroup,
154
+ defaults,
155
+ sections,
156
+ reset
157
+ };
158
+ }
159
+
160
+ export type UseDataTableSideFiltersReturn = ReturnType<typeof useDataTableSideFilters>;
@@ -0,0 +1,62 @@
1
+ // @ts-nocheck
2
+ /* eslint-disable */
3
+ import { useCallback, useMemo, useState } from 'react';
4
+
5
+ interface UseShowMoreOptions<T> {
6
+ items: ReadonlyArray<T>;
7
+ threshold: number;
8
+ /** Initial expanded state. */
9
+ defaultExpanded?: boolean;
10
+ /**
11
+ * Predicate that forces an item to remain visible regardless of
12
+ * collapse state — used to keep selected options pinned so users can
13
+ * always uncheck them.
14
+ */
15
+ isPinned?: (item: T) => boolean;
16
+ }
17
+
18
+ export function useShowMore<T>({
19
+ items,
20
+ threshold,
21
+ defaultExpanded = false,
22
+ isPinned
23
+ }: UseShowMoreOptions<T>) {
24
+ const [expanded, setExpanded] = useState(defaultExpanded);
25
+
26
+ const { visible, hiddenCount, canExpand } = useMemo(() => {
27
+ if (items.length <= threshold || expanded) {
28
+ return { visible: items, hiddenCount: 0, canExpand: items.length > threshold };
29
+ }
30
+
31
+ const pinned: Array<T> = [];
32
+ const rest: Array<T> = [];
33
+
34
+ if (isPinned) {
35
+ for (const it of items) (isPinned(it) ? pinned : rest).push(it);
36
+ } else {
37
+ rest.push(...items);
38
+ }
39
+
40
+ const slot = Math.max(threshold - pinned.length, 0);
41
+ const taken = rest.slice(0, slot);
42
+ const visibleItems = isPinned ? [...pinned, ...taken] : taken;
43
+ const hidden = items.length - visibleItems.length;
44
+
45
+ return { visible: visibleItems, hiddenCount: hidden, canExpand: true };
46
+ }, [
47
+ items,
48
+ threshold,
49
+ expanded,
50
+ isPinned
51
+ ]);
52
+
53
+ const toggle = useCallback(() => setExpanded(v => !v), []);
54
+
55
+ return {
56
+ visible,
57
+ hiddenCount,
58
+ expanded,
59
+ canExpand,
60
+ toggle
61
+ };
62
+ }