@umituz/web-dashboard 8.5.0 → 8.7.0
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 +1 -1
- package/src/domains/calendar/calendar.css +144 -7
- package/src/domains/calendar/components/Calendar.test.tsx +26 -0
- package/src/domains/calendar/components/Calendar.tsx +27 -1
- package/src/domains/calendar/components/CalendarAgenda.test.tsx +73 -0
- package/src/domains/calendar/components/CalendarAgenda.tsx +105 -0
- package/src/domains/calendar/components/CalendarTimeGrid.tsx +5 -4
- package/src/domains/calendar/components/index.ts +2 -0
- package/src/domains/calendar/types/view.types.ts +4 -1
- package/src/domains/calendar/utils/layout.ts +11 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/web-dashboard",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.7.0",
|
|
4
4
|
"description": "Installable app skeleton for the fleet — layouts, analytics (dependency-free SVG charts), calendar, onboarding flow permissions/module registry; udb-* stylesheet on design-system tokens",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -37,6 +37,13 @@
|
|
|
37
37
|
gap: var(--udb-space-3, 12px);
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
.udb-cal-extra {
|
|
41
|
+
display: flex;
|
|
42
|
+
flex-wrap: wrap;
|
|
43
|
+
align-items: center;
|
|
44
|
+
gap: var(--udb-space-2, 8px);
|
|
45
|
+
}
|
|
46
|
+
|
|
40
47
|
.udb-cal-legend {
|
|
41
48
|
display: flex;
|
|
42
49
|
flex-wrap: wrap;
|
|
@@ -60,42 +67,48 @@
|
|
|
60
67
|
|
|
61
68
|
.udb-cal-dot--primary,
|
|
62
69
|
.udb-cal-chip--primary,
|
|
63
|
-
.udb-cal-event--primary
|
|
70
|
+
.udb-cal-event--primary,
|
|
71
|
+
.udb-cal-agenda-item--primary {
|
|
64
72
|
background: color-mix(in srgb, var(--color-primary, #2563eb) 12%, transparent);
|
|
65
73
|
color: var(--color-primary, #2563eb);
|
|
66
74
|
}
|
|
67
75
|
|
|
68
76
|
.udb-cal-dot--success,
|
|
69
77
|
.udb-cal-chip--success,
|
|
70
|
-
.udb-cal-event--success
|
|
78
|
+
.udb-cal-event--success,
|
|
79
|
+
.udb-cal-agenda-item--success {
|
|
71
80
|
background: color-mix(in srgb, var(--color-success, #16a34a) 12%, transparent);
|
|
72
81
|
color: var(--color-success, #16a34a);
|
|
73
82
|
}
|
|
74
83
|
|
|
75
84
|
.udb-cal-dot--warning,
|
|
76
85
|
.udb-cal-chip--warning,
|
|
77
|
-
.udb-cal-event--warning
|
|
86
|
+
.udb-cal-event--warning,
|
|
87
|
+
.udb-cal-agenda-item--warning {
|
|
78
88
|
background: color-mix(in srgb, var(--color-warning, #d97706) 16%, transparent);
|
|
79
89
|
color: var(--color-warning, #d97706);
|
|
80
90
|
}
|
|
81
91
|
|
|
82
92
|
.udb-cal-dot--danger,
|
|
83
93
|
.udb-cal-chip--danger,
|
|
84
|
-
.udb-cal-event--danger
|
|
94
|
+
.udb-cal-event--danger,
|
|
95
|
+
.udb-cal-agenda-item--danger {
|
|
85
96
|
background: color-mix(in srgb, var(--color-destructive, #dc2626) 12%, transparent);
|
|
86
97
|
color: var(--color-destructive, #dc2626);
|
|
87
98
|
}
|
|
88
99
|
|
|
89
100
|
.udb-cal-dot--info,
|
|
90
101
|
.udb-cal-chip--info,
|
|
91
|
-
.udb-cal-event--info
|
|
102
|
+
.udb-cal-event--info,
|
|
103
|
+
.udb-cal-agenda-item--info {
|
|
92
104
|
background: color-mix(in srgb, var(--color-info, #0891b2) 12%, transparent);
|
|
93
105
|
color: var(--color-info, #0891b2);
|
|
94
106
|
}
|
|
95
107
|
|
|
96
108
|
.udb-cal-dot--accent,
|
|
97
109
|
.udb-cal-chip--accent,
|
|
98
|
-
.udb-cal-event--accent
|
|
110
|
+
.udb-cal-event--accent,
|
|
111
|
+
.udb-cal-agenda-item--accent {
|
|
99
112
|
background: color-mix(in srgb, var(--color-accent, #7c3aed) 12%, transparent);
|
|
100
113
|
color: var(--color-accent, #7c3aed);
|
|
101
114
|
}
|
|
@@ -105,7 +118,8 @@
|
|
|
105
118
|
}
|
|
106
119
|
|
|
107
120
|
.udb-cal-chip--neutral,
|
|
108
|
-
.udb-cal-event--neutral
|
|
121
|
+
.udb-cal-event--neutral,
|
|
122
|
+
.udb-cal-agenda-item--neutral {
|
|
109
123
|
background: var(--color-secondary, #f1f5f9);
|
|
110
124
|
color: var(--color-secondary-foreground, #334155);
|
|
111
125
|
}
|
|
@@ -333,3 +347,126 @@
|
|
|
333
347
|
margin: 0;
|
|
334
348
|
color: var(--color-muted-foreground, #94a3b8);
|
|
335
349
|
}
|
|
350
|
+
|
|
351
|
+
.udb-cal-agenda {
|
|
352
|
+
display: flex;
|
|
353
|
+
flex-direction: column;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
.udb-cal-agenda-group + .udb-cal-agenda-group {
|
|
357
|
+
border-top: 1px solid var(--color-border, #e2e8f0);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
.udb-cal-agenda-group.is-today .udb-cal-agenda-head {
|
|
361
|
+
background: color-mix(in srgb, var(--color-primary, #2563eb) 7%, transparent);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
.udb-cal-agenda-head {
|
|
365
|
+
display: flex;
|
|
366
|
+
align-items: center;
|
|
367
|
+
gap: var(--udb-space-2, 8px);
|
|
368
|
+
padding: 8px 14px;
|
|
369
|
+
border-bottom: 1px solid var(--color-border, #eef2f7);
|
|
370
|
+
background: color-mix(in srgb, var(--color-muted, #f8fafc) 60%, transparent);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
.udb-cal-agenda-date {
|
|
374
|
+
font-size: var(--udb-font-size-sm, 12px);
|
|
375
|
+
font-weight: 600;
|
|
376
|
+
color: var(--color-foreground, #0f172a);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
.udb-cal-agenda-today {
|
|
380
|
+
padding: 1px 7px;
|
|
381
|
+
border-radius: 9999px;
|
|
382
|
+
background: var(--color-primary, #2563eb);
|
|
383
|
+
font-size: 10px;
|
|
384
|
+
font-weight: 600;
|
|
385
|
+
text-transform: uppercase;
|
|
386
|
+
letter-spacing: 0.04em;
|
|
387
|
+
color: var(--color-primary-foreground, #ffffff);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
.udb-cal-agenda-count {
|
|
391
|
+
margin-left: auto;
|
|
392
|
+
font-size: var(--udb-font-size-xs, 11px);
|
|
393
|
+
color: var(--color-muted-foreground, #64748b);
|
|
394
|
+
font-variant-numeric: tabular-nums;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
.udb-cal-agenda-rows {
|
|
398
|
+
display: flex;
|
|
399
|
+
flex-direction: column;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
.udb-cal-agenda-item {
|
|
403
|
+
display: grid;
|
|
404
|
+
grid-template-columns: 5.5rem 10px minmax(0, 1fr);
|
|
405
|
+
align-items: start;
|
|
406
|
+
gap: var(--udb-space-2, 8px);
|
|
407
|
+
width: 100%;
|
|
408
|
+
padding: 8px 14px;
|
|
409
|
+
border: none;
|
|
410
|
+
border-left: 3px solid currentColor;
|
|
411
|
+
background: transparent;
|
|
412
|
+
text-align: left;
|
|
413
|
+
font-size: var(--udb-font-size-sm, 12px);
|
|
414
|
+
cursor: pointer;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
.udb-cal-agenda-item + .udb-cal-agenda-item {
|
|
418
|
+
border-top: 1px solid var(--color-border, #eef2f7);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
.udb-cal-agenda-item.is-muted {
|
|
422
|
+
opacity: 0.45;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
.udb-cal-agenda-item:focus-visible {
|
|
426
|
+
outline: 2px solid var(--color-ring, #2563eb);
|
|
427
|
+
outline-offset: -2px;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
.udb-cal-agenda-time {
|
|
431
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
|
|
432
|
+
font-size: 11px;
|
|
433
|
+
line-height: 1.45;
|
|
434
|
+
color: var(--color-muted-foreground, #64748b);
|
|
435
|
+
font-variant-numeric: tabular-nums;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
.udb-cal-agenda-time-end {
|
|
439
|
+
display: block;
|
|
440
|
+
opacity: 0.75;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
.udb-cal-agenda-body {
|
|
444
|
+
display: flex;
|
|
445
|
+
flex-direction: column;
|
|
446
|
+
gap: 2px;
|
|
447
|
+
min-width: 0;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
.udb-cal-agenda-title {
|
|
451
|
+
display: flex;
|
|
452
|
+
align-items: center;
|
|
453
|
+
gap: 6px;
|
|
454
|
+
font-weight: 600;
|
|
455
|
+
color: var(--color-foreground, #0f172a);
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
.udb-cal-agenda-meta {
|
|
459
|
+
font-size: var(--udb-font-size-xs, 11px);
|
|
460
|
+
color: var(--color-muted-foreground, #64748b);
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
.udb-cal-agenda-empty {
|
|
464
|
+
display: grid;
|
|
465
|
+
place-items: center;
|
|
466
|
+
padding: 48px 16px;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
.udb-cal-agenda-empty-text {
|
|
470
|
+
margin: 0;
|
|
471
|
+
color: var(--color-muted-foreground, #94a3b8);
|
|
472
|
+
}
|
|
@@ -65,4 +65,30 @@ describe('Calendar', () => {
|
|
|
65
65
|
mount({ legend: [{ tone: 'success', label: 'Confirmed' }] });
|
|
66
66
|
expect(screen.getByText('Confirmed')).toBeTruthy();
|
|
67
67
|
});
|
|
68
|
+
|
|
69
|
+
it('renders toolbar extras inside the toolbar', () => {
|
|
70
|
+
mount({ toolbarExtra: <span className="calendar-count">4 appointments</span> });
|
|
71
|
+
const extra = screen.getByText('4 appointments').closest('.udb-cal-extra');
|
|
72
|
+
expect(extra).toBeTruthy();
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('switches to the agenda view with a window title', () => {
|
|
76
|
+
mount({ views: ['month', 'agenda'] });
|
|
77
|
+
fireEvent.click(screen.getByText('Agenda'));
|
|
78
|
+
expect(screen.getByText('Mar 10 – Apr 8, 2026')).toBeTruthy();
|
|
79
|
+
expect(screen.getByRole('button', { name: /Kickoff/ })).toBeTruthy();
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('shifts the agenda window by agendaDays', () => {
|
|
83
|
+
render(
|
|
84
|
+
<Calendar
|
|
85
|
+
items={[item('Kickoff', '2026-03-15', 600, 660)]}
|
|
86
|
+
initialCursor="2026-03-10"
|
|
87
|
+
views={['agenda']}
|
|
88
|
+
agendaDays={30}
|
|
89
|
+
/>,
|
|
90
|
+
);
|
|
91
|
+
fireEvent.click(screen.getByRole('button', { name: 'Next' }));
|
|
92
|
+
expect(screen.getByText('Apr 9 – May 8, 2026')).toBeTruthy();
|
|
93
|
+
});
|
|
68
94
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useMemo, useState } from 'react';
|
|
2
|
+
import type { ReactNode } from 'react';
|
|
2
3
|
import { ChevronLeft, ChevronRight } from 'lucide-react';
|
|
3
4
|
import { Button, IconButton } from '@umituz/web-design-system/atoms';
|
|
4
5
|
import { Segmented } from '@umituz/web-design-system/molecules';
|
|
@@ -15,12 +16,14 @@ import {
|
|
|
15
16
|
DEFAULT_MAX_PER_DAY,
|
|
16
17
|
addDaysKey,
|
|
17
18
|
addMonthsKey,
|
|
19
|
+
formatAgendaTitle,
|
|
18
20
|
formatDayTitle,
|
|
19
21
|
formatMonthTitle,
|
|
20
22
|
formatWeekTitle,
|
|
21
23
|
todayKey,
|
|
22
24
|
weekDays,
|
|
23
25
|
} from '../utils/layout';
|
|
26
|
+
import { CalendarAgenda } from './CalendarAgenda';
|
|
24
27
|
import { CalendarMonth } from './CalendarMonth';
|
|
25
28
|
import { CalendarTimeGrid } from './CalendarTimeGrid';
|
|
26
29
|
|
|
@@ -36,9 +39,12 @@ export interface CalendarProps {
|
|
|
36
39
|
dayStartMin?: number;
|
|
37
40
|
dayEndMin?: number;
|
|
38
41
|
maxPerDay?: number;
|
|
42
|
+
agendaDays?: number;
|
|
39
43
|
locale?: string;
|
|
40
44
|
labels?: Partial<CalendarLabels>;
|
|
41
45
|
legend?: readonly CalendarLegendEntry[];
|
|
46
|
+
toolbarExtra?: ReactNode;
|
|
47
|
+
emptyState?: ReactNode;
|
|
42
48
|
onSelectItem?: (item: CalendarItem) => void;
|
|
43
49
|
onSelectDay?: (dayKey: string) => void;
|
|
44
50
|
onSlotClick?: (dayKey: string, minutes: number) => void;
|
|
@@ -57,9 +63,12 @@ export const Calendar = ({
|
|
|
57
63
|
dayStartMin = DEFAULT_DAY_START_MIN,
|
|
58
64
|
dayEndMin = DEFAULT_DAY_END_MIN,
|
|
59
65
|
maxPerDay = DEFAULT_MAX_PER_DAY,
|
|
66
|
+
agendaDays = 30,
|
|
60
67
|
locale = 'en-US',
|
|
61
68
|
labels,
|
|
62
69
|
legend,
|
|
70
|
+
toolbarExtra,
|
|
71
|
+
emptyState,
|
|
63
72
|
onSelectItem,
|
|
64
73
|
onSelectDay,
|
|
65
74
|
onSlotClick,
|
|
@@ -84,14 +93,16 @@ export const Calendar = ({
|
|
|
84
93
|
const shift = (direction: number) => {
|
|
85
94
|
if (activeView === 'month') applyCursor(addMonthsKey(activeCursor, direction));
|
|
86
95
|
else if (activeView === 'week') applyCursor(addDaysKey(activeCursor, direction * 7));
|
|
96
|
+
else if (activeView === 'agenda') applyCursor(addDaysKey(activeCursor, direction * agendaDays));
|
|
87
97
|
else applyCursor(addDaysKey(activeCursor, direction));
|
|
88
98
|
};
|
|
89
99
|
|
|
90
100
|
const title = useMemo(() => {
|
|
91
101
|
if (activeView === 'day') return formatDayTitle(activeCursor, locale);
|
|
92
102
|
if (activeView === 'week') return formatWeekTitle(activeCursor, locale);
|
|
103
|
+
if (activeView === 'agenda') return formatAgendaTitle(activeCursor, agendaDays, locale);
|
|
93
104
|
return formatMonthTitle(activeCursor, locale);
|
|
94
|
-
}, [activeView, activeCursor, locale]);
|
|
105
|
+
}, [activeView, activeCursor, agendaDays, locale]);
|
|
95
106
|
|
|
96
107
|
const handleSelectDay = (dayKey: string) => {
|
|
97
108
|
applyCursor(dayKey);
|
|
@@ -123,6 +134,7 @@ export const Calendar = ({
|
|
|
123
134
|
</Button>
|
|
124
135
|
</div>
|
|
125
136
|
<div className="udb-cal-toolbar-side">
|
|
137
|
+
{toolbarExtra && <div className="udb-cal-extra">{toolbarExtra}</div>}
|
|
126
138
|
{legend && legend.length > 0 && (
|
|
127
139
|
<div className="udb-cal-legend">
|
|
128
140
|
{legend.map((entry) => (
|
|
@@ -163,6 +175,7 @@ export const Calendar = ({
|
|
|
163
175
|
dayEndMin={dayEndMin}
|
|
164
176
|
locale={locale}
|
|
165
177
|
labels={labels}
|
|
178
|
+
emptyState={emptyState}
|
|
166
179
|
onSelectItem={onSelectItem}
|
|
167
180
|
onSlotClick={onSlotClick}
|
|
168
181
|
/>
|
|
@@ -176,10 +189,23 @@ export const Calendar = ({
|
|
|
176
189
|
dayEndMin={dayEndMin}
|
|
177
190
|
locale={locale}
|
|
178
191
|
labels={labels}
|
|
192
|
+
emptyState={emptyState}
|
|
179
193
|
onSelectItem={onSelectItem}
|
|
180
194
|
onSlotClick={onSlotClick}
|
|
181
195
|
/>
|
|
182
196
|
)}
|
|
197
|
+
|
|
198
|
+
{activeView === 'agenda' && (
|
|
199
|
+
<CalendarAgenda
|
|
200
|
+
items={items}
|
|
201
|
+
anchorKey={activeCursor}
|
|
202
|
+
agendaDays={agendaDays}
|
|
203
|
+
locale={locale}
|
|
204
|
+
labels={labels}
|
|
205
|
+
emptyState={emptyState}
|
|
206
|
+
onSelectItem={onSelectItem}
|
|
207
|
+
/>
|
|
208
|
+
)}
|
|
183
209
|
</div>
|
|
184
210
|
);
|
|
185
211
|
};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { fireEvent, render, screen } from '@testing-library/react';
|
|
3
|
+
import { CalendarAgenda } from './CalendarAgenda';
|
|
4
|
+
import type { CalendarItem } from '../types/view.types';
|
|
5
|
+
import { todayKey } from '../utils/layout';
|
|
6
|
+
|
|
7
|
+
const item = (id: string, dayKey: string, startMin?: number, endMin?: number): CalendarItem => ({
|
|
8
|
+
id,
|
|
9
|
+
dayKey,
|
|
10
|
+
startMin,
|
|
11
|
+
endMin,
|
|
12
|
+
title: id,
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
describe('CalendarAgenda', () => {
|
|
16
|
+
it('groups only days with items inside the window', () => {
|
|
17
|
+
render(
|
|
18
|
+
<CalendarAgenda
|
|
19
|
+
items={[
|
|
20
|
+
item('Kickoff', '2026-03-15', 600, 660),
|
|
21
|
+
item('Beyond', '2026-04-20', 900),
|
|
22
|
+
]}
|
|
23
|
+
anchorKey="2026-03-10"
|
|
24
|
+
agendaDays={30}
|
|
25
|
+
/>,
|
|
26
|
+
);
|
|
27
|
+
expect(screen.getByText('Sunday, March 15, 2026')).toBeTruthy();
|
|
28
|
+
expect(screen.queryByText(/April 20/)).toBeNull();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('marks the today group and counts its items', () => {
|
|
32
|
+
const today = todayKey();
|
|
33
|
+
render(
|
|
34
|
+
<CalendarAgenda
|
|
35
|
+
items={[item('First', today, 540, 600), item('Second', today, 720)]}
|
|
36
|
+
anchorKey={today}
|
|
37
|
+
/>,
|
|
38
|
+
);
|
|
39
|
+
expect(screen.getByText('Today')).toBeTruthy();
|
|
40
|
+
expect(screen.getByText('2')).toBeTruthy();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('fires onSelectItem with the payload-carrying item', () => {
|
|
44
|
+
const onSelectItem = vi.fn();
|
|
45
|
+
render(
|
|
46
|
+
<CalendarAgenda
|
|
47
|
+
items={[item('Kickoff', '2026-03-15', 600, 660)]}
|
|
48
|
+
anchorKey="2026-03-15"
|
|
49
|
+
onSelectItem={onSelectItem}
|
|
50
|
+
/>,
|
|
51
|
+
);
|
|
52
|
+
fireEvent.click(screen.getByRole('button', { name: /Kickoff/ }));
|
|
53
|
+
expect(onSelectItem).toHaveBeenCalledWith(
|
|
54
|
+
expect.objectContaining({ id: 'Kickoff', dayKey: '2026-03-15' }),
|
|
55
|
+
);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('renders a custom empty state when the window has no items', () => {
|
|
59
|
+
render(
|
|
60
|
+
<CalendarAgenda
|
|
61
|
+
items={[]}
|
|
62
|
+
anchorKey="2026-03-10"
|
|
63
|
+
emptyState={<button type="button">Book a shoot day</button>}
|
|
64
|
+
/>,
|
|
65
|
+
);
|
|
66
|
+
expect(screen.getByText('Book a shoot day')).toBeTruthy();
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('falls back to the default empty label', () => {
|
|
70
|
+
render(<CalendarAgenda items={[]} anchorKey="2026-03-10" />);
|
|
71
|
+
expect(screen.getByText('Nothing scheduled')).toBeTruthy();
|
|
72
|
+
});
|
|
73
|
+
});
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import type { ReactNode } from 'react';
|
|
3
|
+
import {
|
|
4
|
+
DEFAULT_CALENDAR_LABELS,
|
|
5
|
+
type CalendarItem,
|
|
6
|
+
type CalendarLabels,
|
|
7
|
+
} from '../types/view.types';
|
|
8
|
+
import {
|
|
9
|
+
addDaysKey,
|
|
10
|
+
formatDayTitle,
|
|
11
|
+
groupByDayKey,
|
|
12
|
+
minutesToLabel,
|
|
13
|
+
todayKey,
|
|
14
|
+
} from '../utils/layout';
|
|
15
|
+
|
|
16
|
+
export interface CalendarAgendaProps {
|
|
17
|
+
items: readonly CalendarItem[];
|
|
18
|
+
anchorKey: string;
|
|
19
|
+
agendaDays?: number;
|
|
20
|
+
locale?: string;
|
|
21
|
+
labels?: Partial<CalendarLabels>;
|
|
22
|
+
emptyState?: ReactNode;
|
|
23
|
+
onSelectItem?: (item: CalendarItem) => void;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const CalendarAgenda = ({
|
|
27
|
+
items,
|
|
28
|
+
anchorKey,
|
|
29
|
+
agendaDays = 30,
|
|
30
|
+
locale = 'en-US',
|
|
31
|
+
labels,
|
|
32
|
+
emptyState,
|
|
33
|
+
onSelectItem,
|
|
34
|
+
}: CalendarAgendaProps) => {
|
|
35
|
+
const text = { ...DEFAULT_CALENDAR_LABELS, ...labels };
|
|
36
|
+
const today = todayKey();
|
|
37
|
+
const windowDays = Math.max(agendaDays, 1);
|
|
38
|
+
|
|
39
|
+
const groups = useMemo(() => {
|
|
40
|
+
const byDay = groupByDayKey(items);
|
|
41
|
+
const window: { dayKey: string; dayItems: CalendarItem[] }[] = [];
|
|
42
|
+
for (let offset = 0; offset < windowDays; offset += 1) {
|
|
43
|
+
const dayKey = addDaysKey(anchorKey, offset);
|
|
44
|
+
const dayItems = byDay.get(dayKey);
|
|
45
|
+
if (dayItems && dayItems.length > 0) window.push({ dayKey, dayItems });
|
|
46
|
+
}
|
|
47
|
+
return window;
|
|
48
|
+
}, [items, anchorKey, windowDays]);
|
|
49
|
+
|
|
50
|
+
if (groups.length === 0) {
|
|
51
|
+
return (
|
|
52
|
+
<div className="udb-cal-agenda-empty">
|
|
53
|
+
{emptyState ?? <p className="udb-cal-agenda-empty-text">{text.emptyDay}</p>}
|
|
54
|
+
</div>
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
<div className="udb-cal-agenda">
|
|
60
|
+
{groups.map(({ dayKey, dayItems }) => (
|
|
61
|
+
<section
|
|
62
|
+
className={
|
|
63
|
+
dayKey === today ? 'udb-cal-agenda-group is-today' : 'udb-cal-agenda-group'
|
|
64
|
+
}
|
|
65
|
+
key={dayKey}
|
|
66
|
+
>
|
|
67
|
+
<header className="udb-cal-agenda-head">
|
|
68
|
+
<span className="udb-cal-agenda-date">{formatDayTitle(dayKey, locale)}</span>
|
|
69
|
+
{dayKey === today && <span className="udb-cal-agenda-today">{text.today}</span>}
|
|
70
|
+
<span className="udb-cal-agenda-count">{dayItems.length}</span>
|
|
71
|
+
</header>
|
|
72
|
+
<div className="udb-cal-agenda-rows">
|
|
73
|
+
{dayItems.map((item) => (
|
|
74
|
+
<button
|
|
75
|
+
type="button"
|
|
76
|
+
key={item.id}
|
|
77
|
+
className={
|
|
78
|
+
item.muted
|
|
79
|
+
? `udb-cal-agenda-item udb-cal-agenda-item--${item.tone ?? 'primary'} is-muted`
|
|
80
|
+
: `udb-cal-agenda-item udb-cal-agenda-item--${item.tone ?? 'primary'}`
|
|
81
|
+
}
|
|
82
|
+
onClick={() => onSelectItem?.(item)}
|
|
83
|
+
>
|
|
84
|
+
<span className="udb-cal-agenda-time">
|
|
85
|
+
{item.startMin !== undefined && minutesToLabel(item.startMin)}
|
|
86
|
+
{item.endMin !== undefined && (
|
|
87
|
+
<span className="udb-cal-agenda-time-end">– {minutesToLabel(item.endMin)}</span>
|
|
88
|
+
)}
|
|
89
|
+
</span>
|
|
90
|
+
<span className={`udb-cal-dot udb-cal-dot--${item.tone ?? 'primary'}`} />
|
|
91
|
+
<span className="udb-cal-agenda-body">
|
|
92
|
+
<span className="udb-cal-agenda-title">
|
|
93
|
+
{item.icon}
|
|
94
|
+
{item.title}
|
|
95
|
+
</span>
|
|
96
|
+
{item.meta && <span className="udb-cal-agenda-meta">{item.meta}</span>}
|
|
97
|
+
</span>
|
|
98
|
+
</button>
|
|
99
|
+
))}
|
|
100
|
+
</div>
|
|
101
|
+
</section>
|
|
102
|
+
))}
|
|
103
|
+
</div>
|
|
104
|
+
);
|
|
105
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useMemo } from 'react';
|
|
2
|
-
import type { CSSProperties, MouseEvent } from 'react';
|
|
2
|
+
import type { CSSProperties, MouseEvent, ReactNode } from 'react';
|
|
3
3
|
import {
|
|
4
4
|
DEFAULT_CALENDAR_LABELS,
|
|
5
5
|
type CalendarItem,
|
|
@@ -26,6 +26,7 @@ export interface CalendarTimeGridProps {
|
|
|
26
26
|
dayEndMin?: number;
|
|
27
27
|
locale?: string;
|
|
28
28
|
labels?: Partial<CalendarLabels>;
|
|
29
|
+
emptyState?: ReactNode;
|
|
29
30
|
onSelectItem?: (item: CalendarItem) => void;
|
|
30
31
|
onSlotClick?: (dayKey: string, minutes: number) => void;
|
|
31
32
|
}
|
|
@@ -37,6 +38,7 @@ export const CalendarTimeGrid = ({
|
|
|
37
38
|
dayEndMin = DEFAULT_DAY_END_MIN,
|
|
38
39
|
locale = 'en-US',
|
|
39
40
|
labels,
|
|
41
|
+
emptyState,
|
|
40
42
|
onSelectItem,
|
|
41
43
|
onSlotClick,
|
|
42
44
|
}: CalendarTimeGridProps) => {
|
|
@@ -131,9 +133,8 @@ export const CalendarTimeGrid = ({
|
|
|
131
133
|
</button>
|
|
132
134
|
);
|
|
133
135
|
})}
|
|
134
|
-
{days.length === 1 && dayItems.length === 0 &&
|
|
135
|
-
<p className="udb-cal-empty">{text.emptyDay}</p>
|
|
136
|
-
)}
|
|
136
|
+
{days.length === 1 && dayItems.length === 0 &&
|
|
137
|
+
(emptyState ?? <p className="udb-cal-empty">{text.emptyDay}</p>)}
|
|
137
138
|
</div>
|
|
138
139
|
</section>
|
|
139
140
|
);
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export { Calendar } from './Calendar';
|
|
2
2
|
export type { CalendarProps } from './Calendar';
|
|
3
|
+
export { CalendarAgenda } from './CalendarAgenda';
|
|
4
|
+
export type { CalendarAgendaProps } from './CalendarAgenda';
|
|
3
5
|
export { CalendarMonth } from './CalendarMonth';
|
|
4
6
|
export type { CalendarMonthProps } from './CalendarMonth';
|
|
5
7
|
export { CalendarTimeGrid } from './CalendarTimeGrid';
|
|
@@ -2,7 +2,7 @@ import type { ReactNode } from 'react';
|
|
|
2
2
|
|
|
3
3
|
export type CalendarTone = 'primary' | 'success' | 'warning' | 'danger' | 'info' | 'neutral' | 'accent';
|
|
4
4
|
|
|
5
|
-
export type CalendarScreenView = 'month' | 'week' | 'day';
|
|
5
|
+
export type CalendarScreenView = 'month' | 'week' | 'day' | 'agenda';
|
|
6
6
|
|
|
7
7
|
export interface CalendarItem {
|
|
8
8
|
id: string;
|
|
@@ -15,6 +15,7 @@ export interface CalendarItem {
|
|
|
15
15
|
meta?: ReactNode;
|
|
16
16
|
kind?: string;
|
|
17
17
|
muted?: boolean;
|
|
18
|
+
payload?: unknown;
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
export interface CalendarLegendEntry {
|
|
@@ -29,6 +30,7 @@ export interface CalendarLabels {
|
|
|
29
30
|
month: string;
|
|
30
31
|
week: string;
|
|
31
32
|
day: string;
|
|
33
|
+
agenda: string;
|
|
32
34
|
more: string;
|
|
33
35
|
emptyDay: string;
|
|
34
36
|
}
|
|
@@ -40,6 +42,7 @@ export const DEFAULT_CALENDAR_LABELS: CalendarLabels = {
|
|
|
40
42
|
month: 'Month',
|
|
41
43
|
week: 'Week',
|
|
42
44
|
day: 'Day',
|
|
45
|
+
agenda: 'Agenda',
|
|
43
46
|
more: '+{count} more',
|
|
44
47
|
emptyDay: 'Nothing scheduled',
|
|
45
48
|
};
|
|
@@ -92,6 +92,17 @@ export function formatDayTitle(dayKey: string, locale = 'en-US'): string {
|
|
|
92
92
|
});
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
+
export function formatAgendaTitle(anchorKey: string, days: number, locale = 'en-US'): string {
|
|
96
|
+
const span = Math.max(days - 1, 0);
|
|
97
|
+
const from = parseDayKey(anchorKey).toLocaleDateString(locale, { month: 'short', day: 'numeric' });
|
|
98
|
+
const to = parseDayKey(addDaysKey(anchorKey, span)).toLocaleDateString(locale, {
|
|
99
|
+
month: 'short',
|
|
100
|
+
day: 'numeric',
|
|
101
|
+
year: 'numeric',
|
|
102
|
+
});
|
|
103
|
+
return `${from} – ${to}`;
|
|
104
|
+
}
|
|
105
|
+
|
|
95
106
|
export function minutesToLabel(minutes: number): string {
|
|
96
107
|
const normalized = ((Math.round(minutes) % DAY_MINUTES) + DAY_MINUTES) % DAY_MINUTES;
|
|
97
108
|
return `${pad(Math.floor(normalized / 60))}:${pad(normalized % 60)}`;
|