@umituz/web-dashboard 8.6.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 +137 -7
- package/src/domains/calendar/components/Calendar.test.tsx +20 -0
- package/src/domains/calendar/components/Calendar.tsx +23 -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 +3 -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",
|
|
@@ -67,42 +67,48 @@
|
|
|
67
67
|
|
|
68
68
|
.udb-cal-dot--primary,
|
|
69
69
|
.udb-cal-chip--primary,
|
|
70
|
-
.udb-cal-event--primary
|
|
70
|
+
.udb-cal-event--primary,
|
|
71
|
+
.udb-cal-agenda-item--primary {
|
|
71
72
|
background: color-mix(in srgb, var(--color-primary, #2563eb) 12%, transparent);
|
|
72
73
|
color: var(--color-primary, #2563eb);
|
|
73
74
|
}
|
|
74
75
|
|
|
75
76
|
.udb-cal-dot--success,
|
|
76
77
|
.udb-cal-chip--success,
|
|
77
|
-
.udb-cal-event--success
|
|
78
|
+
.udb-cal-event--success,
|
|
79
|
+
.udb-cal-agenda-item--success {
|
|
78
80
|
background: color-mix(in srgb, var(--color-success, #16a34a) 12%, transparent);
|
|
79
81
|
color: var(--color-success, #16a34a);
|
|
80
82
|
}
|
|
81
83
|
|
|
82
84
|
.udb-cal-dot--warning,
|
|
83
85
|
.udb-cal-chip--warning,
|
|
84
|
-
.udb-cal-event--warning
|
|
86
|
+
.udb-cal-event--warning,
|
|
87
|
+
.udb-cal-agenda-item--warning {
|
|
85
88
|
background: color-mix(in srgb, var(--color-warning, #d97706) 16%, transparent);
|
|
86
89
|
color: var(--color-warning, #d97706);
|
|
87
90
|
}
|
|
88
91
|
|
|
89
92
|
.udb-cal-dot--danger,
|
|
90
93
|
.udb-cal-chip--danger,
|
|
91
|
-
.udb-cal-event--danger
|
|
94
|
+
.udb-cal-event--danger,
|
|
95
|
+
.udb-cal-agenda-item--danger {
|
|
92
96
|
background: color-mix(in srgb, var(--color-destructive, #dc2626) 12%, transparent);
|
|
93
97
|
color: var(--color-destructive, #dc2626);
|
|
94
98
|
}
|
|
95
99
|
|
|
96
100
|
.udb-cal-dot--info,
|
|
97
101
|
.udb-cal-chip--info,
|
|
98
|
-
.udb-cal-event--info
|
|
102
|
+
.udb-cal-event--info,
|
|
103
|
+
.udb-cal-agenda-item--info {
|
|
99
104
|
background: color-mix(in srgb, var(--color-info, #0891b2) 12%, transparent);
|
|
100
105
|
color: var(--color-info, #0891b2);
|
|
101
106
|
}
|
|
102
107
|
|
|
103
108
|
.udb-cal-dot--accent,
|
|
104
109
|
.udb-cal-chip--accent,
|
|
105
|
-
.udb-cal-event--accent
|
|
110
|
+
.udb-cal-event--accent,
|
|
111
|
+
.udb-cal-agenda-item--accent {
|
|
106
112
|
background: color-mix(in srgb, var(--color-accent, #7c3aed) 12%, transparent);
|
|
107
113
|
color: var(--color-accent, #7c3aed);
|
|
108
114
|
}
|
|
@@ -112,7 +118,8 @@
|
|
|
112
118
|
}
|
|
113
119
|
|
|
114
120
|
.udb-cal-chip--neutral,
|
|
115
|
-
.udb-cal-event--neutral
|
|
121
|
+
.udb-cal-event--neutral,
|
|
122
|
+
.udb-cal-agenda-item--neutral {
|
|
116
123
|
background: var(--color-secondary, #f1f5f9);
|
|
117
124
|
color: var(--color-secondary-foreground, #334155);
|
|
118
125
|
}
|
|
@@ -340,3 +347,126 @@
|
|
|
340
347
|
margin: 0;
|
|
341
348
|
color: var(--color-muted-foreground, #94a3b8);
|
|
342
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
|
+
}
|
|
@@ -71,4 +71,24 @@ describe('Calendar', () => {
|
|
|
71
71
|
const extra = screen.getByText('4 appointments').closest('.udb-cal-extra');
|
|
72
72
|
expect(extra).toBeTruthy();
|
|
73
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
|
+
});
|
|
74
94
|
});
|
|
@@ -16,12 +16,14 @@ import {
|
|
|
16
16
|
DEFAULT_MAX_PER_DAY,
|
|
17
17
|
addDaysKey,
|
|
18
18
|
addMonthsKey,
|
|
19
|
+
formatAgendaTitle,
|
|
19
20
|
formatDayTitle,
|
|
20
21
|
formatMonthTitle,
|
|
21
22
|
formatWeekTitle,
|
|
22
23
|
todayKey,
|
|
23
24
|
weekDays,
|
|
24
25
|
} from '../utils/layout';
|
|
26
|
+
import { CalendarAgenda } from './CalendarAgenda';
|
|
25
27
|
import { CalendarMonth } from './CalendarMonth';
|
|
26
28
|
import { CalendarTimeGrid } from './CalendarTimeGrid';
|
|
27
29
|
|
|
@@ -37,10 +39,12 @@ export interface CalendarProps {
|
|
|
37
39
|
dayStartMin?: number;
|
|
38
40
|
dayEndMin?: number;
|
|
39
41
|
maxPerDay?: number;
|
|
42
|
+
agendaDays?: number;
|
|
40
43
|
locale?: string;
|
|
41
44
|
labels?: Partial<CalendarLabels>;
|
|
42
45
|
legend?: readonly CalendarLegendEntry[];
|
|
43
46
|
toolbarExtra?: ReactNode;
|
|
47
|
+
emptyState?: ReactNode;
|
|
44
48
|
onSelectItem?: (item: CalendarItem) => void;
|
|
45
49
|
onSelectDay?: (dayKey: string) => void;
|
|
46
50
|
onSlotClick?: (dayKey: string, minutes: number) => void;
|
|
@@ -59,10 +63,12 @@ export const Calendar = ({
|
|
|
59
63
|
dayStartMin = DEFAULT_DAY_START_MIN,
|
|
60
64
|
dayEndMin = DEFAULT_DAY_END_MIN,
|
|
61
65
|
maxPerDay = DEFAULT_MAX_PER_DAY,
|
|
66
|
+
agendaDays = 30,
|
|
62
67
|
locale = 'en-US',
|
|
63
68
|
labels,
|
|
64
69
|
legend,
|
|
65
70
|
toolbarExtra,
|
|
71
|
+
emptyState,
|
|
66
72
|
onSelectItem,
|
|
67
73
|
onSelectDay,
|
|
68
74
|
onSlotClick,
|
|
@@ -87,14 +93,16 @@ export const Calendar = ({
|
|
|
87
93
|
const shift = (direction: number) => {
|
|
88
94
|
if (activeView === 'month') applyCursor(addMonthsKey(activeCursor, direction));
|
|
89
95
|
else if (activeView === 'week') applyCursor(addDaysKey(activeCursor, direction * 7));
|
|
96
|
+
else if (activeView === 'agenda') applyCursor(addDaysKey(activeCursor, direction * agendaDays));
|
|
90
97
|
else applyCursor(addDaysKey(activeCursor, direction));
|
|
91
98
|
};
|
|
92
99
|
|
|
93
100
|
const title = useMemo(() => {
|
|
94
101
|
if (activeView === 'day') return formatDayTitle(activeCursor, locale);
|
|
95
102
|
if (activeView === 'week') return formatWeekTitle(activeCursor, locale);
|
|
103
|
+
if (activeView === 'agenda') return formatAgendaTitle(activeCursor, agendaDays, locale);
|
|
96
104
|
return formatMonthTitle(activeCursor, locale);
|
|
97
|
-
}, [activeView, activeCursor, locale]);
|
|
105
|
+
}, [activeView, activeCursor, agendaDays, locale]);
|
|
98
106
|
|
|
99
107
|
const handleSelectDay = (dayKey: string) => {
|
|
100
108
|
applyCursor(dayKey);
|
|
@@ -167,6 +175,7 @@ export const Calendar = ({
|
|
|
167
175
|
dayEndMin={dayEndMin}
|
|
168
176
|
locale={locale}
|
|
169
177
|
labels={labels}
|
|
178
|
+
emptyState={emptyState}
|
|
170
179
|
onSelectItem={onSelectItem}
|
|
171
180
|
onSlotClick={onSlotClick}
|
|
172
181
|
/>
|
|
@@ -180,10 +189,23 @@ export const Calendar = ({
|
|
|
180
189
|
dayEndMin={dayEndMin}
|
|
181
190
|
locale={locale}
|
|
182
191
|
labels={labels}
|
|
192
|
+
emptyState={emptyState}
|
|
183
193
|
onSelectItem={onSelectItem}
|
|
184
194
|
onSlotClick={onSlotClick}
|
|
185
195
|
/>
|
|
186
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
|
+
)}
|
|
187
209
|
</div>
|
|
188
210
|
);
|
|
189
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;
|
|
@@ -30,6 +30,7 @@ export interface CalendarLabels {
|
|
|
30
30
|
month: string;
|
|
31
31
|
week: string;
|
|
32
32
|
day: string;
|
|
33
|
+
agenda: string;
|
|
33
34
|
more: string;
|
|
34
35
|
emptyDay: string;
|
|
35
36
|
}
|
|
@@ -41,6 +42,7 @@ export const DEFAULT_CALENDAR_LABELS: CalendarLabels = {
|
|
|
41
42
|
month: 'Month',
|
|
42
43
|
week: 'Week',
|
|
43
44
|
day: 'Day',
|
|
45
|
+
agenda: 'Agenda',
|
|
44
46
|
more: '+{count} more',
|
|
45
47
|
emptyDay: 'Nothing scheduled',
|
|
46
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)}`;
|