@finstack-com-public/design 0.7.0 → 0.8.0
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/CHANGELOG.md +35 -1
- package/dist/css/calendar.css +172 -0
- package/dist/css/calendar.md +169 -0
- package/dist/css/input.css +4 -2
- package/dist/css/input.md +3 -1
- package/dist/css/popover.css +7 -0
- package/dist/css/popover.md +2 -0
- package/dist/css/wave.css +20 -5
- package/dist/css/wave.md +6 -3
- package/dist/css-text/calendar.d.ts +2 -0
- package/dist/css-text/calendar.js +1 -0
- package/dist/css-text/input.js +1 -1
- package/dist/css-text/kit.js +204 -7
- package/dist/css-text/popover.js +1 -1
- package/dist/css-text/wave.js +20 -5
- package/dist/dom/calendar-dates.d.ts +45 -0
- package/dist/dom/calendar-dates.js +129 -0
- package/dist/dom/calendar.d.ts +79 -0
- package/dist/dom/calendar.js +396 -0
- package/dist/dom/index.d.ts +1 -0
- package/dist/dom/index.js +1 -0
- package/dist/kit.css +204 -7
- package/dist/react/inputs.d.ts +23 -2
- package/dist/react/inputs.js +55 -2
- package/dist/react/overlays.d.ts +15 -15
- package/package.json +1 -1
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
// Calendar: year, month and day views (spec 02 B, 03 §3.2, 06 §4; D42). The second helper that
|
|
2
|
+
// builds its own markup, after the toaster: the cells change with every view and page. Dates are
|
|
3
|
+
// ISO strings (`calendar-dates.ts`); every name and word is passed in.
|
|
4
|
+
import { createIcon } from "../icons/index.js";
|
|
5
|
+
import { addDays, addMonths, addYears, clampIso, daysInMonth, formatDay, formatMonth, localToday, monthGrid, parseDay, parseMonth, weekday, yearPage, } from "./calendar-dates.js";
|
|
6
|
+
const VIEWS = {
|
|
7
|
+
day: ['year', 'month', 'day'],
|
|
8
|
+
month: ['year', 'month'],
|
|
9
|
+
};
|
|
10
|
+
/** How many characters of an ISO value a view's cell reads: `YYYY-MM-DD`, `YYYY-MM`, `YYYY`. */
|
|
11
|
+
const WIDTH = { day: 10, month: 7, year: 4 };
|
|
12
|
+
const mod = (a, b) => ((a % b) + b) % b;
|
|
13
|
+
let seq = 0;
|
|
14
|
+
/** `root` is an empty `.fs-calendar` element; the helper renders the header and the grid into it. */
|
|
15
|
+
export function createCalendar(root, options) {
|
|
16
|
+
const doc = root.ownerDocument;
|
|
17
|
+
const headingId = root.id ? `${root.id}-heading` : `fs-calendar-${++seq}-heading`;
|
|
18
|
+
let opts = check({ granularity: 'day', weekStart: 1, ...options });
|
|
19
|
+
let value = null;
|
|
20
|
+
let min;
|
|
21
|
+
let max;
|
|
22
|
+
let today = '';
|
|
23
|
+
let view = opts.granularity ?? 'day';
|
|
24
|
+
/** The cell with the tab stop, always at the granularity, whatever the view. */
|
|
25
|
+
let focusIso = '';
|
|
26
|
+
let lastHeading = '';
|
|
27
|
+
let cellValues = new Map();
|
|
28
|
+
const lowest = () => opts.granularity;
|
|
29
|
+
const rootNode = () => root.getRootNode();
|
|
30
|
+
/** Reads an ISO day or month at the granularity; `edge` says where a month falls in a day calendar. */
|
|
31
|
+
function read(iso, edge = 'first') {
|
|
32
|
+
if (!iso)
|
|
33
|
+
return undefined;
|
|
34
|
+
if (lowest() === 'month') {
|
|
35
|
+
const m = parseMonth(iso.slice(0, 7));
|
|
36
|
+
return m && (iso.length === 7 || parseDay(iso)) ? formatMonth(m.year, m.month) : undefined;
|
|
37
|
+
}
|
|
38
|
+
if (parseDay(iso))
|
|
39
|
+
return iso;
|
|
40
|
+
const m = parseMonth(iso);
|
|
41
|
+
if (!m)
|
|
42
|
+
return undefined;
|
|
43
|
+
return formatDay(m.year, m.month, edge === 'first' ? 1 : daysInMonth(m.year, m.month));
|
|
44
|
+
}
|
|
45
|
+
function readAll(next, first) {
|
|
46
|
+
const granularityChanged = !first && next.granularity !== undefined && next.granularity !== lowest();
|
|
47
|
+
opts = check({ ...opts, ...next });
|
|
48
|
+
min = read(opts.min, 'first');
|
|
49
|
+
max = read(opts.max, 'last');
|
|
50
|
+
today = read(opts.today) ?? localToday(lowest());
|
|
51
|
+
if (first || granularityChanged || 'value' in next)
|
|
52
|
+
value = read(opts.value) ?? null;
|
|
53
|
+
if (first || granularityChanged)
|
|
54
|
+
view = lowest();
|
|
55
|
+
if (first || granularityChanged || 'value' in next || !focusIso)
|
|
56
|
+
focusIso = clampIso(value ?? today, min, max);
|
|
57
|
+
}
|
|
58
|
+
// The header, built once: its buttons keep focus across pages.
|
|
59
|
+
const header = doc.createElement('div');
|
|
60
|
+
header.className = 'fs-calendar__header';
|
|
61
|
+
const viewButton = button('fs-calendar__view');
|
|
62
|
+
const heading = doc.createElement('span');
|
|
63
|
+
heading.className = 'fs-calendar__heading';
|
|
64
|
+
heading.id = headingId;
|
|
65
|
+
const viewIcon = createIcon('chevron-down', { size: 16, className: 'fs-calendar__view-icon', document: doc });
|
|
66
|
+
viewButton.append(heading, viewIcon);
|
|
67
|
+
const prev = button('fs-icon-button fs-calendar__prev');
|
|
68
|
+
prev.append(createIcon('chevron-left', { size: 16, document: doc }));
|
|
69
|
+
const next = button('fs-icon-button fs-calendar__next');
|
|
70
|
+
next.append(createIcon('chevron-right', { size: 16, document: doc }));
|
|
71
|
+
header.append(viewButton, prev, next);
|
|
72
|
+
const grid = doc.createElement('div');
|
|
73
|
+
grid.setAttribute('role', 'grid');
|
|
74
|
+
/** The fallback live region, when the host passes no `announcer` (spec 06 §5). */
|
|
75
|
+
const live = doc.createElement('span');
|
|
76
|
+
live.className = 'fs-visually-hidden fs-calendar__live';
|
|
77
|
+
live.setAttribute('aria-live', 'polite');
|
|
78
|
+
grid.setAttribute('aria-labelledby', headingId);
|
|
79
|
+
function button(className) {
|
|
80
|
+
const b = doc.createElement('button');
|
|
81
|
+
b.type = 'button';
|
|
82
|
+
b.className = className;
|
|
83
|
+
return b;
|
|
84
|
+
}
|
|
85
|
+
function pageOf(v, iso) {
|
|
86
|
+
const year = Number(iso.slice(0, 4));
|
|
87
|
+
if (v === 'day')
|
|
88
|
+
return { view: 'day', year, month: Number(iso.slice(5, 7)) };
|
|
89
|
+
if (v === 'month')
|
|
90
|
+
return { view: 'month', year };
|
|
91
|
+
return { view: 'year', ...yearPage(year) };
|
|
92
|
+
}
|
|
93
|
+
/** The first and last value a page holds, at the granularity. */
|
|
94
|
+
function pageRange(page) {
|
|
95
|
+
const [fy, fm, ly, lm] = page.view === 'day'
|
|
96
|
+
? [page.year, page.month, page.year, page.month]
|
|
97
|
+
: page.view === 'month'
|
|
98
|
+
? [page.year, 1, page.year, 12]
|
|
99
|
+
: [Math.max(page.from, 1), 1, page.to, 12];
|
|
100
|
+
if (lowest() === 'month')
|
|
101
|
+
return [formatMonth(fy, fm), formatMonth(ly, lm)];
|
|
102
|
+
return [formatDay(fy, fm, 1), formatDay(ly, lm, daysInMonth(ly, lm))];
|
|
103
|
+
}
|
|
104
|
+
/** Whether any value on the page is pickable. */
|
|
105
|
+
function pageOpen(page) {
|
|
106
|
+
const [first, last] = pageRange(page);
|
|
107
|
+
return !(max !== undefined && first > max) && !(min !== undefined && last < min);
|
|
108
|
+
}
|
|
109
|
+
/** A cell is enabled when its span meets [min, max]: compared on the cell's own width. */
|
|
110
|
+
function enabled(v, iso) {
|
|
111
|
+
const n = WIDTH[v];
|
|
112
|
+
return !(min !== undefined && iso < min.slice(0, n)) && !(max !== undefined && iso > max.slice(0, n));
|
|
113
|
+
}
|
|
114
|
+
/** Paging: one month, one year or twelve years. */
|
|
115
|
+
function page(v, iso, dir) {
|
|
116
|
+
return v === 'day' ? addMonths(iso, dir) : addYears(iso, v === 'month' ? dir : 12 * dir);
|
|
117
|
+
}
|
|
118
|
+
/** A move that lands on a page with nothing pickable stops at min or max instead. */
|
|
119
|
+
function settle(iso) {
|
|
120
|
+
return pageOpen(pageOf(view, iso)) ? iso : clampIso(iso, min, max);
|
|
121
|
+
}
|
|
122
|
+
/** A cell button; only a day cell gets an aria-label (its full date), the others their text. */
|
|
123
|
+
function makeCell(v, iso, text, label) {
|
|
124
|
+
const el = button('fs-calendar__cell');
|
|
125
|
+
el.setAttribute('role', 'gridcell');
|
|
126
|
+
el.textContent = text;
|
|
127
|
+
if (label !== undefined)
|
|
128
|
+
el.setAttribute('aria-label', label);
|
|
129
|
+
const n = WIDTH[v];
|
|
130
|
+
el.tabIndex = focusIso.slice(0, n) === iso ? 0 : -1;
|
|
131
|
+
if (value !== null && value.slice(0, n) === iso)
|
|
132
|
+
el.setAttribute('aria-selected', 'true');
|
|
133
|
+
if (today.slice(0, n) === iso)
|
|
134
|
+
el.setAttribute('aria-current', 'date');
|
|
135
|
+
if (!enabled(v, iso))
|
|
136
|
+
el.setAttribute('aria-disabled', 'true');
|
|
137
|
+
cellValues.set(el, iso);
|
|
138
|
+
return el;
|
|
139
|
+
}
|
|
140
|
+
function blank() {
|
|
141
|
+
const el = doc.createElement('span');
|
|
142
|
+
el.className = 'fs-calendar__blank';
|
|
143
|
+
el.setAttribute('role', 'gridcell');
|
|
144
|
+
return el;
|
|
145
|
+
}
|
|
146
|
+
function row(children) {
|
|
147
|
+
const el = doc.createElement('div');
|
|
148
|
+
el.className = 'fs-calendar__row';
|
|
149
|
+
el.setAttribute('role', 'row');
|
|
150
|
+
el.append(...children);
|
|
151
|
+
return el;
|
|
152
|
+
}
|
|
153
|
+
function render(focusGrid = false) {
|
|
154
|
+
const hadFocus = focusGrid || grid.contains(rootNode().activeElement);
|
|
155
|
+
const current = pageOf(view, focusIso);
|
|
156
|
+
const rows = [];
|
|
157
|
+
cellValues = new Map();
|
|
158
|
+
if (current.view === 'day') {
|
|
159
|
+
const { year, month } = current;
|
|
160
|
+
const ws = opts.weekStart;
|
|
161
|
+
rows.push(row(Array.from({ length: 7 }, (_, i) => {
|
|
162
|
+
const th = doc.createElement('span');
|
|
163
|
+
th.className = 'fs-calendar__weekday';
|
|
164
|
+
th.setAttribute('role', 'columnheader');
|
|
165
|
+
th.textContent = opts.weekdayNames[mod(ws + i, 7)];
|
|
166
|
+
return th;
|
|
167
|
+
})));
|
|
168
|
+
for (const week of monthGrid(year, month, ws)) {
|
|
169
|
+
rows.push(row(week.map((day) => {
|
|
170
|
+
if (day === null)
|
|
171
|
+
return blank();
|
|
172
|
+
const iso = formatDay(year, month, day);
|
|
173
|
+
const label = opts.cellLabel({ value: iso, year, month, day, weekday: weekday(year, month, day) });
|
|
174
|
+
return makeCell('day', iso, String(day), label);
|
|
175
|
+
})));
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
const units = current.view === 'month'
|
|
180
|
+
? Array.from({ length: 12 }, (_, i) => {
|
|
181
|
+
return makeCell('month', formatMonth(current.year, i + 1), opts.monthNames[i]);
|
|
182
|
+
})
|
|
183
|
+
: Array.from({ length: 12 }, (_, i) => {
|
|
184
|
+
const year = current.from + i;
|
|
185
|
+
if (year < 1)
|
|
186
|
+
return blank();
|
|
187
|
+
const iso = String(year).padStart(4, '0');
|
|
188
|
+
return makeCell('year', iso, String(year));
|
|
189
|
+
});
|
|
190
|
+
for (let i = 0; i < 12; i += 3)
|
|
191
|
+
rows.push(row(units.slice(i, i + 3)));
|
|
192
|
+
}
|
|
193
|
+
grid.className = `fs-calendar__grid fs-calendar__grid--${view}`;
|
|
194
|
+
grid.replaceChildren(...rows);
|
|
195
|
+
const text = opts.heading(current);
|
|
196
|
+
heading.textContent = text;
|
|
197
|
+
const views = VIEWS[lowest()];
|
|
198
|
+
const top = view === views[0];
|
|
199
|
+
const up = view === 'year' ? undefined : opts.labels.up?.[view];
|
|
200
|
+
if (up)
|
|
201
|
+
viewButton.setAttribute('aria-label', `${text}, ${up}`);
|
|
202
|
+
else
|
|
203
|
+
viewButton.removeAttribute('aria-label');
|
|
204
|
+
toggle(viewButton, 'aria-disabled', top);
|
|
205
|
+
if (top)
|
|
206
|
+
viewIcon.remove();
|
|
207
|
+
else
|
|
208
|
+
viewButton.append(viewIcon);
|
|
209
|
+
prev.setAttribute('aria-label', opts.labels.prev[view]);
|
|
210
|
+
next.setAttribute('aria-label', opts.labels.next[view]);
|
|
211
|
+
toggle(prev, 'aria-disabled', !pageOpen(pageOf(view, page(view, focusIso, -1))) || isEdge(-1));
|
|
212
|
+
toggle(next, 'aria-disabled', !pageOpen(pageOf(view, page(view, focusIso, 1))) || isEdge(1));
|
|
213
|
+
// Announce a new heading (paging, stepping), never the first one. Not from inside the view button:
|
|
214
|
+
// a live region in a focused button whose name changes is read twice.
|
|
215
|
+
const out = opts.announcer ?? live;
|
|
216
|
+
if (opts.announcer)
|
|
217
|
+
live.remove();
|
|
218
|
+
else if (live.parentElement !== root)
|
|
219
|
+
root.append(live);
|
|
220
|
+
if (lastHeading && text !== lastHeading)
|
|
221
|
+
out.textContent = text;
|
|
222
|
+
lastHeading = text;
|
|
223
|
+
if (hadFocus)
|
|
224
|
+
stopCell()?.focus();
|
|
225
|
+
}
|
|
226
|
+
/** At year 1 or 9999 paging goes nowhere. */
|
|
227
|
+
function isEdge(dir) {
|
|
228
|
+
return JSON.stringify(pageOf(view, page(view, focusIso, dir))) === JSON.stringify(pageOf(view, focusIso));
|
|
229
|
+
}
|
|
230
|
+
function toggle(el, attr, on) {
|
|
231
|
+
if (on)
|
|
232
|
+
el.setAttribute(attr, 'true');
|
|
233
|
+
else
|
|
234
|
+
el.removeAttribute(attr);
|
|
235
|
+
}
|
|
236
|
+
const stopCell = () => [...cellValues.keys()].find((el) => el.tabIndex === 0);
|
|
237
|
+
/** Puts the focus value on a cell of the current view, keeping the finer parts it doesn't show. */
|
|
238
|
+
function onto(v, iso) {
|
|
239
|
+
if (v === 'year')
|
|
240
|
+
return addYears(focusIso, Number(iso) - Number(focusIso.slice(0, 4)));
|
|
241
|
+
if (v === 'month') {
|
|
242
|
+
const [y, m] = [Number(iso.slice(0, 4)), Number(iso.slice(5, 7))];
|
|
243
|
+
if (lowest() === 'month')
|
|
244
|
+
return iso;
|
|
245
|
+
return formatDay(y, m, Math.min(Number(focusIso.slice(8, 10)), daysInMonth(y, m)));
|
|
246
|
+
}
|
|
247
|
+
return iso;
|
|
248
|
+
}
|
|
249
|
+
function moveTo(iso) {
|
|
250
|
+
focusIso = settle(iso);
|
|
251
|
+
render(true);
|
|
252
|
+
}
|
|
253
|
+
function onKeydown(e) {
|
|
254
|
+
const target = e.target;
|
|
255
|
+
if (!cellValues.has(target) || e.altKey || e.ctrlKey || e.metaKey)
|
|
256
|
+
return;
|
|
257
|
+
const rtl = root.ownerDocument.defaultView?.getComputedStyle(root).direction === 'rtl';
|
|
258
|
+
const across = view === 'day' ? 7 : 3;
|
|
259
|
+
const step = (n) => view === 'day' ? addDays(focusIso, n) : view === 'month' ? addMonths(focusIso, n) : addYears(focusIso, n);
|
|
260
|
+
/** The focus value's column in its row, and the row's length. */
|
|
261
|
+
const column = () => {
|
|
262
|
+
if (view === 'day') {
|
|
263
|
+
const [y, m, d] = [Number(focusIso.slice(0, 4)), Number(focusIso.slice(5, 7)), Number(focusIso.slice(8, 10))];
|
|
264
|
+
const col = mod(weekday(y, m, d) - opts.weekStart, 7);
|
|
265
|
+
return { back: Math.min(col, d - 1), ahead: Math.min(6 - col, daysInMonth(y, m) - d) };
|
|
266
|
+
}
|
|
267
|
+
const index = view === 'month'
|
|
268
|
+
? Number(focusIso.slice(5, 7)) - 1
|
|
269
|
+
: Number(focusIso.slice(0, 4)) - yearPage(Number(focusIso.slice(0, 4))).from;
|
|
270
|
+
return { back: index % 3, ahead: 2 - (index % 3) };
|
|
271
|
+
};
|
|
272
|
+
let to;
|
|
273
|
+
switch (e.key) {
|
|
274
|
+
case 'ArrowRight':
|
|
275
|
+
to = step(rtl ? -1 : 1);
|
|
276
|
+
break;
|
|
277
|
+
case 'ArrowLeft':
|
|
278
|
+
to = step(rtl ? 1 : -1);
|
|
279
|
+
break;
|
|
280
|
+
case 'ArrowDown':
|
|
281
|
+
to = step(across);
|
|
282
|
+
break;
|
|
283
|
+
case 'ArrowUp':
|
|
284
|
+
to = step(-across);
|
|
285
|
+
break;
|
|
286
|
+
case 'Home':
|
|
287
|
+
to = step(-column().back);
|
|
288
|
+
break;
|
|
289
|
+
case 'End':
|
|
290
|
+
to = step(column().ahead);
|
|
291
|
+
break;
|
|
292
|
+
case 'PageUp':
|
|
293
|
+
case 'PageDown': {
|
|
294
|
+
const dir = e.key === 'PageUp' ? -1 : 1;
|
|
295
|
+
to = e.shiftKey && view === 'day' ? addYears(focusIso, dir) : page(view, focusIso, dir);
|
|
296
|
+
break;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
if (to === undefined)
|
|
300
|
+
return;
|
|
301
|
+
e.preventDefault();
|
|
302
|
+
moveTo(to);
|
|
303
|
+
}
|
|
304
|
+
function onClick(e) {
|
|
305
|
+
const target = e.target;
|
|
306
|
+
if (viewButton.contains(target)) {
|
|
307
|
+
const views = VIEWS[lowest()];
|
|
308
|
+
const i = views.indexOf(view);
|
|
309
|
+
if (i > 0) {
|
|
310
|
+
view = views[i - 1];
|
|
311
|
+
render();
|
|
312
|
+
}
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
for (const [b, dir] of [
|
|
316
|
+
[prev, -1],
|
|
317
|
+
[next, 1],
|
|
318
|
+
]) {
|
|
319
|
+
if (b.contains(target)) {
|
|
320
|
+
if (b.getAttribute('aria-disabled') !== 'true') {
|
|
321
|
+
focusIso = settle(page(view, focusIso, dir));
|
|
322
|
+
render();
|
|
323
|
+
}
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
const cell = target.closest('.fs-calendar__cell');
|
|
328
|
+
const iso = cell && cellValues.get(cell);
|
|
329
|
+
if (!cell || !iso || cell.getAttribute('aria-disabled') === 'true')
|
|
330
|
+
return;
|
|
331
|
+
if (view === lowest()) {
|
|
332
|
+
value = iso;
|
|
333
|
+
focusIso = iso;
|
|
334
|
+
render(true);
|
|
335
|
+
root.dispatchEvent(new CustomEvent('fs-change', { bubbles: true, detail: { value: iso } }));
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
focusIso = clampIso(onto(view, iso), min, max);
|
|
339
|
+
const views = VIEWS[lowest()];
|
|
340
|
+
view = views[views.indexOf(view) + 1];
|
|
341
|
+
render(true);
|
|
342
|
+
}
|
|
343
|
+
function onFocusin(e) {
|
|
344
|
+
const iso = cellValues.get(e.target);
|
|
345
|
+
if (iso === undefined || iso === focusIso.slice(0, WIDTH[view]))
|
|
346
|
+
return;
|
|
347
|
+
focusIso = onto(view, iso);
|
|
348
|
+
for (const el of cellValues.keys())
|
|
349
|
+
el.tabIndex = el === e.target ? 0 : -1;
|
|
350
|
+
}
|
|
351
|
+
readAll(options, true);
|
|
352
|
+
root.replaceChildren(header, grid);
|
|
353
|
+
render();
|
|
354
|
+
root.addEventListener('keydown', onKeydown);
|
|
355
|
+
root.addEventListener('click', onClick);
|
|
356
|
+
root.addEventListener('focusin', onFocusin);
|
|
357
|
+
return {
|
|
358
|
+
get value() {
|
|
359
|
+
return value;
|
|
360
|
+
},
|
|
361
|
+
get view() {
|
|
362
|
+
return view;
|
|
363
|
+
},
|
|
364
|
+
setValue(next) {
|
|
365
|
+
readAll({ value: next }, false);
|
|
366
|
+
render();
|
|
367
|
+
},
|
|
368
|
+
setView(next) {
|
|
369
|
+
if (!VIEWS[lowest()].includes(next))
|
|
370
|
+
return;
|
|
371
|
+
view = next;
|
|
372
|
+
render();
|
|
373
|
+
},
|
|
374
|
+
focus() {
|
|
375
|
+
stopCell()?.focus();
|
|
376
|
+
},
|
|
377
|
+
update(next) {
|
|
378
|
+
readAll(next, false);
|
|
379
|
+
render();
|
|
380
|
+
},
|
|
381
|
+
destroy() {
|
|
382
|
+
root.removeEventListener('keydown', onKeydown);
|
|
383
|
+
root.removeEventListener('click', onClick);
|
|
384
|
+
root.removeEventListener('focusin', onFocusin);
|
|
385
|
+
root.replaceChildren();
|
|
386
|
+
cellValues = new Map();
|
|
387
|
+
},
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
function check(o) {
|
|
391
|
+
if (o.monthNames?.length !== 12)
|
|
392
|
+
throw new TypeError('[fs] createCalendar: monthNames needs 12 names');
|
|
393
|
+
if (o.weekdayNames?.length !== 7)
|
|
394
|
+
throw new TypeError('[fs] createCalendar: weekdayNames needs 7 names');
|
|
395
|
+
return o;
|
|
396
|
+
}
|
package/dist/dom/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { type Calendar, type CalendarChangeDetail, type CalendarDay, type CalendarLabels, type CalendarOptions, type CalendarPage, type CalendarView, createCalendar, type Granularity, } from './calendar.ts';
|
|
1
2
|
export { createDialog, createSheet, type Dialog, type DialogCloseDetail, type DialogOptions } from './dialog.ts';
|
|
2
3
|
export { createListbox, type Listbox, type ListboxOptions, type ListboxSelectDetail } from './listbox.ts';
|
|
3
4
|
export { createLoader, type Loader, type LoaderOptions } from './loader.ts';
|
package/dist/dom/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// The plain-DOM behaviour helpers (D13; spec 03 §3). Each is also importable on its own:
|
|
2
2
|
// `@finstack-com-public/design/dom/<helper>`.
|
|
3
|
+
export { createCalendar, } from "./calendar.js";
|
|
3
4
|
export { createDialog, createSheet } from "./dialog.js";
|
|
4
5
|
export { createListbox } from "./listbox.js";
|
|
5
6
|
export { createLoader } from "./loader.js";
|
package/dist/kit.css
CHANGED
|
@@ -1372,6 +1372,179 @@
|
|
|
1372
1372
|
}
|
|
1373
1373
|
}
|
|
1374
1374
|
|
|
1375
|
+
/* Calendar (spec 02 B): year, month and day views. Usage: calendar.md. Behaviour: createCalendar,
|
|
1376
|
+
which renders the header and the grid into an empty .fs-calendar (D42). */
|
|
1377
|
+
@layer fs.components {
|
|
1378
|
+
.fs-calendar {
|
|
1379
|
+
/* One cell's width: seven make the calendar, so it follows the density. */
|
|
1380
|
+
--fs-calendar-cell: var(--fs-control-h);
|
|
1381
|
+
display: inline-flex;
|
|
1382
|
+
flex-direction: column;
|
|
1383
|
+
gap: var(--fs-space-1);
|
|
1384
|
+
box-sizing: content-box;
|
|
1385
|
+
width: calc(7 * var(--fs-calendar-cell));
|
|
1386
|
+
padding: var(--fs-space-2);
|
|
1387
|
+
font-size: var(--fs-text-body-size);
|
|
1388
|
+
line-height: var(--fs-text-body-line);
|
|
1389
|
+
color: var(--fs-ink);
|
|
1390
|
+
}
|
|
1391
|
+
|
|
1392
|
+
.fs-calendar__header {
|
|
1393
|
+
display: flex;
|
|
1394
|
+
align-items: center;
|
|
1395
|
+
gap: var(--fs-space-1);
|
|
1396
|
+
height: var(--fs-control-h);
|
|
1397
|
+
}
|
|
1398
|
+
|
|
1399
|
+
/* Shows the page's heading; steps up a view. In the top view it is the heading alone. */
|
|
1400
|
+
.fs-calendar__view {
|
|
1401
|
+
display: inline-flex;
|
|
1402
|
+
align-items: center;
|
|
1403
|
+
gap: var(--fs-space-1);
|
|
1404
|
+
box-sizing: border-box;
|
|
1405
|
+
min-width: 0;
|
|
1406
|
+
height: var(--fs-control-h);
|
|
1407
|
+
margin: 0 auto 0 0;
|
|
1408
|
+
padding: 0 var(--fs-pad-x);
|
|
1409
|
+
font: inherit;
|
|
1410
|
+
font-weight: var(--fs-weight-semibold);
|
|
1411
|
+
color: var(--fs-ink);
|
|
1412
|
+
white-space: nowrap;
|
|
1413
|
+
background: transparent;
|
|
1414
|
+
border: 0;
|
|
1415
|
+
border-radius: var(--fs-radius-sm);
|
|
1416
|
+
cursor: pointer;
|
|
1417
|
+
}
|
|
1418
|
+
.fs-calendar__view-icon {
|
|
1419
|
+
width: var(--fs-icon-size);
|
|
1420
|
+
height: var(--fs-icon-size);
|
|
1421
|
+
color: var(--fs-ink-2);
|
|
1422
|
+
}
|
|
1423
|
+
|
|
1424
|
+
.fs-calendar__grid {
|
|
1425
|
+
display: grid;
|
|
1426
|
+
align-content: start;
|
|
1427
|
+
/* A six-week month and the 4 × 3 month and year pages are the same height. */
|
|
1428
|
+
min-height: calc(7 * var(--fs-calendar-cell));
|
|
1429
|
+
}
|
|
1430
|
+
.fs-calendar__row {
|
|
1431
|
+
display: grid;
|
|
1432
|
+
grid-template-columns: repeat(3, 1fr);
|
|
1433
|
+
}
|
|
1434
|
+
.fs-calendar__grid--day .fs-calendar__row {
|
|
1435
|
+
grid-template-columns: repeat(7, 1fr);
|
|
1436
|
+
}
|
|
1437
|
+
|
|
1438
|
+
.fs-calendar__weekday {
|
|
1439
|
+
display: grid;
|
|
1440
|
+
place-items: center;
|
|
1441
|
+
height: var(--fs-calendar-cell);
|
|
1442
|
+
font-size: var(--fs-text-xs-size);
|
|
1443
|
+
line-height: var(--fs-text-xs-line);
|
|
1444
|
+
color: var(--fs-ink-muted);
|
|
1445
|
+
}
|
|
1446
|
+
|
|
1447
|
+
.fs-calendar__cell {
|
|
1448
|
+
position: relative;
|
|
1449
|
+
display: grid;
|
|
1450
|
+
place-items: center;
|
|
1451
|
+
box-sizing: border-box;
|
|
1452
|
+
min-width: 0;
|
|
1453
|
+
height: var(--fs-calendar-cell);
|
|
1454
|
+
margin: 0;
|
|
1455
|
+
padding: 0 2px;
|
|
1456
|
+
font: inherit;
|
|
1457
|
+
font-variant-numeric: tabular-nums;
|
|
1458
|
+
color: var(--fs-ink);
|
|
1459
|
+
white-space: nowrap;
|
|
1460
|
+
background: transparent;
|
|
1461
|
+
border: 0;
|
|
1462
|
+
border-radius: var(--fs-radius-sm);
|
|
1463
|
+
cursor: pointer;
|
|
1464
|
+
}
|
|
1465
|
+
.fs-calendar__grid--month .fs-calendar__cell,
|
|
1466
|
+
.fs-calendar__grid--year .fs-calendar__cell {
|
|
1467
|
+
height: calc(1.75 * var(--fs-calendar-cell));
|
|
1468
|
+
}
|
|
1469
|
+
|
|
1470
|
+
@media (hover: hover) {
|
|
1471
|
+
.fs-calendar__view:not([aria-disabled='true']):hover,
|
|
1472
|
+
.fs-calendar__cell:hover {
|
|
1473
|
+
background-color: var(--fs-bg-hover);
|
|
1474
|
+
}
|
|
1475
|
+
.fs-calendar__cell[aria-selected='true']:not([aria-disabled='true']):hover {
|
|
1476
|
+
background-color: var(--fs-primary-bg-hover);
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1479
|
+
.fs-calendar__view:not([aria-disabled='true']):active,
|
|
1480
|
+
.fs-calendar__cell:active {
|
|
1481
|
+
background-color: var(--fs-bg-active);
|
|
1482
|
+
}
|
|
1483
|
+
|
|
1484
|
+
/* Today: an edge, not a fill, drawn inside so it never meets a neighbour's. */
|
|
1485
|
+
.fs-calendar__cell[aria-current='date']::after {
|
|
1486
|
+
content: '';
|
|
1487
|
+
position: absolute;
|
|
1488
|
+
inset: 2px;
|
|
1489
|
+
border: var(--fs-line-width) solid var(--fs-accent);
|
|
1490
|
+
border-radius: var(--fs-radius-sm);
|
|
1491
|
+
pointer-events: none;
|
|
1492
|
+
}
|
|
1493
|
+
|
|
1494
|
+
/* Selected: the accent fill and weight 600, so it never rests on colour alone. */
|
|
1495
|
+
.fs-calendar__cell[aria-selected='true'] {
|
|
1496
|
+
font-weight: var(--fs-weight-semibold);
|
|
1497
|
+
color: var(--fs-primary-ink);
|
|
1498
|
+
background-color: var(--fs-primary-bg);
|
|
1499
|
+
}
|
|
1500
|
+
.fs-calendar__cell[aria-selected='true'][aria-current='date']::after {
|
|
1501
|
+
border-color: var(--fs-primary-ink);
|
|
1502
|
+
}
|
|
1503
|
+
|
|
1504
|
+
/* The ring recipe (D15). The header's own button rings outside; cells touch, so theirs is inside. */
|
|
1505
|
+
.fs-calendar__view:focus-visible {
|
|
1506
|
+
outline: var(--fs-ring-width) solid var(--fs-ring);
|
|
1507
|
+
outline-offset: var(--fs-ring-halo-width);
|
|
1508
|
+
box-shadow: 0 0 0 var(--fs-ring-halo-width) var(--fs-ring-halo);
|
|
1509
|
+
}
|
|
1510
|
+
.fs-calendar__cell:focus-visible {
|
|
1511
|
+
z-index: 1;
|
|
1512
|
+
outline: var(--fs-ring-width) solid var(--fs-ring);
|
|
1513
|
+
outline-offset: calc(-1 * var(--fs-ring-width));
|
|
1514
|
+
box-shadow: inset 0 0 0 calc(var(--fs-ring-width) + var(--fs-ring-halo-width)) var(--fs-ring-halo);
|
|
1515
|
+
}
|
|
1516
|
+
|
|
1517
|
+
/* The top view's heading is not a control. */
|
|
1518
|
+
.fs-calendar__view[aria-disabled='true'] {
|
|
1519
|
+
cursor: default;
|
|
1520
|
+
}
|
|
1521
|
+
|
|
1522
|
+
/* Outside min and max: reachable, never pickable. Last, so it beats hover, press and selected. */
|
|
1523
|
+
.fs-calendar__cell[aria-disabled='true'] {
|
|
1524
|
+
color: var(--fs-ink-disabled);
|
|
1525
|
+
background-color: transparent;
|
|
1526
|
+
cursor: not-allowed;
|
|
1527
|
+
}
|
|
1528
|
+
|
|
1529
|
+
/* Forced colours: washes and fills are erased, so the selected cell takes the Highlight pair, today
|
|
1530
|
+
keeps its edge (borders survive, in the system's colour) and disabled is GrayText. */
|
|
1531
|
+
@media (forced-colors: active) {
|
|
1532
|
+
.fs-calendar__cell[aria-selected='true'] {
|
|
1533
|
+
color: HighlightText;
|
|
1534
|
+
background-color: Highlight;
|
|
1535
|
+
}
|
|
1536
|
+
.fs-calendar__cell[aria-current='date']::after {
|
|
1537
|
+
border-color: CanvasText;
|
|
1538
|
+
}
|
|
1539
|
+
.fs-calendar__cell[aria-selected='true'][aria-current='date']::after {
|
|
1540
|
+
border-color: HighlightText;
|
|
1541
|
+
}
|
|
1542
|
+
.fs-calendar__cell[aria-disabled='true'] {
|
|
1543
|
+
color: GrayText;
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
}
|
|
1547
|
+
|
|
1375
1548
|
/* Card: a whole panel that is one link or button (spec 02 D). Usage: card.md. */
|
|
1376
1549
|
@layer fs.components {
|
|
1377
1550
|
.fs-card {
|
|
@@ -3324,8 +3497,10 @@
|
|
|
3324
3497
|
border-color: var(--fs-danger-fill);
|
|
3325
3498
|
}
|
|
3326
3499
|
|
|
3327
|
-
/* Read-only: no control edge, the value in full ink.
|
|
3328
|
-
|
|
3500
|
+
/* Read-only: no control edge, the value in full ink. `:read-only` matches anything not editable, a
|
|
3501
|
+
<button> too, so the picker button is left out (T84); `:where` keeps the specificity at (0,2,0), so
|
|
3502
|
+
disabled still wins. */
|
|
3503
|
+
.fs-input:where(:not(.fs-input--picker)):read-only,
|
|
3329
3504
|
.fs-textarea:read-only {
|
|
3330
3505
|
background-color: transparent;
|
|
3331
3506
|
border-color: transparent;
|
|
@@ -4259,6 +4434,13 @@
|
|
|
4259
4434
|
margin-top: var(--fs-space-3);
|
|
4260
4435
|
}
|
|
4261
4436
|
|
|
4437
|
+
/* Fits its content and leaves the padding to it: a picker's calendar (T84). */
|
|
4438
|
+
.fs-popover--fit {
|
|
4439
|
+
width: max-content;
|
|
4440
|
+
max-width: calc(100vw - 16px);
|
|
4441
|
+
padding: 0;
|
|
4442
|
+
}
|
|
4443
|
+
|
|
4262
4444
|
/* The ring recipe (D15), when the panel itself takes focus. */
|
|
4263
4445
|
.fs-popover:focus-visible {
|
|
4264
4446
|
outline: var(--fs-ring-width) solid var(--fs-ring);
|
|
@@ -5976,9 +6158,12 @@
|
|
|
5976
6158
|
@layer fs.components {
|
|
5977
6159
|
/* An empty, aria-hidden band: a wave of dots, cyan at the left to blue at the right. The
|
|
5978
6160
|
wave is an image (motifs/wave.webp, D33): the owner's ChatGPT image as white on transparent,
|
|
5979
|
-
used as a mask over the brand colours, so its colour comes from the roles.
|
|
5980
|
-
|
|
5981
|
-
the
|
|
6161
|
+
used as a mask over the brand colours, so its colour comes from the roles. The whole wave
|
|
6162
|
+
shows: the image is fitted to the band's height (its ratio is 5.716), centred and anchored at
|
|
6163
|
+
the bottom. A band narrower than that ratio times its height is filled by the image
|
|
6164
|
+
(`cover`: the sides are cropped, never the crest). A wider band gets a box exactly as wide as
|
|
6165
|
+
the image, centred, with both edges fading out instead of ending in a cut. `--fs-wave-image`
|
|
6166
|
+
points it at a self-hosted copy (keep the ratio). */
|
|
5982
6167
|
.fs-wave {
|
|
5983
6168
|
display: block;
|
|
5984
6169
|
height: var(--fs-wave-height, 160px);
|
|
@@ -5992,9 +6177,21 @@
|
|
|
5992
6177
|
content: '';
|
|
5993
6178
|
display: block;
|
|
5994
6179
|
height: 100%;
|
|
6180
|
+
/* --fs-wave-height is read here, on the host's own value, so a custom height moves the cap too. */
|
|
6181
|
+
max-width: calc(var(--fs-wave-height, 160px) * 5.716);
|
|
6182
|
+
margin-inline: auto;
|
|
5995
6183
|
background: linear-gradient(90deg, var(--fs-brand-end), var(--fs-brand-start) 65%);
|
|
5996
|
-
|
|
5997
|
-
mask:
|
|
6184
|
+
/* Two mask layers, intersected: the soft right edge, then the image. */
|
|
6185
|
+
-webkit-mask:
|
|
6186
|
+
linear-gradient(90deg, transparent, currentcolor 5%, currentcolor 90%, transparent) center bottom / 100% 100%
|
|
6187
|
+
no-repeat,
|
|
6188
|
+
var(--fs-wave-image, url('./motifs/wave.webp')) center bottom / cover no-repeat;
|
|
6189
|
+
-webkit-mask-composite: source-in;
|
|
6190
|
+
mask:
|
|
6191
|
+
linear-gradient(90deg, transparent, currentcolor 5%, currentcolor 90%, transparent) center bottom / 100% 100%
|
|
6192
|
+
no-repeat,
|
|
6193
|
+
var(--fs-wave-image, url('./motifs/wave.webp')) center bottom / cover no-repeat;
|
|
6194
|
+
mask-composite: intersect;
|
|
5998
6195
|
}
|
|
5999
6196
|
/* Decoration: nothing to show in forced colours, nothing to print. */
|
|
6000
6197
|
@media (forced-colors: active) {
|
package/dist/react/inputs.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { type ButtonHTMLAttributes, type HTMLAttributes, type InputHTMLAttributes, type OutputHTMLAttributes, type ReactNode, type SelectHTMLAttributes, type TextareaHTMLAttributes } from 'react';
|
|
1
|
+
import { type ButtonHTMLAttributes, type HTMLAttributes, type InputHTMLAttributes, type OutputHTMLAttributes, type ReactNode, type RefObject, type SelectHTMLAttributes, type TextareaHTMLAttributes } from 'react';
|
|
2
|
+
import { type CalendarOptions } from '../dom/calendar.ts';
|
|
2
3
|
type Tone = 'neutral' | 'caution' | 'warning' | 'danger';
|
|
3
4
|
/** What Field hands its control: spread it onto the input. */
|
|
4
5
|
export interface FieldControlProps {
|
|
@@ -76,4 +77,24 @@ export declare const ReadonlyValue: import("react").ForwardRefExoticComponent<HT
|
|
|
76
77
|
export declare const ComputedValue: import("react").ForwardRefExoticComponent<OutputHTMLAttributes<HTMLOutputElement> & import("react").RefAttributes<HTMLOutputElement>>;
|
|
77
78
|
/** A figure that is a button: every explainable value is keyboard-reachable (GZ §6.3). */
|
|
78
79
|
export declare const ExplainableValue: import("react").ForwardRefExoticComponent<ButtonHTMLAttributes<HTMLButtonElement> & import("react").RefAttributes<HTMLButtonElement>>;
|
|
79
|
-
export {};
|
|
80
|
+
export type { CalendarDay, CalendarLabels, CalendarPage, CalendarView } from '../dom/calendar.ts';
|
|
81
|
+
export interface CalendarProps extends Omit<HTMLAttributes<HTMLDivElement>, 'onChange' | 'defaultValue' | 'children'>, Pick<CalendarOptions, 'min' | 'max' | 'today' | 'granularity' | 'weekStart' | 'monthNames' | 'weekdayNames' | 'heading' | 'cellLabel' | 'labels'> {
|
|
82
|
+
/** Controlled: the picked day (`YYYY-MM-DD`) or month (`YYYY-MM`), or null. */
|
|
83
|
+
value?: string | null;
|
|
84
|
+
/** Uncontrolled: the first value. */
|
|
85
|
+
defaultValue?: string | null;
|
|
86
|
+
/** A lowest-view cell was picked: on every pick, the current value too. */
|
|
87
|
+
onChange?: (value: string) => void;
|
|
88
|
+
/** The host's one live region (CE §7); without it the calendar keeps its own. */
|
|
89
|
+
announcer?: RefObject<HTMLElement | null>;
|
|
90
|
+
/**
|
|
91
|
+
* Focuses the grid's tab stop (the value, else today) when it mounts. A picker remounts the
|
|
92
|
+
* calendar on each open (a new `key`) to start there.
|
|
93
|
+
*/
|
|
94
|
+
autoFocus?: boolean;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* The calendar (D42): renders the empty `.fs-calendar` root and runs `createCalendar` on mount, which
|
|
98
|
+
* renders the header and the grid. On the server it is the empty root. Every name is a required prop.
|
|
99
|
+
*/
|
|
100
|
+
export declare const Calendar: import("react").ForwardRefExoticComponent<CalendarProps & import("react").RefAttributes<HTMLDivElement>>;
|