@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,67 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
import { useCallback } from 'react';
|
|
6
|
+
|
|
7
|
+
import { Search } from 'lucide-react';
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
type Column,
|
|
11
|
+
type DataTableFilterActions,
|
|
12
|
+
type FiltersState
|
|
13
|
+
} from '@kivacore/ui-pro-shared/components/kiva/data-table-filter/core/types';
|
|
14
|
+
import { type Locale, t } from '@kivacore/ui-pro-shared/components/kiva/data-table-filter/lib/i18n';
|
|
15
|
+
import { DebouncedInput } from '@kivacore/ui-pro-shared/components/kiva/data-table-filter/ui/debounced-input';
|
|
16
|
+
|
|
17
|
+
interface SideFilterSearchProps<TData> {
|
|
18
|
+
/** Column id whose `text` filter the search input drives. */
|
|
19
|
+
columnId: string;
|
|
20
|
+
columns: Array<Column<TData>>;
|
|
21
|
+
filters: FiltersState;
|
|
22
|
+
actions: DataTableFilterActions;
|
|
23
|
+
locale?: Locale;
|
|
24
|
+
placeholder?: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function SideFilterSearch<TData>({
|
|
28
|
+
columnId,
|
|
29
|
+
columns,
|
|
30
|
+
filters,
|
|
31
|
+
actions,
|
|
32
|
+
locale = 'en',
|
|
33
|
+
placeholder
|
|
34
|
+
}: SideFilterSearchProps<TData>) {
|
|
35
|
+
const column = columns.find(c => c.id === columnId);
|
|
36
|
+
const filter = filters.find(f => f.columnId === columnId);
|
|
37
|
+
const value = (filter?.values[0] as string | undefined) ?? '';
|
|
38
|
+
|
|
39
|
+
const handleChange = useCallback(
|
|
40
|
+
(next: string | number) => {
|
|
41
|
+
if (!column) return;
|
|
42
|
+
const str = String(next);
|
|
43
|
+
|
|
44
|
+
if (str.trim().length === 0) {
|
|
45
|
+
actions.removeFilter(columnId);
|
|
46
|
+
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
actions.setFilterValue(column as Column<TData, 'text'>, [str]);
|
|
50
|
+
},
|
|
51
|
+
[actions, column, columnId]
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
if (!column || column.type !== 'text') return null;
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<div className="relative">
|
|
58
|
+
<Search className="pointer-events-none absolute left-2.5 top-1/2 size-4 -translate-y-1/2 text-muted-foreground" />
|
|
59
|
+
<DebouncedInput
|
|
60
|
+
type="search"
|
|
61
|
+
value={value}
|
|
62
|
+
onChange={handleChange}
|
|
63
|
+
placeholder={placeholder ?? t('search', locale)}
|
|
64
|
+
className="h-9 w-full pl-8" />
|
|
65
|
+
</div>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
import {
|
|
6
|
+
type ReactNode, useState
|
|
7
|
+
} from 'react';
|
|
8
|
+
|
|
9
|
+
import { ChevronDown } from 'lucide-react';
|
|
10
|
+
|
|
11
|
+
import { cn } from '@kivacore/ui-pro-shared/lib/utils';
|
|
12
|
+
import { Button } from '@kivacore/ui-pro-shared/components/button';
|
|
13
|
+
|
|
14
|
+
interface SideFilterSectionProps {
|
|
15
|
+
id: string;
|
|
16
|
+
title: ReactNode;
|
|
17
|
+
icon?: ReactNode;
|
|
18
|
+
activeCount?: number;
|
|
19
|
+
defaultCollapsed?: boolean;
|
|
20
|
+
onClear?: () => void;
|
|
21
|
+
clearLabel?: string;
|
|
22
|
+
children: ReactNode;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function SideFilterSection({
|
|
26
|
+
id,
|
|
27
|
+
title,
|
|
28
|
+
icon,
|
|
29
|
+
activeCount = 0,
|
|
30
|
+
defaultCollapsed = false,
|
|
31
|
+
onClear,
|
|
32
|
+
clearLabel = 'Clear',
|
|
33
|
+
children
|
|
34
|
+
}: SideFilterSectionProps) {
|
|
35
|
+
const [collapsed, setCollapsed] = useState(defaultCollapsed);
|
|
36
|
+
const hasActive = activeCount > 0;
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<section
|
|
40
|
+
data-side-filter-section={id}
|
|
41
|
+
className="flex flex-col gap-2 border-b border-border/60 py-3 last:border-b-0">
|
|
42
|
+
<header className="flex items-center justify-between gap-2">
|
|
43
|
+
<button
|
|
44
|
+
type="button"
|
|
45
|
+
onClick={() => setCollapsed(v => !v)}
|
|
46
|
+
aria-expanded={!collapsed}
|
|
47
|
+
className="group flex flex-1 items-center gap-2 text-left text-sm font-medium">
|
|
48
|
+
{icon && (
|
|
49
|
+
<span className="shrink-0 text-muted-foreground">{icon}</span>
|
|
50
|
+
)}
|
|
51
|
+
<span className="flex-1 truncate">{title}</span>
|
|
52
|
+
{hasActive && (
|
|
53
|
+
<span className="rounded-full bg-primary/10 px-1.5 py-0.5 text-xs font-semibold tabular-nums text-primary">
|
|
54
|
+
{activeCount}
|
|
55
|
+
</span>
|
|
56
|
+
)}
|
|
57
|
+
<ChevronDown
|
|
58
|
+
className={cn(
|
|
59
|
+
'size-4 shrink-0 text-muted-foreground transition-transform',
|
|
60
|
+
collapsed && '-rotate-90'
|
|
61
|
+
)} />
|
|
62
|
+
</button>
|
|
63
|
+
{hasActive && onClear && !collapsed && (
|
|
64
|
+
<Button
|
|
65
|
+
type="button"
|
|
66
|
+
variant="ghost"
|
|
67
|
+
size="sm"
|
|
68
|
+
onClick={onClear}
|
|
69
|
+
className="h-6 px-2 text-xs text-muted-foreground hover:text-foreground">
|
|
70
|
+
{clearLabel}
|
|
71
|
+
</Button>
|
|
72
|
+
)}
|
|
73
|
+
</header>
|
|
74
|
+
{!collapsed && <div className="pt-1">{children}</div>}
|
|
75
|
+
</section>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
import {
|
|
6
|
+
isValidElement,
|
|
7
|
+
useCallback,
|
|
8
|
+
useEffect,
|
|
9
|
+
useMemo,
|
|
10
|
+
useRef,
|
|
11
|
+
useState
|
|
12
|
+
} from 'react';
|
|
13
|
+
|
|
14
|
+
import { ChevronDown, X } from 'lucide-react';
|
|
15
|
+
|
|
16
|
+
import { cn } from '@kivacore/ui-pro-shared/lib/utils';
|
|
17
|
+
import { Avatar, AvatarFallback, AvatarImage } from '@kivacore/ui-pro-shared/components/avatar';
|
|
18
|
+
import { Badge } from '@kivacore/ui-pro-shared/components/badge';
|
|
19
|
+
import { Button } from '@kivacore/ui-pro-shared/components/button';
|
|
20
|
+
import { Checkbox } from '@kivacore/ui-pro-shared/components/checkbox';
|
|
21
|
+
import {
|
|
22
|
+
Command,
|
|
23
|
+
CommandEmpty,
|
|
24
|
+
CommandGroup,
|
|
25
|
+
CommandInput,
|
|
26
|
+
CommandItem,
|
|
27
|
+
CommandList
|
|
28
|
+
} from '@kivacore/ui-pro-shared/components/command';
|
|
29
|
+
import {
|
|
30
|
+
Popover, PopoverContent, PopoverTrigger
|
|
31
|
+
} from '@kivacore/ui-pro-shared/components/popover';
|
|
32
|
+
import {
|
|
33
|
+
type Column,
|
|
34
|
+
type ColumnOption,
|
|
35
|
+
type DataTableFilterActions,
|
|
36
|
+
type FilterModel,
|
|
37
|
+
type OptionBasedColumnDataType
|
|
38
|
+
} from '@kivacore/ui-pro-shared/components/kiva/data-table-filter/core/types';
|
|
39
|
+
import { type Locale, t } from '@kivacore/ui-pro-shared/components/kiva/data-table-filter/lib/i18n';
|
|
40
|
+
|
|
41
|
+
interface SideFilterAsyncOptionsProps<TData, TType extends OptionBasedColumnDataType> {
|
|
42
|
+
column: Column<TData, TType>;
|
|
43
|
+
filter?: FilterModel<TType>;
|
|
44
|
+
actions: DataTableFilterActions;
|
|
45
|
+
locale?: Locale;
|
|
46
|
+
placeholder?: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function SideFilterAsyncOptions<
|
|
50
|
+
TData,
|
|
51
|
+
TType extends OptionBasedColumnDataType
|
|
52
|
+
>({
|
|
53
|
+
column,
|
|
54
|
+
filter,
|
|
55
|
+
actions,
|
|
56
|
+
locale = 'en',
|
|
57
|
+
placeholder
|
|
58
|
+
}: SideFilterAsyncOptionsProps<TData, TType>) {
|
|
59
|
+
const cfg = column.asyncOptions;
|
|
60
|
+
const pageSize = cfg?.pageSize ?? 25;
|
|
61
|
+
const debounceMs = cfg?.debounceMs ?? 300;
|
|
62
|
+
const isMulti = column.type === 'multiOption';
|
|
63
|
+
|
|
64
|
+
const [open, setOpen] = useState(false);
|
|
65
|
+
const [search, setSearch] = useState('');
|
|
66
|
+
const [debouncedSearch, setDebouncedSearch] = useState('');
|
|
67
|
+
const [items, setItems] = useState<Array<ColumnOption>>([]);
|
|
68
|
+
const [page, setPage] = useState(0);
|
|
69
|
+
const [hasMore, setHasMore] = useState(false);
|
|
70
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
71
|
+
/**
|
|
72
|
+
* Cache options we've ever loaded so previously-selected chips stay
|
|
73
|
+
* labeled even after the search query filters them out of `items`.
|
|
74
|
+
*/
|
|
75
|
+
const [seenOptions, setSeenOptions] = useState<Map<string, ColumnOption>>(
|
|
76
|
+
() => new Map()
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
const loadRef = useRef(cfg?.load);
|
|
80
|
+
|
|
81
|
+
loadRef.current = cfg?.load;
|
|
82
|
+
|
|
83
|
+
const selectedValues = useMemo(
|
|
84
|
+
() => new Set((filter?.values as Array<string>) ?? []),
|
|
85
|
+
[filter?.values]
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
useEffect(() => {
|
|
89
|
+
const timeout = setTimeout(() => setDebouncedSearch(search), debounceMs);
|
|
90
|
+
|
|
91
|
+
return () => clearTimeout(timeout);
|
|
92
|
+
}, [search, debounceMs]);
|
|
93
|
+
|
|
94
|
+
useEffect(() => {
|
|
95
|
+
if (!open) return undefined;
|
|
96
|
+
const load = loadRef.current;
|
|
97
|
+
|
|
98
|
+
if (!load) return undefined;
|
|
99
|
+
const controller = new AbortController();
|
|
100
|
+
|
|
101
|
+
queueMicrotask(() => {
|
|
102
|
+
if (controller.signal.aborted) return;
|
|
103
|
+
setIsLoading(true);
|
|
104
|
+
setPage(0);
|
|
105
|
+
});
|
|
106
|
+
load({
|
|
107
|
+
search: debouncedSearch,
|
|
108
|
+
page: 0,
|
|
109
|
+
pageSize,
|
|
110
|
+
signal: controller.signal
|
|
111
|
+
})
|
|
112
|
+
.then((result) => {
|
|
113
|
+
if (controller.signal.aborted) return;
|
|
114
|
+
setItems(result.items);
|
|
115
|
+
setHasMore(result.hasMore ?? false);
|
|
116
|
+
setSeenOptions((prev) => {
|
|
117
|
+
const next = new Map(prev);
|
|
118
|
+
|
|
119
|
+
for (const o of result.items) next.set(o.value, o);
|
|
120
|
+
|
|
121
|
+
return next;
|
|
122
|
+
});
|
|
123
|
+
})
|
|
124
|
+
.catch((error: unknown) => {
|
|
125
|
+
if (error instanceof Error && error.name === 'AbortError') return;
|
|
126
|
+
throw error;
|
|
127
|
+
})
|
|
128
|
+
.finally(() => {
|
|
129
|
+
if (!controller.signal.aborted) setIsLoading(false);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
return () => controller.abort();
|
|
133
|
+
}, [debouncedSearch, pageSize, open]);
|
|
134
|
+
|
|
135
|
+
const onLoadMore = useCallback(() => {
|
|
136
|
+
const load = loadRef.current;
|
|
137
|
+
|
|
138
|
+
if (!load) return;
|
|
139
|
+
const nextPage = page + 1;
|
|
140
|
+
|
|
141
|
+
setIsLoading(true);
|
|
142
|
+
load({ search: debouncedSearch, page: nextPage, pageSize })
|
|
143
|
+
.then((result) => {
|
|
144
|
+
setItems(prev => [...prev, ...result.items]);
|
|
145
|
+
setSeenOptions((prev) => {
|
|
146
|
+
const next = new Map(prev);
|
|
147
|
+
|
|
148
|
+
for (const o of result.items) next.set(o.value, o);
|
|
149
|
+
|
|
150
|
+
return next;
|
|
151
|
+
});
|
|
152
|
+
setPage(nextPage);
|
|
153
|
+
setHasMore(result.hasMore ?? false);
|
|
154
|
+
})
|
|
155
|
+
.finally(() => setIsLoading(false));
|
|
156
|
+
}, [page, debouncedSearch, pageSize]);
|
|
157
|
+
|
|
158
|
+
const handleToggle = useCallback(
|
|
159
|
+
(option: ColumnOption, checked: boolean) => {
|
|
160
|
+
setSeenOptions((prev) => {
|
|
161
|
+
if (prev.has(option.value)) return prev;
|
|
162
|
+
const next = new Map(prev);
|
|
163
|
+
|
|
164
|
+
next.set(option.value, option);
|
|
165
|
+
|
|
166
|
+
return next;
|
|
167
|
+
});
|
|
168
|
+
if (isMulti) {
|
|
169
|
+
if (checked) {
|
|
170
|
+
actions.addFilterValue(column as Column<TData, 'multiOption'>, [option.value]);
|
|
171
|
+
} else {
|
|
172
|
+
actions.removeFilterValue(column as Column<TData, 'multiOption'>, [option.value]);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
if (checked) {
|
|
178
|
+
actions.setFilterValue(column, [option.value] as FilterModel<TType>['values']);
|
|
179
|
+
setOpen(false);
|
|
180
|
+
} else {
|
|
181
|
+
actions.setFilterValue(column, [] as FilterModel<TType>['values']);
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
[actions, column, isMulti]
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
const removeChip = useCallback(
|
|
188
|
+
(value: string) => {
|
|
189
|
+
if (isMulti) {
|
|
190
|
+
actions.removeFilterValue(
|
|
191
|
+
column as Column<TData, 'multiOption'>,
|
|
192
|
+
[value]
|
|
193
|
+
);
|
|
194
|
+
} else {
|
|
195
|
+
actions.setFilterValue(column, [] as FilterModel<TType>['values']);
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
[actions, column, isMulti]
|
|
199
|
+
);
|
|
200
|
+
|
|
201
|
+
const selectedChips = useMemo(() => {
|
|
202
|
+
return Array.from(selectedValues).map((value) => {
|
|
203
|
+
const known = seenOptions.get(value);
|
|
204
|
+
|
|
205
|
+
return known ?? { label: value, value };
|
|
206
|
+
});
|
|
207
|
+
}, [selectedValues, seenOptions]);
|
|
208
|
+
|
|
209
|
+
const unknownSelectedCount = useMemo(
|
|
210
|
+
() => Array.from(selectedValues).reduce(
|
|
211
|
+
(count, value) => (seenOptions.has(value) ? count : count + 1),
|
|
212
|
+
0
|
|
213
|
+
),
|
|
214
|
+
[selectedValues, seenOptions]
|
|
215
|
+
);
|
|
216
|
+
|
|
217
|
+
const triggerLabel = (() => {
|
|
218
|
+
if (selectedChips.length === 0) {
|
|
219
|
+
return placeholder ?? `${t('search', locale)}...`;
|
|
220
|
+
}
|
|
221
|
+
if (selectedChips.length === 1 && unknownSelectedCount === 0) {
|
|
222
|
+
return selectedChips[0]?.label;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
return `${selectedChips.length} selected`;
|
|
226
|
+
})();
|
|
227
|
+
|
|
228
|
+
if (!cfg) {
|
|
229
|
+
return (
|
|
230
|
+
<p className="px-1 py-2 text-xs text-muted-foreground">
|
|
231
|
+
Async loader not configured
|
|
232
|
+
</p>
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
return (
|
|
237
|
+
<div className="flex flex-col gap-2">
|
|
238
|
+
<Popover open={open} onOpenChange={setOpen}>
|
|
239
|
+
<PopoverTrigger asChild>
|
|
240
|
+
<Button
|
|
241
|
+
type="button"
|
|
242
|
+
variant="outline"
|
|
243
|
+
size="sm"
|
|
244
|
+
className={cn(
|
|
245
|
+
'h-9 w-full justify-between px-3 font-normal',
|
|
246
|
+
selectedChips.length === 0 && 'text-muted-foreground'
|
|
247
|
+
)}>
|
|
248
|
+
<span className="truncate">{triggerLabel}</span>
|
|
249
|
+
<ChevronDown className="size-4 shrink-0 opacity-60" />
|
|
250
|
+
</Button>
|
|
251
|
+
</PopoverTrigger>
|
|
252
|
+
<PopoverContent
|
|
253
|
+
align="start"
|
|
254
|
+
className="w-[var(--radix-popover-trigger-width)] p-0">
|
|
255
|
+
<Command shouldFilter={false}>
|
|
256
|
+
<CommandInput
|
|
257
|
+
value={search}
|
|
258
|
+
onValueChange={setSearch}
|
|
259
|
+
placeholder={t('search', locale)} />
|
|
260
|
+
<CommandList className="max-h-72">
|
|
261
|
+
{!isLoading && items.length === 0 && (
|
|
262
|
+
<CommandEmpty>{t('noresults', locale)}</CommandEmpty>
|
|
263
|
+
)}
|
|
264
|
+
<CommandGroup>
|
|
265
|
+
{items.map((option) => {
|
|
266
|
+
const isSelected = selectedValues.has(option.value);
|
|
267
|
+
const Icon = option.icon;
|
|
268
|
+
const fallback = option.label.slice(0, 2).toUpperCase();
|
|
269
|
+
|
|
270
|
+
return (
|
|
271
|
+
<CommandItem
|
|
272
|
+
key={option.value}
|
|
273
|
+
value={option.value}
|
|
274
|
+
onSelect={() => handleToggle(option, !isSelected)}
|
|
275
|
+
className="flex items-center gap-2">
|
|
276
|
+
<Checkbox checked={isSelected} />
|
|
277
|
+
{option.imageUrl ? (
|
|
278
|
+
<Avatar className="size-6">
|
|
279
|
+
<AvatarImage src={option.imageUrl} alt={option.label} />
|
|
280
|
+
<AvatarFallback className="text-xs">{fallback}</AvatarFallback>
|
|
281
|
+
</Avatar>
|
|
282
|
+
) : Icon ? (
|
|
283
|
+
isValidElement(Icon) ? Icon : <Icon className="size-5 text-muted-foreground" />
|
|
284
|
+
) : null}
|
|
285
|
+
<div className="flex min-w-0 flex-col">
|
|
286
|
+
<span className="truncate">{option.label}</span>
|
|
287
|
+
{option.secondaryLabel && (
|
|
288
|
+
<span className="truncate text-xs text-muted-foreground">
|
|
289
|
+
{option.secondaryLabel}
|
|
290
|
+
</span>
|
|
291
|
+
)}
|
|
292
|
+
</div>
|
|
293
|
+
</CommandItem>
|
|
294
|
+
);
|
|
295
|
+
})}
|
|
296
|
+
</CommandGroup>
|
|
297
|
+
{hasMore && (
|
|
298
|
+
<CommandGroup>
|
|
299
|
+
<CommandItem
|
|
300
|
+
disabled={isLoading}
|
|
301
|
+
onSelect={onLoadMore}
|
|
302
|
+
className="text-xs text-muted-foreground">
|
|
303
|
+
{isLoading ? t('loading', locale) : t('loadMore', locale)}
|
|
304
|
+
</CommandItem>
|
|
305
|
+
</CommandGroup>
|
|
306
|
+
)}
|
|
307
|
+
{isLoading && items.length > 0 && (
|
|
308
|
+
<CommandGroup>
|
|
309
|
+
<CommandItem disabled className="text-xs text-muted-foreground">
|
|
310
|
+
{t('loading', locale)}
|
|
311
|
+
</CommandItem>
|
|
312
|
+
</CommandGroup>
|
|
313
|
+
)}
|
|
314
|
+
</CommandList>
|
|
315
|
+
</Command>
|
|
316
|
+
</PopoverContent>
|
|
317
|
+
</Popover>
|
|
318
|
+
|
|
319
|
+
{selectedChips.length > 0 && (
|
|
320
|
+
<div className="flex flex-wrap gap-1">
|
|
321
|
+
{selectedChips.map((option) => {
|
|
322
|
+
const Icon = (option as ColumnOption).icon;
|
|
323
|
+
const fallback = option.label.slice(0, 2).toUpperCase();
|
|
324
|
+
const { imageUrl } = option as ColumnOption;
|
|
325
|
+
|
|
326
|
+
return (
|
|
327
|
+
<Badge
|
|
328
|
+
key={option.value}
|
|
329
|
+
variant="secondary"
|
|
330
|
+
className="gap-1 pr-1 pl-1.5 text-xs font-normal">
|
|
331
|
+
{imageUrl ? (
|
|
332
|
+
<Avatar className="size-3.5">
|
|
333
|
+
<AvatarImage src={imageUrl} alt={option.label} />
|
|
334
|
+
<AvatarFallback className="text-xs">{fallback}</AvatarFallback>
|
|
335
|
+
</Avatar>
|
|
336
|
+
) : Icon ? (
|
|
337
|
+
isValidElement(Icon) ? Icon : <Icon className="size-3" />
|
|
338
|
+
) : null}
|
|
339
|
+
<span className="truncate max-w-32">{option.label}</span>
|
|
340
|
+
<button
|
|
341
|
+
type="button"
|
|
342
|
+
aria-label={`Remove ${option.label}`}
|
|
343
|
+
onClick={() => removeChip(option.value)}
|
|
344
|
+
className="ml-0.5 rounded-sm p-0.5 transition-colors hover:bg-foreground/10">
|
|
345
|
+
<X className="size-3" />
|
|
346
|
+
</button>
|
|
347
|
+
</Badge>
|
|
348
|
+
);
|
|
349
|
+
})}
|
|
350
|
+
</div>
|
|
351
|
+
)}
|
|
352
|
+
</div>
|
|
353
|
+
);
|
|
354
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
import { useCallback } from 'react';
|
|
6
|
+
|
|
7
|
+
import { cn } from '@kivacore/ui-pro-shared/lib/utils';
|
|
8
|
+
import { Button } from '@kivacore/ui-pro-shared/components/button';
|
|
9
|
+
import {
|
|
10
|
+
type Column,
|
|
11
|
+
type DataTableFilterActions,
|
|
12
|
+
type FilterModel
|
|
13
|
+
} from '@kivacore/ui-pro-shared/components/kiva/data-table-filter/core/types';
|
|
14
|
+
import { type Locale, t } from '@kivacore/ui-pro-shared/components/kiva/data-table-filter/lib/i18n';
|
|
15
|
+
|
|
16
|
+
interface SideFilterBooleanProps<TData> {
|
|
17
|
+
column: Column<TData, 'boolean'>;
|
|
18
|
+
filter?: FilterModel<'boolean'>;
|
|
19
|
+
actions: DataTableFilterActions;
|
|
20
|
+
locale?: Locale;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
type Pick = 'any' | 'true' | 'false';
|
|
24
|
+
|
|
25
|
+
export function SideFilterBoolean<TData>({
|
|
26
|
+
column,
|
|
27
|
+
filter,
|
|
28
|
+
actions,
|
|
29
|
+
locale = 'en'
|
|
30
|
+
}: SideFilterBooleanProps<TData>) {
|
|
31
|
+
const current: Pick = filter?.values[0] === true ? 'true' : filter?.values[0] === false ? 'false' : 'any';
|
|
32
|
+
|
|
33
|
+
const handle = useCallback(
|
|
34
|
+
(pick: Pick) => {
|
|
35
|
+
if (pick === 'any') {
|
|
36
|
+
actions.removeFilter(column.id);
|
|
37
|
+
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
actions.setFilterValue(column, [pick === 'true']);
|
|
41
|
+
},
|
|
42
|
+
[actions, column]
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
const trueLabel = column.trueLabel ?? t('true', locale);
|
|
46
|
+
const falseLabel = column.falseLabel ?? t('false', locale);
|
|
47
|
+
const anyLabel = t('all', locale) === 'all' ? 'Any' : t('all', locale);
|
|
48
|
+
|
|
49
|
+
const items: Array<{ key: Pick; label: string }> = [{ key: 'any', label: anyLabel }, { key: 'true', label: trueLabel }, { key: 'false', label: falseLabel }];
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<div className="grid grid-cols-3 gap-1">
|
|
53
|
+
{items.map(item => (
|
|
54
|
+
<Button
|
|
55
|
+
key={item.key}
|
|
56
|
+
type="button"
|
|
57
|
+
variant={current === item.key ? 'secondary' : 'outline'}
|
|
58
|
+
size="sm"
|
|
59
|
+
className={cn('h-8 text-xs', current === item.key && 'border-primary/30')}
|
|
60
|
+
onClick={() => handle(item.key)}>
|
|
61
|
+
{item.label}
|
|
62
|
+
</Button>
|
|
63
|
+
))}
|
|
64
|
+
</div>
|
|
65
|
+
);
|
|
66
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
import {
|
|
6
|
+
isValidElement, useCallback, useMemo
|
|
7
|
+
} from 'react';
|
|
8
|
+
|
|
9
|
+
import { cn } from '@kivacore/ui-pro-shared/lib/utils';
|
|
10
|
+
import { Avatar, AvatarFallback, AvatarImage } from '@kivacore/ui-pro-shared/components/avatar';
|
|
11
|
+
import { Button } from '@kivacore/ui-pro-shared/components/button';
|
|
12
|
+
import { Checkbox } from '@kivacore/ui-pro-shared/components/checkbox';
|
|
13
|
+
import {
|
|
14
|
+
type Column,
|
|
15
|
+
type ColumnOption,
|
|
16
|
+
type DataTableFilterActions,
|
|
17
|
+
type FilterModel,
|
|
18
|
+
type OptionBasedColumnDataType
|
|
19
|
+
} from '@kivacore/ui-pro-shared/components/kiva/data-table-filter/core/types';
|
|
20
|
+
import { type Locale, t } from '@kivacore/ui-pro-shared/components/kiva/data-table-filter/lib/i18n';
|
|
21
|
+
|
|
22
|
+
import { useShowMore } from '../hooks/use-show-more';
|
|
23
|
+
import { DEFAULT_SHOW_MORE_THRESHOLD } from '../lib/render-mode';
|
|
24
|
+
|
|
25
|
+
interface SideFilterCheckboxListProps<TData, TType extends OptionBasedColumnDataType> {
|
|
26
|
+
column: Column<TData, TType>;
|
|
27
|
+
filter?: FilterModel<TType>;
|
|
28
|
+
actions: DataTableFilterActions;
|
|
29
|
+
locale?: Locale;
|
|
30
|
+
threshold?: number;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
interface DecoratedOption extends ColumnOption {
|
|
34
|
+
selected: boolean;
|
|
35
|
+
count: number;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function SideFilterCheckboxList<
|
|
39
|
+
TData,
|
|
40
|
+
TType extends OptionBasedColumnDataType
|
|
41
|
+
>({
|
|
42
|
+
column,
|
|
43
|
+
filter,
|
|
44
|
+
actions,
|
|
45
|
+
locale = 'en',
|
|
46
|
+
threshold = DEFAULT_SHOW_MORE_THRESHOLD
|
|
47
|
+
}: SideFilterCheckboxListProps<TData, TType>) {
|
|
48
|
+
const decorated = useMemo<Array<DecoratedOption>>(() => {
|
|
49
|
+
const counts = column.getFacetedUniqueValues();
|
|
50
|
+
const options = column.getOptions();
|
|
51
|
+
const selectedSet = new Set((filter?.values as Array<string>) ?? []);
|
|
52
|
+
|
|
53
|
+
return options.map(o => ({
|
|
54
|
+
...o,
|
|
55
|
+
selected: selectedSet.has(o.value),
|
|
56
|
+
count: counts?.get(o.value) ?? 0
|
|
57
|
+
}));
|
|
58
|
+
}, [column, filter?.values]);
|
|
59
|
+
|
|
60
|
+
const {
|
|
61
|
+
visible, hiddenCount, expanded, canExpand, toggle
|
|
62
|
+
} = useShowMore({
|
|
63
|
+
items: decorated,
|
|
64
|
+
threshold,
|
|
65
|
+
isPinned: o => o.selected
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const handleToggle = useCallback(
|
|
69
|
+
(value: string, checked: boolean) => {
|
|
70
|
+
if (checked) {
|
|
71
|
+
actions.addFilterValue(column, [value] as FilterModel<TType>['values']);
|
|
72
|
+
} else {
|
|
73
|
+
actions.removeFilterValue(column, [value] as FilterModel<TType>['values']);
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
[actions, column]
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
if (decorated.length === 0) {
|
|
80
|
+
return (
|
|
81
|
+
<p className="px-1 py-2 text-xs text-muted-foreground">
|
|
82
|
+
{t('noresults', locale)}
|
|
83
|
+
</p>
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return (
|
|
88
|
+
<div className="flex flex-col gap-0.5">
|
|
89
|
+
{visible.map((option) => {
|
|
90
|
+
const Icon = option.icon;
|
|
91
|
+
const fallback = option.label.slice(0, 2).toUpperCase();
|
|
92
|
+
|
|
93
|
+
return (
|
|
94
|
+
<label
|
|
95
|
+
key={option.value}
|
|
96
|
+
className={cn(
|
|
97
|
+
'group flex cursor-pointer items-center gap-2 rounded-md px-2 py-1.5 text-sm transition-colors',
|
|
98
|
+
'hover:bg-accent/60'
|
|
99
|
+
)}>
|
|
100
|
+
<Checkbox
|
|
101
|
+
checked={option.selected}
|
|
102
|
+
onCheckedChange={c => handleToggle(option.value, c === true)} />
|
|
103
|
+
{option.imageUrl ? (
|
|
104
|
+
<Avatar className="size-5">
|
|
105
|
+
<AvatarImage src={option.imageUrl} alt={option.label} />
|
|
106
|
+
<AvatarFallback className="text-xs">{fallback}</AvatarFallback>
|
|
107
|
+
</Avatar>
|
|
108
|
+
) : Icon ? (
|
|
109
|
+
isValidElement(Icon) ? Icon : <Icon className="size-4 text-muted-foreground" />
|
|
110
|
+
) : option.color ? (
|
|
111
|
+
<span
|
|
112
|
+
aria-hidden
|
|
113
|
+
className="size-2.5 shrink-0 rounded-full"
|
|
114
|
+
style={{ backgroundColor: option.color }} />
|
|
115
|
+
) : null}
|
|
116
|
+
<span className="flex-1 truncate">{option.label}</span>
|
|
117
|
+
{option.count > 0 && (
|
|
118
|
+
<span className="tabular-nums text-xs text-muted-foreground">
|
|
119
|
+
{option.count < 100 ? option.count : '100+'}
|
|
120
|
+
</span>
|
|
121
|
+
)}
|
|
122
|
+
</label>
|
|
123
|
+
);
|
|
124
|
+
})}
|
|
125
|
+
{canExpand && (
|
|
126
|
+
<Button
|
|
127
|
+
type="button"
|
|
128
|
+
variant="ghost"
|
|
129
|
+
size="sm"
|
|
130
|
+
onClick={toggle}
|
|
131
|
+
className="mt-1 h-7 justify-start px-2 text-xs text-muted-foreground hover:text-foreground">
|
|
132
|
+
{expanded ? t('showLess', locale) === 'showLess' ? 'Show less' : t('showLess', locale) : `${t('showMore', locale) === 'showMore' ? 'Show more' : t('showMore', locale)}${hiddenCount > 0 ? ` (${hiddenCount})` : ''}`}
|
|
133
|
+
</Button>
|
|
134
|
+
)}
|
|
135
|
+
</div>
|
|
136
|
+
);
|
|
137
|
+
}
|