@umituz/web-dashboard 8.6.0 → 8.8.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 +316 -8
- 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/CalendarResourceTimeline.test.tsx +93 -0
- package/src/domains/calendar/components/CalendarResourceTimeline.tsx +164 -0
- package/src/domains/calendar/components/CalendarTimeGrid.test.tsx +27 -0
- package/src/domains/calendar/components/CalendarTimeGrid.tsx +50 -11
- package/src/domains/calendar/components/index.ts +7 -0
- package/src/domains/calendar/types/view.types.ts +6 -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.8.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,54 @@
|
|
|
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,
|
|
72
|
+
.udb-cal-res-block--primary {
|
|
71
73
|
background: color-mix(in srgb, var(--color-primary, #2563eb) 12%, transparent);
|
|
72
74
|
color: var(--color-primary, #2563eb);
|
|
73
75
|
}
|
|
74
76
|
|
|
75
77
|
.udb-cal-dot--success,
|
|
76
78
|
.udb-cal-chip--success,
|
|
77
|
-
.udb-cal-event--success
|
|
79
|
+
.udb-cal-event--success,
|
|
80
|
+
.udb-cal-agenda-item--success,
|
|
81
|
+
.udb-cal-res-block--success {
|
|
78
82
|
background: color-mix(in srgb, var(--color-success, #16a34a) 12%, transparent);
|
|
79
83
|
color: var(--color-success, #16a34a);
|
|
80
84
|
}
|
|
81
85
|
|
|
82
86
|
.udb-cal-dot--warning,
|
|
83
87
|
.udb-cal-chip--warning,
|
|
84
|
-
.udb-cal-event--warning
|
|
88
|
+
.udb-cal-event--warning,
|
|
89
|
+
.udb-cal-agenda-item--warning,
|
|
90
|
+
.udb-cal-res-block--warning {
|
|
85
91
|
background: color-mix(in srgb, var(--color-warning, #d97706) 16%, transparent);
|
|
86
92
|
color: var(--color-warning, #d97706);
|
|
87
93
|
}
|
|
88
94
|
|
|
89
95
|
.udb-cal-dot--danger,
|
|
90
96
|
.udb-cal-chip--danger,
|
|
91
|
-
.udb-cal-event--danger
|
|
97
|
+
.udb-cal-event--danger,
|
|
98
|
+
.udb-cal-agenda-item--danger,
|
|
99
|
+
.udb-cal-res-block--danger {
|
|
92
100
|
background: color-mix(in srgb, var(--color-destructive, #dc2626) 12%, transparent);
|
|
93
101
|
color: var(--color-destructive, #dc2626);
|
|
94
102
|
}
|
|
95
103
|
|
|
96
104
|
.udb-cal-dot--info,
|
|
97
105
|
.udb-cal-chip--info,
|
|
98
|
-
.udb-cal-event--info
|
|
106
|
+
.udb-cal-event--info,
|
|
107
|
+
.udb-cal-agenda-item--info,
|
|
108
|
+
.udb-cal-res-block--info {
|
|
99
109
|
background: color-mix(in srgb, var(--color-info, #0891b2) 12%, transparent);
|
|
100
110
|
color: var(--color-info, #0891b2);
|
|
101
111
|
}
|
|
102
112
|
|
|
103
113
|
.udb-cal-dot--accent,
|
|
104
114
|
.udb-cal-chip--accent,
|
|
105
|
-
.udb-cal-event--accent
|
|
115
|
+
.udb-cal-event--accent,
|
|
116
|
+
.udb-cal-agenda-item--accent,
|
|
117
|
+
.udb-cal-res-block--accent {
|
|
106
118
|
background: color-mix(in srgb, var(--color-accent, #7c3aed) 12%, transparent);
|
|
107
119
|
color: var(--color-accent, #7c3aed);
|
|
108
120
|
}
|
|
@@ -112,7 +124,9 @@
|
|
|
112
124
|
}
|
|
113
125
|
|
|
114
126
|
.udb-cal-chip--neutral,
|
|
115
|
-
.udb-cal-event--neutral
|
|
127
|
+
.udb-cal-event--neutral,
|
|
128
|
+
.udb-cal-agenda-item--neutral,
|
|
129
|
+
.udb-cal-res-block--neutral {
|
|
116
130
|
background: var(--color-secondary, #f1f5f9);
|
|
117
131
|
color: var(--color-secondary-foreground, #334155);
|
|
118
132
|
}
|
|
@@ -242,6 +256,55 @@
|
|
|
242
256
|
grid-template-columns: 3.5rem repeat(var(--udb-cal-days, 1), minmax(0, 1fr));
|
|
243
257
|
}
|
|
244
258
|
|
|
259
|
+
.udb-cal-days {
|
|
260
|
+
grid-column: 1 / -1;
|
|
261
|
+
display: grid;
|
|
262
|
+
grid-template-columns: 3.5rem repeat(var(--udb-cal-days, 1), minmax(0, 1fr));
|
|
263
|
+
border-bottom: 1px solid var(--color-border, #e2e8f0);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
.udb-cal-days-corner {
|
|
267
|
+
border-right: 1px solid var(--color-border, #e2e8f0);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
.udb-cal-days .udb-cal-day-head + .udb-cal-day-head {
|
|
271
|
+
border-left: 1px solid var(--color-border, #e2e8f0);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
.udb-cal-allday {
|
|
275
|
+
grid-column: 1 / -1;
|
|
276
|
+
display: grid;
|
|
277
|
+
grid-template-columns: 3.5rem repeat(var(--udb-cal-days, 1), minmax(0, 1fr));
|
|
278
|
+
border-bottom: 1px solid var(--color-border, #e2e8f0);
|
|
279
|
+
background: color-mix(in srgb, var(--color-muted, #f8fafc) 45%, transparent);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
.udb-cal-allday-corner {
|
|
283
|
+
display: flex;
|
|
284
|
+
align-items: center;
|
|
285
|
+
justify-content: flex-end;
|
|
286
|
+
padding-right: 8px;
|
|
287
|
+
border-right: 1px solid var(--color-border, #e2e8f0);
|
|
288
|
+
font-size: var(--udb-font-size-xs, 11px);
|
|
289
|
+
color: var(--color-muted-foreground, #94a3b8);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
.udb-cal-allday-cell {
|
|
293
|
+
display: flex;
|
|
294
|
+
flex-wrap: wrap;
|
|
295
|
+
align-content: center;
|
|
296
|
+
gap: 3px;
|
|
297
|
+
padding: 4px 6px;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
.udb-cal-allday-cell + .udb-cal-allday-cell {
|
|
301
|
+
border-left: 1px solid var(--color-border, #eef2f7);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
.udb-cal-allday-cell .udb-cal-chip {
|
|
305
|
+
max-width: 100%;
|
|
306
|
+
}
|
|
307
|
+
|
|
245
308
|
.udb-cal-gutter {
|
|
246
309
|
position: relative;
|
|
247
310
|
border-right: 1px solid var(--color-border, #e2e8f0);
|
|
@@ -266,7 +329,6 @@
|
|
|
266
329
|
justify-content: center;
|
|
267
330
|
gap: 6px;
|
|
268
331
|
padding: 8px 4px;
|
|
269
|
-
border-bottom: 1px solid var(--color-border, #e2e8f0);
|
|
270
332
|
}
|
|
271
333
|
|
|
272
334
|
.udb-cal-day-head.is-today .udb-cal-daynum {
|
|
@@ -340,3 +402,249 @@
|
|
|
340
402
|
margin: 0;
|
|
341
403
|
color: var(--color-muted-foreground, #94a3b8);
|
|
342
404
|
}
|
|
405
|
+
|
|
406
|
+
.udb-cal-agenda {
|
|
407
|
+
display: flex;
|
|
408
|
+
flex-direction: column;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
.udb-cal-agenda-group + .udb-cal-agenda-group {
|
|
412
|
+
border-top: 1px solid var(--color-border, #e2e8f0);
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
.udb-cal-agenda-group.is-today .udb-cal-agenda-head {
|
|
416
|
+
background: color-mix(in srgb, var(--color-primary, #2563eb) 7%, transparent);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
.udb-cal-agenda-head {
|
|
420
|
+
display: flex;
|
|
421
|
+
align-items: center;
|
|
422
|
+
gap: var(--udb-space-2, 8px);
|
|
423
|
+
padding: 8px 14px;
|
|
424
|
+
border-bottom: 1px solid var(--color-border, #eef2f7);
|
|
425
|
+
background: color-mix(in srgb, var(--color-muted, #f8fafc) 60%, transparent);
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
.udb-cal-agenda-date {
|
|
429
|
+
font-size: var(--udb-font-size-sm, 12px);
|
|
430
|
+
font-weight: 600;
|
|
431
|
+
color: var(--color-foreground, #0f172a);
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
.udb-cal-agenda-today {
|
|
435
|
+
padding: 1px 7px;
|
|
436
|
+
border-radius: 9999px;
|
|
437
|
+
background: var(--color-primary, #2563eb);
|
|
438
|
+
font-size: 10px;
|
|
439
|
+
font-weight: 600;
|
|
440
|
+
text-transform: uppercase;
|
|
441
|
+
letter-spacing: 0.04em;
|
|
442
|
+
color: var(--color-primary-foreground, #ffffff);
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
.udb-cal-agenda-count {
|
|
446
|
+
margin-left: auto;
|
|
447
|
+
font-size: var(--udb-font-size-xs, 11px);
|
|
448
|
+
color: var(--color-muted-foreground, #64748b);
|
|
449
|
+
font-variant-numeric: tabular-nums;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
.udb-cal-agenda-rows {
|
|
453
|
+
display: flex;
|
|
454
|
+
flex-direction: column;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
.udb-cal-agenda-item {
|
|
458
|
+
display: grid;
|
|
459
|
+
grid-template-columns: 5.5rem 10px minmax(0, 1fr);
|
|
460
|
+
align-items: start;
|
|
461
|
+
gap: var(--udb-space-2, 8px);
|
|
462
|
+
width: 100%;
|
|
463
|
+
padding: 8px 14px;
|
|
464
|
+
border: none;
|
|
465
|
+
border-left: 3px solid currentColor;
|
|
466
|
+
background: transparent;
|
|
467
|
+
text-align: left;
|
|
468
|
+
font-size: var(--udb-font-size-sm, 12px);
|
|
469
|
+
cursor: pointer;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
.udb-cal-agenda-item + .udb-cal-agenda-item {
|
|
473
|
+
border-top: 1px solid var(--color-border, #eef2f7);
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
.udb-cal-agenda-item.is-muted {
|
|
477
|
+
opacity: 0.45;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
.udb-cal-agenda-item:focus-visible {
|
|
481
|
+
outline: 2px solid var(--color-ring, #2563eb);
|
|
482
|
+
outline-offset: -2px;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
.udb-cal-agenda-time {
|
|
486
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
|
|
487
|
+
font-size: 11px;
|
|
488
|
+
line-height: 1.45;
|
|
489
|
+
color: var(--color-muted-foreground, #64748b);
|
|
490
|
+
font-variant-numeric: tabular-nums;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
.udb-cal-agenda-time-end {
|
|
494
|
+
display: block;
|
|
495
|
+
opacity: 0.75;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
.udb-cal-agenda-body {
|
|
499
|
+
display: flex;
|
|
500
|
+
flex-direction: column;
|
|
501
|
+
gap: 2px;
|
|
502
|
+
min-width: 0;
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
.udb-cal-agenda-title {
|
|
506
|
+
display: flex;
|
|
507
|
+
align-items: center;
|
|
508
|
+
gap: 6px;
|
|
509
|
+
font-weight: 600;
|
|
510
|
+
color: var(--color-foreground, #0f172a);
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
.udb-cal-agenda-meta {
|
|
514
|
+
font-size: var(--udb-font-size-xs, 11px);
|
|
515
|
+
color: var(--color-muted-foreground, #64748b);
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
.udb-cal-agenda-empty {
|
|
519
|
+
display: grid;
|
|
520
|
+
place-items: center;
|
|
521
|
+
padding: 48px 16px;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
.udb-cal-agenda-empty-text {
|
|
525
|
+
margin: 0;
|
|
526
|
+
color: var(--color-muted-foreground, #94a3b8);
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
.udb-cal-res {
|
|
530
|
+
border: 1px solid var(--color-border, #e2e8f0);
|
|
531
|
+
border-radius: 12px;
|
|
532
|
+
background: var(--color-card, #ffffff);
|
|
533
|
+
color: var(--color-foreground, #0f172a);
|
|
534
|
+
overflow: hidden;
|
|
535
|
+
font-size: var(--udb-font-size-sm, 12px);
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
.udb-cal-res-axis {
|
|
539
|
+
position: relative;
|
|
540
|
+
height: 26px;
|
|
541
|
+
margin-left: var(--udb-cal-res-label-width, 11rem);
|
|
542
|
+
border-bottom: 1px solid var(--color-border, #e2e8f0);
|
|
543
|
+
background: color-mix(in srgb, var(--color-muted, #f8fafc) 60%, transparent);
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
.udb-cal-res-axis-label {
|
|
547
|
+
position: absolute;
|
|
548
|
+
top: 6px;
|
|
549
|
+
transform: translateX(-50%);
|
|
550
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
|
|
551
|
+
font-size: 10px;
|
|
552
|
+
color: var(--color-muted-foreground, #94a3b8);
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
.udb-cal-res-row {
|
|
556
|
+
display: grid;
|
|
557
|
+
grid-template-columns: var(--udb-cal-res-label-width, 11rem) minmax(0, 1fr);
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
.udb-cal-res-row + .udb-cal-res-row {
|
|
561
|
+
border-top: 1px solid var(--color-border, #e2e8f0);
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
.udb-cal-res-label {
|
|
565
|
+
display: flex;
|
|
566
|
+
flex-direction: column;
|
|
567
|
+
justify-content: center;
|
|
568
|
+
gap: 1px;
|
|
569
|
+
min-width: 0;
|
|
570
|
+
padding: 6px 12px;
|
|
571
|
+
border-right: 1px solid var(--color-border, #e2e8f0);
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
.udb-cal-res-name {
|
|
575
|
+
overflow: hidden;
|
|
576
|
+
text-overflow: ellipsis;
|
|
577
|
+
white-space: nowrap;
|
|
578
|
+
font-weight: 600;
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
.udb-cal-res-meta {
|
|
582
|
+
overflow: hidden;
|
|
583
|
+
text-overflow: ellipsis;
|
|
584
|
+
white-space: nowrap;
|
|
585
|
+
font-size: var(--udb-font-size-xs, 11px);
|
|
586
|
+
color: var(--color-muted-foreground, #64748b);
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
.udb-cal-res-lane {
|
|
590
|
+
position: relative;
|
|
591
|
+
min-height: 56px;
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
.udb-cal-res-hour {
|
|
595
|
+
position: absolute;
|
|
596
|
+
top: 0;
|
|
597
|
+
bottom: 0;
|
|
598
|
+
border-left: 1px solid var(--color-border, #eef2f7);
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
.udb-cal-res-block {
|
|
602
|
+
position: absolute;
|
|
603
|
+
top: 5px;
|
|
604
|
+
bottom: 5px;
|
|
605
|
+
display: flex;
|
|
606
|
+
flex-direction: column;
|
|
607
|
+
gap: 1px;
|
|
608
|
+
padding: 2px 6px;
|
|
609
|
+
border: none;
|
|
610
|
+
border-left: 3px solid currentColor;
|
|
611
|
+
border-radius: 5px;
|
|
612
|
+
overflow: hidden;
|
|
613
|
+
text-align: left;
|
|
614
|
+
font-size: var(--udb-font-size-xs, 11px);
|
|
615
|
+
font-weight: 500;
|
|
616
|
+
cursor: pointer;
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
.udb-cal-res-block:focus-visible {
|
|
620
|
+
outline: 2px solid var(--color-ring, #2563eb);
|
|
621
|
+
outline-offset: 1px;
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
.udb-cal-res-block.is-muted {
|
|
625
|
+
opacity: 0.45;
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
.udb-cal-res-block-time {
|
|
629
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
|
|
630
|
+
font-size: 10px;
|
|
631
|
+
opacity: 0.8;
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
.udb-cal-res-block-title {
|
|
635
|
+
overflow: hidden;
|
|
636
|
+
text-overflow: ellipsis;
|
|
637
|
+
white-space: nowrap;
|
|
638
|
+
font-weight: 600;
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
.udb-cal-res-empty {
|
|
642
|
+
display: grid;
|
|
643
|
+
place-items: center;
|
|
644
|
+
padding: 48px 16px;
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
.udb-cal-res-empty-text {
|
|
648
|
+
margin: 0;
|
|
649
|
+
color: var(--color-muted-foreground, #94a3b8);
|
|
650
|
+
}
|
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { fireEvent, render, screen } from '@testing-library/react';
|
|
3
|
+
import { CalendarResourceTimeline } from './CalendarResourceTimeline';
|
|
4
|
+
import type { CalendarItem } from '../types/view.types';
|
|
5
|
+
|
|
6
|
+
const item = (id: string, resourceId: string, startMin: number, endMin: number): CalendarItem => ({
|
|
7
|
+
id,
|
|
8
|
+
dayKey: '2026-03-15',
|
|
9
|
+
resourceId,
|
|
10
|
+
startMin,
|
|
11
|
+
endMin,
|
|
12
|
+
title: id,
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
const resources = [
|
|
16
|
+
{ id: 'room-1', label: 'Salle Lumière' },
|
|
17
|
+
{ id: 'room-2', label: 'Salle Méliès' },
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
const mount = (props: Partial<Parameters<typeof CalendarResourceTimeline>[0]> = {}) =>
|
|
21
|
+
render(<CalendarResourceTimeline resources={resources} items={[]} {...props} />);
|
|
22
|
+
|
|
23
|
+
const numberIn = (value: string): number => parseFloat(value.replace(/^calc\(/, ''));
|
|
24
|
+
|
|
25
|
+
afterEach(() => {
|
|
26
|
+
vi.restoreAllMocks();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
describe('CalendarResourceTimeline', () => {
|
|
30
|
+
it('renders one row per resource and drops items without a matching resource', () => {
|
|
31
|
+
const { container } = mount({
|
|
32
|
+
items: [item('Screening', 'room-1', 600, 660), item('Orphan', 'room-9', 660, 720)],
|
|
33
|
+
});
|
|
34
|
+
const rows = container.querySelectorAll('.udb-cal-res-row');
|
|
35
|
+
expect(rows).toHaveLength(2);
|
|
36
|
+
expect(screen.getByText('Salle Lumière')).toBeTruthy();
|
|
37
|
+
expect(screen.queryByText('Orphan')).toBeNull();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('positions blocks along the horizontal minute axis', () => {
|
|
41
|
+
mount({ items: [item('Screening', 'room-1', 600, 660)] });
|
|
42
|
+
const block = screen.getByText('Screening').closest('button') as HTMLElement;
|
|
43
|
+
expect(numberIn(block.style.left)).toBeCloseTo(21.4286, 3);
|
|
44
|
+
expect(numberIn(block.style.width)).toBeCloseTo(7.1429, 3);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('splits overlapping blocks on the same resource into columns', () => {
|
|
48
|
+
mount({ items: [item('first', 'room-1', 600, 660), item('second', 'room-1', 630, 690)] });
|
|
49
|
+
const first = screen.getByText('first').closest('button') as HTMLElement;
|
|
50
|
+
const second = screen.getByText('second').closest('button') as HTMLElement;
|
|
51
|
+
expect(numberIn(first.style.width)).toBeCloseTo(3.5714, 3);
|
|
52
|
+
expect(numberIn(second.style.width)).toBeCloseTo(3.5714, 3);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('quantizes lane clicks to slot boundaries', () => {
|
|
56
|
+
const onSlotClick = vi.fn();
|
|
57
|
+
const { container } = mount({
|
|
58
|
+
items: [item('Screening', 'room-1', 600, 660)],
|
|
59
|
+
onSlotClick,
|
|
60
|
+
});
|
|
61
|
+
vi.spyOn(HTMLElement.prototype, 'getBoundingClientRect').mockReturnValue({
|
|
62
|
+
top: 0,
|
|
63
|
+
height: 56,
|
|
64
|
+
bottom: 56,
|
|
65
|
+
left: 0,
|
|
66
|
+
right: 400,
|
|
67
|
+
width: 400,
|
|
68
|
+
x: 0,
|
|
69
|
+
y: 0,
|
|
70
|
+
toJSON: () => ({}),
|
|
71
|
+
} as DOMRect);
|
|
72
|
+
const lane = container.querySelector('.udb-cal-res-lane') as HTMLElement;
|
|
73
|
+
fireEvent.click(lane, { clientX: 100 });
|
|
74
|
+
expect(onSlotClick).toHaveBeenCalledWith('room-1', 630);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('reports item selection with the payload round-trip', () => {
|
|
78
|
+
const onSelectItem = vi.fn();
|
|
79
|
+
mount({
|
|
80
|
+
items: [{ ...item('Screening', 'room-1', 600, 660), payload: { screeningId: 42 } }],
|
|
81
|
+
onSelectItem,
|
|
82
|
+
});
|
|
83
|
+
fireEvent.click(screen.getByText('Screening'));
|
|
84
|
+
expect(onSelectItem).toHaveBeenCalledWith(
|
|
85
|
+
expect.objectContaining({ id: 'Screening', payload: { screeningId: 42 } }),
|
|
86
|
+
);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('falls back to the default empty label when nothing is scheduled', () => {
|
|
90
|
+
mount();
|
|
91
|
+
expect(screen.getByText('Nothing scheduled')).toBeTruthy();
|
|
92
|
+
});
|
|
93
|
+
});
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import type { CSSProperties, MouseEvent, ReactNode } from 'react';
|
|
3
|
+
import {
|
|
4
|
+
DEFAULT_CALENDAR_LABELS,
|
|
5
|
+
type CalendarItem,
|
|
6
|
+
type CalendarLabels,
|
|
7
|
+
} from '../types/view.types';
|
|
8
|
+
import {
|
|
9
|
+
DEFAULT_DAY_END_MIN,
|
|
10
|
+
DEFAULT_DAY_START_MIN,
|
|
11
|
+
SLOT_QUANTUM_MIN,
|
|
12
|
+
itemSpan,
|
|
13
|
+
layoutColumns,
|
|
14
|
+
minutesToLabel,
|
|
15
|
+
} from '../utils/layout';
|
|
16
|
+
|
|
17
|
+
export interface CalendarResource {
|
|
18
|
+
id: string;
|
|
19
|
+
label: ReactNode;
|
|
20
|
+
meta?: ReactNode;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface CalendarResourceTimelineProps {
|
|
24
|
+
resources: readonly CalendarResource[];
|
|
25
|
+
items: readonly CalendarItem[];
|
|
26
|
+
dayStartMin?: number;
|
|
27
|
+
dayEndMin?: number;
|
|
28
|
+
labels?: Partial<CalendarLabels>;
|
|
29
|
+
emptyState?: ReactNode;
|
|
30
|
+
onSelectItem?: (item: CalendarItem) => void;
|
|
31
|
+
onSlotClick?: (resourceId: string, minutes: number) => void;
|
|
32
|
+
className?: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const CalendarResourceTimeline = ({
|
|
36
|
+
resources,
|
|
37
|
+
items,
|
|
38
|
+
dayStartMin = DEFAULT_DAY_START_MIN,
|
|
39
|
+
dayEndMin = DEFAULT_DAY_END_MIN,
|
|
40
|
+
labels,
|
|
41
|
+
emptyState,
|
|
42
|
+
onSelectItem,
|
|
43
|
+
onSlotClick,
|
|
44
|
+
className,
|
|
45
|
+
}: CalendarResourceTimelineProps) => {
|
|
46
|
+
const text = { ...DEFAULT_CALENDAR_LABELS, ...labels };
|
|
47
|
+
const total = Math.max(dayEndMin - dayStartMin, 60);
|
|
48
|
+
|
|
49
|
+
const hours = useMemo(() => {
|
|
50
|
+
const first = Math.ceil(dayStartMin / 60) * 60;
|
|
51
|
+
const list: number[] = [];
|
|
52
|
+
for (let minute = first; minute < dayEndMin; minute += 60) list.push(minute);
|
|
53
|
+
return list;
|
|
54
|
+
}, [dayStartMin, dayEndMin]);
|
|
55
|
+
|
|
56
|
+
const byResource = useMemo(() => {
|
|
57
|
+
const known = new Set(resources.map((resource) => resource.id));
|
|
58
|
+
const map = new Map<string, CalendarItem[]>();
|
|
59
|
+
for (const item of items) {
|
|
60
|
+
if (!item.resourceId || !known.has(item.resourceId) || item.startMin === undefined) continue;
|
|
61
|
+
const bucket = map.get(item.resourceId);
|
|
62
|
+
if (bucket) bucket.push(item);
|
|
63
|
+
else map.set(item.resourceId, [item]);
|
|
64
|
+
}
|
|
65
|
+
return map;
|
|
66
|
+
}, [items, resources]);
|
|
67
|
+
|
|
68
|
+
const scheduled = useMemo(
|
|
69
|
+
() => [...byResource.values()].reduce((sum, bucket) => sum + bucket.length, 0),
|
|
70
|
+
[byResource],
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
const fractionOf = (minute: number): number =>
|
|
74
|
+
Math.max((minute - dayStartMin) / total, 0);
|
|
75
|
+
|
|
76
|
+
const handleLaneClick = (resourceId: string, event: MouseEvent<HTMLDivElement>) => {
|
|
77
|
+
if (!onSlotClick) return;
|
|
78
|
+
const bounds = event.currentTarget.getBoundingClientRect();
|
|
79
|
+
if (bounds.width <= 0) return;
|
|
80
|
+
const ratio = (event.clientX - bounds.left) / bounds.width;
|
|
81
|
+
const raw = dayStartMin + ratio * total;
|
|
82
|
+
const quantized = Math.floor(raw / SLOT_QUANTUM_MIN) * SLOT_QUANTUM_MIN;
|
|
83
|
+
if (quantized >= dayStartMin && quantized < dayEndMin) onSlotClick(resourceId, quantized);
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const axisStyle = (minute: number): CSSProperties => ({ left: `${fractionOf(minute) * 100}%` });
|
|
87
|
+
|
|
88
|
+
return (
|
|
89
|
+
<div className={className ? `udb-cal-res ${className}` : 'udb-cal-res'}>
|
|
90
|
+
{resources.length > 0 && scheduled > 0 && (
|
|
91
|
+
<>
|
|
92
|
+
<div className="udb-cal-res-axis" aria-hidden="true">
|
|
93
|
+
{hours.map((minute) => (
|
|
94
|
+
<span className="udb-cal-res-axis-label" style={axisStyle(minute)} key={minute}>
|
|
95
|
+
{minutesToLabel(minute)}
|
|
96
|
+
</span>
|
|
97
|
+
))}
|
|
98
|
+
</div>
|
|
99
|
+
<div className="udb-cal-res-body">
|
|
100
|
+
{resources.map((resource) => {
|
|
101
|
+
const rowItems = byResource.get(resource.id) ?? [];
|
|
102
|
+
return (
|
|
103
|
+
<div className="udb-cal-res-row" key={resource.id}>
|
|
104
|
+
<div className="udb-cal-res-label">
|
|
105
|
+
<span className="udb-cal-res-name">{resource.label}</span>
|
|
106
|
+
{resource.meta && <span className="udb-cal-res-meta">{resource.meta}</span>}
|
|
107
|
+
</div>
|
|
108
|
+
<div
|
|
109
|
+
className="udb-cal-res-lane"
|
|
110
|
+
onClick={(event) => handleLaneClick(resource.id, event)}
|
|
111
|
+
>
|
|
112
|
+
{hours.map((minute) => (
|
|
113
|
+
<span className="udb-cal-res-hour" style={axisStyle(minute)} key={minute} />
|
|
114
|
+
))}
|
|
115
|
+
{layoutColumns(rowItems).map(({ item, column, columns }) => {
|
|
116
|
+
const span = itemSpan(item);
|
|
117
|
+
const start = fractionOf(Math.max(span.startMin, dayStartMin)) * 100;
|
|
118
|
+
const width =
|
|
119
|
+
Math.max(
|
|
120
|
+
(Math.min(span.endMin, dayEndMin) - Math.max(span.startMin, dayStartMin)) /
|
|
121
|
+
total,
|
|
122
|
+
0.04,
|
|
123
|
+
) * 100;
|
|
124
|
+
return (
|
|
125
|
+
<button
|
|
126
|
+
type="button"
|
|
127
|
+
key={item.id}
|
|
128
|
+
className={
|
|
129
|
+
item.muted
|
|
130
|
+
? `udb-cal-res-block udb-cal-res-block--${item.tone ?? 'primary'} is-muted`
|
|
131
|
+
: `udb-cal-res-block udb-cal-res-block--${item.tone ?? 'primary'}`
|
|
132
|
+
}
|
|
133
|
+
style={{
|
|
134
|
+
left: `calc(${start + width * (column / columns)}% + 2px)`,
|
|
135
|
+
width: `calc(${width / columns}% - 4px)`,
|
|
136
|
+
}}
|
|
137
|
+
onClick={(click) => {
|
|
138
|
+
click.stopPropagation();
|
|
139
|
+
onSelectItem?.(item);
|
|
140
|
+
}}
|
|
141
|
+
>
|
|
142
|
+
<span className="udb-cal-res-block-time">
|
|
143
|
+
{minutesToLabel(span.startMin)}
|
|
144
|
+
</span>
|
|
145
|
+
<span className="udb-cal-res-block-title">{item.title}</span>
|
|
146
|
+
{item.meta}
|
|
147
|
+
</button>
|
|
148
|
+
);
|
|
149
|
+
})}
|
|
150
|
+
</div>
|
|
151
|
+
</div>
|
|
152
|
+
);
|
|
153
|
+
})}
|
|
154
|
+
</div>
|
|
155
|
+
</>
|
|
156
|
+
)}
|
|
157
|
+
{(resources.length === 0 || scheduled === 0) && (
|
|
158
|
+
<div className="udb-cal-res-empty">
|
|
159
|
+
{emptyState ?? <p className="udb-cal-res-empty-text">{text.emptyDay}</p>}
|
|
160
|
+
</div>
|
|
161
|
+
)}
|
|
162
|
+
</div>
|
|
163
|
+
);
|
|
164
|
+
};
|
|
@@ -69,4 +69,31 @@ describe('CalendarTimeGrid', () => {
|
|
|
69
69
|
expect.objectContaining({ id: 'Consult' }),
|
|
70
70
|
);
|
|
71
71
|
});
|
|
72
|
+
|
|
73
|
+
it('keeps untimed items in the all-day strip instead of dropping them', () => {
|
|
74
|
+
const { container } = mount({
|
|
75
|
+
days: ['2026-03-15', '2026-03-16'],
|
|
76
|
+
items: [
|
|
77
|
+
item('Consult', '2026-03-15', 600, 660),
|
|
78
|
+
{ id: 'Permit expiry', dayKey: '2026-03-16', title: 'Permit expiry', tone: 'danger' },
|
|
79
|
+
],
|
|
80
|
+
});
|
|
81
|
+
const strip = container.querySelector('.udb-cal-allday');
|
|
82
|
+
expect(strip).toBeTruthy();
|
|
83
|
+
expect(screen.getByText('All day')).toBeTruthy();
|
|
84
|
+
expect(strip?.textContent).toContain('Permit expiry');
|
|
85
|
+
expect(strip?.textContent).not.toContain('Consult');
|
|
86
|
+
expect(container.querySelectorAll('.udb-cal-event')).toHaveLength(1);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('does not flag a single day as empty when it only holds all-day items', () => {
|
|
90
|
+
mount({ items: [{ id: 'Expiry', dayKey: '2026-03-15', title: 'Expiry' }] });
|
|
91
|
+
expect(screen.queryByText('Nothing scheduled')).toBeNull();
|
|
92
|
+
expect(screen.getByText('All day')).toBeTruthy();
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('omits the all-day strip when every item is timed', () => {
|
|
96
|
+
const { container } = mount({ items: [item('Consult', '2026-03-15', 600, 660)] });
|
|
97
|
+
expect(container.querySelector('.udb-cal-allday')).toBeNull();
|
|
98
|
+
});
|
|
72
99
|
});
|
|
@@ -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) => {
|
|
@@ -52,7 +54,10 @@ export const CalendarTimeGrid = ({
|
|
|
52
54
|
}, [dayStartMin, dayEndMin]);
|
|
53
55
|
|
|
54
56
|
const timed = useMemo(() => items.filter((item) => item.startMin !== undefined), [items]);
|
|
55
|
-
const
|
|
57
|
+
const untimed = useMemo(() => items.filter((item) => item.startMin === undefined), [items]);
|
|
58
|
+
const timedByDay = useMemo(() => groupByDayKey(timed), [timed]);
|
|
59
|
+
const untimedByDay = useMemo(() => groupByDayKey(untimed), [untimed]);
|
|
60
|
+
const hasAllDay = days.some((dayKey) => (untimedByDay.get(dayKey)?.length ?? 0) > 0);
|
|
56
61
|
|
|
57
62
|
const positionOf = (minute: number): string =>
|
|
58
63
|
`${((minute - dayStartMin) / total) * 100}%`;
|
|
@@ -72,6 +77,44 @@ export const CalendarTimeGrid = ({
|
|
|
72
77
|
className="udb-cal-grid"
|
|
73
78
|
style={{ ['--udb-cal-days' as string]: days.length } as CSSProperties}
|
|
74
79
|
>
|
|
80
|
+
<div className="udb-cal-days">
|
|
81
|
+
<span className="udb-cal-days-corner" />
|
|
82
|
+
{days.map((dayKey) => (
|
|
83
|
+
<div
|
|
84
|
+
className={dayKey === today ? 'udb-cal-day-head is-today' : 'udb-cal-day-head'}
|
|
85
|
+
key={dayKey}
|
|
86
|
+
>
|
|
87
|
+
<span className="udb-cal-weekday">{formatWeekdayShort(dayKey, locale)}</span>
|
|
88
|
+
<span className="udb-cal-daynum">{formatDayNumber(dayKey)}</span>
|
|
89
|
+
</div>
|
|
90
|
+
))}
|
|
91
|
+
</div>
|
|
92
|
+
|
|
93
|
+
{hasAllDay && (
|
|
94
|
+
<div className="udb-cal-allday">
|
|
95
|
+
<span className="udb-cal-allday-corner">{text.allDay}</span>
|
|
96
|
+
{days.map((dayKey) => (
|
|
97
|
+
<div className="udb-cal-allday-cell" key={dayKey}>
|
|
98
|
+
{(untimedByDay.get(dayKey) ?? []).map((item) => (
|
|
99
|
+
<button
|
|
100
|
+
type="button"
|
|
101
|
+
key={item.id}
|
|
102
|
+
className={
|
|
103
|
+
item.muted
|
|
104
|
+
? `udb-cal-chip udb-cal-chip--${item.tone ?? 'primary'} is-muted`
|
|
105
|
+
: `udb-cal-chip udb-cal-chip--${item.tone ?? 'primary'}`
|
|
106
|
+
}
|
|
107
|
+
onClick={() => onSelectItem?.(item)}
|
|
108
|
+
>
|
|
109
|
+
{item.icon}
|
|
110
|
+
<span className="udb-cal-chip-title">{item.title}</span>
|
|
111
|
+
</button>
|
|
112
|
+
))}
|
|
113
|
+
</div>
|
|
114
|
+
))}
|
|
115
|
+
</div>
|
|
116
|
+
)}
|
|
117
|
+
|
|
75
118
|
<div className="udb-cal-gutter" aria-hidden="true">
|
|
76
119
|
{hours.map((minute) => (
|
|
77
120
|
<div className="udb-cal-hour-label" style={{ top: positionOf(minute) }} key={minute}>
|
|
@@ -81,13 +124,10 @@ export const CalendarTimeGrid = ({
|
|
|
81
124
|
</div>
|
|
82
125
|
|
|
83
126
|
{days.map((dayKey) => {
|
|
84
|
-
const
|
|
127
|
+
const laneItems = timedByDay.get(dayKey) ?? [];
|
|
128
|
+
const dayCount = laneItems.length + (untimedByDay.get(dayKey)?.length ?? 0);
|
|
85
129
|
return (
|
|
86
130
|
<section className="udb-cal-day" aria-label={dayKey} key={dayKey}>
|
|
87
|
-
<header className={dayKey === today ? 'udb-cal-day-head is-today' : 'udb-cal-day-head'}>
|
|
88
|
-
<span className="udb-cal-weekday">{formatWeekdayShort(dayKey, locale)}</span>
|
|
89
|
-
<span className="udb-cal-daynum">{formatDayNumber(dayKey)}</span>
|
|
90
|
-
</header>
|
|
91
131
|
<div
|
|
92
132
|
className="udb-cal-lane"
|
|
93
133
|
role="grid"
|
|
@@ -101,7 +141,7 @@ export const CalendarTimeGrid = ({
|
|
|
101
141
|
key={minute}
|
|
102
142
|
/>
|
|
103
143
|
))}
|
|
104
|
-
{layoutColumns(
|
|
144
|
+
{layoutColumns(laneItems).map(({ item, column, columns }) => {
|
|
105
145
|
const geometry = eventGeometry(item, dayStartMin, dayEndMin);
|
|
106
146
|
return (
|
|
107
147
|
<button
|
|
@@ -131,9 +171,8 @@ export const CalendarTimeGrid = ({
|
|
|
131
171
|
</button>
|
|
132
172
|
);
|
|
133
173
|
})}
|
|
134
|
-
{days.length === 1 &&
|
|
135
|
-
<p className="udb-cal-empty">{text.emptyDay}</p>
|
|
136
|
-
)}
|
|
174
|
+
{days.length === 1 && dayCount === 0 &&
|
|
175
|
+
(emptyState ?? <p className="udb-cal-empty">{text.emptyDay}</p>)}
|
|
137
176
|
</div>
|
|
138
177
|
</section>
|
|
139
178
|
);
|
|
@@ -1,6 +1,13 @@
|
|
|
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';
|
|
6
8
|
export type { CalendarTimeGridProps } from './CalendarTimeGrid';
|
|
9
|
+
export { CalendarResourceTimeline } from './CalendarResourceTimeline';
|
|
10
|
+
export type {
|
|
11
|
+
CalendarResource,
|
|
12
|
+
CalendarResourceTimelineProps,
|
|
13
|
+
} from './CalendarResourceTimeline';
|
|
@@ -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;
|
|
@@ -16,6 +16,7 @@ export interface CalendarItem {
|
|
|
16
16
|
kind?: string;
|
|
17
17
|
muted?: boolean;
|
|
18
18
|
payload?: unknown;
|
|
19
|
+
resourceId?: string;
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
export interface CalendarLegendEntry {
|
|
@@ -30,6 +31,8 @@ export interface CalendarLabels {
|
|
|
30
31
|
month: string;
|
|
31
32
|
week: string;
|
|
32
33
|
day: string;
|
|
34
|
+
agenda: string;
|
|
35
|
+
allDay: string;
|
|
33
36
|
more: string;
|
|
34
37
|
emptyDay: string;
|
|
35
38
|
}
|
|
@@ -41,6 +44,8 @@ export const DEFAULT_CALENDAR_LABELS: CalendarLabels = {
|
|
|
41
44
|
month: 'Month',
|
|
42
45
|
week: 'Week',
|
|
43
46
|
day: 'Day',
|
|
47
|
+
agenda: 'Agenda',
|
|
48
|
+
allDay: 'All day',
|
|
44
49
|
more: '+{count} more',
|
|
45
50
|
emptyDay: 'Nothing scheduled',
|
|
46
51
|
};
|
|
@@ -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)}`;
|