@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.
- package/package.json +167 -1
- package/src/.kiva/config.json +27 -0
- package/src/components/avatar-group.tsx +222 -0
- package/src/components/kiva/bulk-update-dialog/bulk-update-dialog.tsx +240 -0
- package/src/components/kiva/bulk-update-dialog/index.tsx +6 -0
- package/src/components/kiva/bulk-update-dialog/types.ts +33 -0
- package/src/components/kiva/calendar/animations.ts +40 -0
- package/src/components/kiva/calendar/calendar-body.tsx +106 -0
- package/src/components/kiva/calendar/calendar-sidebar.tsx +103 -0
- package/src/components/kiva/calendar/calendar.tsx +243 -0
- package/src/components/kiva/calendar/constants.ts +12 -0
- package/src/components/kiva/calendar/contexts/calendar-context.tsx +696 -0
- package/src/components/kiva/calendar/contexts/dnd-context.tsx +173 -0
- package/src/components/kiva/calendar/dialogs/add-edit-event-dialog.tsx +287 -0
- package/src/components/kiva/calendar/dialogs/delete-event-dialog.tsx +73 -0
- package/src/components/kiva/calendar/dialogs/event-details-dialog.tsx +163 -0
- package/src/components/kiva/calendar/dialogs/events-list-dialog.tsx +122 -0
- package/src/components/kiva/calendar/dnd/draggable-event.tsx +66 -0
- package/src/components/kiva/calendar/dnd/droppable-area.tsx +53 -0
- package/src/components/kiva/calendar/dnd/resizable-event.tsx +190 -0
- package/src/components/kiva/calendar/header/calendar-header.tsx +84 -0
- package/src/components/kiva/calendar/header/date-navigator.tsx +188 -0
- package/src/components/kiva/calendar/header/filter.tsx +80 -0
- package/src/components/kiva/calendar/header/today-button.tsx +49 -0
- package/src/components/kiva/calendar/header/user-select.tsx +111 -0
- package/src/components/kiva/calendar/header/view-tabs.tsx +144 -0
- package/src/components/kiva/calendar/helpers.ts +617 -0
- package/src/components/kiva/calendar/hooks/use-disclosure.ts +19 -0
- package/src/components/kiva/calendar/hooks/use-local-storage.ts +40 -0
- package/src/components/kiva/calendar/hooks/use-media-query.ts +25 -0
- package/src/components/kiva/calendar/hooks.ts +5 -0
- package/src/components/kiva/calendar/index.tsx +27 -0
- package/src/components/kiva/calendar/interfaces.ts +35 -0
- package/src/components/kiva/calendar/schemas.ts +20 -0
- package/src/components/kiva/calendar/settings/settings.tsx +116 -0
- package/src/components/kiva/calendar/skeletons/calendar-header-skeleton.tsx +27 -0
- package/src/components/kiva/calendar/skeletons/calendar-skeleton.tsx +19 -0
- package/src/components/kiva/calendar/skeletons/day-view-skeleton.tsx +40 -0
- package/src/components/kiva/calendar/skeletons/month-view-skeleton.tsx +36 -0
- package/src/components/kiva/calendar/skeletons/week-view-skeleton.tsx +48 -0
- package/src/components/kiva/calendar/skeletons/year-view-skeleton.tsx +42 -0
- package/src/components/kiva/calendar/types.ts +25 -0
- package/src/components/kiva/calendar/views/agenda-view/agenda-events.tsx +150 -0
- package/src/components/kiva/calendar/views/month-view/calendar-month-view.tsx +82 -0
- package/src/components/kiva/calendar/views/month-view/day-cell.tsx +218 -0
- package/src/components/kiva/calendar/views/month-view/event-bullet.tsx +46 -0
- package/src/components/kiva/calendar/views/month-view/month-event-badge.tsx +154 -0
- package/src/components/kiva/calendar/views/timeline/calendar-timeline-view.tsx +100 -0
- package/src/components/kiva/calendar/views/timeline/lib/timeline-layout.ts +130 -0
- package/src/components/kiva/calendar/views/timeline/lib/timeline-model.ts +504 -0
- package/src/components/kiva/calendar/views/timeline/timeline-event-bar.tsx +68 -0
- package/src/components/kiva/calendar/views/timeline/timeline-grid-header.tsx +125 -0
- package/src/components/kiva/calendar/views/timeline/timeline-row.tsx +159 -0
- package/src/components/kiva/calendar/views/timeline/timeline-section.tsx +61 -0
- package/src/components/kiva/calendar/views/timeline/use-timeline-sections.ts +278 -0
- package/src/components/kiva/calendar/views/week-and-day-view/calendar-day-view.tsx +277 -0
- package/src/components/kiva/calendar/views/week-and-day-view/calendar-time-line.tsx +47 -0
- package/src/components/kiva/calendar/views/week-and-day-view/calendar-week-view.tsx +229 -0
- package/src/components/kiva/calendar/views/week-and-day-view/day-view-multi-day-events-row.tsx +79 -0
- package/src/components/kiva/calendar/views/week-and-day-view/event-block.tsx +116 -0
- package/src/components/kiva/calendar/views/week-and-day-view/render-grouped-events.tsx +54 -0
- package/src/components/kiva/calendar/views/week-and-day-view/week-view-multi-day-events-row.tsx +159 -0
- package/src/components/kiva/calendar/views/year-view/calendar-year-view.tsx +159 -0
- package/src/components/kiva/data-table-side-filters/components/side-filter-active-chips.tsx +137 -0
- package/src/components/kiva/data-table-side-filters/components/side-filter-clear.tsx +34 -0
- package/src/components/kiva/data-table-side-filters/components/side-filter-search.tsx +67 -0
- package/src/components/kiva/data-table-side-filters/components/side-filter-section.tsx +77 -0
- package/src/components/kiva/data-table-side-filters/controllers/side-filter-async-options.tsx +354 -0
- package/src/components/kiva/data-table-side-filters/controllers/side-filter-boolean.tsx +66 -0
- package/src/components/kiva/data-table-side-filters/controllers/side-filter-checkbox-list.tsx +137 -0
- package/src/components/kiva/data-table-side-filters/controllers/side-filter-date-range.tsx +204 -0
- package/src/components/kiva/data-table-side-filters/controllers/side-filter-numeric-range.tsx +162 -0
- package/src/components/kiva/data-table-side-filters/controllers/side-filter-options-dropdown.tsx +191 -0
- package/src/components/kiva/data-table-side-filters/controllers/side-filter-text.tsx +53 -0
- package/src/components/kiva/data-table-side-filters/core/query-translator.ts +367 -0
- package/src/components/kiva/data-table-side-filters/core/types.ts +81 -0
- package/src/components/kiva/data-table-side-filters/data-table-side-filters.tsx +483 -0
- package/src/components/kiva/data-table-side-filters/hooks/use-data-table-side-filters.tsx +160 -0
- package/src/components/kiva/data-table-side-filters/hooks/use-show-more.tsx +62 -0
- package/src/components/kiva/data-table-side-filters/index.tsx +44 -0
- package/src/components/kiva/data-table-side-filters/lib/render-mode.ts +62 -0
- package/src/components/kiva/date-time-picker.tsx +163 -0
- package/src/components/kiva/editable-record-detail.tsx +809 -0
- package/src/components/kiva/enum-option-editor/enum-option-editor.tsx +891 -0
- package/src/components/kiva/enum-option-editor/index.tsx +26 -0
- package/src/components/kiva/enum-option-editor/kiva-enum-option-editor.tsx +320 -0
- package/src/components/kiva/enum-option-editor/types.ts +90 -0
- package/src/components/kiva/kanban.tsx +1376 -0
- package/src/components/kiva/kiva-data-export-menu.tsx +543 -0
- package/src/components/kiva/map.tsx +1631 -0
- package/src/components/kiva/pivot-calendar/components/group-sidebar.tsx +95 -0
- package/src/components/kiva/pivot-calendar/components/pivot-calendar-toolbar.tsx +113 -0
- package/src/components/kiva/pivot-calendar/components/stats-cell.tsx +126 -0
- package/src/components/kiva/pivot-calendar/helpers.ts +374 -0
- package/src/components/kiva/pivot-calendar/hooks/use-pivot-calendar.ts +222 -0
- package/src/components/kiva/pivot-calendar/index.tsx +32 -0
- package/src/components/kiva/pivot-calendar/pivot-calendar.tsx +107 -0
- package/src/components/kiva/pivot-calendar/types.ts +154 -0
- package/src/components/kiva/pivot-calendar/views/days-of-month-view.tsx +37 -0
- package/src/components/kiva/pivot-calendar/views/days-of-week-view.tsx +37 -0
- package/src/components/kiva/pivot-calendar/views/month-calendar-view.tsx +154 -0
- package/src/components/kiva/pivot-calendar/views/months-of-year-view.tsx +40 -0
- package/src/components/kiva/pivot-calendar/views/pivot-grid-view.tsx +251 -0
- package/src/components/kiva/pivot-filter/index.tsx +9 -0
- package/src/components/kiva/pivot-filter/pivot-filter-item.tsx +159 -0
- package/src/components/kiva/pivot-filter/pivot-filter-settings.tsx +161 -0
- package/src/components/kiva/pivot-filter/pivot-filter.tsx +187 -0
- package/src/components/kiva/pivot-filter/types.ts +82 -0
- package/src/components/kiva/pivot-grid/hooks/use-pivot-grid.ts +683 -0
- package/src/components/kiva/pivot-grid/index.tsx +23 -0
- package/src/components/kiva/pivot-grid/lib/pivot-grid-color-rules.ts +98 -0
- package/src/components/kiva/pivot-grid/lib/pivot-grid-export.ts +265 -0
- package/src/components/kiva/pivot-grid/lib/pivot-grid-model.ts +1110 -0
- package/src/components/kiva/pivot-grid/pivot-grid-demo-data.ts +200 -0
- package/src/components/kiva/pivot-grid/pivot-grid-export-menu.tsx +66 -0
- package/src/components/kiva/pivot-grid/pivot-grid-toolbar.tsx +85 -0
- package/src/components/kiva/pivot-grid/pivot-grid.tsx +601 -0
- package/src/components/kiva/pivot-grid/types.ts +195 -0
- package/src/components/kiva/place-autocomplete.tsx +484 -0
- package/src/components/kiva/record-delete-confirm-dialog/index.tsx +10 -0
- package/src/components/kiva/record-delete-confirm-dialog/record-delete-confirm-dialog.tsx +266 -0
- package/src/components/kiva/record-delete-confirm-dialog/types.ts +25 -0
- package/src/hooks/kiva/_internal/autonumber-setting.ts +112 -0
- package/src/hooks/kiva/_internal/form-layout-to-view.ts +665 -0
- package/src/hooks/kiva/_internal/kiva-hook-utils.ts +143 -0
- package/src/hooks/kiva/_internal/use-computed-field-evaluator.tsx +310 -0
- package/src/hooks/kiva/_internal/use-field-actions-evaluator.tsx +398 -0
- package/src/hooks/kiva/_internal/use-form-actions-evaluator.tsx +363 -0
- package/src/hooks/kiva/_internal/use-form-view-engine.tsx +2200 -0
- package/src/hooks/kiva/_internal/use-kiva-form-view-fields.tsx +190 -0
- package/src/hooks/kiva/_internal/use-kiva-kanban-cards.tsx +311 -0
- package/src/hooks/kiva/use-data-export.tsx +265 -0
- package/src/hooks/kiva/use-kiva-calendar.tsx +992 -0
- package/src/hooks/kiva/use-kiva-data-export.tsx +173 -0
- package/src/hooks/kiva/use-kiva-data-grid.tsx +4750 -0
- package/src/hooks/kiva/use-kiva-data-view-select.tsx +1273 -0
- package/src/hooks/kiva/use-kiva-form-view.tsx +1581 -0
- package/src/hooks/kiva/use-kiva-inventory.tsx +184 -0
- package/src/hooks/kiva/use-kiva-kanban.tsx +1750 -0
- package/src/hooks/kiva/use-kiva-map-view.tsx +2255 -0
- package/src/hooks/kiva/use-kiva-pivot-calendar.tsx +759 -0
- package/src/hooks/kiva/use-kiva-pivot-filter.tsx +1523 -0
- package/src/hooks/kiva/use-kiva-pivot-grid.tsx +543 -0
- package/src/hooks/kiva/use-kiva-tenant.tsx +313 -0
- package/src/hooks/kiva/use-parameter-persistence.ts +191 -0
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
import {
|
|
6
|
+
useCallback, useMemo, useState
|
|
7
|
+
} from 'react';
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
endOfMonth,
|
|
11
|
+
endOfWeek,
|
|
12
|
+
endOfYear,
|
|
13
|
+
isSameDay,
|
|
14
|
+
startOfDay,
|
|
15
|
+
startOfMonth,
|
|
16
|
+
startOfWeek,
|
|
17
|
+
startOfYear,
|
|
18
|
+
subDays
|
|
19
|
+
} from 'date-fns';
|
|
20
|
+
import { CalendarIcon } from 'lucide-react';
|
|
21
|
+
|
|
22
|
+
import { type DateRange } from 'react-day-picker';
|
|
23
|
+
|
|
24
|
+
import { cn } from '@kivacore/ui-pro-shared/lib/utils';
|
|
25
|
+
import { Button } from '@kivacore/ui-pro-shared/components/button';
|
|
26
|
+
import { Calendar } from '@kivacore/ui-pro-shared/components/calendar';
|
|
27
|
+
import {
|
|
28
|
+
Popover, PopoverContent, PopoverTrigger
|
|
29
|
+
} from '@kivacore/ui-pro-shared/components/popover';
|
|
30
|
+
import {
|
|
31
|
+
type Column,
|
|
32
|
+
type DataTableFilterActions,
|
|
33
|
+
type FilterModel
|
|
34
|
+
} from '@kivacore/ui-pro-shared/components/kiva/data-table-filter/core/types';
|
|
35
|
+
import { type Locale, t } from '@kivacore/ui-pro-shared/components/kiva/data-table-filter/lib/i18n';
|
|
36
|
+
import { useDateFormat } from '@kivacore/ui-pro-shared/hooks/kiva/use-date-format';
|
|
37
|
+
|
|
38
|
+
interface SideFilterDateRangeProps<TData> {
|
|
39
|
+
column: Column<TData, 'date'>;
|
|
40
|
+
filter?: FilterModel<'date'>;
|
|
41
|
+
actions: DataTableFilterActions;
|
|
42
|
+
locale?: Locale;
|
|
43
|
+
/** When true, render presets above the from/to row. Default true. */
|
|
44
|
+
withPresets?: boolean;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
interface DatePreset {
|
|
48
|
+
key: string;
|
|
49
|
+
label: string;
|
|
50
|
+
range: () => DateRange;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function buildPresets(locale: Locale): Array<DatePreset> {
|
|
54
|
+
const today = startOfDay(new Date());
|
|
55
|
+
const yesterday = subDays(today, 1);
|
|
56
|
+
const weekOptions = { weekStartsOn: 1 } as const;
|
|
57
|
+
|
|
58
|
+
return [
|
|
59
|
+
{
|
|
60
|
+
key: 'today',
|
|
61
|
+
label: t('datePresets.today', locale),
|
|
62
|
+
range: () => ({ from: today, to: today })
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
key: 'yesterday',
|
|
66
|
+
label: t('datePresets.yesterday', locale),
|
|
67
|
+
range: () => ({ from: yesterday, to: yesterday })
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
key: 'last7Days',
|
|
71
|
+
label: t('datePresets.last7Days', locale),
|
|
72
|
+
range: () => ({ from: subDays(today, 6), to: today })
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
key: 'last30Days',
|
|
76
|
+
label: t('datePresets.last30Days', locale),
|
|
77
|
+
range: () => ({ from: subDays(today, 29), to: today })
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
key: 'thisWeek',
|
|
81
|
+
label: t('datePresets.thisWeek', locale),
|
|
82
|
+
range: () => ({
|
|
83
|
+
from: startOfWeek(today, weekOptions),
|
|
84
|
+
to: endOfWeek(today, weekOptions)
|
|
85
|
+
})
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
key: 'thisMonth',
|
|
89
|
+
label: t('datePresets.thisMonth', locale),
|
|
90
|
+
range: () => ({ from: startOfMonth(today), to: endOfMonth(today) })
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
key: 'thisYear',
|
|
94
|
+
label: t('datePresets.thisYear', locale),
|
|
95
|
+
range: () => ({ from: startOfYear(today), to: endOfYear(today) })
|
|
96
|
+
}
|
|
97
|
+
];
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function rangesEqual(a: DateRange | undefined, b: DateRange): boolean {
|
|
101
|
+
if (!a?.from || !b.from) return false;
|
|
102
|
+
const aTo = a.to ?? a.from;
|
|
103
|
+
const bTo = b.to ?? b.from;
|
|
104
|
+
|
|
105
|
+
return isSameDay(a.from, b.from) && isSameDay(aTo, bTo);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function SideFilterDateRange<TData>({
|
|
109
|
+
column,
|
|
110
|
+
filter,
|
|
111
|
+
actions,
|
|
112
|
+
locale = 'en',
|
|
113
|
+
withPresets = true
|
|
114
|
+
}: SideFilterDateRangeProps<TData>) {
|
|
115
|
+
const { formatDate } = useDateFormat();
|
|
116
|
+
const [open, setOpen] = useState(false);
|
|
117
|
+
|
|
118
|
+
const range = useMemo<DateRange | undefined>(() => {
|
|
119
|
+
const from = filter?.values[0] as Date | undefined;
|
|
120
|
+
const to = filter?.values[1] as Date | undefined;
|
|
121
|
+
|
|
122
|
+
if (!from) return undefined;
|
|
123
|
+
|
|
124
|
+
return { from, to };
|
|
125
|
+
}, [filter?.values]);
|
|
126
|
+
|
|
127
|
+
const presets = useMemo(() => buildPresets(locale), [locale]);
|
|
128
|
+
|
|
129
|
+
const applyRange = useCallback(
|
|
130
|
+
(next: DateRange | undefined) => {
|
|
131
|
+
if (!next?.from) {
|
|
132
|
+
actions.removeFilter(column.id);
|
|
133
|
+
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
const start = next.from;
|
|
137
|
+
const end = next.to ?? undefined;
|
|
138
|
+
const values: Array<Date> = end && !isSameDay(start, end) ? [start, end] : [start];
|
|
139
|
+
|
|
140
|
+
actions.setFilterValue(column, values);
|
|
141
|
+
},
|
|
142
|
+
[actions, column]
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
const triggerLabel = (() => {
|
|
146
|
+
if (!range?.from) return t('search', locale);
|
|
147
|
+
const fromStr = formatDate(range.from);
|
|
148
|
+
|
|
149
|
+
if (!range.to || isSameDay(range.from, range.to)) return fromStr;
|
|
150
|
+
|
|
151
|
+
return `${fromStr} – ${formatDate(range.to)}`;
|
|
152
|
+
})();
|
|
153
|
+
|
|
154
|
+
return (
|
|
155
|
+
<div className="flex flex-col gap-2">
|
|
156
|
+
<Popover open={open} onOpenChange={setOpen}>
|
|
157
|
+
<PopoverTrigger asChild>
|
|
158
|
+
<Button
|
|
159
|
+
type="button"
|
|
160
|
+
variant="outline"
|
|
161
|
+
size="sm"
|
|
162
|
+
className={cn(
|
|
163
|
+
'h-9 w-full justify-between px-3 font-normal',
|
|
164
|
+
!range && 'text-muted-foreground'
|
|
165
|
+
)}>
|
|
166
|
+
<span className="truncate">{triggerLabel}</span>
|
|
167
|
+
<CalendarIcon className="size-4 shrink-0 opacity-60" />
|
|
168
|
+
</Button>
|
|
169
|
+
</PopoverTrigger>
|
|
170
|
+
<PopoverContent align="start" className="w-auto p-2">
|
|
171
|
+
<div className="flex items-stretch gap-2">
|
|
172
|
+
{withPresets && (
|
|
173
|
+
<div className="flex w-32 flex-col gap-1">
|
|
174
|
+
{presets.map((preset) => {
|
|
175
|
+
const presetRange = preset.range();
|
|
176
|
+
const isActive = rangesEqual(range, presetRange);
|
|
177
|
+
|
|
178
|
+
return (
|
|
179
|
+
<Button
|
|
180
|
+
key={preset.key}
|
|
181
|
+
type="button"
|
|
182
|
+
variant={isActive ? 'secondary' : 'ghost'}
|
|
183
|
+
size="sm"
|
|
184
|
+
className="h-7 justify-start px-2 text-xs"
|
|
185
|
+
onClick={() => applyRange(presetRange)}>
|
|
186
|
+
{preset.label}
|
|
187
|
+
</Button>
|
|
188
|
+
);
|
|
189
|
+
})}
|
|
190
|
+
</div>
|
|
191
|
+
)}
|
|
192
|
+
<Calendar
|
|
193
|
+
autoFocus
|
|
194
|
+
mode="range"
|
|
195
|
+
defaultMonth={range?.from}
|
|
196
|
+
selected={range}
|
|
197
|
+
onSelect={applyRange}
|
|
198
|
+
numberOfMonths={1} />
|
|
199
|
+
</div>
|
|
200
|
+
</PopoverContent>
|
|
201
|
+
</Popover>
|
|
202
|
+
</div>
|
|
203
|
+
);
|
|
204
|
+
}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
import {
|
|
6
|
+
type ChangeEvent, useCallback, useEffect, useMemo, useState
|
|
7
|
+
} from 'react';
|
|
8
|
+
|
|
9
|
+
import { cn } from '@kivacore/ui-pro-shared/lib/utils';
|
|
10
|
+
import { Input } from '@kivacore/ui-pro-shared/components/input';
|
|
11
|
+
import { Slider } from '@kivacore/ui-pro-shared/components/slider';
|
|
12
|
+
import {
|
|
13
|
+
type Column,
|
|
14
|
+
type DataTableFilterActions,
|
|
15
|
+
type FilterModel
|
|
16
|
+
} from '@kivacore/ui-pro-shared/components/kiva/data-table-filter/core/types';
|
|
17
|
+
import { useDebounceCallback } from '@kivacore/ui-pro-shared/components/kiva/data-table-filter/hooks/use-debounce-callback';
|
|
18
|
+
import { type Locale, t } from '@kivacore/ui-pro-shared/components/kiva/data-table-filter/lib/i18n';
|
|
19
|
+
|
|
20
|
+
interface SideFilterNumericRangeProps<TData> {
|
|
21
|
+
column: Column<TData, 'number'>;
|
|
22
|
+
filter?: FilterModel<'number'>;
|
|
23
|
+
actions: DataTableFilterActions;
|
|
24
|
+
locale?: Locale;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function clampNumber(value: number, min: number, max: number): number {
|
|
28
|
+
return Math.min(Math.max(value, min), max);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function SideFilterNumericRange<TData>({
|
|
32
|
+
column,
|
|
33
|
+
filter,
|
|
34
|
+
actions,
|
|
35
|
+
locale = 'en'
|
|
36
|
+
}: SideFilterNumericRangeProps<TData>) {
|
|
37
|
+
const minMax = useMemo(() => column.getFacetedMinMaxValues(), [column]);
|
|
38
|
+
const sliderMin = minMax?.[0] ?? column.min ?? 0;
|
|
39
|
+
const sliderMax = minMax?.[1] ?? column.max ?? 100;
|
|
40
|
+
const hasBounds = sliderMax > sliderMin;
|
|
41
|
+
|
|
42
|
+
const initialFrom = filter?.values[0] ?? sliderMin;
|
|
43
|
+
const initialTo = filter?.values[1] ?? sliderMax;
|
|
44
|
+
|
|
45
|
+
const [draft, setDraft] = useState<[number, number]>([initialFrom, initialTo]);
|
|
46
|
+
const [error, setError] = useState<'order' | null>(null);
|
|
47
|
+
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
if (!filter || filter.values.length === 0) {
|
|
50
|
+
queueMicrotask(() => {
|
|
51
|
+
setDraft([sliderMin, sliderMax]);
|
|
52
|
+
setError(null);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const from = filter.values[0] ?? sliderMin;
|
|
58
|
+
const to = filter.values[1] ?? sliderMax;
|
|
59
|
+
|
|
60
|
+
queueMicrotask(() => setDraft([from, to]));
|
|
61
|
+
}, [filter, sliderMin, sliderMax]);
|
|
62
|
+
|
|
63
|
+
const commit = useDebounceCallback((values: [number, number]) => {
|
|
64
|
+
actions.setFilterOperator(column.id, 'is between');
|
|
65
|
+
actions.setFilterValue(column, [...values]);
|
|
66
|
+
}, 300);
|
|
67
|
+
|
|
68
|
+
const handleSlider = useCallback(
|
|
69
|
+
(next: Array<number>) => {
|
|
70
|
+
const [a, b] = [next[0] ?? sliderMin, next[1] ?? sliderMax];
|
|
71
|
+
const ordered: [number, number] = a <= b ? [a, b] : [b, a];
|
|
72
|
+
|
|
73
|
+
setDraft(ordered);
|
|
74
|
+
setError(null);
|
|
75
|
+
commit(ordered);
|
|
76
|
+
},
|
|
77
|
+
[commit, sliderMin, sliderMax]
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
const handleInput = useCallback(
|
|
81
|
+
(which: 'from' | 'to') => (e: ChangeEvent<HTMLInputElement>) => {
|
|
82
|
+
const raw = e.target.value;
|
|
83
|
+
const parsed = raw === '' ? NaN : Number(raw);
|
|
84
|
+
|
|
85
|
+
if (Number.isNaN(parsed)) {
|
|
86
|
+
const next: [number, number] = which === 'from' ? [sliderMin, draft[1]] : [draft[0], sliderMax];
|
|
87
|
+
|
|
88
|
+
setDraft(next);
|
|
89
|
+
setError(null);
|
|
90
|
+
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const clamped = hasBounds ? clampNumber(parsed, sliderMin, sliderMax) : parsed;
|
|
95
|
+
const next: [number, number] = which === 'from' ? [clamped, draft[1]] : [draft[0], clamped];
|
|
96
|
+
|
|
97
|
+
setDraft(next);
|
|
98
|
+
|
|
99
|
+
if (next[0] > next[1]) {
|
|
100
|
+
setError('order');
|
|
101
|
+
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
setError(null);
|
|
105
|
+
commit(next);
|
|
106
|
+
},
|
|
107
|
+
[
|
|
108
|
+
commit,
|
|
109
|
+
draft,
|
|
110
|
+
hasBounds,
|
|
111
|
+
sliderMin,
|
|
112
|
+
sliderMax
|
|
113
|
+
]
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
return (
|
|
117
|
+
<div className="flex flex-col gap-3">
|
|
118
|
+
{hasBounds && (
|
|
119
|
+
<Slider
|
|
120
|
+
value={draft}
|
|
121
|
+
onValueChange={handleSlider}
|
|
122
|
+
min={sliderMin}
|
|
123
|
+
max={sliderMax}
|
|
124
|
+
step={1}
|
|
125
|
+
className="mt-1" />
|
|
126
|
+
)}
|
|
127
|
+
<div className="grid grid-cols-2 gap-2">
|
|
128
|
+
<label className="flex flex-col gap-1">
|
|
129
|
+
<span className="text-xs font-medium text-muted-foreground">
|
|
130
|
+
{t('min', locale)}
|
|
131
|
+
</span>
|
|
132
|
+
<Input
|
|
133
|
+
type="number"
|
|
134
|
+
inputMode="decimal"
|
|
135
|
+
value={draft[0]}
|
|
136
|
+
onChange={handleInput('from')}
|
|
137
|
+
min={hasBounds ? sliderMin : undefined}
|
|
138
|
+
max={hasBounds ? sliderMax : undefined}
|
|
139
|
+
className={cn('h-9', error === 'order' && 'border-destructive')} />
|
|
140
|
+
</label>
|
|
141
|
+
<label className="flex flex-col gap-1">
|
|
142
|
+
<span className="text-xs font-medium text-muted-foreground">
|
|
143
|
+
{t('max', locale)}
|
|
144
|
+
</span>
|
|
145
|
+
<Input
|
|
146
|
+
type="number"
|
|
147
|
+
inputMode="decimal"
|
|
148
|
+
value={draft[1]}
|
|
149
|
+
onChange={handleInput('to')}
|
|
150
|
+
min={hasBounds ? sliderMin : undefined}
|
|
151
|
+
max={hasBounds ? sliderMax : undefined}
|
|
152
|
+
className={cn('h-9', error === 'order' && 'border-destructive')} />
|
|
153
|
+
</label>
|
|
154
|
+
</div>
|
|
155
|
+
{error === 'order' && (
|
|
156
|
+
<p className="text-xs text-destructive">
|
|
157
|
+
Min must be less than or equal to max
|
|
158
|
+
</p>
|
|
159
|
+
)}
|
|
160
|
+
</div>
|
|
161
|
+
);
|
|
162
|
+
}
|
package/src/components/kiva/data-table-side-filters/controllers/side-filter-options-dropdown.tsx
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
import {
|
|
6
|
+
isValidElement, useCallback, useMemo, useState
|
|
7
|
+
} from 'react';
|
|
8
|
+
|
|
9
|
+
import { ChevronDown, X } from 'lucide-react';
|
|
10
|
+
|
|
11
|
+
import { cn } from '@kivacore/ui-pro-shared/lib/utils';
|
|
12
|
+
import { Avatar, AvatarFallback, AvatarImage } from '@kivacore/ui-pro-shared/components/avatar';
|
|
13
|
+
import { Badge } from '@kivacore/ui-pro-shared/components/badge';
|
|
14
|
+
import { Button } from '@kivacore/ui-pro-shared/components/button';
|
|
15
|
+
import { Checkbox } from '@kivacore/ui-pro-shared/components/checkbox';
|
|
16
|
+
import {
|
|
17
|
+
Command,
|
|
18
|
+
CommandEmpty,
|
|
19
|
+
CommandGroup,
|
|
20
|
+
CommandInput,
|
|
21
|
+
CommandItem,
|
|
22
|
+
CommandList
|
|
23
|
+
} from '@kivacore/ui-pro-shared/components/command';
|
|
24
|
+
import {
|
|
25
|
+
Popover, PopoverContent, PopoverTrigger
|
|
26
|
+
} from '@kivacore/ui-pro-shared/components/popover';
|
|
27
|
+
import {
|
|
28
|
+
type Column,
|
|
29
|
+
type ColumnOption,
|
|
30
|
+
type DataTableFilterActions,
|
|
31
|
+
type FilterModel,
|
|
32
|
+
type OptionBasedColumnDataType
|
|
33
|
+
} from '@kivacore/ui-pro-shared/components/kiva/data-table-filter/core/types';
|
|
34
|
+
import { type Locale, t } from '@kivacore/ui-pro-shared/components/kiva/data-table-filter/lib/i18n';
|
|
35
|
+
|
|
36
|
+
interface SideFilterOptionsDropdownProps<TData, TType extends OptionBasedColumnDataType> {
|
|
37
|
+
column: Column<TData, TType>;
|
|
38
|
+
filter?: FilterModel<TType>;
|
|
39
|
+
actions: DataTableFilterActions;
|
|
40
|
+
locale?: Locale;
|
|
41
|
+
/** Override the trigger placeholder when nothing is selected. */
|
|
42
|
+
placeholder?: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function SideFilterOptionsDropdown<
|
|
46
|
+
TData,
|
|
47
|
+
TType extends OptionBasedColumnDataType
|
|
48
|
+
>({
|
|
49
|
+
column,
|
|
50
|
+
filter,
|
|
51
|
+
actions,
|
|
52
|
+
locale = 'en',
|
|
53
|
+
placeholder
|
|
54
|
+
}: SideFilterOptionsDropdownProps<TData, TType>) {
|
|
55
|
+
const [open, setOpen] = useState(false);
|
|
56
|
+
const options = useMemo(() => column.getOptions(), [column]);
|
|
57
|
+
const counts = useMemo(() => column.getFacetedUniqueValues(), [column]);
|
|
58
|
+
const selectedValues = useMemo(
|
|
59
|
+
() => new Set((filter?.values as Array<string>) ?? []),
|
|
60
|
+
[filter?.values]
|
|
61
|
+
);
|
|
62
|
+
const selectedOptions = useMemo<Array<ColumnOption>>(
|
|
63
|
+
() => options.filter(o => selectedValues.has(o.value)),
|
|
64
|
+
[options, selectedValues]
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
const handleToggle = useCallback(
|
|
68
|
+
(value: string, checked: boolean) => {
|
|
69
|
+
if (checked) {
|
|
70
|
+
actions.addFilterValue(column, [value] as FilterModel<TType>['values']);
|
|
71
|
+
} else {
|
|
72
|
+
actions.removeFilterValue(column, [value] as FilterModel<TType>['values']);
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
[actions, column]
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
const removeChip = useCallback(
|
|
79
|
+
(value: string) => {
|
|
80
|
+
actions.removeFilterValue(column, [value] as FilterModel<TType>['values']);
|
|
81
|
+
},
|
|
82
|
+
[actions, column]
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
const triggerLabel = selectedOptions.length === 0 ? placeholder ?? `${t('search', locale)}...` : selectedOptions.length === 1 ? selectedOptions[0]?.label : `${selectedOptions.length} selected`;
|
|
86
|
+
|
|
87
|
+
return (
|
|
88
|
+
<div className="flex flex-col gap-2">
|
|
89
|
+
<Popover open={open} onOpenChange={setOpen}>
|
|
90
|
+
<PopoverTrigger asChild>
|
|
91
|
+
<Button
|
|
92
|
+
type="button"
|
|
93
|
+
variant="outline"
|
|
94
|
+
size="sm"
|
|
95
|
+
className={cn(
|
|
96
|
+
'h-9 w-full justify-between px-3 font-normal',
|
|
97
|
+
selectedOptions.length === 0 && 'text-muted-foreground'
|
|
98
|
+
)}>
|
|
99
|
+
<span className="truncate">{triggerLabel}</span>
|
|
100
|
+
<ChevronDown className="size-4 shrink-0 opacity-60" />
|
|
101
|
+
</Button>
|
|
102
|
+
</PopoverTrigger>
|
|
103
|
+
<PopoverContent
|
|
104
|
+
align="start"
|
|
105
|
+
className="w-[var(--radix-popover-trigger-width)] p-0">
|
|
106
|
+
<Command>
|
|
107
|
+
<CommandInput placeholder={t('search', locale)} />
|
|
108
|
+
<CommandList>
|
|
109
|
+
<CommandEmpty>{t('noresults', locale)}</CommandEmpty>
|
|
110
|
+
<CommandGroup>
|
|
111
|
+
{options.map((option) => {
|
|
112
|
+
const isSelected = selectedValues.has(option.value);
|
|
113
|
+
const Icon = option.icon;
|
|
114
|
+
const count = counts?.get(option.value) ?? 0;
|
|
115
|
+
const fallback = option.label.slice(0, 2).toUpperCase();
|
|
116
|
+
|
|
117
|
+
return (
|
|
118
|
+
<CommandItem
|
|
119
|
+
key={option.value}
|
|
120
|
+
value={option.value}
|
|
121
|
+
onSelect={() => handleToggle(option.value, !isSelected)}
|
|
122
|
+
className="flex items-center gap-2">
|
|
123
|
+
<Checkbox checked={isSelected} />
|
|
124
|
+
{option.imageUrl ? (
|
|
125
|
+
<Avatar className="size-5">
|
|
126
|
+
<AvatarImage src={option.imageUrl} alt={option.label} />
|
|
127
|
+
<AvatarFallback className="text-xs">{fallback}</AvatarFallback>
|
|
128
|
+
</Avatar>
|
|
129
|
+
) : Icon ? (
|
|
130
|
+
isValidElement(Icon) ? Icon : <Icon className="size-4 text-muted-foreground" />
|
|
131
|
+
) : option.color ? (
|
|
132
|
+
<span
|
|
133
|
+
aria-hidden
|
|
134
|
+
className="size-2.5 shrink-0 rounded-full"
|
|
135
|
+
style={{ backgroundColor: option.color }} />
|
|
136
|
+
) : null}
|
|
137
|
+
<span className="flex-1 truncate">{option.label}</span>
|
|
138
|
+
{count > 0 && (
|
|
139
|
+
<span className="tabular-nums text-xs text-muted-foreground">
|
|
140
|
+
{count < 100 ? count : '100+'}
|
|
141
|
+
</span>
|
|
142
|
+
)}
|
|
143
|
+
</CommandItem>
|
|
144
|
+
);
|
|
145
|
+
})}
|
|
146
|
+
</CommandGroup>
|
|
147
|
+
</CommandList>
|
|
148
|
+
</Command>
|
|
149
|
+
</PopoverContent>
|
|
150
|
+
</Popover>
|
|
151
|
+
|
|
152
|
+
{selectedOptions.length > 0 && (
|
|
153
|
+
<div className="flex flex-wrap gap-1">
|
|
154
|
+
{selectedOptions.map((option) => {
|
|
155
|
+
const Icon = option.icon;
|
|
156
|
+
const fallback = option.label.slice(0, 2).toUpperCase();
|
|
157
|
+
|
|
158
|
+
return (
|
|
159
|
+
<Badge
|
|
160
|
+
key={option.value}
|
|
161
|
+
variant="secondary"
|
|
162
|
+
className="gap-1 pr-1 pl-1.5 text-xs font-normal">
|
|
163
|
+
{option.imageUrl ? (
|
|
164
|
+
<Avatar className="size-3.5">
|
|
165
|
+
<AvatarImage src={option.imageUrl} alt={option.label} />
|
|
166
|
+
<AvatarFallback className="text-xs">{fallback}</AvatarFallback>
|
|
167
|
+
</Avatar>
|
|
168
|
+
) : Icon ? (
|
|
169
|
+
isValidElement(Icon) ? Icon : <Icon className="size-3" />
|
|
170
|
+
) : option.color ? (
|
|
171
|
+
<span
|
|
172
|
+
aria-hidden
|
|
173
|
+
className="size-2 rounded-full"
|
|
174
|
+
style={{ backgroundColor: option.color }} />
|
|
175
|
+
) : null}
|
|
176
|
+
<span className="truncate max-w-32">{option.label}</span>
|
|
177
|
+
<button
|
|
178
|
+
type="button"
|
|
179
|
+
aria-label={`Remove ${option.label}`}
|
|
180
|
+
onClick={() => removeChip(option.value)}
|
|
181
|
+
className="ml-0.5 rounded-sm p-0.5 transition-colors hover:bg-foreground/10">
|
|
182
|
+
<X className="size-3" />
|
|
183
|
+
</button>
|
|
184
|
+
</Badge>
|
|
185
|
+
);
|
|
186
|
+
})}
|
|
187
|
+
</div>
|
|
188
|
+
)}
|
|
189
|
+
</div>
|
|
190
|
+
);
|
|
191
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
import { useCallback } from 'react';
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
type Column,
|
|
9
|
+
type DataTableFilterActions,
|
|
10
|
+
type FilterModel
|
|
11
|
+
} from '@kivacore/ui-pro-shared/components/kiva/data-table-filter/core/types';
|
|
12
|
+
import { type Locale, t } from '@kivacore/ui-pro-shared/components/kiva/data-table-filter/lib/i18n';
|
|
13
|
+
import { DebouncedInput } from '@kivacore/ui-pro-shared/components/kiva/data-table-filter/ui/debounced-input';
|
|
14
|
+
|
|
15
|
+
interface SideFilterTextProps<TData> {
|
|
16
|
+
column: Column<TData, 'text'>;
|
|
17
|
+
filter?: FilterModel<'text'>;
|
|
18
|
+
actions: DataTableFilterActions;
|
|
19
|
+
locale?: Locale;
|
|
20
|
+
placeholder?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function SideFilterText<TData>({
|
|
24
|
+
column,
|
|
25
|
+
filter,
|
|
26
|
+
actions,
|
|
27
|
+
locale = 'en',
|
|
28
|
+
placeholder
|
|
29
|
+
}: SideFilterTextProps<TData>) {
|
|
30
|
+
const value = filter?.values[0] ?? '';
|
|
31
|
+
const handleChange = useCallback(
|
|
32
|
+
(next: string | number) => {
|
|
33
|
+
const str = String(next);
|
|
34
|
+
|
|
35
|
+
if (str.trim().length === 0) {
|
|
36
|
+
actions.removeFilter(column.id);
|
|
37
|
+
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
actions.setFilterValue(column, [str]);
|
|
41
|
+
},
|
|
42
|
+
[actions, column]
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<DebouncedInput
|
|
47
|
+
type="search"
|
|
48
|
+
value={value}
|
|
49
|
+
onChange={handleChange}
|
|
50
|
+
placeholder={placeholder ?? t('search', locale)}
|
|
51
|
+
className="h-9 w-full" />
|
|
52
|
+
);
|
|
53
|
+
}
|