@akshayanimateddsa/site-ui 0.0.0-stage → 0.1.1

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/README.md CHANGED
@@ -1,3 +1,81 @@
1
- # Temporary Holding Version
1
+ # @akshayanimateddsa/site-ui
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Generic components for websites: plain DOM, no framework, no runtime dependencies. Every colour is a
4
+ CSS variable, so each site gives them its own theme. Every export is listed with one line in
5
+ [`catalogue.json`](catalogue.json).
6
+
7
+ - **Calendar** (`createCalendar`): an Outlook-style calendar with Day, Week and Month views. It has a
8
+ toolbar, a small month in a sidebar, a time grid with half-hour lines and a red "now" line,
9
+ overlapping events side by side, and drag to pick a span.
10
+ - **Booking calendar** (`createBookingCalendar`): the calendar with 1:1 session booking on top.
11
+ - The admin adds available time (one-off or weekly), sets each session kind's length, and confirms
12
+ or declines requests.
13
+ - A student picks a session kind, sees the open slots and requests one.
14
+ - **Slots** (`openSlots`, `isOpenSlot`, also at `@akshayanimateddsa/site-ui/slots` for servers):
15
+ available time cut into sessions, minus taken times. A server checks a request with the same code.
16
+ - **Dialog** (`openDialog`): a modal on `<dialog>` with async action buttons.
17
+
18
+ ## Using it
19
+ ```bash
20
+ npm install @akshayanimateddsa/site-ui
21
+ ```
22
+
23
+ ```html
24
+ <link rel="stylesheet" href="…/site-ui/css/calendar.css">
25
+ <link rel="stylesheet" href="…/site-ui/css/dialog.css">
26
+ <div id="calendar"></div>
27
+ ```
28
+
29
+ ```js
30
+ import { createBookingCalendar } from '@akshayanimateddsa/site-ui';
31
+
32
+ createBookingCalendar(document.getElementById('calendar'), {
33
+ mode: 'admin', // or 'student'
34
+ previewStudent: true, // admin: a switch to see the student view
35
+ timeZone: 'Asia/Kolkata',
36
+ load: (mode) => fetch(`/api/booking?as=${mode}`).then((r) => r.json()), // { kinds, availability, requests }
37
+ addAvailability: (block) => post('/api/availability', block),
38
+ deleteAvailability: (id) => del(`/api/availability/${id}`),
39
+ saveMinutes: (kind, minutes) => put(`/api/kinds/${kind}`, { minutes }),
40
+ decide: (id, status) => post(`/api/requests/${id}/${status}`),
41
+ request: (req) => post('/api/requests', req),
42
+ notify: (message) => toast(message),
43
+ });
44
+ ```
45
+
46
+ All times are epoch milliseconds and days are `'YYYY-MM-DD'`, read in the `timeZone` you pass.
47
+
48
+ ## Theming
49
+ Set the `--cal-*` tokens on `.cal`, or on `:root` so the dialogs (which sit in `body`) pick them up
50
+ too. For example, a dark theme:
51
+
52
+ ```css
53
+ :root {
54
+ --cal-bg: #060a18; --cal-surface: #0b1228; --cal-surface-2: #0f1833; --cal-hover: #142045;
55
+ --cal-border: rgba(125,165,255,.14); --cal-border-strong: rgba(125,165,255,.28); --cal-line: rgba(125,165,255,.06);
56
+ --cal-text: #e8edfb; --cal-muted: #9aa6c7; --cal-dim: #6a769a;
57
+ --cal-accent: #22d3ee; --cal-accent-contrast: #060a18; --cal-accent-soft: rgba(34,211,238,.14);
58
+ --cal-tone-available: #34d399; --cal-tone-pending: #fbbf24; --cal-tone-confirmed: #a78bfa;
59
+ }
60
+ ```
61
+
62
+ The full list of tokens, with their Outlook-like light defaults, is at the top of `css/calendar.css`.
63
+
64
+ ## Layout
65
+ ```
66
+ src/index.ts exports (one line each in catalogue.json)
67
+ src/calendar/dates.ts days, weeks, month grids, wall-clock times in a time zone (pure)
68
+ src/calendar/slots.ts availability → occurrences → open slots; the server check (pure)
69
+ src/calendar/layout.ts events of a day, time-grid spans and overlap columns (pure)
70
+ src/calendar/calendar.ts the calendar view
71
+ src/calendar/booking.ts the booking calendar
72
+ src/dialog.ts the modal dialog
73
+ src/dom.ts internal element helper (text only, never HTML)
74
+ css/calendar.css calendar and booking styles, --cal-* tokens
75
+ css/dialog.css dialog styles, --ui-* tokens
76
+ ```
77
+
78
+ ## Before changing it
79
+ Rules for agents are in [`AGENT.md`](AGENT.md). Run `npm test -w @akshayanimateddsa/site-ui`, then
80
+ check the change in a site page that uses the components before releasing it. Adding or removing an
81
+ export or a stylesheet is a minor bump while the package is `0.x`.
package/catalogue.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "$comment": "Every export of @akshayanimateddsa/site-ui, one line each (test/catalogue.test.js checks this list against the code). Look here before writing a new site component: a generic one goes into this package.",
3
+ "calendar": {
4
+ "createCalendar": "An Outlook-style calendar in an element: toolbar (Today, ‹ ›, title, view switch), a small month in a sidebar, and Day / Week time grids (half-hour lines, red now line, side-by-side overlaps, drag to pick a span) or a Month of day cells with event chips.",
5
+ "CALENDAR_VIEWS": "The three views in switch order: day, week, month."
6
+ },
7
+ "booking": {
8
+ "createBookingCalendar": "The calendar with 1:1 booking: admin adds available blocks (one-off or weekly), sets session lengths, confirms or declines requests; student picks a session kind, sees open slots and requests one; admin can preview the student view.",
9
+ "NOTE_MAX": "The longest note a student can send with a request (500 characters)."
10
+ },
11
+ "slots": {
12
+ "expandAvailability": "Available blocks (one-off or repeating weekly until a day) as dated occurrences in a span, in a time zone.",
13
+ "openSlots": "The bookable slots: availability cut into back-to-back slots of a length, minus busy times and the past.",
14
+ "isOpenSlot": "Whether a span is exactly one open slot: the server's check before taking a booking.",
15
+ "overlaps": "Whether two spans share any time (touching ends don't)."
16
+ },
17
+ "layout": {
18
+ "eventsOnDay": "The events touching a day, in start order.",
19
+ "layoutDay": "An event's piece on a day of the time grid: its minutes from midnight and its column among overlapping events.",
20
+ "daySpan": "The instants a day starts and ends in a time zone."
21
+ },
22
+ "dates": {
23
+ "zonedParts": "An instant's wall-clock year, month, day, hour, minute and weekday in a time zone.",
24
+ "zonedTime": "The instant a time zone's clock shows given minutes past midnight on a day.",
25
+ "dayKeyOf": "The day ('YYYY-MM-DD') an instant falls on in a time zone.",
26
+ "minuteOfDay": "An instant's minutes since midnight in a time zone.",
27
+ "parseDayKey": "A day's year, month and day of month (throws on a malformed day).",
28
+ "addDays": "The day n days later (or earlier).",
29
+ "addMonths": "The same day of the month n months later, kept inside a shorter month.",
30
+ "weekdayOf": "A day's weekday (0 = Sunday).",
31
+ "daysBetween": "Whole days from one day to another.",
32
+ "startOfWeek": "The first day of a day's week (weeks start Monday unless told otherwise).",
33
+ "weekDays": "The 7 days of a day's week.",
34
+ "startOfMonth": "The first day of a day's month.",
35
+ "monthGrid": "A month as whole weeks (4–6 rows of 7 days), as a wall calendar shows it.",
36
+ "startOfDay": "The instant a day starts in a time zone."
37
+ },
38
+ "dialog": {
39
+ "openDialog": "A modal dialog on <dialog>: title, body, action buttons that may be async (errors shown inside, the dialog stays open)."
40
+ },
41
+ "css": {
42
+ "css/calendar.css": "The calendar and booking calendar: toolbar, sidebar, small month, time grid, month cells, event blocks and chips, booking panels, phone layout; every colour a --cal-* token (Outlook-like light defaults) a site sets to its theme.",
43
+ "css/dialog.css": "The modal dialog, its form fields and buttons, and the booking details list; tokens --ui-* default to the calendar's --cal-*."
44
+ }
45
+ }
@@ -0,0 +1,376 @@
1
+ /*
2
+ * The calendar (.cal) and booking calendar (.bk) from @akshayanimateddsa/site-ui: an Outlook-style
3
+ * layout (toolbar, small month in a sidebar, time grid or month cells). Every colour, font and size
4
+ * is a --cal-* token set on .cal below with Outlook-like light defaults; a site restyles the whole
5
+ * calendar by setting these tokens on .cal (or any parent) in its own stylesheet, e.g.
6
+ * .cal { --cal-bg: #060a18; --cal-accent: #22d3ee; ... }
7
+ * Event colours: --cal-tone-<tone> (the event's `tone`); blocks are tinted with color-mix.
8
+ */
9
+ .cal {
10
+ --cal-bg: #ffffff;
11
+ --cal-surface: #ffffff;
12
+ --cal-surface-2: #f5f5f5;
13
+ --cal-hover: #ebebeb;
14
+ --cal-border: #e0e0e0;
15
+ --cal-border-strong: #c7c7c7;
16
+ --cal-line: #f0f0f0;
17
+ --cal-text: #242424;
18
+ --cal-muted: #616161;
19
+ --cal-dim: #9e9e9e;
20
+ --cal-accent: #0f6cbd;
21
+ --cal-accent-contrast: #ffffff;
22
+ --cal-accent-soft: #ebf3fc;
23
+ --cal-now: #c50f1f;
24
+ --cal-font: "Segoe UI", system-ui, -apple-system, sans-serif;
25
+ --cal-title-font: var(--cal-font);
26
+ --cal-radius: 4px;
27
+ --cal-radius-lg: 8px;
28
+ --cal-hour-height: 48px;
29
+ --cal-height: 640px;
30
+ --cal-sidebar-width: 232px;
31
+ --cal-tint: 22%;
32
+ --cal-tone-event: #0f6cbd;
33
+ --cal-tone-available: #107c10;
34
+ --cal-tone-open: #0f6cbd;
35
+ --cal-tone-pending: #c19c00;
36
+ --cal-tone-confirmed: #5c2e91;
37
+ --cal-tone-declined: #a4262c;
38
+
39
+ display: flex;
40
+ flex-direction: column;
41
+ min-width: 0;
42
+ color: var(--cal-text);
43
+ background: var(--cal-bg);
44
+ border: 1px solid var(--cal-border);
45
+ border-radius: var(--cal-radius-lg);
46
+ font-family: var(--cal-font);
47
+ font-size: 14px;
48
+ line-height: 1.35;
49
+ overflow: hidden;
50
+ }
51
+ .cal *, .cal *::before, .cal *::after { box-sizing: border-box; }
52
+ .cal button { font: inherit; color: inherit; cursor: pointer; }
53
+ .cal :focus-visible { outline: 2px solid var(--cal-accent); outline-offset: 1px; }
54
+
55
+ /* ---------- Toolbar ---------- */
56
+ .cal-toolbar {
57
+ display: flex;
58
+ flex-wrap: wrap;
59
+ align-items: center;
60
+ gap: 6px 8px;
61
+ padding: 10px 12px;
62
+ border-bottom: 1px solid var(--cal-border);
63
+ background: var(--cal-surface);
64
+ }
65
+ .cal-title {
66
+ margin: 0 8px 0 4px;
67
+ font-family: var(--cal-title-font);
68
+ font-size: 18px;
69
+ font-weight: 600;
70
+ white-space: nowrap;
71
+ }
72
+ .cal-toolbar-end { display: flex; flex-wrap: wrap; gap: 8px; margin-left: auto; }
73
+ .cal-toolbar-end:empty { display: none; }
74
+ .cal-toolbar-end:empty + .cal-views { margin-left: auto; }
75
+ .cal-btn {
76
+ padding: 5px 12px;
77
+ border: 1px solid var(--cal-border-strong);
78
+ border-radius: var(--cal-radius);
79
+ background: var(--cal-surface);
80
+ font-weight: 600;
81
+ }
82
+ .cal-btn:hover { background: var(--cal-hover); }
83
+ .cal-btn--primary { background: var(--cal-accent); border-color: var(--cal-accent); color: var(--cal-accent-contrast) !important; }
84
+ .cal-btn--primary:hover { background: color-mix(in srgb, var(--cal-accent) 85%, black); }
85
+ .cal-icon-btn {
86
+ width: 32px;
87
+ height: 32px;
88
+ border: 0;
89
+ border-radius: var(--cal-radius);
90
+ background: transparent;
91
+ font-size: 20px;
92
+ line-height: 1;
93
+ }
94
+ .cal-icon-btn:hover { background: var(--cal-hover); }
95
+ .cal-icon-btn--sm { width: 26px; height: 26px; font-size: 16px; }
96
+ .cal-views {
97
+ display: inline-flex;
98
+ padding: 2px;
99
+ border: 1px solid var(--cal-border);
100
+ border-radius: var(--cal-radius);
101
+ background: var(--cal-surface-2);
102
+ }
103
+ .cal-view-btn {
104
+ padding: 4px 12px;
105
+ border: 0;
106
+ border-radius: calc(var(--cal-radius) - 1px);
107
+ background: transparent;
108
+ color: var(--cal-muted) !important;
109
+ }
110
+ .cal-view-btn:hover { color: var(--cal-text) !important; }
111
+ .cal-view-btn[aria-pressed="true"] { background: var(--cal-surface); color: var(--cal-accent) !important; font-weight: 600; box-shadow: 0 1px 2px rgb(0 0 0 / 0.15); }
112
+
113
+ /* ---------- Body: sidebar + main ---------- */
114
+ .cal-body { display: flex; min-height: 0; }
115
+ .cal-sidebar {
116
+ flex: 0 0 var(--cal-sidebar-width);
117
+ padding: 12px;
118
+ border-right: 1px solid var(--cal-border);
119
+ background: var(--cal-surface);
120
+ overflow-y: auto;
121
+ max-height: calc(var(--cal-height) + 40px);
122
+ }
123
+ .cal-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
124
+
125
+ /* The small month */
126
+ .cal-mini-head { display: flex; align-items: center; gap: 2px; margin-bottom: 6px; }
127
+ .cal-mini-title { flex: 1; font-weight: 600; font-size: 13px; }
128
+ .cal-mini-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; text-align: center; }
129
+ .cal-mini-dayname { font-size: 11px; color: var(--cal-dim); padding: 2px 0; }
130
+ .cal-mini-day {
131
+ aspect-ratio: 1;
132
+ min-width: 0;
133
+ border: 0;
134
+ border-radius: 50%;
135
+ background: transparent;
136
+ font-size: 12px;
137
+ }
138
+ .cal-mini-day:hover { background: var(--cal-hover); }
139
+ .cal-mini-day[data-outside] { color: var(--cal-dim) !important; }
140
+ .cal-mini-day[data-selected] { background: var(--cal-accent-soft); border-radius: 2px; }
141
+ .cal-mini-day[data-today] { background: var(--cal-accent); color: var(--cal-accent-contrast) !important; border-radius: 50%; font-weight: 600; }
142
+
143
+ /* ---------- Day and week: the time grid ---------- */
144
+ .cal-grid { display: flex; flex-direction: column; min-height: 0; }
145
+ .cal-grid-head, .cal-grid-body {
146
+ display: grid;
147
+ grid-template-columns: 56px repeat(var(--cal-days), minmax(0, 1fr));
148
+ }
149
+ .cal-grid-head { border-bottom: 1px solid var(--cal-border); background: var(--cal-surface); overflow: hidden; scrollbar-gutter: stable; }
150
+ /* Both reserve the scrollbar's width, so the day headers line up with their columns. */
151
+ .cal-day-head {
152
+ display: flex;
153
+ flex-direction: column;
154
+ align-items: flex-start;
155
+ padding: 6px 8px;
156
+ border-left: 1px solid var(--cal-border);
157
+ }
158
+ .cal-day-name { font-size: 12px; color: var(--cal-muted); }
159
+ .cal-day-num {
160
+ min-width: 32px;
161
+ height: 32px;
162
+ padding: 0 6px;
163
+ border: 0;
164
+ border-radius: 50%;
165
+ background: transparent;
166
+ font-size: 20px;
167
+ font-weight: 600;
168
+ }
169
+ .cal-day-num:hover { background: var(--cal-hover); }
170
+ .cal-day-head[data-today] .cal-day-name { color: var(--cal-accent); font-weight: 600; }
171
+ .cal-day-head[data-today] .cal-day-num { background: var(--cal-accent); color: var(--cal-accent-contrast) !important; }
172
+ .cal-scroll { height: var(--cal-height); overflow-y: auto; scrollbar-gutter: stable; }
173
+ .cal-grid-body { position: relative; height: calc(24 * var(--cal-hour-height)); }
174
+ .cal-gutter { position: relative; }
175
+ .cal-hour-label {
176
+ position: absolute;
177
+ right: 8px;
178
+ transform: translateY(-50%);
179
+ font-size: 11px;
180
+ color: var(--cal-muted);
181
+ white-space: nowrap;
182
+ }
183
+ .cal-col {
184
+ position: relative;
185
+ border-left: 1px solid var(--cal-border);
186
+ /* An hour line, and a lighter half-hour line, every --cal-hour-height. */
187
+ background-image:
188
+ linear-gradient(to bottom, var(--cal-border) 1px, transparent 1px),
189
+ linear-gradient(to bottom, var(--cal-line) 1px, transparent 1px);
190
+ background-size: 100% var(--cal-hour-height), 100% calc(var(--cal-hour-height) / 2);
191
+ touch-action: pan-y;
192
+ }
193
+ .cal-col[data-today] { background-color: color-mix(in srgb, var(--cal-accent) 4%, transparent); }
194
+ .cal[data-mode="admin"] .cal-col { cursor: cell; }
195
+ .cal-event {
196
+ position: absolute;
197
+ display: flex;
198
+ flex-direction: column;
199
+ align-items: flex-start;
200
+ gap: 1px;
201
+ padding: 3px 6px;
202
+ border: 0;
203
+ border-left: 3px solid var(--tone);
204
+ border-radius: var(--cal-radius);
205
+ background: color-mix(in srgb, var(--tone) var(--cal-tint), var(--cal-surface));
206
+ box-shadow: inset 0 0 0 1px var(--cal-surface);
207
+ text-align: left;
208
+ overflow: hidden;
209
+ font-size: 12px;
210
+ z-index: 1;
211
+ }
212
+ .cal-event:hover { background: color-mix(in srgb, var(--tone) calc(var(--cal-tint) + 12%), var(--cal-surface)); z-index: 2; }
213
+ .cal-event-title { font-weight: 600; }
214
+ .cal-event-time, .cal-event-sub { color: var(--cal-muted); }
215
+ .cal-event--short { flex-direction: row; gap: 6px; padding-block: 1px; }
216
+ .cal-event--short .cal-event-title { flex-shrink: 0; max-width: 70%; }
217
+ .cal-event--short .cal-event-sub { display: none; }
218
+ .cal-event > span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
219
+ .cal-now {
220
+ position: absolute;
221
+ left: -1px;
222
+ right: 0;
223
+ height: 2px;
224
+ background: var(--cal-now);
225
+ z-index: 3;
226
+ pointer-events: none;
227
+ }
228
+ .cal-now::before {
229
+ content: "";
230
+ position: absolute;
231
+ left: -5px;
232
+ top: -4px;
233
+ width: 10px;
234
+ height: 10px;
235
+ border-radius: 50%;
236
+ background: var(--cal-now);
237
+ }
238
+ .cal-selection {
239
+ position: absolute;
240
+ left: 2px;
241
+ right: 2px;
242
+ padding: 2px 6px;
243
+ border-radius: var(--cal-radius);
244
+ background: color-mix(in srgb, var(--cal-accent) 30%, transparent);
245
+ border: 1px solid var(--cal-accent);
246
+ font-size: 12px;
247
+ font-weight: 600;
248
+ z-index: 4;
249
+ pointer-events: none;
250
+ }
251
+
252
+ /* ---------- Month ---------- */
253
+ .cal-month { display: flex; flex-direction: column; }
254
+ .cal-month-head { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-bottom: 1px solid var(--cal-border); }
255
+ .cal-month-dayname { padding: 6px 8px; font-size: 12px; color: var(--cal-muted); }
256
+ .cal-month-body {
257
+ display: grid;
258
+ grid-template-columns: repeat(7, minmax(0, 1fr));
259
+ grid-template-rows: repeat(var(--cal-weeks), minmax(96px, 1fr));
260
+ min-height: var(--cal-height);
261
+ }
262
+ .cal-cell {
263
+ display: flex;
264
+ flex-direction: column;
265
+ gap: 2px;
266
+ min-width: 0;
267
+ padding: 4px;
268
+ border-right: 1px solid var(--cal-border);
269
+ border-bottom: 1px solid var(--cal-border);
270
+ }
271
+ .cal-cell:nth-child(7n) { border-right: 0; }
272
+ .cal-cell[data-outside] { background: var(--cal-surface-2); }
273
+ .cal-cell[data-outside] .cal-cell-num { color: var(--cal-dim) !important; }
274
+ .cal-cell-num {
275
+ align-self: flex-start;
276
+ min-width: 26px;
277
+ height: 26px;
278
+ padding: 0 6px;
279
+ border: 0;
280
+ border-radius: 13px;
281
+ background: transparent;
282
+ font-size: 13px;
283
+ font-weight: 600;
284
+ }
285
+ .cal-cell-num:hover { background: var(--cal-hover); }
286
+ .cal-cell[data-today] .cal-cell-num { background: var(--cal-accent); color: var(--cal-accent-contrast) !important; }
287
+ .cal-chip {
288
+ display: flex;
289
+ align-items: center;
290
+ gap: 5px;
291
+ min-width: 0;
292
+ padding: 2px 5px;
293
+ border: 0;
294
+ border-radius: var(--cal-radius);
295
+ background: color-mix(in srgb, var(--tone) 12%, transparent);
296
+ font-size: 12px;
297
+ text-align: left;
298
+ }
299
+ .cal-chip:hover { background: color-mix(in srgb, var(--tone) 24%, transparent); }
300
+ .cal-chip-dot { flex: 0 0 8px; height: 8px; border-radius: 50%; background: var(--tone); }
301
+ .cal-chip-time { color: var(--cal-muted); white-space: nowrap; }
302
+ .cal-chip-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
303
+ .cal-more { align-self: flex-start; border: 0; background: transparent; padding: 1px 5px; font-size: 12px; font-weight: 600; color: var(--cal-accent) !important; }
304
+
305
+ /* Tone colours: an event's `tone` picks one. */
306
+ .cal [data-tone] { --tone: var(--cal-tone-event); }
307
+ .cal [data-tone="available"] { --tone: var(--cal-tone-available); }
308
+ .cal [data-tone="open"] { --tone: var(--cal-tone-open); }
309
+ .cal [data-tone="pending"] { --tone: var(--cal-tone-pending); }
310
+ .cal [data-tone="confirmed"] { --tone: var(--cal-tone-confirmed); }
311
+ .cal [data-tone="declined"] { --tone: var(--cal-tone-declined); }
312
+
313
+ /* ---------- Booking: sidebar panels ---------- */
314
+ .ui-status { margin: 12px 0 0; font-size: 13px; color: var(--cal-muted); }
315
+ .ui-status:empty { display: none; }
316
+ .bk-panel { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--cal-border); }
317
+ .bk-panel-title { margin: 0 0 8px; font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--cal-muted); }
318
+ .bk-empty, .bk-hint { margin: 0; font-size: 13px; color: var(--cal-muted); }
319
+ .bk-hint { margin-top: 8px; }
320
+ .bk-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
321
+ .bk-item {
322
+ display: grid;
323
+ width: 100%;
324
+ gap: 1px;
325
+ padding: 6px 8px;
326
+ border: 0;
327
+ border-left: 3px solid var(--tone);
328
+ border-radius: var(--cal-radius);
329
+ background: color-mix(in srgb, var(--tone) 10%, transparent);
330
+ text-align: left;
331
+ font-size: 12px;
332
+ }
333
+ .bk-item:hover { background: color-mix(in srgb, var(--tone) 20%, transparent); }
334
+ .bk-item-when { font-weight: 600; }
335
+ .bk-item-what, .bk-item-status { color: var(--cal-muted); }
336
+ .bk-item-status { text-transform: capitalize; }
337
+ .bk-lengths { display: grid; gap: 8px; }
338
+ .bk-length { display: grid; grid-template-columns: 1fr 72px auto; align-items: center; gap: 6px; font-size: 13px; }
339
+ .bk-unit { color: var(--cal-muted); font-size: 12px; }
340
+ .bk-kinds { display: grid; gap: 4px; }
341
+ .bk-kind {
342
+ display: flex;
343
+ align-items: center;
344
+ gap: 8px;
345
+ padding: 6px 8px;
346
+ border: 1px solid var(--cal-border);
347
+ border-radius: var(--cal-radius);
348
+ cursor: pointer;
349
+ font-size: 13px;
350
+ }
351
+ .bk-kind:has(input:checked) { border-color: var(--cal-accent); background: var(--cal-accent-soft); }
352
+ .bk-kind small { margin-left: auto; color: var(--cal-muted); }
353
+ .cal input, .cal select, .cal textarea {
354
+ min-width: 0;
355
+ padding: 5px 8px;
356
+ border: 1px solid var(--cal-border-strong);
357
+ border-radius: var(--cal-radius);
358
+ background: var(--cal-bg);
359
+ color: var(--cal-text);
360
+ font: inherit;
361
+ }
362
+ .cal input[type="radio"], .cal input[type="checkbox"] { accent-color: var(--cal-accent); padding: 0; }
363
+
364
+ /* ---------- Narrow screens: no sidebar (its panels move under the calendar) ---------- */
365
+ @media (max-width: 760px) {
366
+ .cal-body { flex-direction: column-reverse; }
367
+ .cal-sidebar { flex-basis: auto; max-height: none; border-right: 0; border-top: 1px solid var(--cal-border); }
368
+ .cal-mini { display: none; }
369
+ .bk[data-mode="student"] .cal-body { flex-direction: column; } /* pick the session before the slots */
370
+ .bk[data-mode="student"] .cal-sidebar { border-top: 0; border-bottom: 1px solid var(--cal-border); }
371
+ .cal-sidebar-extra > .bk-panel:first-of-type, .cal-sidebar-extra .ui-status + .bk-panels > .bk-panel:first-child { margin-top: 0; border-top: 0; padding-top: 0; }
372
+ .cal-title { order: 10; flex-basis: 100%; margin: 4px 0 0; font-size: 16px; }
373
+ .cal-grid-head, .cal-grid-body { grid-template-columns: 44px repeat(var(--cal-days), minmax(0, 1fr)); }
374
+ .cal-month-body { grid-template-rows: repeat(var(--cal-weeks), minmax(64px, 1fr)); min-height: 0; }
375
+ .cal-chip-time { display: none; }
376
+ }
package/css/dialog.css ADDED
@@ -0,0 +1,72 @@
1
+ /*
2
+ * The modal dialog (.ui-dialog, openDialog in src/dialog.ts) and its form fields (.ui-form,
3
+ * .ui-field, .ui-row, .ui-check) and buttons (.ui-btn). Its tokens default to the calendar's
4
+ * (--cal-*), so a site that themes the calendar themes its dialogs too; set --ui-* to style the
5
+ * dialog on its own. The dialog sits in document.body, outside .cal, so a site sets the tokens it
6
+ * uses on :root (or on .ui-dialog) as well.
7
+ */
8
+ .ui-dialog {
9
+ --ui-bg: var(--cal-surface, #ffffff);
10
+ --ui-text: var(--cal-text, #242424);
11
+ --ui-muted: var(--cal-muted, #616161);
12
+ --ui-border: var(--cal-border-strong, #c7c7c7);
13
+ --ui-accent: var(--cal-accent, #0f6cbd);
14
+ --ui-accent-contrast: var(--cal-accent-contrast, #ffffff);
15
+ --ui-danger: var(--cal-tone-declined, #c50f1f);
16
+ --ui-radius: var(--cal-radius-lg, 8px);
17
+ --ui-font: var(--cal-font, "Segoe UI", system-ui, sans-serif);
18
+
19
+ width: min(440px, calc(100vw - 32px));
20
+ padding: 0;
21
+ border: 1px solid var(--ui-border);
22
+ border-radius: var(--ui-radius);
23
+ background: var(--ui-bg);
24
+ color: var(--ui-text);
25
+ font-family: var(--ui-font);
26
+ font-size: 14px;
27
+ box-shadow: 0 16px 48px rgb(0 0 0 / 0.35);
28
+ }
29
+ .ui-dialog::backdrop { background: rgb(0 0 0 / 0.45); }
30
+ .ui-dialog *, .ui-dialog *::before, .ui-dialog *::after { box-sizing: border-box; }
31
+ .ui-dialog-box { padding: 20px; }
32
+ .ui-dialog-title { margin: 0 0 12px; font-size: 18px; font-weight: 600; text-transform: none; }
33
+ .ui-dialog-error { margin: 12px 0 0; padding: 8px 10px; border-radius: 4px; background: color-mix(in srgb, var(--ui-danger) 14%, transparent); color: var(--ui-text); font-size: 13px; }
34
+ .ui-dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 20px; }
35
+ .ui-btn {
36
+ padding: 6px 14px;
37
+ border: 1px solid var(--ui-border);
38
+ border-radius: 4px;
39
+ background: transparent;
40
+ color: var(--ui-text);
41
+ font: inherit;
42
+ font-weight: 600;
43
+ cursor: pointer;
44
+ }
45
+ .ui-btn:hover { background: color-mix(in srgb, var(--ui-text) 8%, transparent); }
46
+ .ui-btn:disabled { opacity: 0.6; cursor: wait; }
47
+ .ui-btn--primary { background: var(--ui-accent); border-color: var(--ui-accent); color: var(--ui-accent-contrast); }
48
+ .ui-btn--primary:hover { background: color-mix(in srgb, var(--ui-accent) 85%, black); }
49
+ .ui-btn--danger { border-color: var(--ui-danger); color: var(--ui-danger); }
50
+ .ui-btn--danger:hover { background: color-mix(in srgb, var(--ui-danger) 12%, transparent); }
51
+ .ui-btn:focus-visible, .ui-dialog :focus-visible { outline: 2px solid var(--ui-accent); outline-offset: 1px; }
52
+ .ui-form { display: grid; gap: 12px; }
53
+ .ui-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
54
+ .ui-field { display: grid; gap: 4px; font-size: 13px; color: var(--ui-muted); }
55
+ .ui-field[hidden] { display: none; }
56
+ .ui-check { display: flex; align-items: center; gap: 8px; font-size: 14px; }
57
+ .ui-dialog input, .ui-dialog textarea, .ui-dialog select {
58
+ width: 100%;
59
+ min-width: 0;
60
+ padding: 7px 9px;
61
+ border: 1px solid var(--ui-border);
62
+ border-radius: 4px;
63
+ background: transparent;
64
+ color: var(--ui-text);
65
+ font: inherit;
66
+ color-scheme: light dark;
67
+ }
68
+ .ui-dialog input[type="checkbox"] { width: auto; accent-color: var(--ui-accent); }
69
+ .ui-dialog textarea { resize: vertical; }
70
+ .bk-details { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; }
71
+ .bk-details dt { color: var(--ui-muted); }
72
+ .bk-details dd { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
@@ -0,0 +1,74 @@
1
+ import { type Calendar, type CalendarOptions } from './calendar.js';
2
+ import { type DayKey } from './dates.js';
3
+ import { type Availability, type Interval } from './slots.js';
4
+ /** A kind of session (e.g. mentorship, mock interview); `minutes` null: its length isn't set yet. */
5
+ export interface BookingKind {
6
+ id: string;
7
+ name: string;
8
+ minutes: number | null;
9
+ }
10
+ /** A request's state: waiting for the admin, confirmed, or declined. */
11
+ export type BookingStatus = 'pending' | 'confirmed' | 'declined';
12
+ /**
13
+ * A booking request. The admin sees `who`, `contact` and `note`; a student gets other people's
14
+ * requests only as taken times (no names), and their own with `mine: true`.
15
+ */
16
+ export interface BookingRequest extends Interval {
17
+ id: string;
18
+ kind: string;
19
+ status: BookingStatus;
20
+ who?: string;
21
+ contact?: string;
22
+ note?: string;
23
+ mine?: boolean;
24
+ }
25
+ /** Everything the booking calendar shows, from the site's `load()`. */
26
+ export interface BookingData {
27
+ kinds: BookingKind[];
28
+ availability: Availability[];
29
+ requests: BookingRequest[];
30
+ }
31
+ /** A new available block, as the admin entered it. */
32
+ export interface NewAvailability extends Interval {
33
+ repeatWeekly: boolean;
34
+ until: DayKey | null;
35
+ }
36
+ /** A student's request, as they sent it. */
37
+ export interface NewRequest extends Interval {
38
+ kind: string;
39
+ note: string;
40
+ }
41
+ /** The two modes. */
42
+ export type BookingMode = 'admin' | 'student';
43
+ /** Settings for `createBookingCalendar`: the calendar's own, plus the data source and the actions. */
44
+ export interface BookingCalendarOptions extends Pick<CalendarOptions, 'timeZone' | 'locale' | 'view' | 'weekStartsOn' | 'scrollToHour' | 'now'> {
45
+ mode: BookingMode;
46
+ /** Admin mode only: a switch in the toolbar to see the student mode. */
47
+ previewStudent?: boolean;
48
+ /**
49
+ * Loads everything shown, for the mode on screen (called at the start, after every change and when
50
+ * the admin switches mode: a site's server answers a student with taken times only).
51
+ */
52
+ load: (mode: BookingMode) => Promise<BookingData>;
53
+ addAvailability?: (block: NewAvailability) => Promise<unknown>;
54
+ deleteAvailability?: (id: string) => Promise<unknown>;
55
+ saveMinutes?: (kind: string, minutes: number) => Promise<unknown>;
56
+ decide?: (id: string, status: 'confirmed' | 'declined') => Promise<unknown>;
57
+ request?: (request: NewRequest) => Promise<unknown>;
58
+ /** Shows a short message after a change (default: none). */
59
+ notify?: (message: string) => void;
60
+ }
61
+ /** A mounted booking calendar. */
62
+ export interface BookingCalendar {
63
+ calendar: Calendar;
64
+ mode: () => BookingMode;
65
+ /** Switches mode and loads that mode's data. */
66
+ setMode: (mode: BookingMode) => void;
67
+ /** Loads the data again and redraws. */
68
+ reload: () => Promise<void>;
69
+ destroy: () => void;
70
+ }
71
+ /** The longest note a student can send. */
72
+ export declare const NOTE_MAX = 500;
73
+ /** Mounts a booking calendar in `host` (its content is replaced). */
74
+ export declare function createBookingCalendar(host: HTMLElement, options: BookingCalendarOptions): BookingCalendar;