@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,154 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
import { useMemo } from 'react';
|
|
6
|
+
|
|
7
|
+
import { format, isSameMonth } from 'date-fns';
|
|
8
|
+
|
|
9
|
+
import { cn } from '@kivacore/ui-pro-shared/lib/utils';
|
|
10
|
+
|
|
11
|
+
import { StatsCell } from '../components/stats-cell';
|
|
12
|
+
|
|
13
|
+
import {
|
|
14
|
+
bucketKeyForDate,
|
|
15
|
+
getMonthCells,
|
|
16
|
+
getRangeForBucket,
|
|
17
|
+
isToday
|
|
18
|
+
} from '../helpers';
|
|
19
|
+
|
|
20
|
+
import {
|
|
21
|
+
type IPivotCalendarController,
|
|
22
|
+
type IPivotCalendarMeasure
|
|
23
|
+
} from '../types';
|
|
24
|
+
|
|
25
|
+
const WEEKDAYS = [
|
|
26
|
+
'Sun',
|
|
27
|
+
'Mon',
|
|
28
|
+
'Tue',
|
|
29
|
+
'Wed',
|
|
30
|
+
'Thu',
|
|
31
|
+
'Fri',
|
|
32
|
+
'Sat'
|
|
33
|
+
];
|
|
34
|
+
|
|
35
|
+
interface MonthCalendarViewProps<TData> {
|
|
36
|
+
controller: IPivotCalendarController<TData>;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function MonthCalendarView<TData>({ controller }: MonthCalendarViewProps<TData>) {
|
|
40
|
+
const {
|
|
41
|
+
selectedDate,
|
|
42
|
+
measures,
|
|
43
|
+
formatValue,
|
|
44
|
+
groupBy,
|
|
45
|
+
selectedGroupIds,
|
|
46
|
+
groups,
|
|
47
|
+
getCellValues,
|
|
48
|
+
emitCellClick,
|
|
49
|
+
hasCellClickHandler
|
|
50
|
+
} = controller;
|
|
51
|
+
const cells = useMemo(() => getMonthCells(selectedDate), [selectedDate]);
|
|
52
|
+
|
|
53
|
+
const limitedMeasures = useMemo(
|
|
54
|
+
() => measures.slice(0, 2) as Array<IPivotCalendarMeasure<unknown>>,
|
|
55
|
+
[measures]
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
<div className="flex min-w-0 flex-1 flex-col bg-background">
|
|
60
|
+
{/* Legend bar — measure names + dot colors, shown once at the top */}
|
|
61
|
+
{limitedMeasures.length > 0 ? (
|
|
62
|
+
<div className="flex flex-wrap items-center gap-3 border-b bg-muted/20 px-3 py-1.5">
|
|
63
|
+
{limitedMeasures.map(m => (
|
|
64
|
+
<div key={m.id} className="flex items-center gap-1.5 text-xs text-muted-foreground">
|
|
65
|
+
<span
|
|
66
|
+
className="size-2 shrink-0 rounded-full"
|
|
67
|
+
style={{ backgroundColor: m.color ?? 'var(--primary)' }} />
|
|
68
|
+
<span className="font-medium uppercase tracking-wide">
|
|
69
|
+
{m.shortLabel ?? m.label}
|
|
70
|
+
</span>
|
|
71
|
+
</div>
|
|
72
|
+
))}
|
|
73
|
+
</div>
|
|
74
|
+
) : null}
|
|
75
|
+
|
|
76
|
+
<div className="grid grid-cols-7 border-b bg-muted/30">
|
|
77
|
+
{WEEKDAYS.map(day => (
|
|
78
|
+
<div
|
|
79
|
+
key={day}
|
|
80
|
+
className="p-2 text-center text-xs font-semibold uppercase tracking-wide text-muted-foreground">
|
|
81
|
+
{day}
|
|
82
|
+
</div>
|
|
83
|
+
))}
|
|
84
|
+
</div>
|
|
85
|
+
|
|
86
|
+
<div className="grid flex-1 auto-rows-fr grid-cols-7">
|
|
87
|
+
{cells.map((cell) => {
|
|
88
|
+
const isCurrent = isSameMonth(cell.date, selectedDate);
|
|
89
|
+
const today = isToday(cell.date);
|
|
90
|
+
const bucket = bucketKeyForDate(cell.date, 'month-calendar');
|
|
91
|
+
|
|
92
|
+
let values = getCellValues(bucket, null);
|
|
93
|
+
|
|
94
|
+
if (groupBy && selectedGroupIds.length > 0) {
|
|
95
|
+
const totals = new Map<string, number>();
|
|
96
|
+
|
|
97
|
+
for (const id of selectedGroupIds) {
|
|
98
|
+
for (const v of getCellValues(bucket, id)) {
|
|
99
|
+
totals.set(v.measureId, (totals.get(v.measureId) ?? 0) + v.value);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
values = Array.from(totals.entries()).map(([measureId, value]) => ({ measureId, value }));
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return (
|
|
106
|
+
<div
|
|
107
|
+
key={cell.date.toISOString()}
|
|
108
|
+
className={cn(
|
|
109
|
+
'flex min-h-24 flex-col gap-1.5 border-b border-r p-1.5 text-xs',
|
|
110
|
+
!isCurrent && 'bg-muted/20 text-muted-foreground/60'
|
|
111
|
+
)}>
|
|
112
|
+
<div className="flex items-center justify-between">
|
|
113
|
+
<span
|
|
114
|
+
className={cn(
|
|
115
|
+
'inline-flex size-6 items-center justify-center rounded-full text-xs font-medium',
|
|
116
|
+
today && 'bg-primary text-primary-foreground',
|
|
117
|
+
!today && !isCurrent && 'text-muted-foreground/60'
|
|
118
|
+
)}>
|
|
119
|
+
{format(cell.date, 'd')}
|
|
120
|
+
</span>
|
|
121
|
+
</div>
|
|
122
|
+
{isCurrent ? (
|
|
123
|
+
<StatsCell
|
|
124
|
+
measures={limitedMeasures}
|
|
125
|
+
values={values}
|
|
126
|
+
formatValue={formatValue}
|
|
127
|
+
grid="vertical"
|
|
128
|
+
emptyState={null}
|
|
129
|
+
interactive={hasCellClickHandler}
|
|
130
|
+
onMeasureClick={(measure, raw, formatted) => {
|
|
131
|
+
const range = getRangeForBucket(bucket, 'month-calendar');
|
|
132
|
+
const groupId = groupBy && selectedGroupIds.length === 1 ? (selectedGroupIds[0] ?? null) : null;
|
|
133
|
+
const group = groupId ? groups.find(g => g.id === groupId) : undefined;
|
|
134
|
+
|
|
135
|
+
emitCellClick({
|
|
136
|
+
bucket,
|
|
137
|
+
bucketStart: range.start,
|
|
138
|
+
bucketEnd: range.end,
|
|
139
|
+
view: 'month-calendar',
|
|
140
|
+
groupId,
|
|
141
|
+
group,
|
|
142
|
+
measure: measure as IPivotCalendarMeasure<TData>,
|
|
143
|
+
value: raw,
|
|
144
|
+
formattedValue: formatted
|
|
145
|
+
});
|
|
146
|
+
}} />
|
|
147
|
+
) : null}
|
|
148
|
+
</div>
|
|
149
|
+
);
|
|
150
|
+
})}
|
|
151
|
+
</div>
|
|
152
|
+
</div>
|
|
153
|
+
);
|
|
154
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
import { useMemo, useState } from 'react';
|
|
6
|
+
|
|
7
|
+
import { format, getMonth } from 'date-fns';
|
|
8
|
+
|
|
9
|
+
import { getMonthsOfYear } from '../helpers';
|
|
10
|
+
|
|
11
|
+
import { type IPivotCalendarController } from '../types';
|
|
12
|
+
|
|
13
|
+
import { PivotGridView, type PivotColumn } from './pivot-grid-view';
|
|
14
|
+
|
|
15
|
+
export function MonthsOfYearView<TData>({ controller }: { controller: IPivotCalendarController<TData> }) {
|
|
16
|
+
const { selectedDate } = controller;
|
|
17
|
+
const [today] = useState(() => new Date());
|
|
18
|
+
const currentMonth = getMonth(today);
|
|
19
|
+
const currentYear = today.getFullYear();
|
|
20
|
+
|
|
21
|
+
const columns = useMemo<Array<PivotColumn>>(() => {
|
|
22
|
+
const months = getMonthsOfYear(selectedDate);
|
|
23
|
+
|
|
24
|
+
return months.map(month => ({
|
|
25
|
+
id: month.toISOString(),
|
|
26
|
+
bucket: format(month, 'yyyy-MM'),
|
|
27
|
+
primaryLabel: format(month, 'MMM'),
|
|
28
|
+
secondaryLabel: format(month, 'yyyy'),
|
|
29
|
+
isHighlighted:
|
|
30
|
+
getMonth(month) === currentMonth && month.getFullYear() === currentYear
|
|
31
|
+
}));
|
|
32
|
+
}, [selectedDate, currentMonth, currentYear]);
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<PivotGridView
|
|
36
|
+
controller={controller}
|
|
37
|
+
columns={columns}
|
|
38
|
+
leafMinWidth={80} />
|
|
39
|
+
);
|
|
40
|
+
}
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
import { Fragment, type ReactNode } from 'react';
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
Tooltip,
|
|
9
|
+
TooltipContent,
|
|
10
|
+
TooltipTrigger
|
|
11
|
+
} from '@kivacore/ui-pro-shared/components/tooltip';
|
|
12
|
+
import { cn } from '@kivacore/ui-pro-shared/lib/utils';
|
|
13
|
+
|
|
14
|
+
import { AvatarThumbnail } from '@kivacore/ui-pro-shared/components/kiva/avatar-thumbnail';
|
|
15
|
+
|
|
16
|
+
import { getRangeForBucket } from '../helpers';
|
|
17
|
+
|
|
18
|
+
import {
|
|
19
|
+
type IPivotCalendarController,
|
|
20
|
+
type IPivotCalendarGroup,
|
|
21
|
+
type IPivotCalendarMeasure
|
|
22
|
+
} from '../types';
|
|
23
|
+
|
|
24
|
+
const ZERO_TEXT = 'text-muted-foreground/40';
|
|
25
|
+
|
|
26
|
+
export interface PivotColumn {
|
|
27
|
+
id: string;
|
|
28
|
+
bucket: string;
|
|
29
|
+
primaryLabel: ReactNode;
|
|
30
|
+
secondaryLabel?: ReactNode;
|
|
31
|
+
isHighlighted?: boolean;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
interface PivotGridViewProps<TData> {
|
|
35
|
+
controller: IPivotCalendarController<TData>;
|
|
36
|
+
columns: Array<PivotColumn>;
|
|
37
|
+
/** Min width per leaf measure cell. */
|
|
38
|
+
leafMinWidth: number;
|
|
39
|
+
/** Width of the row label cell. */
|
|
40
|
+
rowHeaderWidth?: number;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function PivotGridView<TData>({
|
|
44
|
+
controller,
|
|
45
|
+
columns,
|
|
46
|
+
leafMinWidth,
|
|
47
|
+
rowHeaderWidth = 200
|
|
48
|
+
}: PivotGridViewProps<TData>) {
|
|
49
|
+
const {
|
|
50
|
+
measures,
|
|
51
|
+
formatValue,
|
|
52
|
+
groupBy,
|
|
53
|
+
selectedGroupIds,
|
|
54
|
+
groups,
|
|
55
|
+
getCellValues,
|
|
56
|
+
emitCellClick,
|
|
57
|
+
hasCellClickHandler,
|
|
58
|
+
view
|
|
59
|
+
} = controller;
|
|
60
|
+
|
|
61
|
+
const limitedMeasures: Array<IPivotCalendarMeasure<unknown>>
|
|
62
|
+
= measures.slice(0, 2) as Array<IPivotCalendarMeasure<unknown>>;
|
|
63
|
+
const measureCount = limitedMeasures.length || 1;
|
|
64
|
+
const visibleGroups: Array<IPivotCalendarGroup> = groupBy ? groups.filter((g) => {
|
|
65
|
+
if (selectedGroupIds.length === 0) return true;
|
|
66
|
+
|
|
67
|
+
return selectedGroupIds.includes(g.id);
|
|
68
|
+
}) : [];
|
|
69
|
+
|
|
70
|
+
const totalsRow: IPivotCalendarGroup = {
|
|
71
|
+
id: '__total__',
|
|
72
|
+
label: 'Totals',
|
|
73
|
+
color: null,
|
|
74
|
+
icon: null
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const hasGroups = visibleGroups.length > 0;
|
|
78
|
+
const rows = hasGroups ? [...visibleGroups, totalsRow] : [totalsRow];
|
|
79
|
+
|
|
80
|
+
const leafCols = columns.length * measureCount;
|
|
81
|
+
const totalContentWidth = rowHeaderWidth + leafCols * leafMinWidth;
|
|
82
|
+
const gridTemplate = `${rowHeaderWidth}px repeat(${leafCols}, minmax(${leafMinWidth}px, 1fr))`;
|
|
83
|
+
|
|
84
|
+
function getValuesForRow(row: IPivotCalendarGroup, bucket: string) {
|
|
85
|
+
if (row.id === '__total__') {
|
|
86
|
+
if (!groupBy) {
|
|
87
|
+
return getCellValues(bucket, null);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const totals = new Map<string, number>();
|
|
91
|
+
const useIds = selectedGroupIds.length > 0 ? selectedGroupIds : groups.map(g => g.id);
|
|
92
|
+
|
|
93
|
+
for (const id of useIds) {
|
|
94
|
+
for (const v of getCellValues(bucket, id)) {
|
|
95
|
+
totals.set(v.measureId, (totals.get(v.measureId) ?? 0) + v.value);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return Array.from(totals.entries()).map(([measureId, value]) => ({ measureId, value }));
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return getCellValues(bucket, row.id);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return (
|
|
106
|
+
<div className="flex min-w-0 flex-1 flex-col overflow-hidden">
|
|
107
|
+
<div className="min-w-0 flex-1 overflow-auto">
|
|
108
|
+
<div style={{ minWidth: totalContentWidth }}>
|
|
109
|
+
{/* Header row 1 — column groups (date / month) */}
|
|
110
|
+
<div
|
|
111
|
+
className="sticky top-0 z-20 grid border-b bg-muted/40 backdrop-blur"
|
|
112
|
+
style={{ gridTemplateColumns: gridTemplate }}>
|
|
113
|
+
<div
|
|
114
|
+
className="row-span-2 sticky left-0 z-[2] flex items-center border-r bg-muted/40 px-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground"
|
|
115
|
+
style={{ gridRow: 'span 2 / span 2' }}>
|
|
116
|
+
{groupBy?.label ?? 'Total'}
|
|
117
|
+
</div>
|
|
118
|
+
{columns.map(col => (
|
|
119
|
+
<div
|
|
120
|
+
key={col.id}
|
|
121
|
+
className={cn(
|
|
122
|
+
'flex flex-col items-center justify-center border-r px-2 py-2 text-center',
|
|
123
|
+
col.isHighlighted && 'bg-primary/10'
|
|
124
|
+
)}
|
|
125
|
+
style={{ gridColumn: `span ${measureCount} / span ${measureCount}` }}>
|
|
126
|
+
<div className="text-xs font-medium uppercase tracking-wide text-muted-foreground">
|
|
127
|
+
{col.primaryLabel}
|
|
128
|
+
</div>
|
|
129
|
+
{col.secondaryLabel ? (
|
|
130
|
+
<div className="text-xs font-semibold text-foreground">
|
|
131
|
+
{col.secondaryLabel}
|
|
132
|
+
</div>
|
|
133
|
+
) : null}
|
|
134
|
+
</div>
|
|
135
|
+
))}
|
|
136
|
+
|
|
137
|
+
{/* Header row 2 — measure labels under each group */}
|
|
138
|
+
{columns.map(col => (
|
|
139
|
+
<Fragment key={`${col.id}__measures`}>
|
|
140
|
+
{limitedMeasures.map((m, idx) => (
|
|
141
|
+
<div
|
|
142
|
+
key={`${col.id}__${m.id}`}
|
|
143
|
+
className={cn(
|
|
144
|
+
'flex items-center justify-end gap-1 border-t border-r bg-muted/30 px-2 py-1 text-xs font-medium uppercase tracking-wide text-muted-foreground',
|
|
145
|
+
col.isHighlighted && 'bg-primary/10',
|
|
146
|
+
idx === 0 && 'border-l-0'
|
|
147
|
+
)}>
|
|
148
|
+
<span
|
|
149
|
+
className="size-1.5 shrink-0 rounded-full"
|
|
150
|
+
style={{ backgroundColor: m.color ?? 'var(--primary)' }}
|
|
151
|
+
aria-hidden />
|
|
152
|
+
<span className="truncate">{m.shortLabel ?? m.label}</span>
|
|
153
|
+
</div>
|
|
154
|
+
))}
|
|
155
|
+
</Fragment>
|
|
156
|
+
))}
|
|
157
|
+
</div>
|
|
158
|
+
|
|
159
|
+
{/* Data rows */}
|
|
160
|
+
{rows.map((row) => {
|
|
161
|
+
const isTotal = row.id === '__total__';
|
|
162
|
+
|
|
163
|
+
return (
|
|
164
|
+
<div
|
|
165
|
+
key={row.id}
|
|
166
|
+
className={cn(
|
|
167
|
+
'grid border-b transition-colors',
|
|
168
|
+
isTotal && 'bg-muted/30 font-medium'
|
|
169
|
+
)}
|
|
170
|
+
style={{ gridTemplateColumns: gridTemplate }}>
|
|
171
|
+
<div
|
|
172
|
+
className={cn(
|
|
173
|
+
'sticky left-0 z-[1] flex items-center gap-2 border-r bg-card px-3 py-2 text-sm',
|
|
174
|
+
isTotal && 'bg-muted/30'
|
|
175
|
+
)}>
|
|
176
|
+
{!isTotal ? (
|
|
177
|
+
<AvatarThumbnail
|
|
178
|
+
size={6}
|
|
179
|
+
icon={row.icon ?? null}
|
|
180
|
+
color={row.color ?? null}
|
|
181
|
+
image={row.image ?? null}
|
|
182
|
+
shape="circle" />
|
|
183
|
+
) : null}
|
|
184
|
+
<span className="min-w-0 flex-1 truncate">
|
|
185
|
+
{row.label}
|
|
186
|
+
</span>
|
|
187
|
+
</div>
|
|
188
|
+
{columns.map((col) => {
|
|
189
|
+
const values = getValuesForRow(row, col.bucket);
|
|
190
|
+
const valueByMeasure = new Map(values.map(v => [v.measureId, v.value]));
|
|
191
|
+
|
|
192
|
+
return limitedMeasures.map((m) => {
|
|
193
|
+
const raw = valueByMeasure.get(m.id) ?? 0;
|
|
194
|
+
const display = formatValue(m.id, raw);
|
|
195
|
+
const isZero = raw === 0;
|
|
196
|
+
const clickable = hasCellClickHandler && !isZero;
|
|
197
|
+
|
|
198
|
+
return (
|
|
199
|
+
<Tooltip key={`${col.id}__${m.id}__${row.id}`}>
|
|
200
|
+
<TooltipTrigger asChild>
|
|
201
|
+
<button
|
|
202
|
+
type="button"
|
|
203
|
+
disabled={!clickable}
|
|
204
|
+
onClick={() => {
|
|
205
|
+
if (!clickable) return;
|
|
206
|
+
const range = getRangeForBucket(col.bucket, view);
|
|
207
|
+
const groupId = row.id === '__total__' ? null : row.id;
|
|
208
|
+
const group = groupId ? groups.find(g => g.id === groupId) : undefined;
|
|
209
|
+
|
|
210
|
+
emitCellClick({
|
|
211
|
+
bucket: col.bucket,
|
|
212
|
+
bucketStart: range.start,
|
|
213
|
+
bucketEnd: range.end,
|
|
214
|
+
view,
|
|
215
|
+
groupId,
|
|
216
|
+
group,
|
|
217
|
+
measure: m as IPivotCalendarMeasure<TData>,
|
|
218
|
+
value: raw,
|
|
219
|
+
formattedValue: display
|
|
220
|
+
});
|
|
221
|
+
}}
|
|
222
|
+
className={cn(
|
|
223
|
+
'flex items-center justify-end border-r px-2 py-2 text-xs tabular-nums',
|
|
224
|
+
col.isHighlighted && 'bg-primary/5',
|
|
225
|
+
clickable ? 'cursor-pointer hover:bg-primary/15 focus-visible:outline focus-visible:outline-2 focus-visible:outline-primary/40' : 'cursor-default disabled:opacity-100',
|
|
226
|
+
isZero && ZERO_TEXT
|
|
227
|
+
)}>
|
|
228
|
+
{display}
|
|
229
|
+
</button>
|
|
230
|
+
</TooltipTrigger>
|
|
231
|
+
<TooltipContent side="top" className="text-xs">
|
|
232
|
+
<div className="font-medium">
|
|
233
|
+
{row.label} · {m.label}
|
|
234
|
+
</div>
|
|
235
|
+
<div className="tabular-nums">{display}</div>
|
|
236
|
+
{clickable ? (
|
|
237
|
+
<div className="mt-0.5 text-xs opacity-70">Click to drill down</div>
|
|
238
|
+
) : null}
|
|
239
|
+
</TooltipContent>
|
|
240
|
+
</Tooltip>
|
|
241
|
+
);
|
|
242
|
+
});
|
|
243
|
+
})}
|
|
244
|
+
</div>
|
|
245
|
+
);
|
|
246
|
+
})}
|
|
247
|
+
</div>
|
|
248
|
+
</div>
|
|
249
|
+
</div>
|
|
250
|
+
);
|
|
251
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
import {
|
|
6
|
+
type CSSProperties, type Ref, 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
|
+
|
|
12
|
+
import { resolveColorHex } from '@kivacore/ui-pro-shared/lib/kiva/tailwind-colors';
|
|
13
|
+
|
|
14
|
+
import { KivaIcon } from '@kivacore/ui-pro-shared/components/kiva/kiva-icon';
|
|
15
|
+
|
|
16
|
+
import { type PivotFilterItem } from './types';
|
|
17
|
+
|
|
18
|
+
interface PivotFilterPillProps {
|
|
19
|
+
item: PivotFilterItem | null;
|
|
20
|
+
isAll?: boolean;
|
|
21
|
+
label: string;
|
|
22
|
+
stat: number | undefined;
|
|
23
|
+
selected: boolean;
|
|
24
|
+
vertical: boolean;
|
|
25
|
+
compact: boolean;
|
|
26
|
+
onClick: () => void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function pickAccentToken(color: string | undefined, shade = 500): string {
|
|
30
|
+
if (!color) return `sky-${shade}`;
|
|
31
|
+
if (color.includes('-')) {
|
|
32
|
+
const family = color.split('-')[0] ?? 'sky';
|
|
33
|
+
|
|
34
|
+
return `${family}-${shade}`;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return `${color}-${shade}`;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/*
|
|
41
|
+
* Compose the selected-pill inline style. We can't drive these through
|
|
42
|
+
* Tailwind utility classes because the accent comes from `item.color` (a
|
|
43
|
+
* dynamic enum-option color), so JIT can't pre-generate the variants. The
|
|
44
|
+
* solid color also serves as the `borderColor` to match the Vue reference.
|
|
45
|
+
* `currentColor` on the count badge / icon then inherits the accent.
|
|
46
|
+
*/
|
|
47
|
+
function buildSelectedStyle(accentHex: string): CSSProperties {
|
|
48
|
+
return {
|
|
49
|
+
color: accentHex,
|
|
50
|
+
borderColor: accentHex,
|
|
51
|
+
backgroundColor: `${accentHex}14`, // ~8% alpha tint of the accent
|
|
52
|
+
boxShadow: `0 0 0 1px ${accentHex}33`
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function PivotFilterPill({
|
|
57
|
+
item,
|
|
58
|
+
isAll = false,
|
|
59
|
+
label,
|
|
60
|
+
stat,
|
|
61
|
+
selected,
|
|
62
|
+
vertical,
|
|
63
|
+
compact,
|
|
64
|
+
onClick,
|
|
65
|
+
ref
|
|
66
|
+
}: PivotFilterPillProps & { ref?: Ref<HTMLButtonElement> }) {
|
|
67
|
+
const accentHex = useMemo(
|
|
68
|
+
() => resolveColorHex(pickAccentToken(item?.color, 500)),
|
|
69
|
+
[item?.color]
|
|
70
|
+
);
|
|
71
|
+
const hoverAccentHex = useMemo(
|
|
72
|
+
() => resolveColorHex(pickAccentToken(item?.color, 400)),
|
|
73
|
+
[item?.color]
|
|
74
|
+
);
|
|
75
|
+
const isEmpty = item?.isEmpty === true;
|
|
76
|
+
|
|
77
|
+
const inlineStyle: CSSProperties = selected ? buildSelectedStyle(accentHex) : { '--pivot-pill-hover-accent': hoverAccentHex } as CSSProperties;
|
|
78
|
+
|
|
79
|
+
/*
|
|
80
|
+
* Vertical strip: each item is a full-width row with a left accent bar on
|
|
81
|
+
* selection (no pill background, no shadow). Horizontal strip: rounded
|
|
82
|
+
* pills with shadow, sitting inside a muted track.
|
|
83
|
+
*/
|
|
84
|
+
return (
|
|
85
|
+
<button
|
|
86
|
+
ref={ref}
|
|
87
|
+
type="button"
|
|
88
|
+
onClick={onClick}
|
|
89
|
+
data-state={selected ? 'active' : 'inactive'}
|
|
90
|
+
data-pivot-filter-pill={isAll ? 'all' : 'item'}
|
|
91
|
+
style={inlineStyle}
|
|
92
|
+
className={cn(
|
|
93
|
+
'group relative cursor-pointer whitespace-nowrap text-xs font-medium transition-[color,background-color,border-color,box-shadow] duration-100',
|
|
94
|
+
vertical ? cn(
|
|
95
|
+
'flex w-full items-center gap-2 border-l-2 border-l-transparent px-3 py-1.5 text-left',
|
|
96
|
+
selected ? 'bg-accent text-foreground' : 'text-muted-foreground hover:bg-accent/60 hover:text-foreground'
|
|
97
|
+
) : cn(
|
|
98
|
+
'flex h-7 items-center rounded-md border bg-card px-2 shadow-sm',
|
|
99
|
+
compact ? 'min-w-fit max-w-48 gap-1.5' : 'min-w-24 max-w-48 gap-1.5',
|
|
100
|
+
!selected && 'border-border text-foreground hover:[border-color:var(--pivot-pill-hover-accent)]'
|
|
101
|
+
),
|
|
102
|
+
isAll && !vertical && 'min-w-20 justify-between',
|
|
103
|
+
isEmpty && !selected && 'opacity-70'
|
|
104
|
+
)}>
|
|
105
|
+
{/* Vertical: left accent bar mirrors selected color */}
|
|
106
|
+
{vertical && selected && (
|
|
107
|
+
<span
|
|
108
|
+
aria-hidden
|
|
109
|
+
className="absolute inset-y-0 left-0 w-0.5"
|
|
110
|
+
style={{ backgroundColor: accentHex }} />
|
|
111
|
+
)}
|
|
112
|
+
{item?.user && !isAll && (
|
|
113
|
+
<Avatar className="size-5 shrink-0">
|
|
114
|
+
{item.user.picturePath && (
|
|
115
|
+
<AvatarImage src={item.user.picturePath} alt={item.user.name} />
|
|
116
|
+
)}
|
|
117
|
+
<AvatarFallback className="text-xs uppercase">
|
|
118
|
+
{item.user.name?.[0] ?? '?'}
|
|
119
|
+
</AvatarFallback>
|
|
120
|
+
</Avatar>
|
|
121
|
+
)}
|
|
122
|
+
{item?.icon && !item.user && !isAll && (
|
|
123
|
+
<span
|
|
124
|
+
className="shrink-0"
|
|
125
|
+
style={selected ? { color: accentHex } : undefined}>
|
|
126
|
+
<KivaIcon icon={item.icon} size="xs" />
|
|
127
|
+
</span>
|
|
128
|
+
)}
|
|
129
|
+
<span className="truncate">
|
|
130
|
+
{label}
|
|
131
|
+
{item?.secondary && (
|
|
132
|
+
<span className="ml-1 text-xs font-normal text-muted-foreground">
|
|
133
|
+
{item.secondary}
|
|
134
|
+
</span>
|
|
135
|
+
)}
|
|
136
|
+
</span>
|
|
137
|
+
{stat !== undefined && (
|
|
138
|
+
<span
|
|
139
|
+
className={cn(
|
|
140
|
+
'ml-auto inline-flex shrink-0 items-center font-mono text-xs tabular-nums',
|
|
141
|
+
selected ? 'text-current/80 font-medium' : 'text-muted-foreground'
|
|
142
|
+
)}>
|
|
143
|
+
{formatStat(stat)}
|
|
144
|
+
</span>
|
|
145
|
+
)}
|
|
146
|
+
</button>
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function formatStat(value: number): string {
|
|
151
|
+
if (!Number.isFinite(value)) return '0';
|
|
152
|
+
if (Math.abs(value) >= 1000) {
|
|
153
|
+
return `${(value / 1000).toFixed(value % 1000 === 0 ? 0 : 1)}k`;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return Number.isInteger(value) ? String(value) : value.toFixed(2);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export { PivotFilterPill };
|