@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,116 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
import { type HTMLAttributes } from 'react';
|
|
6
|
+
|
|
7
|
+
import { type VariantProps, cva } from 'class-variance-authority';
|
|
8
|
+
|
|
9
|
+
import { differenceInMinutes, parseISO } from 'date-fns';
|
|
10
|
+
|
|
11
|
+
import { cn } from '@kivacore/ui-pro-shared/lib/utils';
|
|
12
|
+
|
|
13
|
+
import { type IEvent } from '../../interfaces';
|
|
14
|
+
|
|
15
|
+
import { useCalendar } from '../../contexts/calendar-context';
|
|
16
|
+
import { EventDetailsDialog } from '../../dialogs/event-details-dialog';
|
|
17
|
+
import { DraggableEvent } from '../../dnd/draggable-event';
|
|
18
|
+
import { ResizableEvent } from '../../dnd/resizable-event';
|
|
19
|
+
import { formatTime } from '../../helpers';
|
|
20
|
+
|
|
21
|
+
const calendarWeekEventCardVariants = cva(
|
|
22
|
+
'flex select-none flex-col gap-0.5 truncate whitespace-nowrap rounded-md border px-2 py-1.5 text-xs cursor-grab focus-visible:outline-offset-2',
|
|
23
|
+
{
|
|
24
|
+
variants: {
|
|
25
|
+
color: {
|
|
26
|
+
blue: 'border-blue-200 bg-blue-100/50 text-blue-700 hover:bg-blue-100 dark:border-blue-800 dark:bg-blue-950/50 dark:text-blue-300 dark:hover:bg-blue-950',
|
|
27
|
+
green:
|
|
28
|
+
'border-green-200 bg-green-100/50 text-green-700 hover:bg-green-100 dark:border-green-800 dark:bg-green-950/50 dark:text-green-300 dark:hover:bg-green-950',
|
|
29
|
+
red: 'border-red-200 bg-red-100/50 text-red-700 hover:bg-red-100 dark:border-red-800 dark:bg-red-950/50 dark:text-red-300 dark:hover:bg-red-950',
|
|
30
|
+
yellow:
|
|
31
|
+
'border-yellow-200 bg-yellow-100/50 text-yellow-700 hover:bg-yellow-100 dark:border-yellow-800 dark:bg-yellow-950/50 dark:text-yellow-300 dark:hover:bg-yellow-950',
|
|
32
|
+
purple:
|
|
33
|
+
'border-purple-200 bg-purple-100/50 text-purple-700 hover:bg-purple-100 dark:border-purple-800 dark:bg-purple-950/50 dark:text-purple-300 dark:hover:bg-purple-950',
|
|
34
|
+
orange:
|
|
35
|
+
'border-orange-200 bg-orange-100/50 text-orange-700 hover:bg-orange-100 dark:border-orange-800 dark:bg-orange-950/50 dark:text-orange-300 dark:hover:bg-orange-950',
|
|
36
|
+
|
|
37
|
+
'blue-dot':
|
|
38
|
+
'border-border bg-card text-foreground hover:bg-accent [&_svg]:fill-blue-600 dark:[&_svg]:fill-blue-500',
|
|
39
|
+
'green-dot':
|
|
40
|
+
'border-border bg-card text-foreground hover:bg-accent [&_svg]:fill-green-600 dark:[&_svg]:fill-green-500',
|
|
41
|
+
'red-dot':
|
|
42
|
+
'border-border bg-card text-foreground hover:bg-accent [&_svg]:fill-red-600 dark:[&_svg]:fill-red-500',
|
|
43
|
+
'orange-dot':
|
|
44
|
+
'border-border bg-card text-foreground hover:bg-accent [&_svg]:fill-orange-600 dark:[&_svg]:fill-orange-500',
|
|
45
|
+
'purple-dot':
|
|
46
|
+
'border-border bg-card text-foreground hover:bg-accent [&_svg]:fill-purple-600 dark:[&_svg]:fill-purple-500',
|
|
47
|
+
'yellow-dot':
|
|
48
|
+
'border-border bg-card text-foreground hover:bg-accent [&_svg]:fill-yellow-600 dark:[&_svg]:fill-yellow-500'
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
defaultVariants: {
|
|
52
|
+
color: 'blue-dot'
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
interface IProps
|
|
58
|
+
extends
|
|
59
|
+
HTMLAttributes<HTMLDivElement>,
|
|
60
|
+
Omit<VariantProps<typeof calendarWeekEventCardVariants>, 'color'> {
|
|
61
|
+
event: IEvent;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function EventBlock({ event, className }: IProps) {
|
|
65
|
+
const { badgeVariant, use24HourFormat } = useCalendar();
|
|
66
|
+
|
|
67
|
+
const start = parseISO(event.startDate);
|
|
68
|
+
const end = parseISO(event.endDate);
|
|
69
|
+
const durationInMinutes = differenceInMinutes(end, start);
|
|
70
|
+
const heightInPixels = (durationInMinutes / 60) * 96 - 8;
|
|
71
|
+
|
|
72
|
+
const color = (
|
|
73
|
+
badgeVariant === 'dot' ? `${event.color}-dot` : event.color
|
|
74
|
+
) as VariantProps<typeof calendarWeekEventCardVariants>['color'];
|
|
75
|
+
|
|
76
|
+
const calendarWeekEventCardClasses = cn(
|
|
77
|
+
calendarWeekEventCardVariants({ color, className }),
|
|
78
|
+
durationInMinutes < 35 && 'py-0 justify-center'
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
return (
|
|
82
|
+
<ResizableEvent event={event}>
|
|
83
|
+
<DraggableEvent event={event}>
|
|
84
|
+
<EventDetailsDialog event={event}>
|
|
85
|
+
<button
|
|
86
|
+
type="button"
|
|
87
|
+
className={calendarWeekEventCardClasses}
|
|
88
|
+
style={{ height: `${heightInPixels}px` }}>
|
|
89
|
+
<div className="flex items-center gap-1.5 truncate">
|
|
90
|
+
{badgeVariant === 'dot' && (
|
|
91
|
+
<svg
|
|
92
|
+
width="8"
|
|
93
|
+
height="8"
|
|
94
|
+
viewBox="0 0 8 8"
|
|
95
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
96
|
+
className="shrink-0"
|
|
97
|
+
aria-hidden="true">
|
|
98
|
+
<circle cx="4" cy="4" r="4" />
|
|
99
|
+
</svg>
|
|
100
|
+
)}
|
|
101
|
+
|
|
102
|
+
<p className="truncate font-semibold">{event.title}</p>
|
|
103
|
+
</div>
|
|
104
|
+
|
|
105
|
+
{durationInMinutes > 25 && (
|
|
106
|
+
<p>
|
|
107
|
+
{formatTime(start, use24HourFormat)} -{' '}
|
|
108
|
+
{formatTime(end, use24HourFormat)}
|
|
109
|
+
</p>
|
|
110
|
+
)}
|
|
111
|
+
</button>
|
|
112
|
+
</EventDetailsDialog>
|
|
113
|
+
</DraggableEvent>
|
|
114
|
+
</ResizableEvent>
|
|
115
|
+
);
|
|
116
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
import { areIntervalsOverlapping, parseISO } from 'date-fns';
|
|
6
|
+
|
|
7
|
+
import { type IEvent } from '../../interfaces';
|
|
8
|
+
|
|
9
|
+
import { useCalendar } from '../../contexts/calendar-context';
|
|
10
|
+
import { getEventBlockStyle } from '../../helpers';
|
|
11
|
+
import { EventBlock } from './event-block';
|
|
12
|
+
|
|
13
|
+
interface RenderGroupedEventsProps {
|
|
14
|
+
groupedEvents: Array<Array<IEvent>>;
|
|
15
|
+
day: Date;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function RenderGroupedEvents({
|
|
19
|
+
groupedEvents,
|
|
20
|
+
day
|
|
21
|
+
}: RenderGroupedEventsProps) {
|
|
22
|
+
const { startHour, endHour } = useCalendar();
|
|
23
|
+
|
|
24
|
+
return groupedEvents.map((group, groupIndex) => group.map((event) => {
|
|
25
|
+
let style = getEventBlockStyle(
|
|
26
|
+
event,
|
|
27
|
+
day,
|
|
28
|
+
groupIndex,
|
|
29
|
+
groupedEvents.length,
|
|
30
|
+
{ startHour, endHour }
|
|
31
|
+
);
|
|
32
|
+
const hasOverlap = groupedEvents.some(
|
|
33
|
+
(otherGroup, otherIndex) => otherIndex !== groupIndex
|
|
34
|
+
&& otherGroup.some(otherEvent => areIntervalsOverlapping(
|
|
35
|
+
{
|
|
36
|
+
start: parseISO(event.startDate),
|
|
37
|
+
end: parseISO(event.endDate)
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
start: parseISO(otherEvent.startDate),
|
|
41
|
+
end: parseISO(otherEvent.endDate)
|
|
42
|
+
}
|
|
43
|
+
))
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
if (!hasOverlap) style = { ...style, width: '100%', left: '0%' };
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<div key={event.id} className="absolute p-1" style={style}>
|
|
50
|
+
<EventBlock event={event} />
|
|
51
|
+
</div>
|
|
52
|
+
);
|
|
53
|
+
}));
|
|
54
|
+
}
|
package/src/components/kiva/calendar/views/week-and-day-view/week-view-multi-day-events-row.tsx
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
import { useMemo } from 'react';
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
addDays,
|
|
9
|
+
differenceInDays,
|
|
10
|
+
endOfWeek,
|
|
11
|
+
isAfter,
|
|
12
|
+
isBefore,
|
|
13
|
+
parseISO,
|
|
14
|
+
startOfDay,
|
|
15
|
+
startOfWeek
|
|
16
|
+
} from 'date-fns';
|
|
17
|
+
|
|
18
|
+
import { type IEvent } from '../../interfaces';
|
|
19
|
+
|
|
20
|
+
import { useCalendar } from '../../contexts/calendar-context';
|
|
21
|
+
import { MonthEventBadge } from '../month-view/month-event-badge';
|
|
22
|
+
|
|
23
|
+
interface IProps {
|
|
24
|
+
selectedDate: Date;
|
|
25
|
+
multiDayEvents: Array<IEvent>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function WeekViewMultiDayEventsRow({
|
|
29
|
+
selectedDate,
|
|
30
|
+
multiDayEvents
|
|
31
|
+
}: IProps) {
|
|
32
|
+
const { weekStartsOn } = useCalendar();
|
|
33
|
+
const weekStart = startOfWeek(selectedDate, { weekStartsOn });
|
|
34
|
+
const weekEnd = endOfWeek(selectedDate, { weekStartsOn });
|
|
35
|
+
const weekDays = Array.from({ length: 7 }, (_, i) => addDays(weekStart, i));
|
|
36
|
+
|
|
37
|
+
const processedEvents = useMemo(() => {
|
|
38
|
+
return multiDayEvents
|
|
39
|
+
.map((event) => {
|
|
40
|
+
const start = parseISO(event.startDate);
|
|
41
|
+
const end = parseISO(event.endDate);
|
|
42
|
+
const adjustedStart = isBefore(start, weekStart) ? weekStart : start;
|
|
43
|
+
const adjustedEnd = isAfter(end, weekEnd) ? weekEnd : end;
|
|
44
|
+
const startIndex = differenceInDays(adjustedStart, weekStart);
|
|
45
|
+
const endIndex = differenceInDays(adjustedEnd, weekStart);
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
...event,
|
|
49
|
+
adjustedStart,
|
|
50
|
+
adjustedEnd,
|
|
51
|
+
startIndex,
|
|
52
|
+
endIndex
|
|
53
|
+
};
|
|
54
|
+
})
|
|
55
|
+
.sort((a, b) => {
|
|
56
|
+
const startDiff = a.adjustedStart.getTime() - b.adjustedStart.getTime();
|
|
57
|
+
|
|
58
|
+
if (startDiff !== 0) return startDiff;
|
|
59
|
+
|
|
60
|
+
return b.endIndex - b.startIndex - (a.endIndex - a.startIndex);
|
|
61
|
+
});
|
|
62
|
+
}, [multiDayEvents, weekStart, weekEnd]);
|
|
63
|
+
|
|
64
|
+
const eventRows = useMemo(() => {
|
|
65
|
+
const rows: Array<typeof processedEvents> = [];
|
|
66
|
+
|
|
67
|
+
processedEvents.forEach((event) => {
|
|
68
|
+
let rowIndex = rows.findIndex(row => row.every(
|
|
69
|
+
e => e.endIndex < event.startIndex || e.startIndex > event.endIndex
|
|
70
|
+
));
|
|
71
|
+
|
|
72
|
+
if (rowIndex === -1) {
|
|
73
|
+
rowIndex = rows.length;
|
|
74
|
+
rows.push([]);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
rows[rowIndex]?.push(event);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
return rows;
|
|
81
|
+
}, [processedEvents]);
|
|
82
|
+
|
|
83
|
+
const rowKeys = useMemo(
|
|
84
|
+
() => eventRows.map((row, idx) => row[0]?.id ?? `row-empty-${idx}`),
|
|
85
|
+
[eventRows]
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
const hasEventsInWeek = useMemo(() => {
|
|
89
|
+
return multiDayEvents.some((event) => {
|
|
90
|
+
const start = parseISO(event.startDate);
|
|
91
|
+
const end = parseISO(event.endDate);
|
|
92
|
+
|
|
93
|
+
return (
|
|
94
|
+
(start >= weekStart && start <= weekEnd)
|
|
95
|
+
|| (end >= weekStart && end <= weekEnd)
|
|
96
|
+
|| (start <= weekStart && end >= weekEnd)
|
|
97
|
+
);
|
|
98
|
+
});
|
|
99
|
+
}, [multiDayEvents, weekStart, weekEnd]);
|
|
100
|
+
|
|
101
|
+
if (!hasEventsInWeek) {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return (
|
|
106
|
+
<div className="overflow-hidden flex">
|
|
107
|
+
<div className="w-18 border-b" />
|
|
108
|
+
<div className="grid flex-1 grid-cols-7 divide-x border-b border-l">
|
|
109
|
+
{weekDays.map((day, dayIndex) => {
|
|
110
|
+
const dayKey = day.toISOString();
|
|
111
|
+
|
|
112
|
+
return (
|
|
113
|
+
<div
|
|
114
|
+
key={dayKey}
|
|
115
|
+
className="flex h-full flex-col gap-1 py-1">
|
|
116
|
+
{eventRows.map((row, rowIndex) => {
|
|
117
|
+
const event = row.find(
|
|
118
|
+
e => e.startIndex <= dayIndex && e.endIndex >= dayIndex
|
|
119
|
+
);
|
|
120
|
+
const rowKey = rowKeys[rowIndex] ?? `row-${rowIndex}`;
|
|
121
|
+
|
|
122
|
+
if (!event) {
|
|
123
|
+
return (
|
|
124
|
+
<div
|
|
125
|
+
key={`empty-${dayKey}-${rowKey}`}
|
|
126
|
+
className="h-6.5" />
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
let position: 'first' | 'middle' | 'last' | 'none' = 'none';
|
|
131
|
+
|
|
132
|
+
if (
|
|
133
|
+
dayIndex === event.startIndex
|
|
134
|
+
&& dayIndex === event.endIndex
|
|
135
|
+
) {
|
|
136
|
+
position = 'none';
|
|
137
|
+
} else if (dayIndex === event.startIndex) {
|
|
138
|
+
position = 'first';
|
|
139
|
+
} else if (dayIndex === event.endIndex) {
|
|
140
|
+
position = 'last';
|
|
141
|
+
} else {
|
|
142
|
+
position = 'middle';
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return (
|
|
146
|
+
<MonthEventBadge
|
|
147
|
+
key={`${event.id}-${dayKey}`}
|
|
148
|
+
event={event}
|
|
149
|
+
cellDate={startOfDay(day)}
|
|
150
|
+
position={position} />
|
|
151
|
+
);
|
|
152
|
+
})}
|
|
153
|
+
</div>
|
|
154
|
+
);
|
|
155
|
+
})}
|
|
156
|
+
</div>
|
|
157
|
+
</div>
|
|
158
|
+
);
|
|
159
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
import { getYear, isSameDay, isSameMonth } from 'date-fns';
|
|
6
|
+
import { motion } from 'motion/react';
|
|
7
|
+
|
|
8
|
+
import { cn } from '@kivacore/ui-pro-shared/lib/utils';
|
|
9
|
+
|
|
10
|
+
import { type IEvent } from '../../interfaces';
|
|
11
|
+
|
|
12
|
+
import { staggerContainer, transition } from '../../animations';
|
|
13
|
+
import { useCalendar } from '../../contexts/calendar-context';
|
|
14
|
+
import { EventListDialog } from '../../dialogs/events-list-dialog';
|
|
15
|
+
import { getCalendarCells } from '../../helpers';
|
|
16
|
+
import { EventBullet } from '../month-view/event-bullet';
|
|
17
|
+
|
|
18
|
+
interface IProps {
|
|
19
|
+
singleDayEvents: Array<IEvent>;
|
|
20
|
+
multiDayEvents: Array<IEvent>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const MONTHS = [
|
|
24
|
+
'January',
|
|
25
|
+
'February',
|
|
26
|
+
'March',
|
|
27
|
+
'April',
|
|
28
|
+
'May',
|
|
29
|
+
'June',
|
|
30
|
+
'July',
|
|
31
|
+
'August',
|
|
32
|
+
'September',
|
|
33
|
+
'October',
|
|
34
|
+
'November',
|
|
35
|
+
'December'
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
const WEEKDAYS = [
|
|
39
|
+
'Su',
|
|
40
|
+
'Mo',
|
|
41
|
+
'Tu',
|
|
42
|
+
'We',
|
|
43
|
+
'Th',
|
|
44
|
+
'Fr',
|
|
45
|
+
'Sa'
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
export function CalendarYearView({ singleDayEvents, multiDayEvents }: IProps) {
|
|
49
|
+
const { selectedDate, setSelectedDate } = useCalendar();
|
|
50
|
+
const currentYear = getYear(selectedDate);
|
|
51
|
+
const allEvents = [...multiDayEvents, ...singleDayEvents];
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<div className="flex flex-col h-full overflow-y-auto p-4 sm:p-6">
|
|
55
|
+
{/* Year grid */}
|
|
56
|
+
<motion.div
|
|
57
|
+
initial="initial"
|
|
58
|
+
animate="animate"
|
|
59
|
+
variants={staggerContainer}
|
|
60
|
+
className="grid grid-cols-1 gap-4 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 auto-rows-fr">
|
|
61
|
+
{MONTHS.map((month, monthIndex) => {
|
|
62
|
+
const monthDate = new Date(currentYear, monthIndex, 1);
|
|
63
|
+
const cells = getCalendarCells(monthDate);
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<motion.div
|
|
67
|
+
key={month}
|
|
68
|
+
className="flex flex-col border border-border rounded-lg shadow-sm overflow-hidden"
|
|
69
|
+
initial={{ opacity: 0, scale: 0.95 }}
|
|
70
|
+
animate={{ opacity: 1, scale: 1 }}
|
|
71
|
+
transition={{ delay: monthIndex * 0.05, ...transition }}
|
|
72
|
+
aria-label={`${month} ${currentYear} calendar`}>
|
|
73
|
+
{/* Month header */}
|
|
74
|
+
<button
|
|
75
|
+
type="button"
|
|
76
|
+
className="w-full px-3 py-2 text-center font-semibold text-sm sm:text-base cursor-pointer hover:bg-primary/20 transition-colors bg-transparent border-none appearance-none"
|
|
77
|
+
onClick={() => setSelectedDate(new Date(currentYear, monthIndex, 1))}
|
|
78
|
+
aria-label={`Select ${month}`}>
|
|
79
|
+
{month}
|
|
80
|
+
</button>
|
|
81
|
+
|
|
82
|
+
<div className="grid grid-cols-7 text-center text-xs font-medium text-muted-foreground py-2">
|
|
83
|
+
{WEEKDAYS.map(day => (
|
|
84
|
+
<div key={day} className="p-1">
|
|
85
|
+
{day}
|
|
86
|
+
</div>
|
|
87
|
+
))}
|
|
88
|
+
</div>
|
|
89
|
+
|
|
90
|
+
<div className="grid grid-cols-7 gap-0.5 p-1.5 grow text-xs">
|
|
91
|
+
{cells.map((cell) => {
|
|
92
|
+
const isCurrentMonth = isSameMonth(cell.date, monthDate);
|
|
93
|
+
const isToday = isSameDay(cell.date, new Date());
|
|
94
|
+
const dayEvents = allEvents.filter(event => isSameDay(new Date(event.startDate), cell.date));
|
|
95
|
+
const hasEvents = dayEvents.length > 0;
|
|
96
|
+
|
|
97
|
+
return (
|
|
98
|
+
<div
|
|
99
|
+
key={cell.date.toISOString()}
|
|
100
|
+
className={cn(
|
|
101
|
+
'flex flex-col items-center justify-start p-1 min-h-8 relative',
|
|
102
|
+
!isCurrentMonth && 'text-muted-foreground/40',
|
|
103
|
+
hasEvents && isCurrentMonth ? 'cursor-pointer hover:bg-accent/20 hover:rounded-md' : 'cursor-default'
|
|
104
|
+
)}>
|
|
105
|
+
{isCurrentMonth && hasEvents ? (
|
|
106
|
+
<EventListDialog date={cell.date} events={dayEvents}>
|
|
107
|
+
<div className="w-full h-full flex flex-col items-center justify-start gap-0.5">
|
|
108
|
+
<span
|
|
109
|
+
className={cn(
|
|
110
|
+
'size-5 flex items-center justify-center font-medium',
|
|
111
|
+
isToday
|
|
112
|
+
&& 'rounded-full bg-primary text-primary-foreground'
|
|
113
|
+
)}>
|
|
114
|
+
{cell.day}
|
|
115
|
+
</span>
|
|
116
|
+
<div className="flex justify-center items-center gap-0.5">
|
|
117
|
+
{dayEvents.length <= 2 ? (
|
|
118
|
+
dayEvents
|
|
119
|
+
.slice(0, 2)
|
|
120
|
+
.map(event => (
|
|
121
|
+
<EventBullet
|
|
122
|
+
key={event.id}
|
|
123
|
+
color={event.color}
|
|
124
|
+
className="size-1.5" />
|
|
125
|
+
))
|
|
126
|
+
) : (
|
|
127
|
+
<div className="flex flex-col justify-center items-center">
|
|
128
|
+
<EventBullet
|
|
129
|
+
color={dayEvents[0]?.color ?? 'blue'}
|
|
130
|
+
className="size-1.5" />
|
|
131
|
+
<span className="text-[0.6rem]">
|
|
132
|
+
+{dayEvents.length - 1}
|
|
133
|
+
</span>
|
|
134
|
+
</div>
|
|
135
|
+
)}
|
|
136
|
+
</div>
|
|
137
|
+
</div>
|
|
138
|
+
</EventListDialog>
|
|
139
|
+
) : (
|
|
140
|
+
<div className="w-full h-full flex flex-col items-center justify-start">
|
|
141
|
+
<span
|
|
142
|
+
className={cn(
|
|
143
|
+
'size-5 flex items-center justify-center font-medium'
|
|
144
|
+
)}>
|
|
145
|
+
{cell.day}
|
|
146
|
+
</span>
|
|
147
|
+
</div>
|
|
148
|
+
)}
|
|
149
|
+
</div>
|
|
150
|
+
);
|
|
151
|
+
})}
|
|
152
|
+
</div>
|
|
153
|
+
</motion.div>
|
|
154
|
+
);
|
|
155
|
+
})}
|
|
156
|
+
</motion.div>
|
|
157
|
+
</div>
|
|
158
|
+
);
|
|
159
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
import { useMemo } from 'react';
|
|
6
|
+
|
|
7
|
+
import { X } from 'lucide-react';
|
|
8
|
+
|
|
9
|
+
import { Badge } from '@kivacore/ui-pro-shared/components/badge';
|
|
10
|
+
import { Button } from '@kivacore/ui-pro-shared/components/button';
|
|
11
|
+
import {
|
|
12
|
+
type Column,
|
|
13
|
+
type DataTableFilterActions,
|
|
14
|
+
type FilterModel,
|
|
15
|
+
type FiltersState
|
|
16
|
+
} from '@kivacore/ui-pro-shared/components/kiva/data-table-filter/core/types';
|
|
17
|
+
import { useDateFormat } from '@kivacore/ui-pro-shared/hooks/kiva/use-date-format';
|
|
18
|
+
|
|
19
|
+
interface SideFilterActiveChipsProps<TData> {
|
|
20
|
+
filters: FiltersState;
|
|
21
|
+
columns: Array<Column<TData>>;
|
|
22
|
+
actions: DataTableFilterActions;
|
|
23
|
+
clearAllLabel?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function SideFilterActiveChips<TData>({
|
|
27
|
+
filters,
|
|
28
|
+
columns,
|
|
29
|
+
actions,
|
|
30
|
+
clearAllLabel = 'Clear all'
|
|
31
|
+
}: SideFilterActiveChipsProps<TData>) {
|
|
32
|
+
const { formatDate } = useDateFormat();
|
|
33
|
+
|
|
34
|
+
const items = useMemo(() => {
|
|
35
|
+
const byId = new Map(columns.map(c => [c.id, c]));
|
|
36
|
+
const out: Array<{ id: string; label: string }> = [];
|
|
37
|
+
|
|
38
|
+
for (const filter of filters) {
|
|
39
|
+
const column = byId.get(filter.columnId);
|
|
40
|
+
|
|
41
|
+
if (!column) continue;
|
|
42
|
+
const summary = describeFilter(filter, column, formatDate);
|
|
43
|
+
|
|
44
|
+
if (!summary) continue;
|
|
45
|
+
out.push({ id: filter.columnId, label: `${column.displayName}: ${summary}` });
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return out;
|
|
49
|
+
}, [filters, columns, formatDate]);
|
|
50
|
+
|
|
51
|
+
if (items.length === 0) return null;
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<div className="flex flex-wrap items-center gap-1">
|
|
55
|
+
{items.map(item => (
|
|
56
|
+
<Badge
|
|
57
|
+
key={item.id}
|
|
58
|
+
variant="secondary"
|
|
59
|
+
className="gap-1 pr-1 pl-2 text-xs font-normal">
|
|
60
|
+
<span className="truncate max-w-44">{item.label}</span>
|
|
61
|
+
<button
|
|
62
|
+
type="button"
|
|
63
|
+
aria-label={`Remove ${item.label}`}
|
|
64
|
+
onClick={() => actions.removeFilter(item.id)}
|
|
65
|
+
className="ml-0.5 rounded-sm p-0.5 transition-colors hover:bg-foreground/10">
|
|
66
|
+
<X className="size-3" />
|
|
67
|
+
</button>
|
|
68
|
+
</Badge>
|
|
69
|
+
))}
|
|
70
|
+
<Button
|
|
71
|
+
type="button"
|
|
72
|
+
variant="ghost"
|
|
73
|
+
size="sm"
|
|
74
|
+
onClick={actions.removeAllFilters}
|
|
75
|
+
className="h-6 px-2 text-xs text-muted-foreground hover:text-destructive">
|
|
76
|
+
{clearAllLabel}
|
|
77
|
+
</Button>
|
|
78
|
+
</div>
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function describeFilter<TData>(
|
|
83
|
+
filter: FilterModel,
|
|
84
|
+
column: Column<TData>,
|
|
85
|
+
formatDate: (value: unknown) => string
|
|
86
|
+
): string | null {
|
|
87
|
+
if (filter.values.length === 0) {
|
|
88
|
+
if (filter.operator === 'is empty' || filter.operator === 'is not empty') {
|
|
89
|
+
return filter.operator;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
switch (column.type) {
|
|
96
|
+
case 'option':
|
|
97
|
+
|
|
98
|
+
case 'multiOption': {
|
|
99
|
+
const options = column.getOptions();
|
|
100
|
+
const labels = (filter.values as Array<string>)
|
|
101
|
+
.map(v => options.find(o => o.value === v)?.label ?? v);
|
|
102
|
+
|
|
103
|
+
if (labels.length === 1) return labels[0] ?? '';
|
|
104
|
+
if (labels.length <= 2) return labels.join(', ');
|
|
105
|
+
|
|
106
|
+
return `${labels.length} selected`;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
case 'number': {
|
|
110
|
+
if (filter.operator === 'is between' || filter.operator === 'is not between') {
|
|
111
|
+
return `${filter.values[0]}–${filter.values[1]}`;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return `${filter.operator} ${filter.values[0]}`;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
case 'date': {
|
|
118
|
+
const [from, to] = filter.values as Array<Date>;
|
|
119
|
+
|
|
120
|
+
if (!from) return null;
|
|
121
|
+
if (!to) return formatDate(from);
|
|
122
|
+
|
|
123
|
+
return `${formatDate(from)} – ${formatDate(to)}`;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
case 'boolean': {
|
|
127
|
+
const v = filter.values[0];
|
|
128
|
+
|
|
129
|
+
return v === true ? (column.trueLabel ?? 'true') : (column.falseLabel ?? 'false');
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
case 'text':
|
|
133
|
+
|
|
134
|
+
default:
|
|
135
|
+
return String(filter.values[0] ?? '');
|
|
136
|
+
}
|
|
137
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
import { type ReactNode } from 'react';
|
|
6
|
+
|
|
7
|
+
import { X } from 'lucide-react';
|
|
8
|
+
|
|
9
|
+
import { Button } from '@kivacore/ui-pro-shared/components/button';
|
|
10
|
+
|
|
11
|
+
interface SideFilterClearProps {
|
|
12
|
+
count: number;
|
|
13
|
+
onClick: () => void;
|
|
14
|
+
label?: ReactNode;
|
|
15
|
+
className?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function SideFilterClear({
|
|
19
|
+
count, onClick, label = 'Clear all', className
|
|
20
|
+
}: SideFilterClearProps) {
|
|
21
|
+
if (count === 0) return null;
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<Button
|
|
25
|
+
type="button"
|
|
26
|
+
variant="ghost"
|
|
27
|
+
size="sm"
|
|
28
|
+
onClick={onClick}
|
|
29
|
+
className={className ?? 'h-7 gap-1 px-2 text-xs text-muted-foreground hover:text-destructive'}>
|
|
30
|
+
<X className="size-3.5" />
|
|
31
|
+
{label} ({count})
|
|
32
|
+
</Button>
|
|
33
|
+
);
|
|
34
|
+
}
|