@umituz/web-dashboard 11.10.1 → 11.12.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 +5 -1
- package/src/domains/calendar/calendar.css +191 -0
- package/src/domains/calendar/components/CalendarPage.test.tsx +178 -0
- package/src/domains/calendar/components/CalendarPage.tsx +296 -0
- package/src/domains/calendar/components/CalendarSelectedDayPanel.tsx +136 -0
- package/src/domains/calendar/components/index.ts +5 -0
- package/src/domains/calendar/types/calendar-page.types.ts +91 -0
- package/src/domains/calendar/types/index.ts +1 -0
- package/src/domains/kanban/components/KanbanBoard.test.tsx +226 -0
- package/src/domains/kanban/components/KanbanBoard.tsx +135 -0
- package/src/domains/kanban/components/KanbanCard.tsx +160 -0
- package/src/domains/kanban/components/KanbanColumn.tsx +163 -0
- package/src/domains/kanban/components/KanbanPage.test.tsx +115 -0
- package/src/domains/kanban/components/KanbanPage.tsx +91 -0
- package/src/domains/kanban/components/index.ts +4 -0
- package/src/domains/kanban/index.ts +12 -0
- package/src/domains/kanban/kanban.css +406 -0
- package/src/domains/kanban/types.ts +103 -0
- package/src/domains/layouts/components/DashboardLayout.tsx +6 -1
- package/src/index.ts +1 -0
- package/src/styles/chrome.css +4 -0
- package/src/styles/dashboard.css +2 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/web-dashboard",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.12.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",
|
|
@@ -25,6 +25,10 @@
|
|
|
25
25
|
"./calendar/utils": "./src/domains/calendar/utils/index.ts",
|
|
26
26
|
"./chrome.css": "./src/styles/chrome.css",
|
|
27
27
|
"./config": "./src/config/index.ts",
|
|
28
|
+
"./kanban": "./src/domains/kanban/index.ts",
|
|
29
|
+
"./kanban/kanban.css": "./src/domains/kanban/kanban.css",
|
|
30
|
+
"./kanban/components": "./src/domains/kanban/components/index.ts",
|
|
31
|
+
"./kanban/types": "./src/domains/kanban/types.ts",
|
|
28
32
|
"./layouts": "./src/domains/layouts/index.ts",
|
|
29
33
|
"./layouts/components": "./src/domains/layouts/components/index.ts",
|
|
30
34
|
"./layouts/hooks": "./src/domains/layouts/hooks/index.ts",
|
|
@@ -1 +1,192 @@
|
|
|
1
|
+
.udb-cal-page {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: column;
|
|
4
|
+
width: 100%;
|
|
5
|
+
gap: var(--udb-space-5, 20px);
|
|
6
|
+
}
|
|
1
7
|
|
|
8
|
+
.udb-cal-callout {
|
|
9
|
+
width: 100%;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.udb-cal-legend {
|
|
13
|
+
display: flex;
|
|
14
|
+
flex-wrap: wrap;
|
|
15
|
+
align-items: center;
|
|
16
|
+
gap: 8px;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.udb-cal-chip {
|
|
20
|
+
display: inline-flex;
|
|
21
|
+
align-items: center;
|
|
22
|
+
gap: 6px;
|
|
23
|
+
padding: 6px 12px;
|
|
24
|
+
font-size: 13px;
|
|
25
|
+
font-weight: 500;
|
|
26
|
+
border-radius: var(--radius-md, 8px);
|
|
27
|
+
border: 1px solid var(--color-border, #e2e8f0);
|
|
28
|
+
background: var(--color-card, #ffffff);
|
|
29
|
+
color: var(--color-foreground, #0f172a);
|
|
30
|
+
cursor: pointer;
|
|
31
|
+
transition: all 0.15s ease;
|
|
32
|
+
user-select: none;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.udb-cal-chip:hover {
|
|
36
|
+
background: var(--color-muted, #f1f5f9);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.udb-cal-chip:focus-visible {
|
|
40
|
+
outline: 2px solid var(--color-ring, #2563eb);
|
|
41
|
+
outline-offset: 2px;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.udb-cal-chip.is-active {
|
|
45
|
+
background: var(--color-primary, #2563eb);
|
|
46
|
+
color: var(--color-primary-foreground, #ffffff);
|
|
47
|
+
border-color: var(--color-primary, #2563eb);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.udb-cal-chip.is-active .udb-cal-count {
|
|
51
|
+
background: rgba(255, 255, 255, 0.2);
|
|
52
|
+
color: #ffffff;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.udb-cal-count {
|
|
56
|
+
display: inline-flex;
|
|
57
|
+
align-items: center;
|
|
58
|
+
justify-content: center;
|
|
59
|
+
padding: 1px 6px;
|
|
60
|
+
font-size: 11px;
|
|
61
|
+
border-radius: 9999px;
|
|
62
|
+
background: var(--color-muted, #f1f5f9);
|
|
63
|
+
color: var(--color-muted-foreground, #64748b);
|
|
64
|
+
font-variant-numeric: tabular-nums;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.udb-cal-card {
|
|
68
|
+
border-radius: var(--radius-lg, 12px);
|
|
69
|
+
border: 1px solid var(--color-border, #e2e8f0);
|
|
70
|
+
background: var(--color-card, #ffffff);
|
|
71
|
+
overflow: hidden;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.udb-cal-selected-card {
|
|
75
|
+
border-radius: var(--radius-lg, 12px);
|
|
76
|
+
border: 1px solid var(--color-border, #e2e8f0);
|
|
77
|
+
background: var(--color-card, #ffffff);
|
|
78
|
+
padding: 16px;
|
|
79
|
+
display: flex;
|
|
80
|
+
flex-direction: column;
|
|
81
|
+
gap: 12px;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.udb-cal-selected-header {
|
|
85
|
+
display: flex;
|
|
86
|
+
align-items: center;
|
|
87
|
+
justify-content: space-between;
|
|
88
|
+
flex-wrap: wrap;
|
|
89
|
+
gap: 8px;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.udb-cal-selected-header-left {
|
|
93
|
+
display: flex;
|
|
94
|
+
align-items: baseline;
|
|
95
|
+
gap: 10px;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.udb-cal-selected-eyebrow {
|
|
99
|
+
font-size: 11px;
|
|
100
|
+
text-transform: uppercase;
|
|
101
|
+
letter-spacing: 0.05em;
|
|
102
|
+
font-weight: 600;
|
|
103
|
+
color: var(--color-muted-foreground, #64748b);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
.udb-cal-selected-title {
|
|
107
|
+
font-size: 16px;
|
|
108
|
+
font-weight: 600;
|
|
109
|
+
color: var(--color-foreground, #0f172a);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
.udb-cal-feed-list {
|
|
113
|
+
display: flex;
|
|
114
|
+
flex-direction: column;
|
|
115
|
+
gap: 8px;
|
|
116
|
+
list-style: none;
|
|
117
|
+
padding: 0;
|
|
118
|
+
margin: 0;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
.udb-cal-feed-item {
|
|
122
|
+
display: flex;
|
|
123
|
+
align-items: center;
|
|
124
|
+
gap: 12px;
|
|
125
|
+
padding: 10px 12px;
|
|
126
|
+
border-radius: var(--radius-md, 8px);
|
|
127
|
+
border: 1px solid var(--color-border, #e2e8f0);
|
|
128
|
+
background: var(--color-card, #ffffff);
|
|
129
|
+
transition: background 0.15s ease;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
.udb-cal-feed-btn {
|
|
133
|
+
width: 100%;
|
|
134
|
+
text-align: left;
|
|
135
|
+
font: inherit;
|
|
136
|
+
color: inherit;
|
|
137
|
+
cursor: pointer;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
.udb-cal-feed-btn:hover {
|
|
141
|
+
background: var(--color-muted, #f8fafc);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
.udb-cal-feed-btn:focus-visible {
|
|
145
|
+
outline: 2px solid var(--color-ring, #2563eb);
|
|
146
|
+
outline-offset: 2px;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
.udb-cal-feed-item.is-muted {
|
|
150
|
+
opacity: 0.55;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
.udb-cal-feed-body {
|
|
154
|
+
flex: 1;
|
|
155
|
+
min-width: 0;
|
|
156
|
+
display: flex;
|
|
157
|
+
flex-direction: column;
|
|
158
|
+
gap: 2px;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
.udb-cal-feed-title {
|
|
162
|
+
font-size: 14px;
|
|
163
|
+
font-weight: 500;
|
|
164
|
+
color: var(--color-foreground, #0f172a);
|
|
165
|
+
overflow: hidden;
|
|
166
|
+
text-overflow: ellipsis;
|
|
167
|
+
white-space: nowrap;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
.udb-cal-feed-meta {
|
|
171
|
+
font-size: 12px;
|
|
172
|
+
color: var(--color-muted-foreground, #64748b);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
.udb-cal-feed-end {
|
|
176
|
+
display: flex;
|
|
177
|
+
align-items: center;
|
|
178
|
+
gap: 8px;
|
|
179
|
+
font-size: 12px;
|
|
180
|
+
color: var(--color-muted-foreground, #64748b);
|
|
181
|
+
white-space: nowrap;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
.udb-cal-empty {
|
|
185
|
+
padding: 16px 0;
|
|
186
|
+
font-size: 13px;
|
|
187
|
+
color: var(--color-muted-foreground, #64748b);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
.udb-cal-footer {
|
|
191
|
+
width: 100%;
|
|
192
|
+
}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { render, screen, fireEvent, within } from '@testing-library/react';
|
|
3
|
+
import { MemoryRouter } from 'react-router';
|
|
4
|
+
import { CalendarPage } from './CalendarPage';
|
|
5
|
+
import type { CalendarCategory, CalendarPageItem } from '../types';
|
|
6
|
+
|
|
7
|
+
interface TestPayload {
|
|
8
|
+
kind: 'task' | 'inspection';
|
|
9
|
+
priority: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const ITEMS: readonly CalendarPageItem<TestPayload>[] = [
|
|
13
|
+
{
|
|
14
|
+
id: 'evt-1',
|
|
15
|
+
dayKey: '2026-11-20',
|
|
16
|
+
title: 'HVAC Filter Replacement',
|
|
17
|
+
tone: 'info',
|
|
18
|
+
startMin: 540,
|
|
19
|
+
endMin: 600,
|
|
20
|
+
meta: 'HQ Tower · 3rd Floor',
|
|
21
|
+
kind: 'task',
|
|
22
|
+
payload: { kind: 'task', priority: 'high' },
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
id: 'evt-2',
|
|
26
|
+
dayKey: '2026-11-20',
|
|
27
|
+
title: 'Fire Safety Inspection',
|
|
28
|
+
tone: 'warning',
|
|
29
|
+
startMin: 660,
|
|
30
|
+
endMin: 720,
|
|
31
|
+
meta: 'DC Annex',
|
|
32
|
+
kind: 'inspection',
|
|
33
|
+
payload: { kind: 'inspection', priority: 'critical' },
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
id: 'evt-3',
|
|
37
|
+
dayKey: '2026-11-21',
|
|
38
|
+
title: 'Roof Membrane Check',
|
|
39
|
+
tone: 'info',
|
|
40
|
+
meta: 'HQ Tower',
|
|
41
|
+
kind: 'task',
|
|
42
|
+
payload: { kind: 'task', priority: 'medium' },
|
|
43
|
+
},
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
const CATEGORIES: readonly CalendarCategory[] = [
|
|
47
|
+
{ id: 'task', label: 'Tasks', tone: 'info' },
|
|
48
|
+
{ id: 'inspection', label: 'Inspections', tone: 'warning' },
|
|
49
|
+
];
|
|
50
|
+
|
|
51
|
+
function mount(props: Partial<Parameters<typeof CalendarPage<TestPayload>>[0]> = {}) {
|
|
52
|
+
return render(
|
|
53
|
+
<MemoryRouter>
|
|
54
|
+
<CalendarPage<TestPayload>
|
|
55
|
+
title="Site Operations"
|
|
56
|
+
subtitle="Operational schedule"
|
|
57
|
+
items={ITEMS}
|
|
58
|
+
initialCursor="2026-11-20"
|
|
59
|
+
initialSelectedDay="2026-11-20"
|
|
60
|
+
{...props}
|
|
61
|
+
/>
|
|
62
|
+
</MemoryRouter>,
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
describe('CalendarPage', () => {
|
|
67
|
+
it('renders header, subtitle and calendar events', () => {
|
|
68
|
+
mount();
|
|
69
|
+
expect(screen.getByText('Site Operations')).toBeDefined();
|
|
70
|
+
expect(screen.getByText('Operational schedule')).toBeDefined();
|
|
71
|
+
expect(screen.getAllByText('HVAC Filter Replacement').length).toBeGreaterThan(0);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('renders custom actions correctly', () => {
|
|
75
|
+
const handleAdd = vi.fn();
|
|
76
|
+
mount({
|
|
77
|
+
actions: {
|
|
78
|
+
label: 'Add Event',
|
|
79
|
+
onClick: handleAdd,
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
const addBtn = screen.getByRole('button', { name: /Add Event/i });
|
|
83
|
+
expect(addBtn).toBeDefined();
|
|
84
|
+
fireEvent.click(addBtn);
|
|
85
|
+
expect(handleAdd).toHaveBeenCalledTimes(1);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('renders multiple actions as array', () => {
|
|
89
|
+
const fn1 = vi.fn();
|
|
90
|
+
const fn2 = vi.fn();
|
|
91
|
+
mount({
|
|
92
|
+
actions: [
|
|
93
|
+
{ label: 'Action 1', onClick: fn1 },
|
|
94
|
+
{ label: 'Action 2', onClick: fn2 },
|
|
95
|
+
],
|
|
96
|
+
});
|
|
97
|
+
expect(screen.getByRole('button', { name: /Action 1/i })).toBeDefined();
|
|
98
|
+
expect(screen.getByRole('button', { name: /Action 2/i })).toBeDefined();
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('renders categories with counts and filters items on category click', () => {
|
|
102
|
+
mount({
|
|
103
|
+
categories: CATEGORIES,
|
|
104
|
+
selectedDayDetail: true,
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
expect(screen.getByText('Tasks')).toBeDefined();
|
|
108
|
+
expect(screen.getByText('Inspections')).toBeDefined();
|
|
109
|
+
|
|
110
|
+
const inspectionChip = screen.getByRole('button', { name: /Inspections/i });
|
|
111
|
+
fireEvent.click(inspectionChip);
|
|
112
|
+
|
|
113
|
+
const allChip = screen.getByRole('button', { name: /^All/i });
|
|
114
|
+
fireEvent.click(allChip);
|
|
115
|
+
expect(allChip.getAttribute('aria-pressed')).toBe('true');
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('supports single category filter mode', () => {
|
|
119
|
+
mount({
|
|
120
|
+
categories: CATEGORIES,
|
|
121
|
+
categoryMode: 'single',
|
|
122
|
+
selectedDayDetail: true,
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
const taskChip = screen.getByRole('button', { name: /Tasks/i });
|
|
126
|
+
fireEvent.click(taskChip);
|
|
127
|
+
expect(taskChip.getAttribute('aria-pressed')).toBe('true');
|
|
128
|
+
|
|
129
|
+
const allChip = screen.getByRole('button', { name: /^All/i });
|
|
130
|
+
expect(allChip.getAttribute('aria-pressed')).toBe('false');
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it('renders selected day detail panel when enabled', () => {
|
|
134
|
+
const onSelect = vi.fn();
|
|
135
|
+
const onAddForDay = vi.fn();
|
|
136
|
+
mount({
|
|
137
|
+
selectedDayDetail: {
|
|
138
|
+
action: {
|
|
139
|
+
label: 'Create for day',
|
|
140
|
+
onClick: onAddForDay,
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
onSelectItem: onSelect,
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
const panel = screen.getByTestId('calendar-selected-day-panel');
|
|
147
|
+
expect(panel).toBeDefined();
|
|
148
|
+
|
|
149
|
+
const addForDayBtn = screen.getByRole('button', { name: /Create for day/i });
|
|
150
|
+
fireEvent.click(addForDayBtn);
|
|
151
|
+
expect(onAddForDay).toHaveBeenCalledWith('2026-11-20');
|
|
152
|
+
|
|
153
|
+
const itemRow = within(panel).getByText('HVAC Filter Replacement');
|
|
154
|
+
fireEvent.click(itemRow);
|
|
155
|
+
expect(onSelect).toHaveBeenCalled();
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it('shows empty text in selected day detail panel when no items exist', () => {
|
|
159
|
+
mount({
|
|
160
|
+
selectedDay: '2026-11-25',
|
|
161
|
+
selectedDayDetail: {
|
|
162
|
+
emptyText: 'Zero tasks today.',
|
|
163
|
+
},
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
expect(screen.getByText('Zero tasks today.')).toBeDefined();
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it('supports custom renderItem and renderEmpty in selected day panel', () => {
|
|
170
|
+
mount({
|
|
171
|
+
selectedDayDetail: {
|
|
172
|
+
renderItem: (item) => <div data-testid="custom-item">{item.title} (custom)</div>,
|
|
173
|
+
},
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
expect(screen.getByText('HVAC Filter Replacement (custom)')).toBeDefined();
|
|
177
|
+
});
|
|
178
|
+
});
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
import { useCallback, useMemo, useState, type ReactNode } from 'react';
|
|
2
|
+
import { PageHeader } from '@umituz/web-design-system/templates';
|
|
3
|
+
import { Calendar } from '@umituz/web-design-system/organisms';
|
|
4
|
+
import { Button } from '@umituz/web-design-system/atoms';
|
|
5
|
+
import { todayKey } from '@umituz/web-design-system/utils';
|
|
6
|
+
import type {
|
|
7
|
+
CalendarCategory,
|
|
8
|
+
CalendarPageAction,
|
|
9
|
+
CalendarPageItem,
|
|
10
|
+
CalendarPageProps,
|
|
11
|
+
CalendarScreenView,
|
|
12
|
+
CalendarSelectedDayConfig,
|
|
13
|
+
} from '../types';
|
|
14
|
+
import { CalendarSelectedDayPanel } from './CalendarSelectedDayPanel';
|
|
15
|
+
|
|
16
|
+
const matchesCategory = (
|
|
17
|
+
item: CalendarPageItem<unknown>,
|
|
18
|
+
cat: CalendarCategory,
|
|
19
|
+
): boolean => {
|
|
20
|
+
if (cat.match) return cat.match(item);
|
|
21
|
+
if (item.category === cat.id) return true;
|
|
22
|
+
if (item.kind === cat.id) return true;
|
|
23
|
+
if (item.tone === cat.id) return true;
|
|
24
|
+
const payload = item.payload as Record<string, unknown> | null | undefined;
|
|
25
|
+
if (payload && typeof payload === 'object') {
|
|
26
|
+
if (payload.kind === cat.id) return true;
|
|
27
|
+
if (payload.type === cat.id) return true;
|
|
28
|
+
if (payload.category === cat.id) return true;
|
|
29
|
+
}
|
|
30
|
+
if (cat.tone && item.tone === cat.tone) return true;
|
|
31
|
+
return false;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export function CalendarPage<T = unknown>({
|
|
35
|
+
title,
|
|
36
|
+
subtitle,
|
|
37
|
+
kicker,
|
|
38
|
+
actions,
|
|
39
|
+
callout,
|
|
40
|
+
items,
|
|
41
|
+
categories,
|
|
42
|
+
categoryMode = 'multiple',
|
|
43
|
+
activeCategoryIds,
|
|
44
|
+
onActiveCategoriesChange,
|
|
45
|
+
views,
|
|
46
|
+
defaultView,
|
|
47
|
+
view,
|
|
48
|
+
onViewChange,
|
|
49
|
+
cursor,
|
|
50
|
+
initialCursor,
|
|
51
|
+
onCursorChange,
|
|
52
|
+
selectedDay,
|
|
53
|
+
initialSelectedDay,
|
|
54
|
+
onSelectDay,
|
|
55
|
+
selectedDayDetail,
|
|
56
|
+
onSelectItem,
|
|
57
|
+
onSlotClick,
|
|
58
|
+
weekStartsOn = 1,
|
|
59
|
+
dayStartMin,
|
|
60
|
+
dayEndMin,
|
|
61
|
+
maxPerDay,
|
|
62
|
+
agendaDays,
|
|
63
|
+
locale,
|
|
64
|
+
labels,
|
|
65
|
+
toolbarExtra,
|
|
66
|
+
footer,
|
|
67
|
+
children,
|
|
68
|
+
className,
|
|
69
|
+
}: CalendarPageProps<T>): ReactNode {
|
|
70
|
+
const [internalView, setInternalView] = useState<CalendarScreenView>(
|
|
71
|
+
() => defaultView ?? 'month',
|
|
72
|
+
);
|
|
73
|
+
const currentView = view ?? internalView;
|
|
74
|
+
const handleViewChange = useCallback(
|
|
75
|
+
(nextView: CalendarScreenView) => {
|
|
76
|
+
if (onViewChange) {
|
|
77
|
+
onViewChange(nextView);
|
|
78
|
+
}
|
|
79
|
+
setInternalView(nextView);
|
|
80
|
+
},
|
|
81
|
+
[onViewChange],
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
const [internalCategoryIds, setInternalCategoryIds] = useState<readonly string[]>(() =>
|
|
85
|
+
categories ? categories.map((c) => c.id) : [],
|
|
86
|
+
);
|
|
87
|
+
const activeIds = activeCategoryIds ?? internalCategoryIds;
|
|
88
|
+
const activeSet = useMemo(() => new Set(activeIds), [activeIds]);
|
|
89
|
+
|
|
90
|
+
const isAllActive =
|
|
91
|
+
!categories || categories.length === 0 || activeIds.length === categories.length;
|
|
92
|
+
|
|
93
|
+
const handleCategoryToggle = (catId: string) => {
|
|
94
|
+
let next: string[];
|
|
95
|
+
if (categoryMode === 'single') {
|
|
96
|
+
const isCurrentlySingle = activeIds.length === 1 && activeIds[0] === catId;
|
|
97
|
+
next = isCurrentlySingle ? (categories ?? []).map((c) => c.id) : [catId];
|
|
98
|
+
} else {
|
|
99
|
+
const set = new Set(activeIds);
|
|
100
|
+
if (set.has(catId)) {
|
|
101
|
+
set.delete(catId);
|
|
102
|
+
} else {
|
|
103
|
+
set.add(catId);
|
|
104
|
+
}
|
|
105
|
+
next = Array.from(set);
|
|
106
|
+
}
|
|
107
|
+
if (onActiveCategoriesChange) {
|
|
108
|
+
onActiveCategoriesChange(next);
|
|
109
|
+
} else {
|
|
110
|
+
setInternalCategoryIds(next);
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const handleSelectAllCategories = () => {
|
|
115
|
+
const allIds = (categories ?? []).map((c) => c.id);
|
|
116
|
+
if (onActiveCategoriesChange) {
|
|
117
|
+
onActiveCategoriesChange(allIds);
|
|
118
|
+
} else {
|
|
119
|
+
setInternalCategoryIds(allIds);
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const categoryCounts = useMemo(() => {
|
|
124
|
+
if (!categories) return new Map<string, number>();
|
|
125
|
+
const counts = new Map<string, number>();
|
|
126
|
+
for (const cat of categories) {
|
|
127
|
+
const count = items.filter((item) => matchesCategory(item, cat)).length;
|
|
128
|
+
counts.set(cat.id, count);
|
|
129
|
+
}
|
|
130
|
+
return counts;
|
|
131
|
+
}, [categories, items]);
|
|
132
|
+
|
|
133
|
+
const filteredItems = useMemo(() => {
|
|
134
|
+
if (!categories || categories.length === 0 || isAllActive) {
|
|
135
|
+
return items;
|
|
136
|
+
}
|
|
137
|
+
const activeCats = categories.filter((c) => activeSet.has(c.id));
|
|
138
|
+
return items.filter((item) => activeCats.some((cat) => matchesCategory(item, cat)));
|
|
139
|
+
}, [items, categories, isAllActive, activeSet]);
|
|
140
|
+
|
|
141
|
+
const [internalSelectedDay, setInternalSelectedDay] = useState<string>(() =>
|
|
142
|
+
initialSelectedDay ?? initialCursor ?? todayKey(),
|
|
143
|
+
);
|
|
144
|
+
const currentSelectedDay = selectedDay !== undefined ? selectedDay : internalSelectedDay;
|
|
145
|
+
|
|
146
|
+
const handleSelectDay = useCallback(
|
|
147
|
+
(dayKey: string) => {
|
|
148
|
+
if (onSelectDay) {
|
|
149
|
+
onSelectDay(dayKey);
|
|
150
|
+
}
|
|
151
|
+
setInternalSelectedDay(dayKey);
|
|
152
|
+
},
|
|
153
|
+
[onSelectDay],
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
const detailConfig: CalendarSelectedDayConfig<T> | null = useMemo(() => {
|
|
157
|
+
if (!selectedDayDetail) return null;
|
|
158
|
+
if (typeof selectedDayDetail === 'boolean') return {};
|
|
159
|
+
return selectedDayDetail;
|
|
160
|
+
}, [selectedDayDetail]);
|
|
161
|
+
|
|
162
|
+
const selectedDayItems = useMemo(() => {
|
|
163
|
+
if (!currentSelectedDay) return [];
|
|
164
|
+
return filteredItems.filter((item) => item.dayKey === currentSelectedDay);
|
|
165
|
+
}, [filteredItems, currentSelectedDay]);
|
|
166
|
+
|
|
167
|
+
const renderedActions = useMemo(() => {
|
|
168
|
+
if (!actions) return undefined;
|
|
169
|
+
if (Array.isArray(actions)) {
|
|
170
|
+
return (
|
|
171
|
+
<div className="flex items-center gap-2">
|
|
172
|
+
{actions.map((act) => (
|
|
173
|
+
<Button
|
|
174
|
+
key={act.label}
|
|
175
|
+
variant={act.variant ?? 'outline'}
|
|
176
|
+
onClick={act.onClick}
|
|
177
|
+
disabled={act.disabled}
|
|
178
|
+
size="sm"
|
|
179
|
+
>
|
|
180
|
+
{act.icon}
|
|
181
|
+
{act.label}
|
|
182
|
+
</Button>
|
|
183
|
+
))}
|
|
184
|
+
</div>
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
if (
|
|
188
|
+
typeof actions === 'object' &&
|
|
189
|
+
actions !== null &&
|
|
190
|
+
'onClick' in actions &&
|
|
191
|
+
'label' in actions
|
|
192
|
+
) {
|
|
193
|
+
const act = actions as CalendarPageAction;
|
|
194
|
+
return (
|
|
195
|
+
<Button
|
|
196
|
+
variant={act.variant ?? 'primary'}
|
|
197
|
+
onClick={act.onClick}
|
|
198
|
+
disabled={act.disabled}
|
|
199
|
+
size="sm"
|
|
200
|
+
>
|
|
201
|
+
{act.icon}
|
|
202
|
+
{act.label}
|
|
203
|
+
</Button>
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
return actions as ReactNode;
|
|
207
|
+
}, [actions]);
|
|
208
|
+
|
|
209
|
+
return (
|
|
210
|
+
<div className={`udb-cal-page ${className ?? ''}`.trim()}>
|
|
211
|
+
<PageHeader
|
|
212
|
+
kicker={kicker}
|
|
213
|
+
title={title}
|
|
214
|
+
subtitle={subtitle}
|
|
215
|
+
actions={renderedActions}
|
|
216
|
+
/>
|
|
217
|
+
|
|
218
|
+
{callout && <div className="udb-cal-callout">{callout}</div>}
|
|
219
|
+
|
|
220
|
+
{categories && categories.length > 0 && (
|
|
221
|
+
<div className="udb-cal-legend" role="toolbar" aria-label="Filter by category">
|
|
222
|
+
<button
|
|
223
|
+
type="button"
|
|
224
|
+
className={`udb-cal-chip${isAllActive ? ' is-active' : ''}`}
|
|
225
|
+
onClick={handleSelectAllCategories}
|
|
226
|
+
aria-pressed={isAllActive}
|
|
227
|
+
>
|
|
228
|
+
<span>{labels?.allCategories ?? 'All'}</span>
|
|
229
|
+
<span className="udb-cal-count">{items.length}</span>
|
|
230
|
+
</button>
|
|
231
|
+
{categories.map((cat) => {
|
|
232
|
+
const isActive = activeSet.has(cat.id);
|
|
233
|
+
const count = categoryCounts.get(cat.id) ?? 0;
|
|
234
|
+
return (
|
|
235
|
+
<button
|
|
236
|
+
key={cat.id}
|
|
237
|
+
type="button"
|
|
238
|
+
className={`udb-cal-chip${isActive ? ' is-active' : ''}`}
|
|
239
|
+
onClick={() => handleCategoryToggle(cat.id)}
|
|
240
|
+
aria-pressed={isActive}
|
|
241
|
+
>
|
|
242
|
+
<span
|
|
243
|
+
className={`ds-cal-legend-dot ds-cal-dot--${cat.tone ?? 'primary'}`}
|
|
244
|
+
aria-hidden
|
|
245
|
+
/>
|
|
246
|
+
{cat.icon}
|
|
247
|
+
<span>{cat.label}</span>
|
|
248
|
+
<span className="udb-cal-count">{count}</span>
|
|
249
|
+
</button>
|
|
250
|
+
);
|
|
251
|
+
})}
|
|
252
|
+
</div>
|
|
253
|
+
)}
|
|
254
|
+
|
|
255
|
+
<div className="udb-cal-card">
|
|
256
|
+
<Calendar
|
|
257
|
+
items={filteredItems}
|
|
258
|
+
views={views}
|
|
259
|
+
view={currentView}
|
|
260
|
+
onViewChange={handleViewChange}
|
|
261
|
+
cursor={cursor}
|
|
262
|
+
initialCursor={initialCursor}
|
|
263
|
+
onCursorChange={onCursorChange}
|
|
264
|
+
weekStartsOn={weekStartsOn}
|
|
265
|
+
dayStartMin={dayStartMin}
|
|
266
|
+
dayEndMin={dayEndMin}
|
|
267
|
+
maxPerDay={maxPerDay}
|
|
268
|
+
agendaDays={agendaDays}
|
|
269
|
+
locale={locale}
|
|
270
|
+
labels={labels}
|
|
271
|
+
toolbarExtra={toolbarExtra}
|
|
272
|
+
onSelectItem={
|
|
273
|
+
onSelectItem
|
|
274
|
+
? (item) => onSelectItem(item as CalendarPageItem<T>)
|
|
275
|
+
: undefined
|
|
276
|
+
}
|
|
277
|
+
onSelectDay={handleSelectDay}
|
|
278
|
+
onSlotClick={onSlotClick}
|
|
279
|
+
/>
|
|
280
|
+
</div>
|
|
281
|
+
|
|
282
|
+
{detailConfig && currentSelectedDay && (
|
|
283
|
+
<CalendarSelectedDayPanel
|
|
284
|
+
config={detailConfig}
|
|
285
|
+
dayKey={currentSelectedDay}
|
|
286
|
+
items={selectedDayItems}
|
|
287
|
+
labels={labels}
|
|
288
|
+
onSelectItem={onSelectItem}
|
|
289
|
+
/>
|
|
290
|
+
)}
|
|
291
|
+
|
|
292
|
+
{footer && <div className="udb-cal-footer">{footer}</div>}
|
|
293
|
+
{children}
|
|
294
|
+
</div>
|
|
295
|
+
);
|
|
296
|
+
}
|