@jsb188/calendar 1.1.11 → 1.1.13

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.
@@ -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
  *
@@ -47,8 +55,8 @@ export const CalendarMonthUI = memo((p: CalendarMonthUIProps) => {
47
55
  {weekdayLabels.map((label) => (
48
56
  <div
49
57
  key={label}
50
- className="f a_c ft_tn cl_lt"
51
- style={{ paddingTop: 4, paddingBottom: 4 }}
58
+ className="f a_c ft_xxs cl_lt"
59
+ style={FILE_CONSTANTS.weekdayStyle}
52
60
  >
53
61
  {label}
54
62
  </div>
@@ -77,12 +85,12 @@ export const CalendarMonthUI = memo((p: CalendarMonthUIProps) => {
77
85
  <button
78
86
  type="button"
79
87
  className="w_f a_l"
80
- style={{ paddingLeft: 4, paddingRight: 4, paddingTop: 2 }}
88
+ style={FILE_CONSTANTS.dayButtonStyle}
81
89
  onClick={() => onSelectDay(cell.day.dateKey)}
82
90
  >
83
91
  <span
84
92
  className={cn(
85
- 'ft_tn',
93
+ 'ft_xxs',
86
94
  cell.day.isToday ? 'ft_bold' : '',
87
95
  // A leading or trailing day belongs to the
88
96
  // neighbouring month; dimmed, not hidden
@@ -93,13 +101,13 @@ export const CalendarMonthUI = memo((p: CalendarMonthUIProps) => {
93
101
  </span>
94
102
  </button>
95
103
 
96
- <div style={{ paddingLeft: 2, paddingRight: 2 }}>
104
+ <div style={FILE_CONSTANTS.eventsStyle}>
97
105
  {cell.events.map((event) => (
98
106
  <button
99
107
  key={event.id}
100
108
  type="button"
101
109
  className={cn(
102
- 'w_f a_l ellip ft_tn r_xs rel of',
110
+ 'w_f a_l ellip ft_xxs r_xs rel of',
103
111
  event.status === 'DRAFT'
104
112
  ? CALENDAR_DRAFT_PATTERN_CLASS_NAME
105
113
  : '',
@@ -107,7 +115,7 @@ export const CalendarMonthUI = memo((p: CalendarMonthUIProps) => {
107
115
  event.isMine ? 'bg_active' : 'bg_alt',
108
116
  selectedEventId === event.id ? 'bd_1 bd_bd' : '',
109
117
  )}
110
- style={{ paddingLeft: 3, paddingRight: 3, marginBottom: 1 }}
118
+ style={FILE_CONSTANTS.eventStyle}
111
119
  onClick={() => onSelectEvent(event.id)}
112
120
  >
113
121
  {event.title}
@@ -117,8 +125,8 @@ export const CalendarMonthUI = memo((p: CalendarMonthUIProps) => {
117
125
  {cell.overflowCount > 0 ? (
118
126
  <button
119
127
  type="button"
120
- className="w_f a_l ellip ft_tn cl_lt"
121
- style={{ paddingLeft: 3, paddingRight: 3 }}
128
+ className="w_f a_l ellip ft_xxs cl_lt"
129
+ style={FILE_CONSTANTS.overflowStyle}
122
130
  onClick={() => onSelectOverflow(cell.day.dateKey)}
123
131
  >
124
132
  {moreLabel(cell.overflowCount)}
@@ -1,11 +1,6 @@
1
- import { cn } from '@jsb188/app/utils/string.ts';
2
- import {
3
- Button,
4
- SegmentedControl,
5
- type SegmentedControlOption,
6
- } from '@jsb188/react-web/ui/Button';
7
- import { ToggleSwitch } from '@jsb188/react-web/ui/Form';
8
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';
9
4
  import { memo } from 'react';
10
5
 
11
6
  /**
@@ -18,12 +13,15 @@ import { memo } from 'react';
18
13
  */
19
14
 
20
15
  export interface CalendarToolbarUIProps {
16
+ compact?: boolean;
21
17
  // The range heading, e.g. "Jul 19 – 25, 2026"
22
18
  title: string;
19
+ // The view picker is shown only when there are two or more views
23
20
  viewOptions: SegmentedControlOption[];
24
21
  selectedView: string;
25
- mineOnly: boolean;
26
- mineOnlyText: string;
22
+ // The "mine only" switch is shown only with onToggleMineOnly
23
+ mineOnly?: boolean;
24
+ mineOnlyText?: string;
27
25
  todayText: string;
28
26
  previousText: string;
29
27
  nextText: string;
@@ -32,7 +30,7 @@ export interface CalendarToolbarUIProps {
32
30
  onSelectView: (value: string) => void;
33
31
  onStep: (direction: 1 | -1) => void;
34
32
  onToday: () => void;
35
- onToggleMineOnly: (nextValue: boolean) => void;
33
+ onToggleMineOnly?: (nextValue: boolean) => void;
36
34
  }
37
35
 
38
36
  export const CalendarToolbarUI = memo((p: CalendarToolbarUIProps) => {
@@ -54,7 +52,7 @@ export const CalendarToolbarUI = memo((p: CalendarToolbarUIProps) => {
54
52
 
55
53
  return (
56
54
  <div
57
- className="no_shrink h_item gap_sm bd_b_1 bd_b_bd"
55
+ className="no_shrink h_item f_wrap gap_sm bd_b_1 bd_b_bd"
58
56
  style={{
59
57
  paddingLeft: 12,
60
58
  paddingRight: 12,
@@ -91,27 +89,47 @@ export const CalendarToolbarUI = memo((p: CalendarToolbarUIProps) => {
91
89
  <Icon name="arrow-right" />
92
90
  </button>
93
91
 
94
- <span className={cn('f ellip ft_md ft_bold')}>{title}</span>
92
+ <span className="f ellip ft_md ft_bold">{title}</span>
95
93
 
96
- <label className="h_item gap_sm pointer unsel no_shrink">
97
- <ToggleSwitch
98
- size="sm"
99
- checked={mineOnly}
100
- onChange={(event) => onToggleMineOnly(event.currentTarget.checked)}
101
- />
102
- <span className="ft_tn cl_md">{mineOnlyText}</span>
103
- </label>
94
+ {onToggleMineOnly ? (
95
+ <label className="h_item gap_sm pointer unsel no_shrink">
96
+ <ToggleSwitch
97
+ size="sm"
98
+ checked={!!mineOnly}
99
+ onChange={(event) => onToggleMineOnly(event.currentTarget.checked)}
100
+ />
101
+ <span className="ft_xxs cl_md">{mineOnlyText}</span>
102
+ </label>
103
+ ) : null}
104
104
 
105
- <SegmentedControl
106
- className="no_shrink ft_sm"
107
- heightClassName="h_30"
108
- borderRadiusClassName="r_df"
109
- selectedBorderRadiusClassName="r_smw"
110
- gapSize={3}
111
- options={viewOptions}
112
- selectedValue={selectedView}
113
- onClickItem={(_event, value) => onSelectView(value)}
114
- />
105
+ {viewOptions.length < 2 ? null : p.compact ? (
106
+ <select
107
+ className="p_8 bd_1 bd_bd r_sm"
108
+ aria-label={p.title}
109
+ value={selectedView}
110
+ onChange={(event) => onSelectView(event.target.value)}
111
+ >
112
+ {viewOptions.map((option) => (
113
+ <option
114
+ key={option.value}
115
+ value={option.value}
116
+ >
117
+ {option.text}
118
+ </option>
119
+ ))}
120
+ </select>
121
+ ) : (
122
+ <SegmentedControl
123
+ className="no_shrink ft_sm"
124
+ heightClassName="h_30"
125
+ borderRadiusClassName="r_df"
126
+ selectedBorderRadiusClassName="r_smw"
127
+ gapSize={3}
128
+ options={viewOptions}
129
+ selectedValue={selectedView}
130
+ onClickItem={(_event, value) => onSelectView(value)}
131
+ />
132
+ )}
115
133
 
116
134
  {RightComponent}
117
135
  </div>
@@ -1,3 +1,4 @@
1
+ import i18n from '@jsb188/app/i18n/index.ts';
1
2
  import { cn } from '@jsb188/app/utils/string.ts';
2
3
  import { memo } from 'react';
3
4
  import {
@@ -39,11 +40,14 @@ export const CalendarTimeGutterUI = memo(
39
40
  const { hourHeight, hourLabels } = p;
40
41
 
41
42
  return (
42
- <div className="no_shrink rel" style={{ width: CALENDAR_GUTTER_WIDTH }}>
43
+ <div
44
+ className="no_shrink rel"
45
+ style={{ width: CALENDAR_GUTTER_WIDTH }}
46
+ >
43
47
  {hourLabels.map((label, hour) => (
44
48
  <div
45
49
  key={hour}
46
- className="abs w_f a_r ft_tn cl_lt"
50
+ className="abs w_f a_r ft_xxs cl_lt"
47
51
  // Pulled up by half a line so the label sits ON its gridline
48
52
  // rather than hanging below it. Midnight is unlabelled: it is
49
53
  // the day boundary the header already names.
@@ -85,8 +89,14 @@ export const CalendarHourLinesUI = memo(
85
89
 
86
90
  export const CalendarNowLineUI = memo((p: { topOffset: number }) => {
87
91
  return (
88
- <div className="abs w_f z3" style={{ top: p.topOffset }}>
89
- <div className="bg_red" style={{ height: 2 }} />
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
+ />
90
100
  </div>
91
101
  );
92
102
  });
@@ -149,6 +159,8 @@ export const CalendarEventUI = memo(
149
159
  selected ? 'z3' : 'z2',
150
160
  getCalendarEventStatusClassName(event.status),
151
161
  event.isMine ? 'bg_active' : 'bg_alt',
162
+ event.pending ? 'op_60' : '',
163
+ event.kind === 'BLOCK' ? 'pattern_texture cl_lt' : '',
152
164
  )}
153
165
  style={{
154
166
  top,
@@ -170,11 +182,25 @@ export const CalendarEventUI = memo(
170
182
  aria-current={selected ? 'true' : undefined}
171
183
  data-calendar-event-id={event.id}
172
184
  >
173
- <span className="ellip ft_tn ft_bold">{event.title}</span>
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}
174
200
 
175
201
  {/* Below roughly 40 minutes there is only room for one line */}
176
202
  {height >= 32 ? (
177
- <span className="ellip ft_tn cl_lt">{timeLabel}</span>
203
+ <span className="ellip ft_xxs cl_lt">{timeLabel}</span>
178
204
  ) : null}
179
205
 
180
206
  {/* Resize grips. Only offered when the block is tall enough to leave
@@ -259,9 +285,11 @@ export const CalendarAllDayBandUI = memo(
259
285
  key={bar.event.id}
260
286
  type="button"
261
287
  className={cn(
262
- 'abs of a_l r_xs ellip ft_tn',
288
+ 'abs of a_l r_xs ellip ft_xxs',
263
289
  getCalendarEventStatusClassName(bar.event.status),
264
290
  bar.event.isMine ? 'bg_active' : 'bg_alt',
291
+ bar.event.pending ? 'op_60' : '',
292
+ bar.event.kind === 'BLOCK' ? 'pattern_texture cl_lt' : '',
265
293
  selectedEventId === bar.event.id ? 'z3' : 'z2',
266
294
  )}
267
295
  style={{
@@ -316,7 +344,7 @@ export const CalendarDayHeaderUI = memo(
316
344
  disabled={!onSelectDay}
317
345
  onClick={onSelectDay ? () => onSelectDay(day.dateKey) : undefined}
318
346
  >
319
- <span className="ellip ft_tn cl_lt">
347
+ <span className="ellip ft_xxs cl_lt">
320
348
  {dayLabels[index]?.weekday}
321
349
  </span>
322
350
  <span
@@ -366,7 +394,7 @@ export const CalendarDraftBlockUI = memo(
366
394
  pointerEvents: 'none',
367
395
  }}
368
396
  >
369
- <span className="ellip ft_tn ft_bold">{label}</span>
397
+ <span className="ellip ft_xxs ft_bold">{label}</span>
370
398
  </div>
371
399
  );
372
400
  },
@@ -0,0 +1,239 @@
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 { CALENDAR_DRAFT_PATTERN_CLASS_NAME } from '../constants/calendar.ts';
5
+ import type {
6
+ RosterChipObj,
7
+ RosterRowObj,
8
+ RosterLayoutObj,
9
+ } from '../libs/roster-layout.ts';
10
+
11
+ /*
12
+ * Return the colour class for a finding's severity.
13
+ */
14
+ function getRosterBreachClassName(
15
+ breach: RosterChipObj['breach'],
16
+ block: string,
17
+ warn: string,
18
+ ): string {
19
+ return breach === 'BLOCK' ? block : breach === 'WARN' ? warn : '';
20
+ }
21
+
22
+ /*
23
+ * Return the text of a row header.
24
+ */
25
+ function getRosterRowName(row: RosterRowObj): string {
26
+ if (row.kind === 'OPEN') return i18n.t('calendar.roster_open_row');
27
+ if (row.kind === 'GROUP') return row.name || i18n.t('calendar.no_room');
28
+ return row.name || i18n.t('c.unknown');
29
+ }
30
+
31
+ /* Draw one seat: role, times, room, and a visible draft or canceled mark. */
32
+ const RosterChipUI = memo((p: { chip: RosterChipObj }) => {
33
+ const { chip } = p;
34
+ const title = chip.roleName || chip.label;
35
+ return (
36
+ <div
37
+ data-status={chip.status}
38
+ className={cn(
39
+ 'bl w_f a_l r_sm px_4 py_2 ft_xxs bd_1 bd_bd',
40
+ chip.status === 'DRAFT'
41
+ ? `${CALENDAR_DRAFT_PATTERN_CLASS_NAME} rel`
42
+ : '',
43
+ chip.status === 'CANCELED' ? 'strikethrough op_50' : '',
44
+ chip.isMine ? 'bg_active' : 'bg_alt',
45
+ getRosterBreachClassName(chip.breach, 'bd_red_md', 'bd_amber_md'),
46
+ )}
47
+ style={
48
+ chip.roleColor
49
+ ? { borderLeftWidth: 3, borderLeftColor: chip.roleColor }
50
+ : undefined
51
+ }
52
+ >
53
+ {title ? <span className="bl ellip ft_bold">{title}</span> : null}
54
+ <span className="bl">
55
+ {chip.startLabel}–{chip.endLabel}
56
+ {chip.overnight ? ' →' : ''}
57
+ </span>
58
+ {chip.roleName && chip.label ? (
59
+ <span className="bl ellip">{chip.label}</span>
60
+ ) : null}
61
+ {chip.roomName ? (
62
+ <span className="bl ellip cl_md">{chip.roomName}</span>
63
+ ) : null}
64
+ {chip.status === 'DRAFT' ? (
65
+ <span className="bl cl_md">{i18n.t('calendar.draft')}</span>
66
+ ) : chip.status === 'CANCELED' ? (
67
+ <span className="bl">{i18n.t('calendar.canceled')}</span>
68
+ ) : null}
69
+ </div>
70
+ );
71
+ });
72
+
73
+ /* Render a read-only people-by-day grid: one row per person plus the open seats. */
74
+ export const RosterUI = memo(
75
+ (p: {
76
+ layout: RosterLayoutObj;
77
+ narrow?: boolean;
78
+ selectedDay?: string;
79
+ onSelectDay: (dateKey: string) => void;
80
+ }) => {
81
+ const indexes = p.narrow
82
+ ? [
83
+ Math.max(
84
+ 0,
85
+ p.layout.days.findIndex((day) => day.dateKey === p.selectedDay),
86
+ ),
87
+ ]
88
+ : p.layout.days.map((_, index) => index);
89
+ return (
90
+ <div className="f h_0 auto_x auto_y app_scr">
91
+ {p.narrow ? (
92
+ <div className="h_item gap_xs p_8">
93
+ {p.layout.days.map((day) => (
94
+ <button
95
+ key={day.dateKey}
96
+ type="button"
97
+ className={cn(
98
+ 'f p_8 r_sm',
99
+ day.dateKey === p.selectedDay ? 'bg_active' : 'bg_alt',
100
+ )}
101
+ onClick={() => p.onSelectDay(day.dateKey)}
102
+ >
103
+ {day.label}
104
+ </button>
105
+ ))}
106
+ </div>
107
+ ) : null}
108
+ <div
109
+ role="grid"
110
+ aria-readonly="true"
111
+ aria-label={i18n.t('calendar.roster')}
112
+ style={{
113
+ display: 'grid',
114
+ gridTemplateColumns: p.narrow
115
+ ? '114px minmax(160px,1fr) 56px'
116
+ : `200px repeat(${indexes.length},minmax(130px,1fr)) 64px`,
117
+ minWidth: p.narrow ? 0 : 1000,
118
+ }}
119
+ >
120
+ <div
121
+ role="row"
122
+ style={{ display: 'contents' }}
123
+ >
124
+ <div
125
+ role="columnheader"
126
+ className="sticky_top sticky_left bg z3 p_8 ft_bold"
127
+ >
128
+ {i18n.t('schedule.resources')}
129
+ </div>
130
+ {indexes.map((index) => {
131
+ const day = p.layout.days[index];
132
+ return (
133
+ <div
134
+ key={day.dateKey}
135
+ role="columnheader"
136
+ className="sticky_top bg z2 bd_b_1 bd_b_bd"
137
+ >
138
+ <button
139
+ className="w_f p_8"
140
+ type="button"
141
+ onClick={() => p.onSelectDay(day.dateKey)}
142
+ >
143
+ <span className="ft_bold">{day.label}</span>
144
+ <span
145
+ className={cn(
146
+ 'bl ft_xxs',
147
+ getRosterBreachClassName(
148
+ day.breach,
149
+ 'cl_err',
150
+ 'cl_warn',
151
+ ) || 'cl_md',
152
+ )}
153
+ >
154
+ {i18n.t('calendar.staff_count', {
155
+ count: day.staffCount,
156
+ })}{' '}
157
+ ·{' '}
158
+ {i18n.t('calendar.open_count', { count: day.openCount })}
159
+ </span>
160
+ </button>
161
+ </div>
162
+ );
163
+ })}
164
+ <div
165
+ role="columnheader"
166
+ className="sticky_top bg z2 p_4 ft_xxs"
167
+ style={{ whiteSpace: 'nowrap' }}
168
+ >
169
+ {i18n.t('calendar.hours_week')}
170
+ </div>
171
+ </div>
172
+ {p.layout.rows.map((row) => (
173
+ <div
174
+ key={row.key}
175
+ role="row"
176
+ data-kind={row.kind}
177
+ style={{ display: 'contents' }}
178
+ >
179
+ <div
180
+ role="rowheader"
181
+ className={cn(
182
+ 'sticky_left bg z1 p_8 bd_b_1 bd_b_bd ellip',
183
+ row.kind === 'GROUP' ? 'ft_bold bg_alt' : 'ft_sm',
184
+ getRosterBreachClassName(row.breach, 'cl_err', 'cl_warn'),
185
+ )}
186
+ >
187
+ {getRosterRowName(row)}
188
+ </div>
189
+ {indexes.map((index) => {
190
+ const cell = row.cells[index];
191
+ return (
192
+ <div
193
+ key={cell.dateKey}
194
+ role="gridcell"
195
+ data-date={cell.dateKey}
196
+ className={cn(
197
+ 'v_stretch gap_xs p_4 bd_b_1 bd_b_bd bd_l_1 bd_l_bd',
198
+ row.kind === 'GROUP' ? 'bg_alt' : '',
199
+ cell.timeOff?.status === 'APPROVED'
200
+ ? 'bg_alt'
201
+ : cell.timeOff
202
+ ? `${CALENDAR_DRAFT_PATTERN_CLASS_NAME} rel`
203
+ : '',
204
+ )}
205
+ style={{ minHeight: 48 }}
206
+ >
207
+ {cell.timeOff ? (
208
+ <span className="bl ft_xxs cl_md">
209
+ {i18n.t('schedule.time_off')}
210
+ </span>
211
+ ) : null}
212
+ {cell.chips.map((chip) => (
213
+ <RosterChipUI
214
+ key={chip.shiftId}
215
+ chip={chip}
216
+ />
217
+ ))}
218
+ </div>
219
+ );
220
+ })}
221
+ <div
222
+ role="gridcell"
223
+ className={cn(
224
+ 'p_8 bd_b_1 bd_b_bd ft_xxs',
225
+ row.kind === 'GROUP' ? 'bg_alt' : '',
226
+ )}
227
+ >
228
+ {row.kind === 'PERSON' ? (row.weekMinutes / 60).toFixed(1) : ''}
229
+ </div>
230
+ </div>
231
+ ))}
232
+ </div>
233
+ </div>
234
+ );
235
+ },
236
+ );
237
+
238
+ RosterChipUI.displayName = 'RosterChipUI';
239
+ RosterUI.displayName = 'RosterUI';