@jsb188/calendar 1.1.2
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 +45 -0
- package/src/constants/calendar.ts +153 -0
- package/src/css.d.ts +7 -0
- package/src/libs/calendar-geometry.ts +500 -0
- package/src/libs/calendar-gesture.ts +341 -0
- package/src/libs/calendar-now.ts +39 -0
- package/src/libs/calendar-range.ts +401 -0
- package/src/libs/calendar-state.ts +26 -0
- package/src/libs/calendar-url.ts +191 -0
- package/src/libs/roster-layout.ts +388 -0
- package/src/main.ts +32 -0
- package/src/modules/Calendar.tsx +736 -0
- package/src/modules/MiniCalendar.tsx +376 -0
- package/src/types/calendar.d.ts +128 -0
- package/src/types/shift-form.d.ts +19 -0
- package/src/ui/CalendarAgendaUI.tsx +115 -0
- package/src/ui/CalendarMonthUI.tsx +142 -0
- package/src/ui/CalendarToolbarUI.tsx +133 -0
- package/src/ui/CalendarUI.tsx +401 -0
- package/src/ui/CalendarYearUI.tsx +67 -0
- package/src/ui/RosterUI.tsx +273 -0
- package/src/ui/ShiftFormUI.tsx +333 -0
- package/tests/calendar-geometry.test.ts +549 -0
- package/tests/calendar-gesture.test.ts +340 -0
- package/tests/calendar-range.test.ts +358 -0
- package/tests/calendar-url.test.ts +189 -0
- package/tests/roster-layout.test.ts +210 -0
- package/tsconfig.json +13 -0
- package/vitest.config.ts +11 -0
|
@@ -0,0 +1,142 @@
|
|
|
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
|
+
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
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The month grid.
|
|
16
|
+
*
|
|
17
|
+
* Six weeks tall always, never five: a grid that changed height between months
|
|
18
|
+
* would make every row jump as the user pages through the year, and the cell
|
|
19
|
+
* heights would have to be recomputed on each navigation.
|
|
20
|
+
*
|
|
21
|
+
* Truncation is decided by the layout pass, not by CSS overflow — a cell that
|
|
22
|
+
* silently clipped its third event would tell a manager the day is quieter
|
|
23
|
+
* than it is, so the count comes through as an explicit "+N more".
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
export interface CalendarMonthUIProps {
|
|
27
|
+
cells: CalendarMonthCellObj[];
|
|
28
|
+
// Weekday abbreviations for the header, already localized
|
|
29
|
+
weekdayLabels: string[];
|
|
30
|
+
// Day-of-month labels, indexed alongside cells
|
|
31
|
+
dayNumberLabels: string[];
|
|
32
|
+
selectedEventId: string | null;
|
|
33
|
+
onSelectEvent: (eventId: string) => void;
|
|
34
|
+
onSelectDay: (dateKey: string) => void;
|
|
35
|
+
// Opens the day so the user can see what the cell could not fit
|
|
36
|
+
onSelectOverflow: (dateKey: string) => void;
|
|
37
|
+
moreLabel: (count: number) => string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const CalendarMonthUI = memo((p: CalendarMonthUIProps) => {
|
|
41
|
+
const {
|
|
42
|
+
cells,
|
|
43
|
+
weekdayLabels,
|
|
44
|
+
dayNumberLabels,
|
|
45
|
+
selectedEventId,
|
|
46
|
+
onSelectEvent,
|
|
47
|
+
onSelectDay,
|
|
48
|
+
onSelectOverflow,
|
|
49
|
+
moreLabel,
|
|
50
|
+
} = p;
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<div className="v_stretch h_f w_f of">
|
|
54
|
+
<div className="no_shrink h_stretch bd_b_1 bd_b_bd">
|
|
55
|
+
{weekdayLabels.map((label) => (
|
|
56
|
+
<div
|
|
57
|
+
key={label}
|
|
58
|
+
className="f a_c ft_xxs cl_lt"
|
|
59
|
+
style={FILE_CONSTANTS.weekdayStyle}
|
|
60
|
+
>
|
|
61
|
+
{label}
|
|
62
|
+
</div>
|
|
63
|
+
))}
|
|
64
|
+
</div>
|
|
65
|
+
|
|
66
|
+
<div className="f h_0 app_scr auto_y">
|
|
67
|
+
{/* Six rows of seven; the grid is the layout, so the cells need no
|
|
68
|
+
per-row wrapper */}
|
|
69
|
+
<div
|
|
70
|
+
className="h_f"
|
|
71
|
+
style={{
|
|
72
|
+
display: 'grid',
|
|
73
|
+
gridTemplateColumns: 'repeat(7, minmax(0, 1fr))',
|
|
74
|
+
gridTemplateRows: 'repeat(6, minmax(72px, 1fr))',
|
|
75
|
+
}}
|
|
76
|
+
>
|
|
77
|
+
{cells.map((cell, index) => (
|
|
78
|
+
<div
|
|
79
|
+
key={cell.day.dateKey}
|
|
80
|
+
className={cn(
|
|
81
|
+
'rel of bd_t_1 bd_t_bd bd_l_1 bd_l_bd',
|
|
82
|
+
cell.day.isWeekend ? 'bg_alt' : '',
|
|
83
|
+
)}
|
|
84
|
+
>
|
|
85
|
+
<button
|
|
86
|
+
type="button"
|
|
87
|
+
className="w_f a_l"
|
|
88
|
+
style={FILE_CONSTANTS.dayButtonStyle}
|
|
89
|
+
onClick={() => onSelectDay(cell.day.dateKey)}
|
|
90
|
+
>
|
|
91
|
+
<span
|
|
92
|
+
className={cn(
|
|
93
|
+
'ft_xxs',
|
|
94
|
+
cell.day.isToday ? 'ft_bold' : '',
|
|
95
|
+
// A leading or trailing day belongs to the
|
|
96
|
+
// neighbouring month; dimmed, not hidden
|
|
97
|
+
cell.day.isInPrimaryRange ? 'cl_md' : 'cl_lt',
|
|
98
|
+
)}
|
|
99
|
+
>
|
|
100
|
+
{dayNumberLabels[index]}
|
|
101
|
+
</span>
|
|
102
|
+
</button>
|
|
103
|
+
|
|
104
|
+
<div style={FILE_CONSTANTS.eventsStyle}>
|
|
105
|
+
{cell.events.map((event) => (
|
|
106
|
+
<button
|
|
107
|
+
key={event.id}
|
|
108
|
+
type="button"
|
|
109
|
+
className={cn(
|
|
110
|
+
'w_f a_l ellip ft_xxs r_xs rel of',
|
|
111
|
+
event.status === 'DRAFT'
|
|
112
|
+
? CALENDAR_DRAFT_PATTERN_CLASS_NAME
|
|
113
|
+
: '',
|
|
114
|
+
event.status === 'CANCELED' ? 'strikethrough' : '',
|
|
115
|
+
event.isMine ? 'bg_active' : 'bg_alt',
|
|
116
|
+
selectedEventId === event.id ? 'bd_1 bd_bd' : '',
|
|
117
|
+
)}
|
|
118
|
+
style={FILE_CONSTANTS.eventStyle}
|
|
119
|
+
onClick={() => onSelectEvent(event.id)}
|
|
120
|
+
>
|
|
121
|
+
{event.title}
|
|
122
|
+
</button>
|
|
123
|
+
))}
|
|
124
|
+
|
|
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}
|
|
135
|
+
</div>
|
|
136
|
+
</div>
|
|
137
|
+
))}
|
|
138
|
+
</div>
|
|
139
|
+
</div>
|
|
140
|
+
</div>
|
|
141
|
+
);
|
|
142
|
+
});
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { Icon } from '@jsb188/react-web/svgs/Icon';
|
|
2
|
+
import { Button, SegmentedControl, type SegmentedControlOption } from '@jsb188/react-web/ui/Button';
|
|
3
|
+
import { ToggleSwitch } from '@jsb188/form/ui/Form';
|
|
4
|
+
import { memo } from 'react';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The calendar's own control row: where you are, how to move, and what you
|
|
8
|
+
* are looking at.
|
|
9
|
+
*
|
|
10
|
+
* Every control is a pure callback out — the toolbar reads nothing and writes
|
|
11
|
+
* nothing. The page turns these into URL updates, which is what keeps the
|
|
12
|
+
* whole surface linkable and survives a route remount.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export interface CalendarToolbarUIProps {
|
|
16
|
+
compact?: boolean;
|
|
17
|
+
// The range heading, e.g. "Jul 19 – 25, 2026"
|
|
18
|
+
title: string;
|
|
19
|
+
viewOptions: SegmentedControlOption[];
|
|
20
|
+
selectedView: string;
|
|
21
|
+
mineOnly: boolean;
|
|
22
|
+
mineOnlyText: string;
|
|
23
|
+
todayText: string;
|
|
24
|
+
previousText: string;
|
|
25
|
+
nextText: string;
|
|
26
|
+
// Rendered at the right end: publish button, subscribe, overflow menu
|
|
27
|
+
RightComponent?: React.ReactNode;
|
|
28
|
+
onSelectView: (value: string) => void;
|
|
29
|
+
onStep: (direction: 1 | -1) => void;
|
|
30
|
+
onToday: () => void;
|
|
31
|
+
onToggleMineOnly: (nextValue: boolean) => void;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const CalendarToolbarUI = memo((p: CalendarToolbarUIProps) => {
|
|
35
|
+
const {
|
|
36
|
+
title,
|
|
37
|
+
viewOptions,
|
|
38
|
+
selectedView,
|
|
39
|
+
mineOnly,
|
|
40
|
+
mineOnlyText,
|
|
41
|
+
todayText,
|
|
42
|
+
previousText,
|
|
43
|
+
nextText,
|
|
44
|
+
RightComponent,
|
|
45
|
+
onSelectView,
|
|
46
|
+
onStep,
|
|
47
|
+
onToday,
|
|
48
|
+
onToggleMineOnly,
|
|
49
|
+
} = p;
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<div
|
|
53
|
+
className="no_shrink h_item f_wrap gap_sm bd_b_1 bd_b_bd"
|
|
54
|
+
style={{
|
|
55
|
+
paddingLeft: 12,
|
|
56
|
+
paddingRight: 12,
|
|
57
|
+
paddingTop: 6,
|
|
58
|
+
paddingBottom: 6,
|
|
59
|
+
}}
|
|
60
|
+
>
|
|
61
|
+
<Button
|
|
62
|
+
preset="bg_secondary"
|
|
63
|
+
size="sm"
|
|
64
|
+
text={todayText}
|
|
65
|
+
onClick={onToday}
|
|
66
|
+
/>
|
|
67
|
+
|
|
68
|
+
{/* No IconButton exists in the kit, so these are the documented raw
|
|
69
|
+
pattern: a bare button wrapping an Icon */}
|
|
70
|
+
<button
|
|
71
|
+
type="button"
|
|
72
|
+
className="av_sm h_center"
|
|
73
|
+
aria-label={previousText}
|
|
74
|
+
title={previousText}
|
|
75
|
+
onClick={() => onStep(-1)}
|
|
76
|
+
>
|
|
77
|
+
<Icon name="arrow-left" />
|
|
78
|
+
</button>
|
|
79
|
+
|
|
80
|
+
<button
|
|
81
|
+
type="button"
|
|
82
|
+
className="av_sm h_center"
|
|
83
|
+
aria-label={nextText}
|
|
84
|
+
title={nextText}
|
|
85
|
+
onClick={() => onStep(1)}
|
|
86
|
+
>
|
|
87
|
+
<Icon name="arrow-right" />
|
|
88
|
+
</button>
|
|
89
|
+
|
|
90
|
+
<span className="f ellip ft_md ft_bold">{title}</span>
|
|
91
|
+
|
|
92
|
+
<label className="h_item gap_sm pointer unsel no_shrink">
|
|
93
|
+
<ToggleSwitch
|
|
94
|
+
size="sm"
|
|
95
|
+
checked={mineOnly}
|
|
96
|
+
onChange={(event) => onToggleMineOnly(event.currentTarget.checked)}
|
|
97
|
+
/>
|
|
98
|
+
<span className="ft_xxs cl_md">{mineOnlyText}</span>
|
|
99
|
+
</label>
|
|
100
|
+
|
|
101
|
+
{p.compact ? (
|
|
102
|
+
<select
|
|
103
|
+
className="p_8 bd_1 bd_bd r_sm"
|
|
104
|
+
aria-label={p.title}
|
|
105
|
+
value={selectedView}
|
|
106
|
+
onChange={(event) => onSelectView(event.target.value)}
|
|
107
|
+
>
|
|
108
|
+
{viewOptions.map((option) => (
|
|
109
|
+
<option
|
|
110
|
+
key={option.value}
|
|
111
|
+
value={option.value}
|
|
112
|
+
>
|
|
113
|
+
{option.text}
|
|
114
|
+
</option>
|
|
115
|
+
))}
|
|
116
|
+
</select>
|
|
117
|
+
) : (
|
|
118
|
+
<SegmentedControl
|
|
119
|
+
className="no_shrink ft_sm"
|
|
120
|
+
heightClassName="h_30"
|
|
121
|
+
borderRadiusClassName="r_df"
|
|
122
|
+
selectedBorderRadiusClassName="r_smw"
|
|
123
|
+
gapSize={3}
|
|
124
|
+
options={viewOptions}
|
|
125
|
+
selectedValue={selectedView}
|
|
126
|
+
onClickItem={(_event, value) => onSelectView(value)}
|
|
127
|
+
/>
|
|
128
|
+
)}
|
|
129
|
+
|
|
130
|
+
{RightComponent}
|
|
131
|
+
</div>
|
|
132
|
+
);
|
|
133
|
+
});
|
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
import i18n from '@jsb188/app/i18n/index.ts';
|
|
2
|
+
import { cn } from '@jsb188/app/utils/string.ts';
|
|
3
|
+
import { memo } from 'react';
|
|
4
|
+
import {
|
|
5
|
+
CALENDAR_ALL_DAY_ROW_HEIGHT,
|
|
6
|
+
CALENDAR_DRAFT_PATTERN_CLASS_NAME,
|
|
7
|
+
CALENDAR_GUTTER_WIDTH,
|
|
8
|
+
} from '../constants/calendar.ts';
|
|
9
|
+
import type { CalendarAllDayBarObj } from '../libs/calendar-geometry.ts';
|
|
10
|
+
import type {
|
|
11
|
+
CalendarDayObj,
|
|
12
|
+
CalendarEventLayoutObj,
|
|
13
|
+
} from '../types/calendar.d.ts';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Stateless calendar UI.
|
|
17
|
+
*
|
|
18
|
+
* Nothing here fetches, mutates, or holds state — every component takes what
|
|
19
|
+
* it draws and reports what was clicked. The geometry arrives as numbers
|
|
20
|
+
* already computed by calendar-geometry, so these components never do date
|
|
21
|
+
* math either.
|
|
22
|
+
*
|
|
23
|
+
* Positions are inline styles rather than classes on purpose: an event's top
|
|
24
|
+
* and height are DATA (a function of when it happens and how tall an hour is),
|
|
25
|
+
* and no utility class can express "17.3% from the top". Everything that IS
|
|
26
|
+
* design — colour, weight, radius, spacing, borders — uses the existing global
|
|
27
|
+
* utility classes, and no new CSS is introduced.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The left-hand hour labels.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
export const CalendarTimeGutterUI = memo(
|
|
35
|
+
(p: {
|
|
36
|
+
hourHeight: number;
|
|
37
|
+
// Labels for hours 0..23, already formatted and localized by the caller
|
|
38
|
+
hourLabels: string[];
|
|
39
|
+
}) => {
|
|
40
|
+
const { hourHeight, hourLabels } = p;
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<div
|
|
44
|
+
className="no_shrink rel"
|
|
45
|
+
style={{ width: CALENDAR_GUTTER_WIDTH }}
|
|
46
|
+
>
|
|
47
|
+
{hourLabels.map((label, hour) => (
|
|
48
|
+
<div
|
|
49
|
+
key={hour}
|
|
50
|
+
className="abs w_f a_r ft_xxs cl_lt"
|
|
51
|
+
// Pulled up by half a line so the label sits ON its gridline
|
|
52
|
+
// rather than hanging below it. Midnight is unlabelled: it is
|
|
53
|
+
// the day boundary the header already names.
|
|
54
|
+
style={{ top: hour * hourHeight - 7, paddingRight: 6 }}
|
|
55
|
+
>
|
|
56
|
+
{hour === 0 ? null : label}
|
|
57
|
+
</div>
|
|
58
|
+
))}
|
|
59
|
+
</div>
|
|
60
|
+
);
|
|
61
|
+
},
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The horizontal hour lines behind the day columns.
|
|
66
|
+
*/
|
|
67
|
+
|
|
68
|
+
export const CalendarHourLinesUI = memo(
|
|
69
|
+
(p: { hourCount: number; hourHeight: number }) => {
|
|
70
|
+
const { hourCount, hourHeight } = p;
|
|
71
|
+
|
|
72
|
+
return (
|
|
73
|
+
<>
|
|
74
|
+
{Array.from({ length: hourCount }, (_unused, hour) => (
|
|
75
|
+
<div
|
|
76
|
+
key={hour}
|
|
77
|
+
className="abs w_f bd_t_1 bd_t_bd"
|
|
78
|
+
style={{ top: hour * hourHeight }}
|
|
79
|
+
/>
|
|
80
|
+
))}
|
|
81
|
+
</>
|
|
82
|
+
);
|
|
83
|
+
},
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* The "now" line, drawn only on the day that is actually today.
|
|
88
|
+
*/
|
|
89
|
+
|
|
90
|
+
export const CalendarNowLineUI = memo((p: { topOffset: number }) => {
|
|
91
|
+
return (
|
|
92
|
+
<div
|
|
93
|
+
className="abs w_f z3"
|
|
94
|
+
style={{ top: p.topOffset }}
|
|
95
|
+
>
|
|
96
|
+
<div
|
|
97
|
+
className="bg_red"
|
|
98
|
+
style={{ height: 2 }}
|
|
99
|
+
/>
|
|
100
|
+
</div>
|
|
101
|
+
);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
/*
|
|
105
|
+
* Return the classes that carry an occurrence's status.
|
|
106
|
+
*
|
|
107
|
+
* A DRAFT is striped rather than merely faded: faded reads as "still loading",
|
|
108
|
+
* and a schedule that has not been published yet is a different thing from one
|
|
109
|
+
* that is still arriving. CANCELED stays on the calendar struck through,
|
|
110
|
+
* because somebody hunting for a shift that was cancelled has to find it
|
|
111
|
+
* rather than wonder whether they imagined it.
|
|
112
|
+
*/
|
|
113
|
+
|
|
114
|
+
function getCalendarEventStatusClassName(status: string): string {
|
|
115
|
+
switch (status) {
|
|
116
|
+
case 'DRAFT':
|
|
117
|
+
return CALENDAR_DRAFT_PATTERN_CLASS_NAME;
|
|
118
|
+
case 'CANCELED':
|
|
119
|
+
return 'strikethrough';
|
|
120
|
+
default:
|
|
121
|
+
return '';
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export interface CalendarEventUIProps {
|
|
126
|
+
layout: CalendarEventLayoutObj;
|
|
127
|
+
hourHeight: number;
|
|
128
|
+
selected: boolean;
|
|
129
|
+
// Offers the resize grips; a viewer without edit rights gets a block that
|
|
130
|
+
// can be opened but not dragged
|
|
131
|
+
editable: boolean;
|
|
132
|
+
timeLabel: string;
|
|
133
|
+
onSelect: (eventId: string) => void;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* One event block in the time grid.
|
|
138
|
+
*/
|
|
139
|
+
|
|
140
|
+
export const CalendarEventUI = memo(
|
|
141
|
+
(p: CalendarEventUIProps) => {
|
|
142
|
+
const { layout, hourHeight, selected, editable, timeLabel, onSelect } = p;
|
|
143
|
+
const { event } = layout;
|
|
144
|
+
|
|
145
|
+
const top = (layout.startMinute / 60) * hourHeight;
|
|
146
|
+
// Never shorter than a line of text, or it stops being clickable
|
|
147
|
+
const height = Math.max(
|
|
148
|
+
((layout.endMinute - layout.startMinute) / 60) * hourHeight,
|
|
149
|
+
16,
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
return (
|
|
153
|
+
<button
|
|
154
|
+
type="button"
|
|
155
|
+
className={cn(
|
|
156
|
+
'abs of a_l r_xs bd_1 bd_bd',
|
|
157
|
+
// A stacked event has to paint over the ones behind it, and the
|
|
158
|
+
// selected one over everything
|
|
159
|
+
selected ? 'z3' : 'z2',
|
|
160
|
+
getCalendarEventStatusClassName(event.status),
|
|
161
|
+
event.isMine ? 'bg_active' : 'bg_alt',
|
|
162
|
+
event.pending ? 'op_60' : '',
|
|
163
|
+
event.kind === 'BLOCK' ? 'pattern_texture cl_lt' : '',
|
|
164
|
+
)}
|
|
165
|
+
style={{
|
|
166
|
+
top,
|
|
167
|
+
height,
|
|
168
|
+
left: `${layout.left * 100}%`,
|
|
169
|
+
width: `calc(${layout.width * 100}% - 2px)`,
|
|
170
|
+
paddingLeft: 4,
|
|
171
|
+
paddingRight: 4,
|
|
172
|
+
// A continued block keeps square edges where it was cut, so the
|
|
173
|
+
// user can see it runs off the end of the day
|
|
174
|
+
borderTopLeftRadius: layout.continuesFromPreviousDay ? 0 : undefined,
|
|
175
|
+
borderTopRightRadius: layout.continuesFromPreviousDay ? 0 : undefined,
|
|
176
|
+
borderBottomLeftRadius: layout.continuesToNextDay ? 0 : undefined,
|
|
177
|
+
borderBottomRightRadius: layout.continuesToNextDay ? 0 : undefined,
|
|
178
|
+
borderLeftColor: event.color || undefined,
|
|
179
|
+
borderLeftWidth: event.color ? 3 : undefined,
|
|
180
|
+
}}
|
|
181
|
+
onClick={() => onSelect(event.id)}
|
|
182
|
+
aria-current={selected ? 'true' : undefined}
|
|
183
|
+
data-calendar-event-id={event.id}
|
|
184
|
+
>
|
|
185
|
+
<span className="ellip ft_xxs ft_bold">{event.title}</span>
|
|
186
|
+
{event.breach ? (
|
|
187
|
+
<span
|
|
188
|
+
className={cn(
|
|
189
|
+
'abs r_5',
|
|
190
|
+
event.breach === 'BLOCK' ? 'bg_err' : 'bg_warn',
|
|
191
|
+
)}
|
|
192
|
+
style={{ width: 6, height: 6, right: 3, top: 3 }}
|
|
193
|
+
/>
|
|
194
|
+
) : null}
|
|
195
|
+
{(event.openCount || 0) > 0 ? (
|
|
196
|
+
<span className="pill bg_amber_alt_lt ft_xxs">
|
|
197
|
+
{i18n.t('calendar.open_count', { count: event.openCount })}
|
|
198
|
+
</span>
|
|
199
|
+
) : null}
|
|
200
|
+
|
|
201
|
+
{/* Below roughly 40 minutes there is only room for one line */}
|
|
202
|
+
{height >= 32 ? (
|
|
203
|
+
<span className="ellip ft_xxs cl_lt">{timeLabel}</span>
|
|
204
|
+
) : null}
|
|
205
|
+
|
|
206
|
+
{/* Resize grips. Only offered when the block is tall enough to leave
|
|
207
|
+
a middle over to grab for moving — on a short block the grips
|
|
208
|
+
would cover the whole thing and moving would become impossible */}
|
|
209
|
+
{editable && height >= 28 ? (
|
|
210
|
+
<>
|
|
211
|
+
<span
|
|
212
|
+
className="abs w_f"
|
|
213
|
+
style={{
|
|
214
|
+
top: 0,
|
|
215
|
+
left: 0,
|
|
216
|
+
height: 6,
|
|
217
|
+
cursor: 'ns-resize',
|
|
218
|
+
touchAction: 'none',
|
|
219
|
+
}}
|
|
220
|
+
data-calendar-edge="START"
|
|
221
|
+
/>
|
|
222
|
+
<span
|
|
223
|
+
className="abs w_f"
|
|
224
|
+
style={{
|
|
225
|
+
bottom: 0,
|
|
226
|
+
left: 0,
|
|
227
|
+
height: 6,
|
|
228
|
+
cursor: 'ns-resize',
|
|
229
|
+
touchAction: 'none',
|
|
230
|
+
}}
|
|
231
|
+
data-calendar-edge="END"
|
|
232
|
+
/>
|
|
233
|
+
</>
|
|
234
|
+
) : null}
|
|
235
|
+
</button>
|
|
236
|
+
);
|
|
237
|
+
},
|
|
238
|
+
(prev, next) =>
|
|
239
|
+
// The layout objects are rebuilt on every data change, so comparing them by
|
|
240
|
+
// identity would defeat the memo; compare what is actually drawn
|
|
241
|
+
prev.layout.event === next.layout.event &&
|
|
242
|
+
prev.layout.startMinute === next.layout.startMinute &&
|
|
243
|
+
prev.layout.endMinute === next.layout.endMinute &&
|
|
244
|
+
prev.layout.left === next.layout.left &&
|
|
245
|
+
prev.layout.width === next.layout.width &&
|
|
246
|
+
prev.layout.continuesFromPreviousDay ===
|
|
247
|
+
next.layout.continuesFromPreviousDay &&
|
|
248
|
+
prev.layout.continuesToNextDay === next.layout.continuesToNextDay &&
|
|
249
|
+
prev.hourHeight === next.hourHeight &&
|
|
250
|
+
prev.selected === next.selected &&
|
|
251
|
+
prev.editable === next.editable &&
|
|
252
|
+
prev.timeLabel === next.timeLabel &&
|
|
253
|
+
prev.onSelect === next.onSelect,
|
|
254
|
+
);
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* The all-day band above the time grid.
|
|
258
|
+
*/
|
|
259
|
+
|
|
260
|
+
export const CalendarAllDayBandUI = memo(
|
|
261
|
+
(p: {
|
|
262
|
+
bars: CalendarAllDayBarObj[];
|
|
263
|
+
dayCount: number;
|
|
264
|
+
selectedEventId: string | null;
|
|
265
|
+
onSelect: (eventId: string) => void;
|
|
266
|
+
}) => {
|
|
267
|
+
const { bars, dayCount, selectedEventId, onSelect } = p;
|
|
268
|
+
|
|
269
|
+
if (!bars.length) {
|
|
270
|
+
return null;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
const rowCount = Math.max(...bars.map((bar) => bar.row)) + 1;
|
|
274
|
+
|
|
275
|
+
return (
|
|
276
|
+
<div
|
|
277
|
+
className="no_shrink rel bd_b_1 bd_b_bd"
|
|
278
|
+
style={{
|
|
279
|
+
marginLeft: CALENDAR_GUTTER_WIDTH,
|
|
280
|
+
height: rowCount * (CALENDAR_ALL_DAY_ROW_HEIGHT + 2) + 4,
|
|
281
|
+
}}
|
|
282
|
+
>
|
|
283
|
+
{bars.map((bar) => (
|
|
284
|
+
<button
|
|
285
|
+
key={bar.event.id}
|
|
286
|
+
type="button"
|
|
287
|
+
className={cn(
|
|
288
|
+
'abs of a_l r_xs ellip ft_xxs',
|
|
289
|
+
getCalendarEventStatusClassName(bar.event.status),
|
|
290
|
+
bar.event.isMine ? 'bg_active' : 'bg_alt',
|
|
291
|
+
bar.event.pending ? 'op_60' : '',
|
|
292
|
+
bar.event.kind === 'BLOCK' ? 'pattern_texture cl_lt' : '',
|
|
293
|
+
selectedEventId === bar.event.id ? 'z3' : 'z2',
|
|
294
|
+
)}
|
|
295
|
+
style={{
|
|
296
|
+
top: bar.row * (CALENDAR_ALL_DAY_ROW_HEIGHT + 2) + 2,
|
|
297
|
+
height: CALENDAR_ALL_DAY_ROW_HEIGHT,
|
|
298
|
+
left: `${(bar.startDayIndex / dayCount) * 100}%`,
|
|
299
|
+
width: `calc(${((bar.endDayIndex - bar.startDayIndex + 1) / dayCount) * 100}% - 2px)`,
|
|
300
|
+
paddingLeft: 4,
|
|
301
|
+
paddingRight: 4,
|
|
302
|
+
borderTopLeftRadius: bar.continuesFromPreviousDay ? 0 : undefined,
|
|
303
|
+
borderBottomLeftRadius: bar.continuesFromPreviousDay
|
|
304
|
+
? 0
|
|
305
|
+
: undefined,
|
|
306
|
+
borderTopRightRadius: bar.continuesToNextDay ? 0 : undefined,
|
|
307
|
+
borderBottomRightRadius: bar.continuesToNextDay ? 0 : undefined,
|
|
308
|
+
}}
|
|
309
|
+
onClick={() => onSelect(bar.event.id)}
|
|
310
|
+
aria-current={selectedEventId === bar.event.id ? 'true' : undefined}
|
|
311
|
+
>
|
|
312
|
+
{bar.event.title}
|
|
313
|
+
</button>
|
|
314
|
+
))}
|
|
315
|
+
</div>
|
|
316
|
+
);
|
|
317
|
+
},
|
|
318
|
+
);
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* The day-of-week header row above the grid.
|
|
322
|
+
*/
|
|
323
|
+
|
|
324
|
+
export const CalendarDayHeaderUI = memo(
|
|
325
|
+
(p: {
|
|
326
|
+
days: CalendarDayObj[];
|
|
327
|
+
// Pre-formatted per day: the weekday abbreviation and the day number
|
|
328
|
+
dayLabels: Array<{ weekday: string; dayNumber: string }>;
|
|
329
|
+
onSelectDay?: (dateKey: string) => void;
|
|
330
|
+
}) => {
|
|
331
|
+
const { days, dayLabels, onSelectDay } = p;
|
|
332
|
+
|
|
333
|
+
return (
|
|
334
|
+
<div
|
|
335
|
+
className="no_shrink h_stretch bd_b_1 bd_b_bd"
|
|
336
|
+
style={{ marginLeft: CALENDAR_GUTTER_WIDTH }}
|
|
337
|
+
>
|
|
338
|
+
{days.map((day, index) => (
|
|
339
|
+
<button
|
|
340
|
+
key={day.dateKey}
|
|
341
|
+
type="button"
|
|
342
|
+
className={cn('f a_c', day.isWeekend ? 'bg_alt' : '')}
|
|
343
|
+
style={{ paddingTop: 4, paddingBottom: 4 }}
|
|
344
|
+
disabled={!onSelectDay}
|
|
345
|
+
onClick={onSelectDay ? () => onSelectDay(day.dateKey) : undefined}
|
|
346
|
+
>
|
|
347
|
+
<span className="ellip ft_xxs cl_lt">
|
|
348
|
+
{dayLabels[index]?.weekday}
|
|
349
|
+
</span>
|
|
350
|
+
<span
|
|
351
|
+
className={cn('ellip ft_sm', day.isToday ? 'ft_bold' : 'cl_md')}
|
|
352
|
+
>
|
|
353
|
+
{dayLabels[index]?.dayNumber}
|
|
354
|
+
</span>
|
|
355
|
+
</button>
|
|
356
|
+
))}
|
|
357
|
+
</div>
|
|
358
|
+
);
|
|
359
|
+
},
|
|
360
|
+
);
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* The ghost block shown while a range is being drawn, moved, or resized.
|
|
364
|
+
*
|
|
365
|
+
* Deliberately not an event: it carries no id, cannot be clicked, and is not
|
|
366
|
+
* part of the overlap layout, because it is a preview of an intention rather
|
|
367
|
+
* than something that exists yet.
|
|
368
|
+
*/
|
|
369
|
+
|
|
370
|
+
export const CalendarDraftBlockUI = memo(
|
|
371
|
+
(p: {
|
|
372
|
+
startMinute: number;
|
|
373
|
+
endMinute: number;
|
|
374
|
+
hourHeight: number;
|
|
375
|
+
label: string;
|
|
376
|
+
}) => {
|
|
377
|
+
const { startMinute, endMinute, hourHeight, label } = p;
|
|
378
|
+
|
|
379
|
+
const top = (startMinute / 60) * hourHeight;
|
|
380
|
+
const height = Math.max(((endMinute - startMinute) / 60) * hourHeight, 16);
|
|
381
|
+
|
|
382
|
+
return (
|
|
383
|
+
<div
|
|
384
|
+
className="abs of a_l r_xs bd_1 bd_bd bg_active z4"
|
|
385
|
+
style={{
|
|
386
|
+
top,
|
|
387
|
+
height,
|
|
388
|
+
left: 0,
|
|
389
|
+
width: 'calc(100% - 2px)',
|
|
390
|
+
paddingLeft: 4,
|
|
391
|
+
paddingRight: 4,
|
|
392
|
+
opacity: 0.8,
|
|
393
|
+
// The ghost must never eat the pointer stream that is drawing it
|
|
394
|
+
pointerEvents: 'none',
|
|
395
|
+
}}
|
|
396
|
+
>
|
|
397
|
+
<span className="ellip ft_xxs ft_bold">{label}</span>
|
|
398
|
+
</div>
|
|
399
|
+
);
|
|
400
|
+
},
|
|
401
|
+
);
|