@jsb188/calendar 1.1.10
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 +44 -0
- package/src/constants/calendar.ts +139 -0
- package/src/css.d.ts +7 -0
- package/src/libs/calendar-geometry.ts +426 -0
- package/src/libs/calendar-gesture.ts +298 -0
- package/src/libs/calendar-range.ts +340 -0
- package/src/libs/calendar-state.ts +161 -0
- package/src/libs/calendar-url.ts +144 -0
- package/src/main.ts +29 -0
- package/src/modules/Calendar.tsx +648 -0
- package/src/types/calendar.d.ts +122 -0
- package/src/ui/CalendarAgendaUI.tsx +86 -0
- package/src/ui/CalendarCoverageUI.tsx +199 -0
- package/src/ui/CalendarEventDetailUI.tsx +260 -0
- package/src/ui/CalendarEventFormUI.tsx +239 -0
- package/src/ui/CalendarMonthUI.tsx +130 -0
- package/src/ui/CalendarRailUI.tsx +282 -0
- package/src/ui/CalendarRequestUI.tsx +537 -0
- package/src/ui/CalendarToolbarUI.tsx +110 -0
- package/src/ui/CalendarUI.tsx +347 -0
- package/src/ui/CalendarViolationUI.tsx +207 -0
- package/src/ui/CalendarYearUI.tsx +81 -0
- package/tests/calendar-geometry.test.ts +403 -0
- package/tests/calendar-gesture.test.ts +309 -0
- package/tests/calendar-range.test.ts +232 -0
- package/tests/calendar-url.test.ts +124 -0
- package/tsconfig.json +13 -0
- package/vitest.config.ts +11 -0
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { cn } from '@jsb188/app/utils/string.ts';
|
|
2
|
+
import { Input, Textarea } from '@jsb188/react-web/modules/Form';
|
|
3
|
+
import { Button } from '@jsb188/react-web/ui/Button';
|
|
4
|
+
import { ToggleSwitch } from '@jsb188/react-web/ui/Form';
|
|
5
|
+
import { memo } from 'react';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The create / edit form for one occurrence.
|
|
9
|
+
*
|
|
10
|
+
* Fully controlled: every keystroke leaves through onChangeValue and comes
|
|
11
|
+
* back as a prop. The form owns no draft of its own, because the same draft
|
|
12
|
+
* has to survive the bubble closing, a drag on the grid moving the block, and
|
|
13
|
+
* the modal being reopened — none of which this component can see.
|
|
14
|
+
*
|
|
15
|
+
* Dates and times are kept as the browser's own wire formats ("yyyy-MM-dd" and
|
|
16
|
+
* "HH:mm") rather than as Date objects. There is no datetime picker in the UI
|
|
17
|
+
* kit, so these are native date/time inputs, and native inputs speak those two
|
|
18
|
+
* strings; keeping the props in the same shape means nothing here has to parse
|
|
19
|
+
* or re-serialize, and the zone stays the caller's problem — which is correct,
|
|
20
|
+
* since only the caller knows the calendar's display zone.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
export interface CalendarEventFormValuesObj {
|
|
24
|
+
title: string;
|
|
25
|
+
allDay: boolean;
|
|
26
|
+
// "yyyy-MM-dd", the value an <input type='date'> reads and writes
|
|
27
|
+
startDate: string;
|
|
28
|
+
// "HH:mm" in 24-hour time, the value an <input type='time'> reads and writes
|
|
29
|
+
startTime: string;
|
|
30
|
+
endDate: string;
|
|
31
|
+
endTime: string;
|
|
32
|
+
location: string;
|
|
33
|
+
note: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export type CalendarEventFormFieldEnum = keyof CalendarEventFormValuesObj;
|
|
37
|
+
|
|
38
|
+
export interface CalendarEventFormUIProps {
|
|
39
|
+
className?: string;
|
|
40
|
+
values: CalendarEventFormValuesObj;
|
|
41
|
+
headingText: string;
|
|
42
|
+
titleLabel: string;
|
|
43
|
+
titlePlaceholder: string;
|
|
44
|
+
allDayText: string;
|
|
45
|
+
startLabel: string;
|
|
46
|
+
endLabel: string;
|
|
47
|
+
locationLabel: string;
|
|
48
|
+
locationPlaceholder: string;
|
|
49
|
+
noteLabel: string;
|
|
50
|
+
notePlaceholder: string;
|
|
51
|
+
saveText: string;
|
|
52
|
+
// Swapped in for saveText while a save is in flight, if the caller has one
|
|
53
|
+
savingText?: string;
|
|
54
|
+
cancelText: string;
|
|
55
|
+
// Validation or mutation failure, already worded by the caller
|
|
56
|
+
errorText?: string | null;
|
|
57
|
+
saving?: boolean;
|
|
58
|
+
// Lets the caller veto a save the form cannot see is wrong — an end before
|
|
59
|
+
// its start, a slot that violates a rule
|
|
60
|
+
disableSave?: boolean;
|
|
61
|
+
onChangeValue: (field: CalendarEventFormFieldEnum, value: string | boolean) => void;
|
|
62
|
+
onSubmit: () => void;
|
|
63
|
+
onCancel: () => void;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export const CalendarEventFormUI = memo((p: CalendarEventFormUIProps) => {
|
|
67
|
+
const {
|
|
68
|
+
className,
|
|
69
|
+
values,
|
|
70
|
+
headingText,
|
|
71
|
+
titleLabel,
|
|
72
|
+
titlePlaceholder,
|
|
73
|
+
allDayText,
|
|
74
|
+
startLabel,
|
|
75
|
+
endLabel,
|
|
76
|
+
locationLabel,
|
|
77
|
+
locationPlaceholder,
|
|
78
|
+
noteLabel,
|
|
79
|
+
notePlaceholder,
|
|
80
|
+
saveText,
|
|
81
|
+
savingText,
|
|
82
|
+
cancelText,
|
|
83
|
+
errorText,
|
|
84
|
+
saving,
|
|
85
|
+
disableSave,
|
|
86
|
+
onChangeValue,
|
|
87
|
+
onSubmit,
|
|
88
|
+
onCancel,
|
|
89
|
+
} = p;
|
|
90
|
+
|
|
91
|
+
// An untitled occurrence is unreadable on the grid, so it is the one rule
|
|
92
|
+
// the form enforces by itself; everything else is the caller's to judge
|
|
93
|
+
const saveDisabled = !!saving || !!disableSave || !values.title.trim();
|
|
94
|
+
|
|
95
|
+
return (
|
|
96
|
+
<div className={cn('v_stretch of', className)}>
|
|
97
|
+
<div
|
|
98
|
+
className='no_shrink ft_md ft_bold bd_b_1 bd_b_bd'
|
|
99
|
+
style={{ paddingLeft: 12, paddingRight: 12, paddingTop: 8, paddingBottom: 8 }}
|
|
100
|
+
>
|
|
101
|
+
{headingText}
|
|
102
|
+
</div>
|
|
103
|
+
|
|
104
|
+
<div
|
|
105
|
+
className='f h_0 app_scr auto_y'
|
|
106
|
+
style={{ paddingLeft: 12, paddingRight: 12, paddingTop: 8, paddingBottom: 8 }}
|
|
107
|
+
>
|
|
108
|
+
<Input
|
|
109
|
+
fullWidth
|
|
110
|
+
autoFocus
|
|
111
|
+
preset='fill'
|
|
112
|
+
name='title'
|
|
113
|
+
label={titleLabel}
|
|
114
|
+
placeholder={titlePlaceholder}
|
|
115
|
+
disabled={saving}
|
|
116
|
+
value={values.title}
|
|
117
|
+
onChange={(e) => onChangeValue('title', e.currentTarget.value)}
|
|
118
|
+
/>
|
|
119
|
+
|
|
120
|
+
<label className='h_item gap_sm pointer unsel' style={{ paddingTop: 10, paddingBottom: 6 }}>
|
|
121
|
+
<ToggleSwitch
|
|
122
|
+
size='sm'
|
|
123
|
+
disabled={saving}
|
|
124
|
+
checked={values.allDay}
|
|
125
|
+
onChange={(e) => onChangeValue('allDay', e.currentTarget.checked)}
|
|
126
|
+
/>
|
|
127
|
+
<span className='ft_sm'>{allDayText}</span>
|
|
128
|
+
</label>
|
|
129
|
+
|
|
130
|
+
{/* The kit has no datetime control, so a row is a native date input
|
|
131
|
+
plus a native time input; the time half disappears for an all-day
|
|
132
|
+
entry rather than being disabled, because there is no time to edit */}
|
|
133
|
+
<div className='h_item gap_sm' style={{ paddingTop: 4, paddingBottom: 4 }}>
|
|
134
|
+
<Input
|
|
135
|
+
fullWidth
|
|
136
|
+
className='f'
|
|
137
|
+
preset='fill'
|
|
138
|
+
type='date'
|
|
139
|
+
name='startDate'
|
|
140
|
+
label={startLabel}
|
|
141
|
+
disabled={saving}
|
|
142
|
+
value={values.startDate}
|
|
143
|
+
onChange={(e) => onChangeValue('startDate', e.currentTarget.value)}
|
|
144
|
+
/>
|
|
145
|
+
|
|
146
|
+
{values.allDay
|
|
147
|
+
? null
|
|
148
|
+
: (
|
|
149
|
+
<Input
|
|
150
|
+
className='no_shrink'
|
|
151
|
+
preset='fill'
|
|
152
|
+
type='time'
|
|
153
|
+
name='startTime'
|
|
154
|
+
disabled={saving}
|
|
155
|
+
value={values.startTime}
|
|
156
|
+
onChange={(e) => onChangeValue('startTime', e.currentTarget.value)}
|
|
157
|
+
/>
|
|
158
|
+
)}
|
|
159
|
+
</div>
|
|
160
|
+
|
|
161
|
+
<div className='h_item gap_sm' style={{ paddingTop: 4, paddingBottom: 4 }}>
|
|
162
|
+
<Input
|
|
163
|
+
fullWidth
|
|
164
|
+
className='f'
|
|
165
|
+
preset='fill'
|
|
166
|
+
type='date'
|
|
167
|
+
name='endDate'
|
|
168
|
+
label={endLabel}
|
|
169
|
+
disabled={saving}
|
|
170
|
+
value={values.endDate}
|
|
171
|
+
onChange={(e) => onChangeValue('endDate', e.currentTarget.value)}
|
|
172
|
+
/>
|
|
173
|
+
|
|
174
|
+
{values.allDay
|
|
175
|
+
? null
|
|
176
|
+
: (
|
|
177
|
+
<Input
|
|
178
|
+
className='no_shrink'
|
|
179
|
+
preset='fill'
|
|
180
|
+
type='time'
|
|
181
|
+
name='endTime'
|
|
182
|
+
disabled={saving}
|
|
183
|
+
value={values.endTime}
|
|
184
|
+
onChange={(e) => onChangeValue('endTime', e.currentTarget.value)}
|
|
185
|
+
/>
|
|
186
|
+
)}
|
|
187
|
+
</div>
|
|
188
|
+
|
|
189
|
+
<Input
|
|
190
|
+
fullWidth
|
|
191
|
+
className='mt_xs'
|
|
192
|
+
preset='fill'
|
|
193
|
+
name='location'
|
|
194
|
+
label={locationLabel}
|
|
195
|
+
placeholder={locationPlaceholder}
|
|
196
|
+
disabled={saving}
|
|
197
|
+
value={values.location}
|
|
198
|
+
onChange={(e) => onChangeValue('location', e.currentTarget.value)}
|
|
199
|
+
/>
|
|
200
|
+
|
|
201
|
+
<Textarea
|
|
202
|
+
fullWidth
|
|
203
|
+
className='mt_xs'
|
|
204
|
+
preset='fill'
|
|
205
|
+
name='note'
|
|
206
|
+
label={noteLabel}
|
|
207
|
+
placeholder={notePlaceholder}
|
|
208
|
+
minHeight={80}
|
|
209
|
+
disabled={saving}
|
|
210
|
+
value={values.note}
|
|
211
|
+
onChange={(e) => onChangeValue('note', e.currentTarget.value)}
|
|
212
|
+
/>
|
|
213
|
+
|
|
214
|
+
{errorText ? <div className='ft_xs cl_err mt_xs'>{errorText}</div> : null}
|
|
215
|
+
</div>
|
|
216
|
+
|
|
217
|
+
<div
|
|
218
|
+
className='no_shrink h_right gap_sm bd_t_1 bd_t_bd'
|
|
219
|
+
style={{ paddingLeft: 12, paddingRight: 12, paddingTop: 8, paddingBottom: 8 }}
|
|
220
|
+
>
|
|
221
|
+
<Button
|
|
222
|
+
preset='bg'
|
|
223
|
+
size='sm'
|
|
224
|
+
disabled={saving}
|
|
225
|
+
text={cancelText}
|
|
226
|
+
onClick={onCancel}
|
|
227
|
+
/>
|
|
228
|
+
|
|
229
|
+
<Button
|
|
230
|
+
preset='bg_secondary'
|
|
231
|
+
size='sm'
|
|
232
|
+
disabled={saveDisabled}
|
|
233
|
+
text={saving && savingText ? savingText : saveText}
|
|
234
|
+
onClick={onSubmit}
|
|
235
|
+
/>
|
|
236
|
+
</div>
|
|
237
|
+
</div>
|
|
238
|
+
);
|
|
239
|
+
});
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { cn } from '@jsb188/app/utils/string.ts';
|
|
2
|
+
import { memo } from 'react';
|
|
3
|
+
import { CALENDAR_DRAFT_PATTERN_CLASS_NAME } from '../constants/calendar.ts';
|
|
4
|
+
import type { CalendarMonthCellObj } from '../libs/calendar-geometry.ts';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The month grid.
|
|
8
|
+
*
|
|
9
|
+
* Six weeks tall always, never five: a grid that changed height between months
|
|
10
|
+
* would make every row jump as the user pages through the year, and the cell
|
|
11
|
+
* heights would have to be recomputed on each navigation.
|
|
12
|
+
*
|
|
13
|
+
* Truncation is decided by the layout pass, not by CSS overflow — a cell that
|
|
14
|
+
* silently clipped its third event would tell a manager the day is quieter
|
|
15
|
+
* than it is, so the count comes through as an explicit "+N more".
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
export interface CalendarMonthUIProps {
|
|
19
|
+
cells: CalendarMonthCellObj[];
|
|
20
|
+
// Weekday abbreviations for the header, already localized
|
|
21
|
+
weekdayLabels: string[];
|
|
22
|
+
// Day-of-month labels, indexed alongside cells
|
|
23
|
+
dayNumberLabels: string[];
|
|
24
|
+
selectedEventId: string | null;
|
|
25
|
+
onSelectEvent: (eventId: string) => void;
|
|
26
|
+
onSelectDay: (dateKey: string) => void;
|
|
27
|
+
// Opens the day so the user can see what the cell could not fit
|
|
28
|
+
onSelectOverflow: (dateKey: string) => void;
|
|
29
|
+
moreLabel: (count: number) => string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const CalendarMonthUI = memo((p: CalendarMonthUIProps) => {
|
|
33
|
+
const {
|
|
34
|
+
cells,
|
|
35
|
+
weekdayLabels,
|
|
36
|
+
dayNumberLabels,
|
|
37
|
+
selectedEventId,
|
|
38
|
+
onSelectEvent,
|
|
39
|
+
onSelectDay,
|
|
40
|
+
onSelectOverflow,
|
|
41
|
+
moreLabel,
|
|
42
|
+
} = p;
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<div className='v_stretch h_f w_f of'>
|
|
46
|
+
<div className='no_shrink h_stretch bd_b_1 bd_b_bd'>
|
|
47
|
+
{weekdayLabels.map((label) => (
|
|
48
|
+
<div key={label} className='f a_c ft_tn cl_lt' style={{ paddingTop: 4, paddingBottom: 4 }}>
|
|
49
|
+
{label}
|
|
50
|
+
</div>
|
|
51
|
+
))}
|
|
52
|
+
</div>
|
|
53
|
+
|
|
54
|
+
<div className='f h_0 app_scr auto_y'>
|
|
55
|
+
{/* Six rows of seven; the grid is the layout, so the cells need no
|
|
56
|
+
per-row wrapper */}
|
|
57
|
+
<div
|
|
58
|
+
className='h_f'
|
|
59
|
+
style={{
|
|
60
|
+
display: 'grid',
|
|
61
|
+
gridTemplateColumns: 'repeat(7, minmax(0, 1fr))',
|
|
62
|
+
gridTemplateRows: 'repeat(6, minmax(72px, 1fr))',
|
|
63
|
+
}}
|
|
64
|
+
>
|
|
65
|
+
{cells.map((cell, index) => (
|
|
66
|
+
<div
|
|
67
|
+
key={cell.day.dateKey}
|
|
68
|
+
className={cn(
|
|
69
|
+
'rel of bd_t_1 bd_t_bd bd_l_1 bd_l_bd',
|
|
70
|
+
cell.day.isWeekend ? 'bg_alt' : '',
|
|
71
|
+
)}
|
|
72
|
+
>
|
|
73
|
+
<button
|
|
74
|
+
type='button'
|
|
75
|
+
className='w_f a_l'
|
|
76
|
+
style={{ paddingLeft: 4, paddingRight: 4, paddingTop: 2 }}
|
|
77
|
+
onClick={() => onSelectDay(cell.day.dateKey)}
|
|
78
|
+
>
|
|
79
|
+
<span
|
|
80
|
+
className={cn(
|
|
81
|
+
'ft_tn',
|
|
82
|
+
cell.day.isToday ? 'ft_bold' : '',
|
|
83
|
+
// A leading or trailing day belongs to the
|
|
84
|
+
// neighbouring month; dimmed, not hidden
|
|
85
|
+
cell.day.isInPrimaryRange ? 'cl_md' : 'cl_lt',
|
|
86
|
+
)}
|
|
87
|
+
>
|
|
88
|
+
{dayNumberLabels[index]}
|
|
89
|
+
</span>
|
|
90
|
+
</button>
|
|
91
|
+
|
|
92
|
+
<div style={{ paddingLeft: 2, paddingRight: 2 }}>
|
|
93
|
+
{cell.events.map((event) => (
|
|
94
|
+
<button
|
|
95
|
+
key={event.id}
|
|
96
|
+
type='button'
|
|
97
|
+
className={cn(
|
|
98
|
+
'w_f a_l ellip ft_tn r_xs rel of',
|
|
99
|
+
event.status === 'DRAFT' ? CALENDAR_DRAFT_PATTERN_CLASS_NAME : '',
|
|
100
|
+
event.status === 'CANCELED' ? 'strikethrough' : '',
|
|
101
|
+
event.isMine ? 'bg_active' : 'bg_alt',
|
|
102
|
+
selectedEventId === event.id ? 'bd_1 bd_bd' : '',
|
|
103
|
+
)}
|
|
104
|
+
style={{ paddingLeft: 3, paddingRight: 3, marginBottom: 1 }}
|
|
105
|
+
onClick={() => onSelectEvent(event.id)}
|
|
106
|
+
>
|
|
107
|
+
{event.title}
|
|
108
|
+
</button>
|
|
109
|
+
))}
|
|
110
|
+
|
|
111
|
+
{cell.overflowCount > 0
|
|
112
|
+
? (
|
|
113
|
+
<button
|
|
114
|
+
type='button'
|
|
115
|
+
className='w_f a_l ellip ft_tn cl_lt'
|
|
116
|
+
style={{ paddingLeft: 3, paddingRight: 3 }}
|
|
117
|
+
onClick={() => onSelectOverflow(cell.day.dateKey)}
|
|
118
|
+
>
|
|
119
|
+
{moreLabel(cell.overflowCount)}
|
|
120
|
+
</button>
|
|
121
|
+
)
|
|
122
|
+
: null}
|
|
123
|
+
</div>
|
|
124
|
+
</div>
|
|
125
|
+
))}
|
|
126
|
+
</div>
|
|
127
|
+
</div>
|
|
128
|
+
</div>
|
|
129
|
+
);
|
|
130
|
+
});
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { cn } from '@jsb188/app/utils/string.ts';
|
|
2
|
+
import { Icon } from '@jsb188/react-web/svgs/Icon';
|
|
3
|
+
import { ToggleSwitch } from '@jsb188/react-web/ui/Form';
|
|
4
|
+
import { memo } from 'react';
|
|
5
|
+
import type { CalendarDayObj, CalendarSourceObj } from '../types/calendar.d.ts';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The calendar's left rail: which calendars are drawn, and a mini month for
|
|
9
|
+
* jumping somewhere else.
|
|
10
|
+
*
|
|
11
|
+
* Stateless like the rest of /ui/. It holds no visibility map of its own — a
|
|
12
|
+
* calendar's toggle reflects the `visible` flag it arrives with, so the
|
|
13
|
+
* "absent means visible" rule stays in one place (isCalendarVisible in
|
|
14
|
+
* calendar-state) instead of being re-decided here. That is what makes a
|
|
15
|
+
* newly granted calendar show up without the viewer hunting for it: only an
|
|
16
|
+
* explicit untick ever hides one.
|
|
17
|
+
*
|
|
18
|
+
* The mini month deliberately draws no events. It is a jump target, and a
|
|
19
|
+
* month of dots at this size is noise that would also force the rail to load
|
|
20
|
+
* a range nobody is looking at.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* One month for the rail's navigator, shaped exactly like the year view's
|
|
25
|
+
* mini grids so the two read as the same control.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
export interface CalendarRailMiniMonthObj {
|
|
29
|
+
// Localized month and year, e.g. "July 2026"
|
|
30
|
+
label: string;
|
|
31
|
+
// Leading blanks before the 1st, so it lands under its own weekday
|
|
32
|
+
leadingBlankCount: number;
|
|
33
|
+
days: CalendarDayObj[];
|
|
34
|
+
dayNumberLabels: string[];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface CalendarRailUIProps {
|
|
38
|
+
open: boolean;
|
|
39
|
+
// Every calendar the viewer can see, in display order
|
|
40
|
+
calendars: CalendarSourceObj[];
|
|
41
|
+
miniMonth?: CalendarRailMiniMonthObj | null;
|
|
42
|
+
// Single-letter weekday initials for the mini grid's header
|
|
43
|
+
weekdayInitials: string[];
|
|
44
|
+
// The day the calendar is anchored on, marked in the mini grid
|
|
45
|
+
selectedDateKey?: string | null;
|
|
46
|
+
// Display strings. This package holds no copy of its own: the app owns
|
|
47
|
+
// i18n, so every user-visible word is passed in.
|
|
48
|
+
calendarsText: string;
|
|
49
|
+
emptyText: string;
|
|
50
|
+
expandText: string;
|
|
51
|
+
collapseText: string;
|
|
52
|
+
previousMonthText: string;
|
|
53
|
+
nextMonthText: string;
|
|
54
|
+
// Rendered at the bottom: subscribe, new calendar, whatever the page owns
|
|
55
|
+
FooterComponent?: React.ReactNode;
|
|
56
|
+
onToggleCalendar: (calendarId: string, nextVisible: boolean) => void;
|
|
57
|
+
onSelectDay: (dateKey: string) => void;
|
|
58
|
+
onStepMonth: (direction: 1 | -1) => void;
|
|
59
|
+
// Omitted when the page collapses the rail from somewhere else, in which
|
|
60
|
+
// case a closed rail takes no width at all
|
|
61
|
+
onToggleOpen?: (nextOpen: boolean) => void;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The rail's mini month grid.
|
|
66
|
+
*/
|
|
67
|
+
|
|
68
|
+
const CalendarRailMiniMonthUI = memo((p: {
|
|
69
|
+
miniMonth: CalendarRailMiniMonthObj;
|
|
70
|
+
weekdayInitials: string[];
|
|
71
|
+
selectedDateKey?: string | null;
|
|
72
|
+
previousMonthText: string;
|
|
73
|
+
nextMonthText: string;
|
|
74
|
+
onSelectDay: (dateKey: string) => void;
|
|
75
|
+
onStepMonth: (direction: 1 | -1) => void;
|
|
76
|
+
}) => {
|
|
77
|
+
const { miniMonth, weekdayInitials, selectedDateKey, previousMonthText, nextMonthText, onSelectDay, onStepMonth } = p;
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
<div className='no_shrink' style={{ paddingLeft: 12, paddingRight: 12, paddingTop: 8, paddingBottom: 8 }}>
|
|
81
|
+
<div className='h_item gap_sm'>
|
|
82
|
+
<span className='f ellip ft_sm ft_bold cl_md'>{miniMonth.label}</span>
|
|
83
|
+
|
|
84
|
+
{/* No IconButton exists in the kit, so these are the documented raw
|
|
85
|
+
pattern: a bare button wrapping an Icon */}
|
|
86
|
+
<button
|
|
87
|
+
type='button'
|
|
88
|
+
className='no_shrink av_sm h_center'
|
|
89
|
+
aria-label={previousMonthText}
|
|
90
|
+
title={previousMonthText}
|
|
91
|
+
onClick={() => onStepMonth(-1)}
|
|
92
|
+
>
|
|
93
|
+
<Icon name='arrow-left' />
|
|
94
|
+
</button>
|
|
95
|
+
|
|
96
|
+
<button
|
|
97
|
+
type='button'
|
|
98
|
+
className='no_shrink av_sm h_center'
|
|
99
|
+
aria-label={nextMonthText}
|
|
100
|
+
title={nextMonthText}
|
|
101
|
+
onClick={() => onStepMonth(1)}
|
|
102
|
+
>
|
|
103
|
+
<Icon name='arrow-right' />
|
|
104
|
+
</button>
|
|
105
|
+
</div>
|
|
106
|
+
|
|
107
|
+
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(7, minmax(0, 1fr))' }}>
|
|
108
|
+
{weekdayInitials.map((initial, index) => (
|
|
109
|
+
<div key={index} className='a_c ft_tn cl_lt'>
|
|
110
|
+
{initial}
|
|
111
|
+
</div>
|
|
112
|
+
))}
|
|
113
|
+
|
|
114
|
+
{Array.from({ length: miniMonth.leadingBlankCount }, (_unused, index) => <div key={`blank${index}`} />)}
|
|
115
|
+
|
|
116
|
+
{miniMonth.days.map((day, index) => (
|
|
117
|
+
<button
|
|
118
|
+
key={day.dateKey}
|
|
119
|
+
type='button'
|
|
120
|
+
className={cn(
|
|
121
|
+
'a_c ft_tn r_xs',
|
|
122
|
+
// Today is bold and the anchored day is filled, so the two
|
|
123
|
+
// stay tellable apart when they are not the same day; a
|
|
124
|
+
// day borrowed from the next month recedes rather than
|
|
125
|
+
// disappearing
|
|
126
|
+
day.isToday ? 'ft_bold' : day.isInPrimaryRange ? 'cl_md' : 'cl_lt',
|
|
127
|
+
day.dateKey === selectedDateKey ? 'bg_active' : '',
|
|
128
|
+
)}
|
|
129
|
+
style={{ paddingTop: 2, paddingBottom: 2 }}
|
|
130
|
+
onClick={() => onSelectDay(day.dateKey)}
|
|
131
|
+
aria-current={day.dateKey === selectedDateKey ? 'date' : undefined}
|
|
132
|
+
>
|
|
133
|
+
{miniMonth.dayNumberLabels[index]}
|
|
134
|
+
</button>
|
|
135
|
+
))}
|
|
136
|
+
</div>
|
|
137
|
+
</div>
|
|
138
|
+
);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* One calendar's row: its colour, its name, and whether it is drawn.
|
|
143
|
+
*/
|
|
144
|
+
|
|
145
|
+
const CalendarRailSourceUI = memo((p: {
|
|
146
|
+
calendar: CalendarSourceObj;
|
|
147
|
+
onToggleCalendar: (calendarId: string, nextVisible: boolean) => void;
|
|
148
|
+
}) => {
|
|
149
|
+
const { calendar, onToggleCalendar } = p;
|
|
150
|
+
|
|
151
|
+
return (
|
|
152
|
+
<label
|
|
153
|
+
className='h_item gap_sm pointer unsel'
|
|
154
|
+
style={{ paddingLeft: 12, paddingRight: 12, paddingTop: 4, paddingBottom: 4 }}
|
|
155
|
+
>
|
|
156
|
+
{/* The swatch is DATA — it is the calendar's own colour — so it is an
|
|
157
|
+
inline background rather than a class. A calendar with no colour
|
|
158
|
+
set gets the neutral chip instead of a black dot. */}
|
|
159
|
+
<span
|
|
160
|
+
className={cn('no_shrink r_xs bd_1 bd_bd', calendar.color ? '' : 'bg_alt')}
|
|
161
|
+
style={{ width: 10, height: 10, backgroundColor: calendar.color || undefined }}
|
|
162
|
+
/>
|
|
163
|
+
|
|
164
|
+
<span className='f ellip ft_sm' title={calendar.name}>{calendar.name}</span>
|
|
165
|
+
|
|
166
|
+
{/* Visibility is a viewer's own concern, so even a calendar they
|
|
167
|
+
cannot edit can be hidden */}
|
|
168
|
+
<ToggleSwitch
|
|
169
|
+
size='sm'
|
|
170
|
+
className='no_shrink'
|
|
171
|
+
checked={calendar.visible}
|
|
172
|
+
onChange={(event) => onToggleCalendar(calendar.id, event.currentTarget.checked)}
|
|
173
|
+
/>
|
|
174
|
+
</label>
|
|
175
|
+
);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
export const CalendarRailUI = memo((p: CalendarRailUIProps) => {
|
|
179
|
+
const {
|
|
180
|
+
open,
|
|
181
|
+
calendars,
|
|
182
|
+
miniMonth,
|
|
183
|
+
weekdayInitials,
|
|
184
|
+
selectedDateKey,
|
|
185
|
+
calendarsText,
|
|
186
|
+
emptyText,
|
|
187
|
+
expandText,
|
|
188
|
+
collapseText,
|
|
189
|
+
previousMonthText,
|
|
190
|
+
nextMonthText,
|
|
191
|
+
FooterComponent,
|
|
192
|
+
onToggleCalendar,
|
|
193
|
+
onSelectDay,
|
|
194
|
+
onStepMonth,
|
|
195
|
+
onToggleOpen,
|
|
196
|
+
} = p;
|
|
197
|
+
|
|
198
|
+
if (!open) {
|
|
199
|
+
// With no way to reopen it from here, a closed rail is simply gone; the
|
|
200
|
+
// page's own control is what brings it back
|
|
201
|
+
if (!onToggleOpen) {
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return (
|
|
206
|
+
<div className='no_shrink v_stretch h_f bd_r_1 bd_r_bd bg' style={{ width: 36, paddingTop: 6 }}>
|
|
207
|
+
<button
|
|
208
|
+
type='button'
|
|
209
|
+
className='av_sm h_center'
|
|
210
|
+
aria-label={expandText}
|
|
211
|
+
title={expandText}
|
|
212
|
+
onClick={() => onToggleOpen(true)}
|
|
213
|
+
>
|
|
214
|
+
<Icon name='sidebar-expand' />
|
|
215
|
+
</button>
|
|
216
|
+
</div>
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return (
|
|
221
|
+
<div className='no_shrink v_stretch h_f bd_r_1 bd_r_bd bg' style={{ width: 232 }}>
|
|
222
|
+
{miniMonth
|
|
223
|
+
? (
|
|
224
|
+
<CalendarRailMiniMonthUI
|
|
225
|
+
miniMonth={miniMonth}
|
|
226
|
+
weekdayInitials={weekdayInitials}
|
|
227
|
+
selectedDateKey={selectedDateKey}
|
|
228
|
+
previousMonthText={previousMonthText}
|
|
229
|
+
nextMonthText={nextMonthText}
|
|
230
|
+
onSelectDay={onSelectDay}
|
|
231
|
+
onStepMonth={onStepMonth}
|
|
232
|
+
/>
|
|
233
|
+
)
|
|
234
|
+
: null}
|
|
235
|
+
|
|
236
|
+
<div
|
|
237
|
+
className='no_shrink h_item gap_sm bd_t_1 bd_t_bd'
|
|
238
|
+
style={{ paddingLeft: 12, paddingRight: 6, paddingTop: 6, paddingBottom: 2 }}
|
|
239
|
+
>
|
|
240
|
+
<span className='f ellip ft_tn cl_lt'>{calendarsText}</span>
|
|
241
|
+
|
|
242
|
+
{onToggleOpen
|
|
243
|
+
? (
|
|
244
|
+
<button
|
|
245
|
+
type='button'
|
|
246
|
+
className='no_shrink av_sm h_center'
|
|
247
|
+
aria-label={collapseText}
|
|
248
|
+
title={collapseText}
|
|
249
|
+
onClick={() => onToggleOpen(false)}
|
|
250
|
+
>
|
|
251
|
+
<Icon name='sidebar-close' />
|
|
252
|
+
</button>
|
|
253
|
+
)
|
|
254
|
+
: null}
|
|
255
|
+
</div>
|
|
256
|
+
|
|
257
|
+
<div className='f h_0 app_scr auto_y'>
|
|
258
|
+
{calendars.length
|
|
259
|
+
? calendars.map((calendar) => (
|
|
260
|
+
<CalendarRailSourceUI
|
|
261
|
+
key={calendar.id}
|
|
262
|
+
calendar={calendar}
|
|
263
|
+
onToggleCalendar={onToggleCalendar}
|
|
264
|
+
/>
|
|
265
|
+
))
|
|
266
|
+
: (
|
|
267
|
+
<div className='ft_tn cl_lt' style={{ paddingLeft: 12, paddingRight: 12, paddingTop: 4 }}>
|
|
268
|
+
{emptyText}
|
|
269
|
+
</div>
|
|
270
|
+
)}
|
|
271
|
+
</div>
|
|
272
|
+
|
|
273
|
+
{FooterComponent
|
|
274
|
+
? (
|
|
275
|
+
<div className='no_shrink bd_t_1 bd_t_bd' style={{ padding: 8 }}>
|
|
276
|
+
{FooterComponent}
|
|
277
|
+
</div>
|
|
278
|
+
)
|
|
279
|
+
: null}
|
|
280
|
+
</div>
|
|
281
|
+
);
|
|
282
|
+
});
|