@jsb188/calendar 1.1.10 → 1.1.12
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 +16 -15
- package/src/constants/calendar.ts +17 -3
- package/src/libs/calendar-geometry.ts +165 -91
- package/src/libs/calendar-gesture.ts +58 -15
- package/src/libs/calendar-now.ts +39 -0
- package/src/libs/calendar-range.ts +88 -27
- package/src/libs/calendar-state.ts +21 -156
- package/src/libs/calendar-url.ts +55 -8
- package/src/libs/roster-layout.ts +388 -0
- package/src/main.ts +3 -0
- package/src/modules/Calendar.tsx +375 -287
- package/src/modules/MiniCalendar.tsx +376 -0
- package/src/types/calendar.d.ts +7 -1
- package/src/types/shift-form.d.ts +19 -0
- package/src/ui/CalendarAgendaUI.tsx +43 -14
- package/src/ui/CalendarMonthUI.tsx +38 -26
- package/src/ui/CalendarToolbarUI.tsx +50 -27
- package/src/ui/CalendarUI.tsx +280 -226
- package/src/ui/CalendarYearUI.tsx +36 -50
- package/src/ui/RosterUI.tsx +273 -0
- package/src/ui/ShiftFormUI.tsx +333 -0
- package/tests/calendar-geometry.test.ts +230 -84
- package/tests/calendar-gesture.test.ts +43 -12
- package/tests/calendar-range.test.ts +159 -33
- package/tests/calendar-url.test.ts +77 -12
- package/tests/roster-layout.test.ts +210 -0
- package/src/ui/CalendarCoverageUI.tsx +0 -199
- package/src/ui/CalendarEventDetailUI.tsx +0 -260
- package/src/ui/CalendarEventFormUI.tsx +0 -239
- package/src/ui/CalendarRailUI.tsx +0 -282
- package/src/ui/CalendarRequestUI.tsx +0 -537
- package/src/ui/CalendarViolationUI.tsx +0 -207
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
import { cn } from '@jsb188/app/utils/string.ts';
|
|
2
|
+
import { Icon } from '@jsb188/react-web/svgs/Icon';
|
|
3
|
+
import { DateTime } from 'luxon';
|
|
4
|
+
import { type MouseEvent, memo, useCallback, useMemo } from 'react';
|
|
5
|
+
import {
|
|
6
|
+
getCalendarTimeZone,
|
|
7
|
+
normalizeCalendarWeekStartsOn,
|
|
8
|
+
} from '../libs/calendar-range.ts';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A month at a glance.
|
|
12
|
+
*
|
|
13
|
+
* Standalone on purpose: it reads nothing from the rest of this package — no
|
|
14
|
+
* range math, no atoms, no CalendarDayObj — so it drops into a sidebar, a date
|
|
15
|
+
* picker, or a surface that never imports the calendar grid at all. It draws
|
|
16
|
+
* the month itself from a single date and reports clicks back out; every other
|
|
17
|
+
* decision is a prop.
|
|
18
|
+
*
|
|
19
|
+
* Days are addressed by their local date key ("yyyy-MM-dd") rather than by
|
|
20
|
+
* Date, so a caller asking "is this day selected" never has to reason about
|
|
21
|
+
* instants and zones, which disagree about which day it is.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
const FILE_CONSTANTS = {
|
|
25
|
+
// Six rows always, never five: a grid that changed height between months
|
|
26
|
+
// would make everything below it jump on every step
|
|
27
|
+
weekCount: 6,
|
|
28
|
+
dateFormat: 'yyyy-MM-dd',
|
|
29
|
+
daySize: 26,
|
|
30
|
+
headerStyle: { marginBottom: 6 },
|
|
31
|
+
gridStyle: {
|
|
32
|
+
display: 'grid' as const,
|
|
33
|
+
gridTemplateColumns: 'repeat(7, minmax(0, 1fr))',
|
|
34
|
+
},
|
|
35
|
+
columnLabelStyle: { paddingBottom: 2 },
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/*
|
|
39
|
+
* One drawn cell.
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
interface MiniCalendarDayObj {
|
|
43
|
+
dateKey: string;
|
|
44
|
+
// Day of month, localized
|
|
45
|
+
label: string;
|
|
46
|
+
// False for the leading and trailing days of the neighbouring months
|
|
47
|
+
isInMonth: boolean;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/*
|
|
51
|
+
* Build the six-by-seven grid a month is drawn on, padded at both ends so the
|
|
52
|
+
* 1st lands under its own weekday column.
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
function buildMiniCalendarWeeks(p: {
|
|
56
|
+
monthDate: Date;
|
|
57
|
+
timeZone?: string | null;
|
|
58
|
+
locale?: string | null;
|
|
59
|
+
weekStartsOn: number;
|
|
60
|
+
}): MiniCalendarDayObj[][] {
|
|
61
|
+
const { monthDate, timeZone, locale, weekStartsOn } = p;
|
|
62
|
+
const monthStart = DateTime.fromJSDate(monthDate, {
|
|
63
|
+
zone: timeZone || undefined,
|
|
64
|
+
})
|
|
65
|
+
.setLocale(locale || 'en')
|
|
66
|
+
.startOf('month');
|
|
67
|
+
// luxon: 1 = Monday .. 7 = Sunday; normalize to 0 = Sunday
|
|
68
|
+
const gridStart = monthStart.minus({
|
|
69
|
+
days: ((monthStart.weekday % 7) - weekStartsOn + 7) % 7,
|
|
70
|
+
});
|
|
71
|
+
const weeks: MiniCalendarDayObj[][] = [];
|
|
72
|
+
|
|
73
|
+
for (let weekIndex = 0; weekIndex < FILE_CONSTANTS.weekCount; weekIndex++) {
|
|
74
|
+
const week: MiniCalendarDayObj[] = [];
|
|
75
|
+
|
|
76
|
+
for (let dayIndex = 0; dayIndex < 7; dayIndex++) {
|
|
77
|
+
const day = gridStart.plus({ days: weekIndex * 7 + dayIndex });
|
|
78
|
+
|
|
79
|
+
week.push({
|
|
80
|
+
dateKey: day.toFormat(FILE_CONSTANTS.dateFormat),
|
|
81
|
+
label: day.toFormat('d'),
|
|
82
|
+
isInMonth:
|
|
83
|
+
day.month === monthStart.month && day.year === monthStart.year,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
weeks.push(week);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return weeks;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/*
|
|
94
|
+
* Return the text treatment one day gets. A selected day takes its colour from
|
|
95
|
+
* the fill behind it, so it opts out of all three.
|
|
96
|
+
*/
|
|
97
|
+
|
|
98
|
+
function getMiniCalendarDayColorClassName(p: {
|
|
99
|
+
isSelected: boolean;
|
|
100
|
+
isToday: boolean;
|
|
101
|
+
isInMonth: boolean;
|
|
102
|
+
}): string {
|
|
103
|
+
if (p.isSelected) {
|
|
104
|
+
return '';
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (p.isToday) {
|
|
108
|
+
return 'cl_primary ft_bold';
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// A leading or trailing day belongs to the neighbouring month; dimmed, not
|
|
112
|
+
// hidden, so the week it sits in still reads as a week
|
|
113
|
+
return p.isInMonth ? 'cl_md' : 'cl_lt';
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export interface MiniCalendarProps {
|
|
117
|
+
className?: string;
|
|
118
|
+
// Any instant inside the month to draw
|
|
119
|
+
monthDate: Date;
|
|
120
|
+
timeZone?: string | null;
|
|
121
|
+
locale?: string | null;
|
|
122
|
+
// 0 = Sunday .. 6 = Saturday
|
|
123
|
+
weekStartsOn?: number;
|
|
124
|
+
// The heading above the grid. Absent, and with no stepper, the header row
|
|
125
|
+
// is not drawn at all, so a caller that titles its own panel gets only the
|
|
126
|
+
// month.
|
|
127
|
+
title?: string | null;
|
|
128
|
+
// Column headings; derived from the locale when not supplied
|
|
129
|
+
weekdayLabels?: string[];
|
|
130
|
+
// Days drawn as chosen: a solid filled square
|
|
131
|
+
selectedDateKeys?: string[];
|
|
132
|
+
// Days drawn as the range currently on screen: a faint band behind the row.
|
|
133
|
+
// Any run of them is joined, so a week reads as one band and four days read
|
|
134
|
+
// as one shorter band, without the caller saying which shape it meant.
|
|
135
|
+
highlightedDateKeys?: string[];
|
|
136
|
+
// The day marked as today, passed in rather than read from the system
|
|
137
|
+
// clock, so this agrees with whatever zone its owner draws in
|
|
138
|
+
todayDateKey?: string | null;
|
|
139
|
+
// Leading and trailing days of the neighbouring months, dimmed. Off leaves
|
|
140
|
+
// those cells empty so the month reads as its own block.
|
|
141
|
+
showAdjacentMonthDays?: boolean;
|
|
142
|
+
// Edge of one day square, in pixels
|
|
143
|
+
daySize?: number;
|
|
144
|
+
// Display strings; the package owns no copy of its own
|
|
145
|
+
previousText?: string;
|
|
146
|
+
nextText?: string;
|
|
147
|
+
// The two paint states, so a caller can theme the grid without forking it
|
|
148
|
+
selectedClassName?: string;
|
|
149
|
+
highlightClassName?: string;
|
|
150
|
+
// Absent means no stepper is drawn, for a grid somebody else navigates
|
|
151
|
+
onStepMonth?: (direction: 1 | -1) => void;
|
|
152
|
+
onSelectDay?: (dateKey: string) => void;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export const MiniCalendar = memo((p: MiniCalendarProps) => {
|
|
156
|
+
const {
|
|
157
|
+
className,
|
|
158
|
+
monthDate,
|
|
159
|
+
timeZone,
|
|
160
|
+
locale,
|
|
161
|
+
weekStartsOn,
|
|
162
|
+
title,
|
|
163
|
+
weekdayLabels,
|
|
164
|
+
selectedDateKeys,
|
|
165
|
+
highlightedDateKeys,
|
|
166
|
+
todayDateKey,
|
|
167
|
+
showAdjacentMonthDays,
|
|
168
|
+
daySize,
|
|
169
|
+
previousText,
|
|
170
|
+
nextText,
|
|
171
|
+
selectedClassName,
|
|
172
|
+
highlightClassName,
|
|
173
|
+
onStepMonth,
|
|
174
|
+
onSelectDay,
|
|
175
|
+
} = p;
|
|
176
|
+
|
|
177
|
+
const resolvedTimeZone = getCalendarTimeZone(timeZone);
|
|
178
|
+
const weekStart = normalizeCalendarWeekStartsOn(weekStartsOn);
|
|
179
|
+
const size = daySize || FILE_CONSTANTS.daySize;
|
|
180
|
+
const cellStyle = useMemo(() => ({ height: size + 4 }), [size]);
|
|
181
|
+
const dayStyle = useMemo(() => ({ width: size, height: size }), [size]);
|
|
182
|
+
|
|
183
|
+
// The grid only changes when the date crosses into another month, so it is
|
|
184
|
+
// keyed on the month rather than the instant: a caller passing a live clock
|
|
185
|
+
// would otherwise rebuild all 42 cells on every tick
|
|
186
|
+
const monthKey = useMemo(
|
|
187
|
+
() =>
|
|
188
|
+
DateTime.fromJSDate(monthDate, { zone: resolvedTimeZone }).toFormat(
|
|
189
|
+
'yyyy-MM',
|
|
190
|
+
),
|
|
191
|
+
[monthDate, resolvedTimeZone],
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
const weeks = useMemo(
|
|
195
|
+
// "monthDate" is read inside but "monthKey" is the dependency; see above
|
|
196
|
+
() =>
|
|
197
|
+
buildMiniCalendarWeeks({
|
|
198
|
+
monthDate,
|
|
199
|
+
timeZone: resolvedTimeZone,
|
|
200
|
+
locale,
|
|
201
|
+
weekStartsOn: weekStart,
|
|
202
|
+
}),
|
|
203
|
+
[monthKey, resolvedTimeZone, locale, weekStart],
|
|
204
|
+
);
|
|
205
|
+
|
|
206
|
+
/*
|
|
207
|
+
* Column headings, built from a real week so they honour the locale and the
|
|
208
|
+
* configured week start rather than a hardcoded list.
|
|
209
|
+
*/
|
|
210
|
+
|
|
211
|
+
const columnLabels = useMemo(() => {
|
|
212
|
+
if (weekdayLabels) {
|
|
213
|
+
return weekdayLabels;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// Any Sunday; 2026-01-04 is one
|
|
217
|
+
const sunday = DateTime.fromObject(
|
|
218
|
+
{ year: 2026, month: 1, day: 4 },
|
|
219
|
+
{ zone: resolvedTimeZone },
|
|
220
|
+
).setLocale(locale || 'en');
|
|
221
|
+
|
|
222
|
+
return Array.from({ length: 7 }, (_unused, index) =>
|
|
223
|
+
sunday
|
|
224
|
+
.plus({ days: index + weekStart })
|
|
225
|
+
.toFormat('ccc')
|
|
226
|
+
.slice(0, 2),
|
|
227
|
+
);
|
|
228
|
+
}, [weekdayLabels, resolvedTimeZone, locale, weekStart]);
|
|
229
|
+
|
|
230
|
+
// Membership is asked 42 times per render, so the lists become sets once
|
|
231
|
+
const selectedSet = useMemo(
|
|
232
|
+
() => new Set(selectedDateKeys || []),
|
|
233
|
+
[selectedDateKeys],
|
|
234
|
+
);
|
|
235
|
+
const highlightedSet = useMemo(
|
|
236
|
+
() => new Set(highlightedDateKeys || []),
|
|
237
|
+
[highlightedDateKeys],
|
|
238
|
+
);
|
|
239
|
+
|
|
240
|
+
/*
|
|
241
|
+
* Move to the month represented by the clicked step action.
|
|
242
|
+
*/
|
|
243
|
+
const handleStepMonth = useCallback(
|
|
244
|
+
(event: MouseEvent<HTMLButtonElement>) => {
|
|
245
|
+
onStepMonth?.(
|
|
246
|
+
event.currentTarget.dataset.direction === 'PREVIOUS' ? -1 : 1,
|
|
247
|
+
);
|
|
248
|
+
},
|
|
249
|
+
[onStepMonth],
|
|
250
|
+
);
|
|
251
|
+
|
|
252
|
+
/*
|
|
253
|
+
* Report the date stored on the clicked day without allocating one callback
|
|
254
|
+
* for every day cell.
|
|
255
|
+
*/
|
|
256
|
+
const handleSelectDay = useCallback(
|
|
257
|
+
(event: MouseEvent<HTMLButtonElement>) => {
|
|
258
|
+
const dateKey = event.currentTarget.dataset.dateKey;
|
|
259
|
+
if (dateKey) {
|
|
260
|
+
onSelectDay?.(dateKey);
|
|
261
|
+
}
|
|
262
|
+
},
|
|
263
|
+
[onSelectDay],
|
|
264
|
+
);
|
|
265
|
+
|
|
266
|
+
return (
|
|
267
|
+
<div className={cn('unsel', className)}>
|
|
268
|
+
{title || onStepMonth ? (
|
|
269
|
+
<div
|
|
270
|
+
className="h_spread"
|
|
271
|
+
style={FILE_CONSTANTS.headerStyle}
|
|
272
|
+
>
|
|
273
|
+
<span className="f ellip ft_sm ft_bold cl_md">{title || ''}</span>
|
|
274
|
+
|
|
275
|
+
{onStepMonth ? (
|
|
276
|
+
<span className="h_item no_shrink">
|
|
277
|
+
{/* No IconButton exists in the kit, so these are the
|
|
278
|
+
documented raw pattern: a bare button wrapping an
|
|
279
|
+
Icon. The sprite has no chevron-left, so the
|
|
280
|
+
previous arrow is the right one turned around. */}
|
|
281
|
+
<button
|
|
282
|
+
type="button"
|
|
283
|
+
className="av_sm h_center tf_rotate_180"
|
|
284
|
+
aria-label={previousText}
|
|
285
|
+
title={previousText}
|
|
286
|
+
data-direction="PREVIOUS"
|
|
287
|
+
onClick={handleStepMonth}
|
|
288
|
+
>
|
|
289
|
+
<Icon name="chevron-right" />
|
|
290
|
+
</button>
|
|
291
|
+
|
|
292
|
+
<button
|
|
293
|
+
type="button"
|
|
294
|
+
className="av_sm h_center"
|
|
295
|
+
aria-label={nextText}
|
|
296
|
+
title={nextText}
|
|
297
|
+
data-direction="NEXT"
|
|
298
|
+
onClick={handleStepMonth}
|
|
299
|
+
>
|
|
300
|
+
<Icon name="chevron-right" />
|
|
301
|
+
</button>
|
|
302
|
+
</span>
|
|
303
|
+
) : null}
|
|
304
|
+
</div>
|
|
305
|
+
) : null}
|
|
306
|
+
|
|
307
|
+
<div style={FILE_CONSTANTS.gridStyle}>
|
|
308
|
+
{columnLabels.map((label, index) => (
|
|
309
|
+
<div
|
|
310
|
+
key={index}
|
|
311
|
+
className="a_c ft_xxs cl_lt"
|
|
312
|
+
style={FILE_CONSTANTS.columnLabelStyle}
|
|
313
|
+
>
|
|
314
|
+
{label}
|
|
315
|
+
</div>
|
|
316
|
+
))}
|
|
317
|
+
</div>
|
|
318
|
+
|
|
319
|
+
{weeks.map((week, weekIndex) => (
|
|
320
|
+
<div
|
|
321
|
+
key={weekIndex}
|
|
322
|
+
style={FILE_CONSTANTS.gridStyle}
|
|
323
|
+
>
|
|
324
|
+
{week.map((day, dayIndex) => {
|
|
325
|
+
const isHighlighted = highlightedSet.has(day.dateKey);
|
|
326
|
+
const isSelected = selectedSet.has(day.dateKey);
|
|
327
|
+
const isDrawn = day.isInMonth || !!showAdjacentMonthDays;
|
|
328
|
+
|
|
329
|
+
return (
|
|
330
|
+
<div
|
|
331
|
+
key={day.dateKey}
|
|
332
|
+
className={cn(
|
|
333
|
+
'h_center',
|
|
334
|
+
isHighlighted ? highlightClassName || 'bg_alt' : '',
|
|
335
|
+
// Only the ends of a run are rounded, so a highlighted
|
|
336
|
+
// week reads as one band rather than seven pills
|
|
337
|
+
isHighlighted &&
|
|
338
|
+
!highlightedSet.has(week[dayIndex - 1]?.dateKey || '')
|
|
339
|
+
? 'rl_df'
|
|
340
|
+
: '',
|
|
341
|
+
isHighlighted &&
|
|
342
|
+
!highlightedSet.has(week[dayIndex + 1]?.dateKey || '')
|
|
343
|
+
? 'rr_df'
|
|
344
|
+
: '',
|
|
345
|
+
)}
|
|
346
|
+
style={cellStyle}
|
|
347
|
+
>
|
|
348
|
+
{isDrawn ? (
|
|
349
|
+
<button
|
|
350
|
+
type="button"
|
|
351
|
+
className={cn(
|
|
352
|
+
'h_center ft_sm r_df',
|
|
353
|
+
isSelected
|
|
354
|
+
? selectedClassName || 'bg_primary'
|
|
355
|
+
: 'bg_active_hv',
|
|
356
|
+
getMiniCalendarDayColorClassName({
|
|
357
|
+
isSelected,
|
|
358
|
+
isToday: day.dateKey === todayDateKey,
|
|
359
|
+
isInMonth: day.isInMonth,
|
|
360
|
+
}),
|
|
361
|
+
)}
|
|
362
|
+
data-date-key={day.dateKey}
|
|
363
|
+
style={dayStyle}
|
|
364
|
+
onClick={handleSelectDay}
|
|
365
|
+
>
|
|
366
|
+
{day.label}
|
|
367
|
+
</button>
|
|
368
|
+
) : null}
|
|
369
|
+
</div>
|
|
370
|
+
);
|
|
371
|
+
})}
|
|
372
|
+
</div>
|
|
373
|
+
))}
|
|
374
|
+
</div>
|
|
375
|
+
);
|
|
376
|
+
});
|
package/src/types/calendar.d.ts
CHANGED
|
@@ -30,7 +30,13 @@ export interface CalendarEventObj {
|
|
|
30
30
|
note?: string | null;
|
|
31
31
|
color?: string | null;
|
|
32
32
|
// Everyone working this entry, for the assignee chips and "my calendar only"
|
|
33
|
-
|
|
33
|
+
assigneeResourceIds: string[];
|
|
34
|
+
assigneeNames?: string[];
|
|
35
|
+
roomId?: string | null;
|
|
36
|
+
roomName?: string | null;
|
|
37
|
+
breach?: 'BLOCK' | 'WARN' | null;
|
|
38
|
+
version?: string;
|
|
39
|
+
pending?: boolean;
|
|
34
40
|
// How many people the entry still needs; drives the "open shift" treatment
|
|
35
41
|
openCount?: number;
|
|
36
42
|
// Set when the viewer is one of the assignees, so the grid can mark it
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ScheduleSlotInput } from '@jsb188/graphql/schedule.d';
|
|
2
|
+
export interface ShiftFormValues {
|
|
3
|
+
kind: 'SHIFT' | 'EVENT' | 'BLOCK';
|
|
4
|
+
title: string;
|
|
5
|
+
roomId: string;
|
|
6
|
+
start: string;
|
|
7
|
+
end: string;
|
|
8
|
+
allDay: boolean;
|
|
9
|
+
note: string;
|
|
10
|
+
location: string;
|
|
11
|
+
slots: ScheduleSlotInput[];
|
|
12
|
+
repeat: '' | 'DAILY' | 'WEEKLY' | 'MONTHLY';
|
|
13
|
+
interval: number;
|
|
14
|
+
weekdays: number[];
|
|
15
|
+
monthDay: number;
|
|
16
|
+
count: string;
|
|
17
|
+
until: string;
|
|
18
|
+
future: boolean;
|
|
19
|
+
}
|
|
@@ -3,6 +3,22 @@ import { memo } from 'react';
|
|
|
3
3
|
import { CALENDAR_DRAFT_PATTERN_CLASS_NAME } from '../constants/calendar.ts';
|
|
4
4
|
import type { CalendarEventObj } from '../types/calendar.d.ts';
|
|
5
5
|
|
|
6
|
+
const FILE_CONSTANTS = {
|
|
7
|
+
dayHeaderStyle: {
|
|
8
|
+
paddingLeft: 12,
|
|
9
|
+
paddingRight: 12,
|
|
10
|
+
paddingTop: 6,
|
|
11
|
+
paddingBottom: 2,
|
|
12
|
+
},
|
|
13
|
+
eventStyle: {
|
|
14
|
+
paddingLeft: 12,
|
|
15
|
+
paddingRight: 12,
|
|
16
|
+
paddingTop: 4,
|
|
17
|
+
paddingBottom: 4,
|
|
18
|
+
},
|
|
19
|
+
timeLabelStyle: { width: 104 },
|
|
20
|
+
};
|
|
21
|
+
|
|
6
22
|
/**
|
|
7
23
|
* The agenda ("Schedule") list.
|
|
8
24
|
*
|
|
@@ -31,23 +47,32 @@ export interface CalendarAgendaUIProps {
|
|
|
31
47
|
}
|
|
32
48
|
|
|
33
49
|
export const CalendarAgendaUI = memo((p: CalendarAgendaUIProps) => {
|
|
34
|
-
const {
|
|
50
|
+
const {
|
|
51
|
+
days,
|
|
52
|
+
selectedEventId,
|
|
53
|
+
timeLabelByEventId,
|
|
54
|
+
emptyText,
|
|
55
|
+
onSelectEvent,
|
|
56
|
+
} = p;
|
|
35
57
|
|
|
36
58
|
if (!days.length) {
|
|
37
59
|
return (
|
|
38
|
-
<div className=
|
|
39
|
-
<span className=
|
|
60
|
+
<div className="f h_0 v_center a_c">
|
|
61
|
+
<span className="ft_sm cl_lt">{emptyText}</span>
|
|
40
62
|
</div>
|
|
41
63
|
);
|
|
42
64
|
}
|
|
43
65
|
|
|
44
66
|
return (
|
|
45
|
-
<div className=
|
|
67
|
+
<div className="f h_0 app_scr auto_y">
|
|
46
68
|
{days.map((day) => (
|
|
47
|
-
<div
|
|
69
|
+
<div
|
|
70
|
+
key={day.dateKey}
|
|
71
|
+
className="bd_t_1 bd_t_bd"
|
|
72
|
+
>
|
|
48
73
|
<div
|
|
49
|
-
className={cn('
|
|
50
|
-
style={
|
|
74
|
+
className={cn('ft_xxs', day.isToday ? 'ft_bold' : 'cl_lt')}
|
|
75
|
+
style={FILE_CONSTANTS.dayHeaderStyle}
|
|
51
76
|
>
|
|
52
77
|
{day.label}
|
|
53
78
|
</div>
|
|
@@ -55,28 +80,32 @@ export const CalendarAgendaUI = memo((p: CalendarAgendaUIProps) => {
|
|
|
55
80
|
{day.events.map((event) => (
|
|
56
81
|
<button
|
|
57
82
|
key={`${day.dateKey}:${event.id}`}
|
|
58
|
-
type=
|
|
83
|
+
type="button"
|
|
59
84
|
className={cn(
|
|
60
85
|
'w_f a_l h_item gap_sm',
|
|
61
86
|
event.status === 'CANCELED' ? 'strikethrough' : '',
|
|
62
87
|
selectedEventId === event.id ? 'bg_active' : '',
|
|
63
88
|
)}
|
|
64
|
-
style={
|
|
89
|
+
style={FILE_CONSTANTS.eventStyle}
|
|
65
90
|
onClick={() => onSelectEvent(event.id)}
|
|
66
91
|
>
|
|
67
92
|
<span
|
|
68
93
|
className={cn(
|
|
69
|
-
'no_shrink
|
|
70
|
-
event.status === 'DRAFT'
|
|
94
|
+
'no_shrink ft_xxs cl_lt rel of',
|
|
95
|
+
event.status === 'DRAFT'
|
|
96
|
+
? CALENDAR_DRAFT_PATTERN_CLASS_NAME
|
|
97
|
+
: '',
|
|
71
98
|
)}
|
|
72
|
-
style={
|
|
99
|
+
style={FILE_CONSTANTS.timeLabelStyle}
|
|
73
100
|
>
|
|
74
101
|
{timeLabelByEventId.get(event.id) || ''}
|
|
75
102
|
</span>
|
|
76
103
|
|
|
77
|
-
<span className=
|
|
104
|
+
<span className="f ellip ft_sm">{event.title}</span>
|
|
78
105
|
|
|
79
|
-
{event.isMine ?
|
|
106
|
+
{event.isMine ? (
|
|
107
|
+
<span className="no_shrink ft_xxs cl_lt">•</span>
|
|
108
|
+
) : null}
|
|
80
109
|
</button>
|
|
81
110
|
))}
|
|
82
111
|
</div>
|
|
@@ -3,6 +3,14 @@ import { memo } from 'react';
|
|
|
3
3
|
import { CALENDAR_DRAFT_PATTERN_CLASS_NAME } from '../constants/calendar.ts';
|
|
4
4
|
import type { CalendarMonthCellObj } from '../libs/calendar-geometry.ts';
|
|
5
5
|
|
|
6
|
+
const FILE_CONSTANTS = {
|
|
7
|
+
weekdayStyle: { paddingTop: 4, paddingBottom: 4 },
|
|
8
|
+
dayButtonStyle: { paddingLeft: 4, paddingRight: 4, paddingTop: 2 },
|
|
9
|
+
eventsStyle: { paddingLeft: 2, paddingRight: 2 },
|
|
10
|
+
eventStyle: { paddingLeft: 3, paddingRight: 3, marginBottom: 1 },
|
|
11
|
+
overflowStyle: { paddingLeft: 3, paddingRight: 3 },
|
|
12
|
+
};
|
|
13
|
+
|
|
6
14
|
/**
|
|
7
15
|
* The month grid.
|
|
8
16
|
*
|
|
@@ -42,20 +50,24 @@ export const CalendarMonthUI = memo((p: CalendarMonthUIProps) => {
|
|
|
42
50
|
} = p;
|
|
43
51
|
|
|
44
52
|
return (
|
|
45
|
-
<div className=
|
|
46
|
-
<div className=
|
|
53
|
+
<div className="v_stretch h_f w_f of">
|
|
54
|
+
<div className="no_shrink h_stretch bd_b_1 bd_b_bd">
|
|
47
55
|
{weekdayLabels.map((label) => (
|
|
48
|
-
<div
|
|
56
|
+
<div
|
|
57
|
+
key={label}
|
|
58
|
+
className="f a_c ft_xxs cl_lt"
|
|
59
|
+
style={FILE_CONSTANTS.weekdayStyle}
|
|
60
|
+
>
|
|
49
61
|
{label}
|
|
50
62
|
</div>
|
|
51
63
|
))}
|
|
52
64
|
</div>
|
|
53
65
|
|
|
54
|
-
<div className=
|
|
66
|
+
<div className="f h_0 app_scr auto_y">
|
|
55
67
|
{/* Six rows of seven; the grid is the layout, so the cells need no
|
|
56
68
|
per-row wrapper */}
|
|
57
69
|
<div
|
|
58
|
-
className=
|
|
70
|
+
className="h_f"
|
|
59
71
|
style={{
|
|
60
72
|
display: 'grid',
|
|
61
73
|
gridTemplateColumns: 'repeat(7, minmax(0, 1fr))',
|
|
@@ -71,14 +83,14 @@ export const CalendarMonthUI = memo((p: CalendarMonthUIProps) => {
|
|
|
71
83
|
)}
|
|
72
84
|
>
|
|
73
85
|
<button
|
|
74
|
-
type=
|
|
75
|
-
className=
|
|
76
|
-
style={
|
|
86
|
+
type="button"
|
|
87
|
+
className="w_f a_l"
|
|
88
|
+
style={FILE_CONSTANTS.dayButtonStyle}
|
|
77
89
|
onClick={() => onSelectDay(cell.day.dateKey)}
|
|
78
90
|
>
|
|
79
91
|
<span
|
|
80
92
|
className={cn(
|
|
81
|
-
'
|
|
93
|
+
'ft_xxs',
|
|
82
94
|
cell.day.isToday ? 'ft_bold' : '',
|
|
83
95
|
// A leading or trailing day belongs to the
|
|
84
96
|
// neighbouring month; dimmed, not hidden
|
|
@@ -89,37 +101,37 @@ export const CalendarMonthUI = memo((p: CalendarMonthUIProps) => {
|
|
|
89
101
|
</span>
|
|
90
102
|
</button>
|
|
91
103
|
|
|
92
|
-
<div style={
|
|
104
|
+
<div style={FILE_CONSTANTS.eventsStyle}>
|
|
93
105
|
{cell.events.map((event) => (
|
|
94
106
|
<button
|
|
95
107
|
key={event.id}
|
|
96
|
-
type=
|
|
108
|
+
type="button"
|
|
97
109
|
className={cn(
|
|
98
|
-
'w_f a_l ellip
|
|
99
|
-
event.status === 'DRAFT'
|
|
110
|
+
'w_f a_l ellip ft_xxs r_xs rel of',
|
|
111
|
+
event.status === 'DRAFT'
|
|
112
|
+
? CALENDAR_DRAFT_PATTERN_CLASS_NAME
|
|
113
|
+
: '',
|
|
100
114
|
event.status === 'CANCELED' ? 'strikethrough' : '',
|
|
101
115
|
event.isMine ? 'bg_active' : 'bg_alt',
|
|
102
116
|
selectedEventId === event.id ? 'bd_1 bd_bd' : '',
|
|
103
117
|
)}
|
|
104
|
-
style={
|
|
118
|
+
style={FILE_CONSTANTS.eventStyle}
|
|
105
119
|
onClick={() => onSelectEvent(event.id)}
|
|
106
120
|
>
|
|
107
121
|
{event.title}
|
|
108
122
|
</button>
|
|
109
123
|
))}
|
|
110
124
|
|
|
111
|
-
{cell.overflowCount > 0
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
)
|
|
122
|
-
: null}
|
|
125
|
+
{cell.overflowCount > 0 ? (
|
|
126
|
+
<button
|
|
127
|
+
type="button"
|
|
128
|
+
className="w_f a_l ellip ft_xxs cl_lt"
|
|
129
|
+
style={FILE_CONSTANTS.overflowStyle}
|
|
130
|
+
onClick={() => onSelectOverflow(cell.day.dateKey)}
|
|
131
|
+
>
|
|
132
|
+
{moreLabel(cell.overflowCount)}
|
|
133
|
+
</button>
|
|
134
|
+
) : null}
|
|
123
135
|
</div>
|
|
124
136
|
</div>
|
|
125
137
|
))}
|