@kivacore/ui-pro-shared 0.0.9 → 0.0.10
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 +187 -21
- 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,122 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
import { type ReactNode } from 'react';
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
Dialog,
|
|
9
|
+
DialogContent,
|
|
10
|
+
DialogHeader,
|
|
11
|
+
DialogTitle,
|
|
12
|
+
DialogTrigger
|
|
13
|
+
} from '@kivacore/ui-pro-shared/components/dialog';
|
|
14
|
+
import { cn } from '@kivacore/ui-pro-shared/lib/utils';
|
|
15
|
+
|
|
16
|
+
import { useUiTranslation } from '@kivacore/ui-pro-shared/hooks/kiva/use-ui-translation';
|
|
17
|
+
import { useDateFormat } from '@kivacore/ui-pro-shared/hooks/kiva/use-date-format';
|
|
18
|
+
|
|
19
|
+
import { cva } from 'class-variance-authority';
|
|
20
|
+
|
|
21
|
+
import { type IEvent } from '../interfaces';
|
|
22
|
+
import { useCalendar } from '../contexts/calendar-context';
|
|
23
|
+
import { formatTime } from '../helpers';
|
|
24
|
+
import { EventBullet } from '../views/month-view/event-bullet';
|
|
25
|
+
import { EventDetailsDialog } from './event-details-dialog';
|
|
26
|
+
|
|
27
|
+
interface EventListDialogProps {
|
|
28
|
+
date: Date;
|
|
29
|
+
events: Array<IEvent>;
|
|
30
|
+
maxVisibleEvents?: number;
|
|
31
|
+
children?: ReactNode;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function EventListDialog({
|
|
35
|
+
date,
|
|
36
|
+
events,
|
|
37
|
+
maxVisibleEvents = 3,
|
|
38
|
+
children
|
|
39
|
+
}: EventListDialogProps) {
|
|
40
|
+
const { t } = useUiTranslation();
|
|
41
|
+
const { formatDate } = useDateFormat();
|
|
42
|
+
const cellEvents = events;
|
|
43
|
+
const hiddenEventsCount = Math.max(cellEvents.length - maxVisibleEvents, 0);
|
|
44
|
+
const { badgeVariant, use24HourFormat } = useCalendar();
|
|
45
|
+
|
|
46
|
+
const defaultTrigger = (
|
|
47
|
+
<span className="cursor-pointer">
|
|
48
|
+
<span className="sm:hidden">+{hiddenEventsCount}</span>
|
|
49
|
+
<span className="hidden sm:inline py-0.5 px-2 my-1 rounded-xl border">
|
|
50
|
+
{hiddenEventsCount}
|
|
51
|
+
<span className="mx-1">{t('ui.calendar.more', 'more')}</span>
|
|
52
|
+
</span>
|
|
53
|
+
</span>
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<Dialog>
|
|
58
|
+
<DialogTrigger asChild>{children || defaultTrigger}</DialogTrigger>
|
|
59
|
+
<DialogContent className="sm:max-w-[425px]">
|
|
60
|
+
<DialogHeader>
|
|
61
|
+
<DialogTitle className="my-2">
|
|
62
|
+
<div className="flex items-center gap-2">
|
|
63
|
+
<EventBullet color={cellEvents[0]?.color ?? 'blue'} className="" />
|
|
64
|
+
<p className="text-sm font-medium">
|
|
65
|
+
{t('ui.calendar.eventsOn', 'Events on')} {formatDate(date)}
|
|
66
|
+
</p>
|
|
67
|
+
</div>
|
|
68
|
+
</DialogTitle>
|
|
69
|
+
</DialogHeader>
|
|
70
|
+
<div className="max-h-[60vh] overflow-y-auto space-y-2">
|
|
71
|
+
{cellEvents.length > 0 ? (
|
|
72
|
+
cellEvents.map(event => (
|
|
73
|
+
<EventDetailsDialog event={event} key={event.id}>
|
|
74
|
+
<div
|
|
75
|
+
className={cn(
|
|
76
|
+
'flex items-center gap-2 p-2 border rounded-md hover:bg-muted cursor-pointer',
|
|
77
|
+
{
|
|
78
|
+
[dayCellVariants({ color: event.color })]:
|
|
79
|
+
badgeVariant === 'colored'
|
|
80
|
+
}
|
|
81
|
+
)}>
|
|
82
|
+
<EventBullet color={event.color} />
|
|
83
|
+
<div className="flex justify-between items-center w-full">
|
|
84
|
+
<p className="text-sm font-medium">{event.title}</p>
|
|
85
|
+
<p className="text-xs">
|
|
86
|
+
{formatTime(event.startDate, use24HourFormat)}
|
|
87
|
+
</p>
|
|
88
|
+
</div>
|
|
89
|
+
</div>
|
|
90
|
+
</EventDetailsDialog>
|
|
91
|
+
))
|
|
92
|
+
) : (
|
|
93
|
+
<p className="text-sm text-muted-foreground">
|
|
94
|
+
{t('ui.calendar.noEvents', 'No events for this date.')}
|
|
95
|
+
</p>
|
|
96
|
+
)}
|
|
97
|
+
</div>
|
|
98
|
+
</DialogContent>
|
|
99
|
+
</Dialog>
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export const dayCellVariants = cva('text-white', {
|
|
104
|
+
variants: {
|
|
105
|
+
color: {
|
|
106
|
+
blue: 'bg-blue-600 dark:bg-blue-500 hover:bg-blue-700 dark:hover:bg-blue-400 ',
|
|
107
|
+
green:
|
|
108
|
+
'bg-green-600 dark:bg-green-500 hover:bg-green-700 dark:hover:bg-green-400',
|
|
109
|
+
red: 'bg-red-600 dark:bg-red-500 hover:bg-red-700 dark:hover:bg-red-400',
|
|
110
|
+
yellow:
|
|
111
|
+
'bg-yellow-600 dark:bg-yellow-500 hover:bg-yellow-700 dark:hover:bg-yellow-400',
|
|
112
|
+
purple:
|
|
113
|
+
'bg-purple-600 dark:bg-purple-500 hover:bg-purple-700 dark:hover:bg-purple-400',
|
|
114
|
+
orange:
|
|
115
|
+
'bg-orange-600 dark:bg-orange-500 hover:bg-orange-700 dark:hover:bg-orange-400',
|
|
116
|
+
gray: 'bg-gray-600 dark:bg-gray-500 hover:bg-gray-700 dark:hover:bg-gray-400'
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
defaultVariants: {
|
|
120
|
+
color: 'blue'
|
|
121
|
+
}
|
|
122
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
import {
|
|
6
|
+
type DragEvent, type MouseEvent, type ReactNode, useCallback, useRef
|
|
7
|
+
} from 'react';
|
|
8
|
+
|
|
9
|
+
import { motion } from 'motion/react';
|
|
10
|
+
|
|
11
|
+
import { type IEvent } from '../interfaces';
|
|
12
|
+
|
|
13
|
+
import { useDragDrop } from '../contexts/dnd-context';
|
|
14
|
+
|
|
15
|
+
interface DraggableEventProps {
|
|
16
|
+
event: IEvent;
|
|
17
|
+
children: ReactNode;
|
|
18
|
+
className?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function DraggableEvent({
|
|
22
|
+
event,
|
|
23
|
+
children,
|
|
24
|
+
className
|
|
25
|
+
}: DraggableEventProps) {
|
|
26
|
+
const {
|
|
27
|
+
startDrag, endDrag, isDragging, draggedEvent
|
|
28
|
+
} = useDragDrop();
|
|
29
|
+
const ref = useRef<HTMLDivElement>(null);
|
|
30
|
+
|
|
31
|
+
const isCurrentlyDragged = isDragging && draggedEvent?.id === event.id;
|
|
32
|
+
|
|
33
|
+
const handleClick = (e: MouseEvent<HTMLDivElement>) => {
|
|
34
|
+
e.stopPropagation();
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const handleDragStart = useCallback((e: DragEvent<HTMLDivElement>) => {
|
|
38
|
+
e.dataTransfer.setData('text/plain', event.id.toString());
|
|
39
|
+
startDrag(event);
|
|
40
|
+
}, [event, startDrag]);
|
|
41
|
+
|
|
42
|
+
const handleDragEnd = useCallback(() => {
|
|
43
|
+
endDrag();
|
|
44
|
+
}, [endDrag]);
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<motion.div
|
|
48
|
+
ref={ref}
|
|
49
|
+
/*
|
|
50
|
+
* `initial={false}` because `CalendarBody`'s wrapper animates a `fadeIn`
|
|
51
|
+
* variant and Motion propagates variant labels to every descendant motion
|
|
52
|
+
* component — without this every event mount replays that spring, which
|
|
53
|
+
* turns a period switch in the timeline views into dozens of bars fading
|
|
54
|
+
* in one by one.
|
|
55
|
+
*/
|
|
56
|
+
initial={false}
|
|
57
|
+
className={`${className || ''} ${isCurrentlyDragged ? 'opacity-50 cursor-grabbing' : 'cursor-grab'}`}
|
|
58
|
+
draggable
|
|
59
|
+
onClick={(e: MouseEvent<HTMLDivElement>) => handleClick(e)}
|
|
60
|
+
// @ts-expect-error -- native HTML drag events conflict with motion's gesture types
|
|
61
|
+
onDragStart={handleDragStart}
|
|
62
|
+
onDragEnd={handleDragEnd}>
|
|
63
|
+
{children}
|
|
64
|
+
</motion.div>
|
|
65
|
+
);
|
|
66
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
import { type CSSProperties, type ReactNode } from 'react';
|
|
6
|
+
|
|
7
|
+
import { useUiTranslation } from '@kivacore/ui-pro-shared/hooks/kiva/use-ui-translation';
|
|
8
|
+
|
|
9
|
+
import { useDragDrop } from '../contexts/dnd-context';
|
|
10
|
+
|
|
11
|
+
interface DroppableAreaProps {
|
|
12
|
+
date: Date;
|
|
13
|
+
hour?: number;
|
|
14
|
+
minute?: number;
|
|
15
|
+
children: ReactNode;
|
|
16
|
+
className?: string;
|
|
17
|
+
style?: CSSProperties;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function DroppableArea({
|
|
21
|
+
date,
|
|
22
|
+
hour,
|
|
23
|
+
minute,
|
|
24
|
+
children,
|
|
25
|
+
className,
|
|
26
|
+
style
|
|
27
|
+
}: DroppableAreaProps) {
|
|
28
|
+
const { t } = useUiTranslation();
|
|
29
|
+
const { handleEventDrop, isDragging } = useDragDrop();
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<div
|
|
33
|
+
role="gridcell"
|
|
34
|
+
aria-label={t('ui.calendar.droppableArea', 'Droppable area')}
|
|
35
|
+
tabIndex={-1}
|
|
36
|
+
className={`${className || ''} ${isDragging ? 'drop-target' : ''}`}
|
|
37
|
+
style={style}
|
|
38
|
+
onDragOver={(e) => {
|
|
39
|
+
e.preventDefault();
|
|
40
|
+
e.currentTarget.classList.add('bg-primary/10');
|
|
41
|
+
}}
|
|
42
|
+
onDragLeave={(e) => {
|
|
43
|
+
e.currentTarget.classList.remove('bg-primary/10');
|
|
44
|
+
}}
|
|
45
|
+
onDrop={(e) => {
|
|
46
|
+
e.preventDefault();
|
|
47
|
+
e.currentTarget.classList.remove('bg-primary/10');
|
|
48
|
+
handleEventDrop(date, hour, minute);
|
|
49
|
+
}}>
|
|
50
|
+
{children}
|
|
51
|
+
</div>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
import {
|
|
6
|
+
useCallback, useMemo, useState, type ReactNode
|
|
7
|
+
} from 'react';
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
addMinutes,
|
|
11
|
+
differenceInMinutes,
|
|
12
|
+
isAfter,
|
|
13
|
+
isBefore,
|
|
14
|
+
parseISO
|
|
15
|
+
} from 'date-fns';
|
|
16
|
+
import { motion } from 'motion/react';
|
|
17
|
+
import { Resizable, type ResizeCallback } from 're-resizable';
|
|
18
|
+
|
|
19
|
+
import { cn } from '@kivacore/ui-pro-shared/lib/utils';
|
|
20
|
+
|
|
21
|
+
import { type IEvent } from '../interfaces';
|
|
22
|
+
|
|
23
|
+
import { useCalendar } from '../contexts/calendar-context';
|
|
24
|
+
import { formatTime } from '../helpers';
|
|
25
|
+
|
|
26
|
+
interface ResizableEventBlockProps {
|
|
27
|
+
event: IEvent;
|
|
28
|
+
children: ReactNode;
|
|
29
|
+
className?: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const PIXELS_PER_HOUR = 96;
|
|
33
|
+
const MINUTES_PER_PIXEL = 60 / PIXELS_PER_HOUR;
|
|
34
|
+
const MIN_DURATION = 15;
|
|
35
|
+
|
|
36
|
+
export function ResizableEvent({
|
|
37
|
+
event,
|
|
38
|
+
children,
|
|
39
|
+
className
|
|
40
|
+
}: ResizableEventBlockProps) {
|
|
41
|
+
const { updateEvent, use24HourFormat } = useCalendar();
|
|
42
|
+
|
|
43
|
+
const [isResizing, setIsResizing] = useState(false);
|
|
44
|
+
const [resizePreview, setResizePreview] = useState<{
|
|
45
|
+
start: string;
|
|
46
|
+
end: string;
|
|
47
|
+
} | null>(null);
|
|
48
|
+
|
|
49
|
+
const start = useMemo(() => parseISO(event.startDate), [event.startDate]);
|
|
50
|
+
const end = useMemo(() => parseISO(event.endDate), [event.endDate]);
|
|
51
|
+
const durationInMinutes = useMemo(
|
|
52
|
+
() => differenceInMinutes(end, start),
|
|
53
|
+
[start, end]
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
const resizeBoundaries = useMemo(() => {
|
|
57
|
+
const dayStart = new Date(start);
|
|
58
|
+
|
|
59
|
+
dayStart.setHours(0, 0, 0, 0);
|
|
60
|
+
|
|
61
|
+
const dayEnd = new Date(start);
|
|
62
|
+
|
|
63
|
+
dayEnd.setHours(23, 59, 59, 999);
|
|
64
|
+
|
|
65
|
+
return { dayStart, dayEnd };
|
|
66
|
+
}, [start]);
|
|
67
|
+
|
|
68
|
+
const handleResizeStart = useCallback(() => {
|
|
69
|
+
setIsResizing(true);
|
|
70
|
+
}, []);
|
|
71
|
+
|
|
72
|
+
const handleResize: ResizeCallback = useCallback(
|
|
73
|
+
(_, direction, ref) => {
|
|
74
|
+
const newHeight = parseInt(ref.style.height, 10);
|
|
75
|
+
const newDuration = Math.max(
|
|
76
|
+
MIN_DURATION,
|
|
77
|
+
Math.round((newHeight + 8) * MINUTES_PER_PIXEL)
|
|
78
|
+
);
|
|
79
|
+
const delta = newDuration - durationInMinutes;
|
|
80
|
+
|
|
81
|
+
let newStart = start;
|
|
82
|
+
let newEnd = end;
|
|
83
|
+
|
|
84
|
+
if (direction.includes('top')) {
|
|
85
|
+
newStart = addMinutes(start, -delta);
|
|
86
|
+
} else if (direction.includes('bottom')) {
|
|
87
|
+
newEnd = addMinutes(end, delta);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (isBefore(newStart, resizeBoundaries.dayStart)) {
|
|
91
|
+
newStart = resizeBoundaries.dayStart;
|
|
92
|
+
}
|
|
93
|
+
if (isAfter(newEnd, resizeBoundaries.dayEnd)) {
|
|
94
|
+
newEnd = resizeBoundaries.dayEnd;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
setResizePreview({
|
|
98
|
+
start: formatTime(newStart, use24HourFormat),
|
|
99
|
+
end: formatTime(newEnd, use24HourFormat)
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
updateEvent({
|
|
103
|
+
...event,
|
|
104
|
+
startDate: newStart.toISOString(),
|
|
105
|
+
endDate: newEnd.toISOString()
|
|
106
|
+
});
|
|
107
|
+
},
|
|
108
|
+
[
|
|
109
|
+
start,
|
|
110
|
+
end,
|
|
111
|
+
durationInMinutes,
|
|
112
|
+
resizeBoundaries,
|
|
113
|
+
use24HourFormat,
|
|
114
|
+
updateEvent,
|
|
115
|
+
event
|
|
116
|
+
]
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
const handleResizeStop = useCallback(() => {
|
|
120
|
+
setIsResizing(false);
|
|
121
|
+
setResizePreview(null);
|
|
122
|
+
}, []);
|
|
123
|
+
|
|
124
|
+
const resizeConfig = useMemo(
|
|
125
|
+
() => ({
|
|
126
|
+
minHeight: 15,
|
|
127
|
+
maxHeight: 1440,
|
|
128
|
+
enable: {
|
|
129
|
+
top: true,
|
|
130
|
+
bottom: true,
|
|
131
|
+
topRight: false,
|
|
132
|
+
bottomRight: false,
|
|
133
|
+
bottomLeft: false,
|
|
134
|
+
topLeft: false
|
|
135
|
+
},
|
|
136
|
+
handleStyles: {
|
|
137
|
+
top: {
|
|
138
|
+
cursor: 'ns-resize',
|
|
139
|
+
height: '8px',
|
|
140
|
+
top: '-4px',
|
|
141
|
+
backgroundColor: 'transparent'
|
|
142
|
+
},
|
|
143
|
+
bottom: {
|
|
144
|
+
cursor: 'ns-resize',
|
|
145
|
+
height: '8px',
|
|
146
|
+
bottom: '-4px',
|
|
147
|
+
backgroundColor: 'transparent'
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
handleClasses: {
|
|
151
|
+
top: 'transition-colors rounded-sm',
|
|
152
|
+
bottom: 'transition-colors rounded-sm'
|
|
153
|
+
},
|
|
154
|
+
onResizeStart: handleResizeStart,
|
|
155
|
+
onResize: handleResize,
|
|
156
|
+
onResizeStop: handleResizeStop,
|
|
157
|
+
className: cn(
|
|
158
|
+
'transition-all duration-200',
|
|
159
|
+
isResizing && 'z-50 shadow-lg'
|
|
160
|
+
)
|
|
161
|
+
}),
|
|
162
|
+
[
|
|
163
|
+
handleResizeStart,
|
|
164
|
+
handleResize,
|
|
165
|
+
handleResizeStop,
|
|
166
|
+
isResizing
|
|
167
|
+
]
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
return (
|
|
171
|
+
<motion.div
|
|
172
|
+
initial={{ opacity: 0, scale: 0.95 }}
|
|
173
|
+
animate={{ opacity: 1, scale: 1 }}
|
|
174
|
+
exit={{ opacity: 0, scale: 0.95 }}
|
|
175
|
+
transition={{ duration: 0.2 }}
|
|
176
|
+
className={cn('relative group', className)}>
|
|
177
|
+
<Resizable {...resizeConfig}>{children}</Resizable>
|
|
178
|
+
|
|
179
|
+
{isResizing && resizePreview && (
|
|
180
|
+
<motion.div
|
|
181
|
+
initial={{ opacity: 0, y: -10 }}
|
|
182
|
+
animate={{ opacity: 1, y: 0 }}
|
|
183
|
+
exit={{ opacity: 0, y: -10 }}
|
|
184
|
+
className="absolute -top-8 left-1/2 transform -translate-x-1/2 bg-zinc-900 text-white text-xs px-2 py-1 rounded shadow-lg z-50 whitespace-nowrap">
|
|
185
|
+
{resizePreview.start} - {resizePreview.end}
|
|
186
|
+
</motion.div>
|
|
187
|
+
)}
|
|
188
|
+
</motion.div>
|
|
189
|
+
);
|
|
190
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
import { motion } from 'motion/react';
|
|
6
|
+
import { Plus } from 'lucide-react';
|
|
7
|
+
|
|
8
|
+
import { Button } from '@kivacore/ui-pro-shared/components/button';
|
|
9
|
+
|
|
10
|
+
import { useUiTranslation } from '@kivacore/ui-pro-shared/hooks/kiva/use-ui-translation';
|
|
11
|
+
|
|
12
|
+
import {
|
|
13
|
+
slideFromLeft,
|
|
14
|
+
slideFromRight,
|
|
15
|
+
transition
|
|
16
|
+
} from '../animations';
|
|
17
|
+
import { useCalendar } from '../contexts/calendar-context';
|
|
18
|
+
import { AddEditEventDialog } from '../dialogs/add-edit-event-dialog';
|
|
19
|
+
import { Settings } from '../settings/settings';
|
|
20
|
+
import { DateNavigator } from './date-navigator';
|
|
21
|
+
import FilterEvents from './filter';
|
|
22
|
+
import { TodayButton } from './today-button';
|
|
23
|
+
import { UserSelect } from './user-select';
|
|
24
|
+
import Views from './view-tabs';
|
|
25
|
+
|
|
26
|
+
export function CalendarHeader() {
|
|
27
|
+
const {
|
|
28
|
+
view,
|
|
29
|
+
events,
|
|
30
|
+
hideAddButton,
|
|
31
|
+
hideHeaderAddButton,
|
|
32
|
+
hideUserSelect,
|
|
33
|
+
hideSettings,
|
|
34
|
+
hideFilter,
|
|
35
|
+
addButtonLabel
|
|
36
|
+
} = useCalendar();
|
|
37
|
+
const { t } = useUiTranslation();
|
|
38
|
+
|
|
39
|
+
const shouldHideHeaderAdd = hideHeaderAddButton ?? hideAddButton;
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<div className="space-y-2 border-b p-3 sm:p-4">
|
|
43
|
+
<div className="flex items-center justify-between gap-3">
|
|
44
|
+
<motion.div
|
|
45
|
+
className="flex items-center gap-3"
|
|
46
|
+
variants={slideFromLeft}
|
|
47
|
+
initial="initial"
|
|
48
|
+
animate="animate"
|
|
49
|
+
transition={transition}>
|
|
50
|
+
<TodayButton />
|
|
51
|
+
<DateNavigator view={view} events={events} />
|
|
52
|
+
</motion.div>
|
|
53
|
+
|
|
54
|
+
<motion.div
|
|
55
|
+
className="flex items-center gap-2"
|
|
56
|
+
variants={slideFromRight}
|
|
57
|
+
initial="initial"
|
|
58
|
+
animate="animate"
|
|
59
|
+
transition={transition}>
|
|
60
|
+
{!hideFilter && <FilterEvents />}
|
|
61
|
+
<Views />
|
|
62
|
+
</motion.div>
|
|
63
|
+
</div>
|
|
64
|
+
|
|
65
|
+
<motion.div
|
|
66
|
+
className="flex items-center justify-end gap-2"
|
|
67
|
+
variants={slideFromRight}
|
|
68
|
+
initial="initial"
|
|
69
|
+
animate="animate"
|
|
70
|
+
transition={transition}>
|
|
71
|
+
{!hideUserSelect && <UserSelect />}
|
|
72
|
+
{!shouldHideHeaderAdd && (
|
|
73
|
+
<AddEditEventDialog>
|
|
74
|
+
<Button size="sm">
|
|
75
|
+
<Plus className="size-4" />
|
|
76
|
+
<span className="hidden sm:inline">{addButtonLabel ?? t('ui.calendar.addEvent', 'Add Event')}</span>
|
|
77
|
+
</Button>
|
|
78
|
+
</AddEditEventDialog>
|
|
79
|
+
)}
|
|
80
|
+
{!hideSettings && <Settings />}
|
|
81
|
+
</motion.div>
|
|
82
|
+
</div>
|
|
83
|
+
);
|
|
84
|
+
}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
import { useMemo } from 'react';
|
|
6
|
+
|
|
7
|
+
import { AnimatePresence, motion } from 'motion/react';
|
|
8
|
+
import { ChevronLeft, ChevronRight } from 'lucide-react';
|
|
9
|
+
|
|
10
|
+
import { Badge } from '@kivacore/ui-pro-shared/components/badge';
|
|
11
|
+
|
|
12
|
+
import { Button } from '@kivacore/ui-pro-shared/components/button';
|
|
13
|
+
import { isDefaultDateFormatContext, useDateFormat } from '@kivacore/ui-pro-shared/hooks/kiva/use-date-format';
|
|
14
|
+
import { useUiTranslation } from '@kivacore/ui-pro-shared/hooks/kiva/use-ui-translation';
|
|
15
|
+
|
|
16
|
+
import { type TCalendarView } from '../types';
|
|
17
|
+
import { type IEvent } from '../interfaces';
|
|
18
|
+
|
|
19
|
+
import { buttonHover, transition } from '../animations';
|
|
20
|
+
import { useCalendar } from '../contexts/calendar-context';
|
|
21
|
+
import {
|
|
22
|
+
getEventsCount,
|
|
23
|
+
navigateDate,
|
|
24
|
+
rangeText
|
|
25
|
+
} from '../helpers';
|
|
26
|
+
import { isTimelineView, timelineRangeTitle } from '../views/timeline/lib/timeline-model';
|
|
27
|
+
|
|
28
|
+
interface IProps {
|
|
29
|
+
view: TCalendarView;
|
|
30
|
+
events: Array<IEvent>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const MotionButton = motion.create(Button);
|
|
34
|
+
const MotionBadge = motion.create(Badge);
|
|
35
|
+
|
|
36
|
+
const monthFormatter = new Intl.DateTimeFormat(undefined, { month: 'long' });
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* What one prev/next step means in each view, so the arrows say where they go
|
|
40
|
+
* ("Next quarter") instead of leaving the user to guess.
|
|
41
|
+
*/
|
|
42
|
+
const NAV_LABELS: Record<TCalendarView, {
|
|
43
|
+
previous: [string, string];
|
|
44
|
+
next: [string, string];
|
|
45
|
+
}> = {
|
|
46
|
+
day: {
|
|
47
|
+
previous: ['ui.calendar.previousDay', 'Previous day'],
|
|
48
|
+
next: ['ui.calendar.nextDay', 'Next day']
|
|
49
|
+
},
|
|
50
|
+
week: {
|
|
51
|
+
previous: ['ui.calendar.previousWeek', 'Previous week'],
|
|
52
|
+
next: ['ui.calendar.nextWeek', 'Next week']
|
|
53
|
+
},
|
|
54
|
+
month: {
|
|
55
|
+
previous: ['ui.calendar.previousMonth', 'Previous month'],
|
|
56
|
+
next: ['ui.calendar.nextMonth', 'Next month']
|
|
57
|
+
},
|
|
58
|
+
agenda: {
|
|
59
|
+
previous: ['ui.calendar.previousMonth', 'Previous month'],
|
|
60
|
+
next: ['ui.calendar.nextMonth', 'Next month']
|
|
61
|
+
},
|
|
62
|
+
year: {
|
|
63
|
+
previous: ['ui.calendar.previousYear', 'Previous year'],
|
|
64
|
+
next: ['ui.calendar.nextYear', 'Next year']
|
|
65
|
+
},
|
|
66
|
+
'year-timeline': {
|
|
67
|
+
previous: ['ui.calendar.previousYear', 'Previous year'],
|
|
68
|
+
next: ['ui.calendar.nextYear', 'Next year']
|
|
69
|
+
},
|
|
70
|
+
quarter: {
|
|
71
|
+
previous: ['ui.calendar.previousQuarter', 'Previous quarter'],
|
|
72
|
+
next: ['ui.calendar.nextQuarter', 'Next quarter']
|
|
73
|
+
},
|
|
74
|
+
'13weeks': {
|
|
75
|
+
previous: ['ui.calendar.previousPeriod', 'Previous period'],
|
|
76
|
+
next: ['ui.calendar.nextPeriod', 'Next period']
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export function DateNavigator({ view, events }: IProps) {
|
|
81
|
+
const {
|
|
82
|
+
selectedDate,
|
|
83
|
+
setSelectedDate,
|
|
84
|
+
hideEventCount,
|
|
85
|
+
eventCountLabel,
|
|
86
|
+
weekStartsOn,
|
|
87
|
+
timelineRange
|
|
88
|
+
} = useCalendar();
|
|
89
|
+
const dateFormat = useDateFormat();
|
|
90
|
+
const { t } = useUiTranslation();
|
|
91
|
+
|
|
92
|
+
/*
|
|
93
|
+
* Without a `<DateFormatProvider>` the context formatter is the raw-string
|
|
94
|
+
* fallback, which would print an ISO timestamp in the range label — pass
|
|
95
|
+
* `undefined` instead so `rangeText` uses its own `MMM d, yyyy` format.
|
|
96
|
+
*/
|
|
97
|
+
const formatDate = isDefaultDateFormatContext(dateFormat) ? undefined : dateFormat.formatDate;
|
|
98
|
+
|
|
99
|
+
const month = monthFormatter.format(selectedDate);
|
|
100
|
+
const year = selectedDate.getFullYear();
|
|
101
|
+
|
|
102
|
+
/* Timeline views span periods, so their title comes from the rendered window. */
|
|
103
|
+
const isTimeline = isTimelineView(view);
|
|
104
|
+
const countRange = isTimeline ? timelineRange : null;
|
|
105
|
+
let title = `${month} ${year}`;
|
|
106
|
+
|
|
107
|
+
if (isTimeline) title = timelineRangeTitle(view, selectedDate, timelineRange, weekStartsOn);
|
|
108
|
+
|
|
109
|
+
const navLabels = NAV_LABELS[view];
|
|
110
|
+
const previousLabel = t(...navLabels.previous);
|
|
111
|
+
const nextLabel = t(...navLabels.next);
|
|
112
|
+
|
|
113
|
+
const eventCount = useMemo(
|
|
114
|
+
() => getEventsCount(events, selectedDate, view, countRange),
|
|
115
|
+
[
|
|
116
|
+
events,
|
|
117
|
+
selectedDate,
|
|
118
|
+
view,
|
|
119
|
+
countRange
|
|
120
|
+
]
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
const handlePrevious = () => setSelectedDate(navigateDate(selectedDate, view, 'previous'));
|
|
124
|
+
const handleNext = () => setSelectedDate(navigateDate(selectedDate, view, 'next'));
|
|
125
|
+
|
|
126
|
+
return (
|
|
127
|
+
<div className="space-y-0.5">
|
|
128
|
+
<div className="flex items-center gap-2">
|
|
129
|
+
<motion.span
|
|
130
|
+
className="text-lg font-semibold"
|
|
131
|
+
initial={{ x: -20, opacity: 0 }}
|
|
132
|
+
animate={{ x: 0, opacity: 1 }}
|
|
133
|
+
transition={transition}>
|
|
134
|
+
{title}
|
|
135
|
+
</motion.span>
|
|
136
|
+
{!hideEventCount && (
|
|
137
|
+
<AnimatePresence mode="wait">
|
|
138
|
+
<MotionBadge
|
|
139
|
+
key={eventCount}
|
|
140
|
+
variant="secondary"
|
|
141
|
+
initial={{ scale: 0.8, opacity: 0 }}
|
|
142
|
+
animate={{ scale: 1, opacity: 1 }}
|
|
143
|
+
exit={{ scale: 0.8, opacity: 0 }}
|
|
144
|
+
transition={transition}>
|
|
145
|
+
{eventCount} {eventCountLabel ?? 'events'}
|
|
146
|
+
</MotionBadge>
|
|
147
|
+
</AnimatePresence>
|
|
148
|
+
)}
|
|
149
|
+
</div>
|
|
150
|
+
|
|
151
|
+
<div className="flex items-center gap-2">
|
|
152
|
+
<MotionButton
|
|
153
|
+
variant="outline"
|
|
154
|
+
size="icon"
|
|
155
|
+
className="size-6"
|
|
156
|
+
aria-label={previousLabel}
|
|
157
|
+
title={previousLabel}
|
|
158
|
+
onClick={handlePrevious}
|
|
159
|
+
variants={buttonHover}
|
|
160
|
+
whileHover="hover"
|
|
161
|
+
whileTap="tap">
|
|
162
|
+
<ChevronLeft className="size-4" />
|
|
163
|
+
</MotionButton>
|
|
164
|
+
|
|
165
|
+
<motion.p
|
|
166
|
+
className="text-sm text-muted-foreground"
|
|
167
|
+
initial={{ opacity: 0 }}
|
|
168
|
+
animate={{ opacity: 1 }}
|
|
169
|
+
transition={transition}>
|
|
170
|
+
{rangeText(view, selectedDate, formatDate, weekStartsOn)}
|
|
171
|
+
</motion.p>
|
|
172
|
+
|
|
173
|
+
<MotionButton
|
|
174
|
+
variant="outline"
|
|
175
|
+
size="icon"
|
|
176
|
+
className="size-6"
|
|
177
|
+
aria-label={nextLabel}
|
|
178
|
+
title={nextLabel}
|
|
179
|
+
onClick={handleNext}
|
|
180
|
+
variants={buttonHover}
|
|
181
|
+
whileHover="hover"
|
|
182
|
+
whileTap="tap">
|
|
183
|
+
<ChevronRight className="size-4" />
|
|
184
|
+
</MotionButton>
|
|
185
|
+
</div>
|
|
186
|
+
</div>
|
|
187
|
+
);
|
|
188
|
+
}
|