@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,161 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
import { type DataSourceField } from '@kivacore/app-utils';
|
|
6
|
+
|
|
7
|
+
import { Button } from '@kivacore/ui-pro-shared/components/button';
|
|
8
|
+
import { Label } from '@kivacore/ui-pro-shared/components/label';
|
|
9
|
+
import { RadioGroup, RadioGroupItem } from '@kivacore/ui-pro-shared/components/radio-group';
|
|
10
|
+
import {
|
|
11
|
+
Select,
|
|
12
|
+
SelectContent,
|
|
13
|
+
SelectItem,
|
|
14
|
+
SelectTrigger,
|
|
15
|
+
SelectValue
|
|
16
|
+
} from '@kivacore/ui-pro-shared/components/select';
|
|
17
|
+
|
|
18
|
+
import { useUiTranslation } from '@kivacore/ui-pro-shared/hooks/kiva/use-ui-translation';
|
|
19
|
+
|
|
20
|
+
import {
|
|
21
|
+
type PivotFilterAggregateFunc,
|
|
22
|
+
type PivotFilterCalculation,
|
|
23
|
+
type PivotFilterDateBucket,
|
|
24
|
+
type PivotFilterFieldType
|
|
25
|
+
} from '@kivacore/ui-pro-shared/hooks/kiva/use-kiva-pivot-filter';
|
|
26
|
+
|
|
27
|
+
const DATE_BUCKET_KEYS: Array<{ id: PivotFilterDateBucket; tKey: string; fallback: string }> = [
|
|
28
|
+
{ id: 'hours_of_today', tKey: 'ui.pivotFilter.bucket.hoursOfToday', fallback: 'Hours of today' },
|
|
29
|
+
{ id: 'days_of_week', tKey: 'ui.pivotFilter.bucket.daysOfWeek', fallback: 'Days of week' },
|
|
30
|
+
{ id: 'days_of_month', tKey: 'ui.pivotFilter.bucket.daysOfMonth', fallback: 'Days of month' },
|
|
31
|
+
{ id: 'weeks_of_month', tKey: 'ui.pivotFilter.bucket.weeksOfMonth', fallback: 'Weeks of month' },
|
|
32
|
+
{ id: 'weeks_of_quarter', tKey: 'ui.pivotFilter.bucket.weeksOfQuarter', fallback: 'Weeks of quarter' },
|
|
33
|
+
{ id: 'months_of_quarter', tKey: 'ui.pivotFilter.bucket.monthsOfQuarter', fallback: 'Months of quarter' },
|
|
34
|
+
{ id: 'months_of_year', tKey: 'ui.pivotFilter.bucket.monthsOfYear', fallback: 'Months of year' },
|
|
35
|
+
{ id: 'quarters_of_year', tKey: 'ui.pivotFilter.bucket.quartersOfYear', fallback: 'Quarters of year' }
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
const AGGREGATE_FUNCS: Array<{ id: PivotFilterAggregateFunc; label: string }> = [
|
|
39
|
+
{ id: 'sum', label: 'SUM' },
|
|
40
|
+
{ id: 'avg', label: 'AVG' },
|
|
41
|
+
{ id: 'min', label: 'MIN' },
|
|
42
|
+
{ id: 'max', label: 'MAX' }
|
|
43
|
+
];
|
|
44
|
+
|
|
45
|
+
interface PivotFilterSettingsProps {
|
|
46
|
+
fieldType: PivotFilterFieldType;
|
|
47
|
+
dateBucket: PivotFilterDateBucket;
|
|
48
|
+
onDateBucketChange: (next: PivotFilterDateBucket) => void;
|
|
49
|
+
calculation: PivotFilterCalculation | null;
|
|
50
|
+
onCalculationChange: (next: PivotFilterCalculation | null) => void;
|
|
51
|
+
aggregateFields: Array<DataSourceField>;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function PivotFilterSettings({
|
|
55
|
+
fieldType,
|
|
56
|
+
dateBucket,
|
|
57
|
+
onDateBucketChange,
|
|
58
|
+
calculation,
|
|
59
|
+
onCalculationChange,
|
|
60
|
+
aggregateFields
|
|
61
|
+
}: PivotFilterSettingsProps) {
|
|
62
|
+
const { t } = useUiTranslation();
|
|
63
|
+
|
|
64
|
+
const isCountOfRecords = calculation === null || (calculation.func === 'count' && calculation.field === 'id');
|
|
65
|
+
|
|
66
|
+
const handleAggregateFuncChange = (func: PivotFilterAggregateFunc) => {
|
|
67
|
+
const existingField = calculation && calculation.func !== 'count' ? calculation.field : aggregateFields[0]?.slug;
|
|
68
|
+
|
|
69
|
+
if (!existingField) return;
|
|
70
|
+
onCalculationChange({ func, field: existingField });
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const handleAggregateFieldChange = (fieldSlug: string) => {
|
|
74
|
+
const existingFunc = calculation && calculation.func !== 'count' ? calculation.func : 'sum';
|
|
75
|
+
|
|
76
|
+
onCalculationChange({ func: existingFunc, field: fieldSlug });
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
<div className="space-y-4">
|
|
81
|
+
{fieldType === 'date' && (
|
|
82
|
+
<section className="space-y-2">
|
|
83
|
+
<Label className="text-xs font-medium text-muted-foreground">
|
|
84
|
+
{t('ui.pivotFilter.dateFilterType', 'Date filter type')}
|
|
85
|
+
</Label>
|
|
86
|
+
<RadioGroup
|
|
87
|
+
value={dateBucket}
|
|
88
|
+
onValueChange={value => onDateBucketChange(value as PivotFilterDateBucket)}
|
|
89
|
+
className="grid grid-cols-2 gap-1.5">
|
|
90
|
+
{DATE_BUCKET_KEYS.map(option => (
|
|
91
|
+
<div key={option.id} className="flex items-center gap-2">
|
|
92
|
+
<RadioGroupItem value={option.id} id={`pf-bucket-${option.id}`} />
|
|
93
|
+
<Label
|
|
94
|
+
htmlFor={`pf-bucket-${option.id}`}
|
|
95
|
+
className="cursor-pointer text-xs font-normal">
|
|
96
|
+
{t(option.tKey, option.fallback)}
|
|
97
|
+
</Label>
|
|
98
|
+
</div>
|
|
99
|
+
))}
|
|
100
|
+
</RadioGroup>
|
|
101
|
+
</section>
|
|
102
|
+
)}
|
|
103
|
+
|
|
104
|
+
<section className="space-y-2">
|
|
105
|
+
<Label className="text-xs font-medium text-muted-foreground">
|
|
106
|
+
{t('ui.pivotFilter.calculation', 'Calculation')}
|
|
107
|
+
</Label>
|
|
108
|
+
<Button
|
|
109
|
+
type="button"
|
|
110
|
+
variant={isCountOfRecords ? 'default' : 'outline'}
|
|
111
|
+
size="sm"
|
|
112
|
+
className="w-full justify-start"
|
|
113
|
+
onClick={() => onCalculationChange(null)}>
|
|
114
|
+
{t('ui.pivotFilter.countOfRecords', 'COUNT of records')}
|
|
115
|
+
</Button>
|
|
116
|
+
|
|
117
|
+
<div className="grid grid-cols-2 gap-2 pt-1">
|
|
118
|
+
<Select
|
|
119
|
+
value={calculation && !isCountOfRecords ? calculation.func : ''}
|
|
120
|
+
onValueChange={value => handleAggregateFuncChange(value as PivotFilterAggregateFunc)}
|
|
121
|
+
disabled={aggregateFields.length === 0}>
|
|
122
|
+
<SelectTrigger className="h-8 text-xs">
|
|
123
|
+
<SelectValue placeholder={t('ui.pivotFilter.function', 'Function')} />
|
|
124
|
+
</SelectTrigger>
|
|
125
|
+
<SelectContent>
|
|
126
|
+
{AGGREGATE_FUNCS.map(option => (
|
|
127
|
+
<SelectItem key={option.id} value={option.id}>
|
|
128
|
+
{option.label}
|
|
129
|
+
</SelectItem>
|
|
130
|
+
))}
|
|
131
|
+
</SelectContent>
|
|
132
|
+
</Select>
|
|
133
|
+
|
|
134
|
+
<Select
|
|
135
|
+
value={calculation && !isCountOfRecords ? calculation.field : ''}
|
|
136
|
+
onValueChange={handleAggregateFieldChange}
|
|
137
|
+
disabled={aggregateFields.length === 0}>
|
|
138
|
+
<SelectTrigger className="h-8 text-xs">
|
|
139
|
+
<SelectValue placeholder={t('ui.pivotFilter.field', 'Field')} />
|
|
140
|
+
</SelectTrigger>
|
|
141
|
+
<SelectContent>
|
|
142
|
+
{aggregateFields.map(field => (
|
|
143
|
+
<SelectItem key={field.slug} value={field.slug}>
|
|
144
|
+
{field.name}
|
|
145
|
+
</SelectItem>
|
|
146
|
+
))}
|
|
147
|
+
</SelectContent>
|
|
148
|
+
</Select>
|
|
149
|
+
</div>
|
|
150
|
+
{aggregateFields.length === 0 && (
|
|
151
|
+
<p className="text-xs text-muted-foreground">
|
|
152
|
+
{t(
|
|
153
|
+
'ui.pivotFilter.noNumericFields',
|
|
154
|
+
'This data source has no numeric / money / duration fields available for aggregation.'
|
|
155
|
+
)}
|
|
156
|
+
</p>
|
|
157
|
+
)}
|
|
158
|
+
</section>
|
|
159
|
+
</div>
|
|
160
|
+
);
|
|
161
|
+
}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
import {
|
|
6
|
+
useMemo, useState, type CSSProperties, type Ref
|
|
7
|
+
} from 'react';
|
|
8
|
+
|
|
9
|
+
import { RotateCw, Settings as SettingsIcon } from 'lucide-react';
|
|
10
|
+
|
|
11
|
+
import { Button } from '@kivacore/ui-pro-shared/components/button';
|
|
12
|
+
import { cn } from '@kivacore/ui-pro-shared/lib/utils';
|
|
13
|
+
import { Popover, PopoverContent, PopoverTrigger } from '@kivacore/ui-pro-shared/components/popover';
|
|
14
|
+
import { Skeleton } from '@kivacore/ui-pro-shared/components/skeleton';
|
|
15
|
+
|
|
16
|
+
import { useUiTranslation } from '@kivacore/ui-pro-shared/hooks/kiva/use-ui-translation';
|
|
17
|
+
|
|
18
|
+
import { PivotFilterPill } from './pivot-filter-item';
|
|
19
|
+
import { type PivotFilterItem, type PivotFilterProps } from './types';
|
|
20
|
+
|
|
21
|
+
function PivotFilter({
|
|
22
|
+
items,
|
|
23
|
+
selectedItemId,
|
|
24
|
+
onSelect,
|
|
25
|
+
total,
|
|
26
|
+
totalLabel,
|
|
27
|
+
loading = false,
|
|
28
|
+
vertical = false,
|
|
29
|
+
compact = false,
|
|
30
|
+
hideZeroValues = false,
|
|
31
|
+
hideAllPill = false,
|
|
32
|
+
onRefresh,
|
|
33
|
+
settingsContent,
|
|
34
|
+
settingsOpen,
|
|
35
|
+
onSettingsOpenChange,
|
|
36
|
+
emptyState,
|
|
37
|
+
className,
|
|
38
|
+
ref
|
|
39
|
+
}: PivotFilterProps & { ref?: Ref<HTMLDivElement> }) {
|
|
40
|
+
const { t } = useUiTranslation();
|
|
41
|
+
const [internalSettingsOpen, setInternalSettingsOpen] = useState(false);
|
|
42
|
+
|
|
43
|
+
const popoverOpen = settingsOpen ?? internalSettingsOpen;
|
|
44
|
+
const handlePopoverOpenChange = (next: boolean) => {
|
|
45
|
+
if (onSettingsOpenChange) {
|
|
46
|
+
onSettingsOpenChange(next);
|
|
47
|
+
} else {
|
|
48
|
+
setInternalSettingsOpen(next);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const visibleItems = useMemo(() => {
|
|
53
|
+
return items.filter((item) => {
|
|
54
|
+
if (item.id === selectedItemId) return true;
|
|
55
|
+
if (item.isEmpty && item.stat === 0) return false;
|
|
56
|
+
if (hideZeroValues && item.stat === 0) return false;
|
|
57
|
+
|
|
58
|
+
return true;
|
|
59
|
+
});
|
|
60
|
+
}, [items, hideZeroValues, selectedItemId]);
|
|
61
|
+
|
|
62
|
+
const showToolbar = Boolean(onRefresh) || Boolean(settingsContent);
|
|
63
|
+
const showAllPill = !hideAllPill;
|
|
64
|
+
const allSelected = selectedItemId === null;
|
|
65
|
+
const resolvedTotalLabel = totalLabel ?? t('ui.pivotFilter.all', 'All');
|
|
66
|
+
|
|
67
|
+
/*
|
|
68
|
+
* Horizontal: toolbar is a single-row pill at the start of the strip,
|
|
69
|
+
* matching the items' `h-7` so they all sit on the same baseline. Refresh
|
|
70
|
+
* and gear buttons sit side-by-side, not stacked.
|
|
71
|
+
*
|
|
72
|
+
* Vertical: a thin row of ghost buttons sits along the top edge of the
|
|
73
|
+
* rail, with a faint divider underneath. Keeps the column body clean for
|
|
74
|
+
* the item rows.
|
|
75
|
+
*/
|
|
76
|
+
const renderToolbar = () => {
|
|
77
|
+
if (!showToolbar) return null;
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
<div
|
|
81
|
+
className={cn(
|
|
82
|
+
vertical ? 'flex w-full items-center justify-end gap-0.5 border-b border-border/60 px-1 py-0.5' : 'flex h-7 shrink-0 items-center gap-0.5 rounded-md border border-border bg-card px-0.5 shadow-sm'
|
|
83
|
+
)}>
|
|
84
|
+
{onRefresh && (
|
|
85
|
+
<Button
|
|
86
|
+
type="button"
|
|
87
|
+
variant="ghost"
|
|
88
|
+
size="icon"
|
|
89
|
+
className="size-6 hover:bg-muted"
|
|
90
|
+
onClick={onRefresh}
|
|
91
|
+
aria-label={t('ui.pivotFilter.refresh', 'Refresh')}>
|
|
92
|
+
<RotateCw className="size-3.5" />
|
|
93
|
+
</Button>
|
|
94
|
+
)}
|
|
95
|
+
{settingsContent && (
|
|
96
|
+
<Popover open={popoverOpen} onOpenChange={handlePopoverOpenChange}>
|
|
97
|
+
<PopoverTrigger asChild>
|
|
98
|
+
<Button
|
|
99
|
+
type="button"
|
|
100
|
+
variant="ghost"
|
|
101
|
+
size="icon"
|
|
102
|
+
className="size-6 hover:bg-muted"
|
|
103
|
+
aria-label={t('ui.pivotFilter.settings', 'Settings')}>
|
|
104
|
+
<SettingsIcon className="size-3.5" />
|
|
105
|
+
</Button>
|
|
106
|
+
</PopoverTrigger>
|
|
107
|
+
<PopoverContent
|
|
108
|
+
align={vertical ? 'end' : 'start'}
|
|
109
|
+
sideOffset={6}
|
|
110
|
+
className="w-96 p-3">
|
|
111
|
+
{settingsContent}
|
|
112
|
+
</PopoverContent>
|
|
113
|
+
</Popover>
|
|
114
|
+
)}
|
|
115
|
+
</div>
|
|
116
|
+
);
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const renderEmpty = () => emptyState ?? (
|
|
120
|
+
<div
|
|
121
|
+
className={cn(
|
|
122
|
+
'text-xs text-muted-foreground',
|
|
123
|
+
vertical ? 'px-3 py-2' : 'inline-flex h-7 min-w-24 items-center rounded-md border border-dashed border-border bg-card px-2'
|
|
124
|
+
)}>
|
|
125
|
+
{t('ui.pivotFilter.empty', 'No data')}
|
|
126
|
+
</div>
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
const containerStyle: CSSProperties | undefined = vertical ? undefined : { gridAutoColumns: 'max-content' };
|
|
130
|
+
|
|
131
|
+
return (
|
|
132
|
+
<div
|
|
133
|
+
ref={ref}
|
|
134
|
+
data-pivot-filter
|
|
135
|
+
data-orientation={vertical ? 'vertical' : 'horizontal'}
|
|
136
|
+
style={containerStyle}
|
|
137
|
+
className={cn(
|
|
138
|
+
'relative text-foreground',
|
|
139
|
+
vertical ? 'flex h-fit w-full flex-col overflow-hidden rounded-md border border-border bg-card' : 'inline-grid h-fit w-fit max-w-full grid-flow-col items-center justify-stretch gap-1 overflow-x-auto overflow-y-hidden rounded-lg bg-muted/70 p-1',
|
|
140
|
+
className
|
|
141
|
+
)}>
|
|
142
|
+
{renderToolbar()}
|
|
143
|
+
|
|
144
|
+
{showAllPill && (
|
|
145
|
+
<PivotFilterPill
|
|
146
|
+
isAll
|
|
147
|
+
item={null}
|
|
148
|
+
label={resolvedTotalLabel}
|
|
149
|
+
stat={total}
|
|
150
|
+
selected={allSelected}
|
|
151
|
+
vertical={vertical}
|
|
152
|
+
compact={compact}
|
|
153
|
+
onClick={() => onSelect(null)} />
|
|
154
|
+
)}
|
|
155
|
+
|
|
156
|
+
{loading && renderSkeletons(vertical)}
|
|
157
|
+
|
|
158
|
+
{!loading && visibleItems.length === 0 && !showAllPill && renderEmpty()}
|
|
159
|
+
|
|
160
|
+
{!loading && visibleItems.map(item => (
|
|
161
|
+
<PivotFilterPill
|
|
162
|
+
key={item.id}
|
|
163
|
+
item={item}
|
|
164
|
+
label={item.name}
|
|
165
|
+
stat={item.stat}
|
|
166
|
+
selected={selectedItemId === item.id}
|
|
167
|
+
vertical={vertical}
|
|
168
|
+
compact={compact}
|
|
169
|
+
onClick={() => onSelect(item)} />
|
|
170
|
+
))}
|
|
171
|
+
</div>
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function renderSkeletons(vertical: boolean) {
|
|
176
|
+
return (
|
|
177
|
+
<>
|
|
178
|
+
<Skeleton
|
|
179
|
+
className={cn(vertical ? 'mx-3 my-2 h-4 w-2/3' : 'h-7 w-28 rounded-md')} />
|
|
180
|
+
<Skeleton
|
|
181
|
+
className={cn(vertical ? 'mx-3 my-2 h-4 w-1/2' : 'h-7 w-24 rounded-md')} />
|
|
182
|
+
</>
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export { PivotFilter };
|
|
187
|
+
export type { PivotFilterItem, PivotFilterProps };
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
import { type ReactNode } from 'react';
|
|
4
|
+
|
|
5
|
+
export interface PivotFilterUser {
|
|
6
|
+
id: string;
|
|
7
|
+
name: string;
|
|
8
|
+
picturePath?: string | null;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface PivotFilterItem {
|
|
12
|
+
/** Stable identifier for the item. Used to match `selectedItemId`. */
|
|
13
|
+
id: string;
|
|
14
|
+
/** Display label rendered in the pill. */
|
|
15
|
+
name: string;
|
|
16
|
+
/** Numeric value shown on the right side of the pill (count, sum, etc.). */
|
|
17
|
+
stat: number;
|
|
18
|
+
/**
|
|
19
|
+
* Secondary text rendered next to the name in compact mode or under it in
|
|
20
|
+
* regular mode (e.g. "to 14" for hours, "01.01 - 07.01" for week ranges).
|
|
21
|
+
*/
|
|
22
|
+
secondary?: string;
|
|
23
|
+
/** Tailwind color token (e.g. `'sky'`, `'emerald-500'`) or hex value. Drives selected/hover accents. */
|
|
24
|
+
color?: string;
|
|
25
|
+
/** Kiva icon identifier (e.g. `'huge building-06'`, `'fal star'`). Rendered via `KivaIcon`. */
|
|
26
|
+
icon?: string;
|
|
27
|
+
/** User object — when present, an avatar is rendered instead of an icon. */
|
|
28
|
+
user?: PivotFilterUser;
|
|
29
|
+
/**
|
|
30
|
+
* Indicates the item is a synthetic "Not Set" / empty bucket. The pill
|
|
31
|
+
* receives a muted style and is automatically hidden when its `stat` is 0
|
|
32
|
+
* (regardless of `hideZeroValues`).
|
|
33
|
+
*/
|
|
34
|
+
isEmpty?: boolean;
|
|
35
|
+
/** Arbitrary payload returned to `onSelect`. The component does not read this. */
|
|
36
|
+
meta?: Record<string, unknown>;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface PivotFilterProps {
|
|
40
|
+
/** Items rendered in the strip. */
|
|
41
|
+
items: Array<PivotFilterItem>;
|
|
42
|
+
/** Currently selected item id, or `null` when the "All" pill is active. */
|
|
43
|
+
selectedItemId: string | null;
|
|
44
|
+
/** Fired when an item is selected. The "All" pill fires with `null`. */
|
|
45
|
+
onSelect: (item: PivotFilterItem | null) => void;
|
|
46
|
+
/** Aggregate stat displayed on the "All" pill. */
|
|
47
|
+
total?: number;
|
|
48
|
+
/** Label for the "All" pill. Defaults to a translated "All". */
|
|
49
|
+
totalLabel?: string;
|
|
50
|
+
/** Renders skeleton pills instead of items. */
|
|
51
|
+
loading?: boolean;
|
|
52
|
+
/** Vertical column layout. Defaults to horizontal scrollable strip. */
|
|
53
|
+
vertical?: boolean;
|
|
54
|
+
/** Compact layout — name + stat collapsed into a single row. */
|
|
55
|
+
compact?: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Hide items whose `stat === 0` (except the currently selected one).
|
|
58
|
+
* Items flagged `isEmpty` are always hidden when `stat === 0`.
|
|
59
|
+
*/
|
|
60
|
+
hideZeroValues?: boolean;
|
|
61
|
+
/** Hide the "All" pill — useful when the filter is required. */
|
|
62
|
+
hideAllPill?: boolean;
|
|
63
|
+
/** Refresh button click handler. Pass `undefined` to hide the refresh button. */
|
|
64
|
+
onRefresh?: () => void;
|
|
65
|
+
/**
|
|
66
|
+
* Content rendered inside the settings popover. When `undefined`, the
|
|
67
|
+
* settings gear button is hidden. Use it to slot in the date-filter-type
|
|
68
|
+
* and calculation controls supplied by your data layer.
|
|
69
|
+
*/
|
|
70
|
+
settingsContent?: ReactNode;
|
|
71
|
+
/**
|
|
72
|
+
* Whether the settings popover should be open. When omitted, the popover
|
|
73
|
+
* manages its own open state.
|
|
74
|
+
*/
|
|
75
|
+
settingsOpen?: boolean;
|
|
76
|
+
/** Called when the settings popover open state changes. */
|
|
77
|
+
onSettingsOpenChange?: (open: boolean) => void;
|
|
78
|
+
/** Override the default empty / loading / error placeholder. */
|
|
79
|
+
emptyState?: ReactNode;
|
|
80
|
+
/** Wrapper class name. */
|
|
81
|
+
className?: string;
|
|
82
|
+
}
|