@finstack-com-public/design 0.7.1 → 0.9.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 +51 -0
- package/dist/css/calendar.css +266 -0
- package/dist/css/calendar.md +301 -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-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 +278 -2
- package/dist/css-text/popover.js +1 -1
- package/dist/dom/calendar-dates.d.ts +45 -0
- package/dist/dom/calendar-dates.js +129 -0
- package/dist/dom/calendar.d.ts +124 -0
- package/dist/dom/calendar.js +612 -0
- package/dist/dom/index.d.ts +1 -0
- package/dist/dom/index.js +1 -0
- package/dist/kit.css +278 -2
- package/dist/react/inputs.d.ts +41 -2
- package/dist/react/inputs.js +129 -2
- package/dist/react/overlays.d.ts +15 -15
- package/package.json +1 -1
package/dist/css/popover.md
CHANGED
|
@@ -25,3 +25,5 @@ const pop = createPopover(popEl, { anchor: whyButton, placement: 'bottom-start',
|
|
|
25
25
|
- `closeOnBlur` closes it when Tab leaves it.
|
|
26
26
|
- Write it `hidden`, so it stays out of sight before the helper runs (or without script); the
|
|
27
27
|
helper moves it to the top layer where the browser has one.
|
|
28
|
+
- `.fs-popover--fit` drops the 340 px width and the padding, so the popover fits content that pads
|
|
29
|
+
itself, such as the date picker's calendar (`calendar.md`).
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default "/* Calendar (spec 02 B): year, month and day views; one value or a range (T85), one page or two.\n Usage: calendar.md. Behaviour: createCalendar, which renders the header and the grid into an empty\n .fs-calendar (D42). */\n@layer fs.components {\n .fs-calendar {\n /* One cell's width: seven make the calendar, so it follows the density. */\n --fs-calendar-cell: var(--fs-control-h);\n /* Between two pages side by side (months: 2). */\n --fs-calendar-gap: var(--fs-space-4);\n display: inline-flex;\n flex-direction: column;\n gap: var(--fs-space-1);\n box-sizing: content-box;\n width: calc(7 * var(--fs-calendar-cell));\n padding: var(--fs-space-2);\n font-size: var(--fs-text-body-size);\n line-height: var(--fs-text-body-line);\n color: var(--fs-ink);\n }\n\n .fs-calendar__header {\n position: relative;\n display: flex;\n align-items: center;\n gap: var(--fs-space-1);\n height: var(--fs-control-h);\n }\n\n /* Two pages side by side (months: 2): twice as wide in every view, so a popover never resizes. The\n higher views' one grid spans both columns. */\n .fs-calendar:has(> .fs-calendar__months) {\n width: calc(14 * var(--fs-calendar-cell) + var(--fs-calendar-gap));\n }\n .fs-calendar__months {\n display: grid;\n grid-template-columns: repeat(2, 1fr);\n column-gap: var(--fs-calendar-gap);\n }\n .fs-calendar__months > .fs-calendar__grid:only-child {\n grid-column: 1 / -1;\n }\n\n /* The second page's heading, over its grid; the view button names the first. Not a control. */\n .fs-calendar__caption {\n position: absolute;\n inset-block: 0;\n inset-inline-start: calc(7 * var(--fs-calendar-cell) + var(--fs-calendar-gap));\n display: flex;\n align-items: center;\n padding: 0 var(--fs-pad-x);\n font-weight: var(--fs-weight-semibold);\n white-space: nowrap;\n }\n\n /* Shows the page's heading; steps up a view. In the top view it is the heading alone. */\n .fs-calendar__view {\n display: inline-flex;\n align-items: center;\n gap: var(--fs-space-1);\n box-sizing: border-box;\n min-width: 0;\n height: var(--fs-control-h);\n margin: 0 auto 0 0;\n padding: 0 var(--fs-pad-x);\n font: inherit;\n font-weight: var(--fs-weight-semibold);\n color: var(--fs-ink);\n white-space: nowrap;\n background: transparent;\n border: 0;\n border-radius: var(--fs-radius-sm);\n cursor: pointer;\n }\n .fs-calendar__view-icon {\n width: var(--fs-icon-size);\n height: var(--fs-icon-size);\n color: var(--fs-ink-2);\n }\n\n .fs-calendar__grid {\n display: grid;\n align-content: start;\n /* A six-week month and the 4 × 3 month and year pages are the same height. */\n min-height: calc(7 * var(--fs-calendar-cell));\n }\n .fs-calendar__row {\n display: grid;\n grid-template-columns: repeat(3, 1fr);\n }\n .fs-calendar__grid--day .fs-calendar__row {\n grid-template-columns: repeat(7, 1fr);\n }\n\n .fs-calendar__weekday {\n display: grid;\n place-items: center;\n height: var(--fs-calendar-cell);\n font-size: var(--fs-text-xs-size);\n line-height: var(--fs-text-xs-line);\n color: var(--fs-ink-muted);\n }\n\n .fs-calendar__cell {\n position: relative;\n display: grid;\n place-items: center;\n box-sizing: border-box;\n min-width: 0;\n height: var(--fs-calendar-cell);\n margin: 0;\n padding: 0 2px;\n font: inherit;\n font-variant-numeric: tabular-nums;\n color: var(--fs-ink);\n white-space: nowrap;\n background: transparent;\n border: 0;\n border-radius: var(--fs-radius-sm);\n cursor: pointer;\n }\n .fs-calendar__grid--month .fs-calendar__cell,\n .fs-calendar__grid--year .fs-calendar__cell {\n height: calc(1.75 * var(--fs-calendar-cell));\n }\n\n @media (hover: hover) {\n .fs-calendar__view:not([aria-disabled='true']):hover,\n .fs-calendar__cell:hover {\n background-color: var(--fs-bg-hover);\n }\n .fs-calendar__cell[aria-selected='true']:not([aria-disabled='true']):hover {\n background-color: var(--fs-primary-bg-hover);\n }\n .fs-calendar__cell--range[aria-selected='true']:not([aria-disabled='true']):hover {\n background-color: var(--fs-bg-hover);\n }\n }\n .fs-calendar__view:not([aria-disabled='true']):active,\n .fs-calendar__cell:active {\n background-color: var(--fs-bg-active);\n }\n\n /* Today: an edge, not a fill, drawn inside so it never meets a neighbour's. */\n .fs-calendar__cell[aria-current='date']::after {\n content: '';\n position: absolute;\n inset: 2px;\n border: var(--fs-line-width) solid var(--fs-accent);\n border-radius: var(--fs-radius-sm);\n pointer-events: none;\n }\n\n /* Selected: the accent fill and weight 600, so it never rests on colour alone. */\n .fs-calendar__cell[aria-selected='true'] {\n font-weight: var(--fs-weight-semibold);\n color: var(--fs-primary-ink);\n background-color: var(--fs-primary-bg);\n }\n .fs-calendar__cell[aria-selected='true'][aria-current='date']::after {\n border-color: var(--fs-primary-ink);\n }\n\n /* A range (T85): start and end are filled as selected; the cells between are a band on the accent\n wash. Each end squares off where it meets the band, and the band's cells are square, so the band\n runs unbroken across a row. Start and end are also in the cells' names (cellLabel's range role). */\n .fs-calendar__cell--range-start {\n border-start-end-radius: 0;\n border-end-end-radius: 0;\n }\n .fs-calendar__cell--range-end {\n border-start-start-radius: 0;\n border-end-start-radius: 0;\n }\n .fs-calendar__cell--range[aria-selected='true'] {\n font-weight: inherit;\n color: var(--fs-ink);\n background-color: var(--fs-accent-wash);\n border-radius: 0;\n }\n .fs-calendar__cell--range[aria-selected='true'][aria-current='date']::after {\n border-color: var(--fs-accent);\n }\n\n /* The preview, while only the start is picked: from the start to the hovered or focused cell, a\n dashed edge above and below, joined across the row. Not a fill: nothing is picked yet. */\n .fs-calendar__cell--preview::before {\n content: '';\n position: absolute;\n inset: 3px 0;\n border-block: var(--fs-line-width) dashed var(--fs-accent);\n pointer-events: none;\n }\n\n /* The ring recipe (D15). The header's own button rings outside; cells touch, so theirs is inside. */\n .fs-calendar__view:focus-visible {\n outline: var(--fs-ring-width) solid var(--fs-ring);\n outline-offset: var(--fs-ring-halo-width);\n box-shadow: 0 0 0 var(--fs-ring-halo-width) var(--fs-ring-halo);\n }\n .fs-calendar__cell:focus-visible {\n z-index: 1;\n outline: var(--fs-ring-width) solid var(--fs-ring);\n outline-offset: calc(-1 * var(--fs-ring-width));\n box-shadow: inset 0 0 0 calc(var(--fs-ring-width) + var(--fs-ring-halo-width)) var(--fs-ring-halo);\n }\n\n /* The top view's heading is not a control. */\n .fs-calendar__view[aria-disabled='true'] {\n cursor: default;\n }\n\n /* Outside min and max: reachable, never pickable. Last, so it beats hover, press and selected. */\n .fs-calendar__cell[aria-disabled='true'] {\n color: var(--fs-ink-disabled);\n background-color: transparent;\n cursor: not-allowed;\n }\n\n /* Forced colours: washes and fills are erased, so the selected cell keeps CanvasText on Canvas (Firefox\n and WebKit repaint the background but keep the ink, so a Highlight pair fails contrast: I15) and is\n marked by a 2px Highlight edge inside the cell, as the segmented control does. Today keeps its edge\n (borders survive, in the system's colour), inset further when the cell is selected too. Disabled is\n GrayText. */\n @media (forced-colors: active) {\n .fs-calendar__cell[aria-selected='true'] {\n color: CanvasText;\n background-color: Canvas;\n }\n .fs-calendar__cell[aria-selected='true']:not(.fs-calendar__cell--range)::before {\n content: '';\n position: absolute;\n inset: 0;\n border: 2px solid Highlight;\n border-radius: var(--fs-radius-sm);\n pointer-events: none;\n }\n .fs-calendar__cell[aria-current='date']::after {\n border-color: CanvasText;\n }\n .fs-calendar__cell[aria-selected='true'][aria-current='date']:not(.fs-calendar__cell--range)::after {\n inset: 4px;\n border-color: CanvasText;\n }\n .fs-calendar__cell[aria-disabled='true'] {\n color: GrayText;\n }\n /* The band keeps its shape as a Highlight edge above and below; start and end take the edge above. */\n .fs-calendar__cell--range[aria-selected='true'] {\n color: CanvasText;\n background-color: Canvas;\n }\n .fs-calendar__cell--range[aria-selected='true']::before {\n content: '';\n position: absolute;\n inset: 2px 0;\n border-block: var(--fs-line-width) solid Highlight;\n pointer-events: none;\n }\n .fs-calendar__cell--range[aria-selected='true'][aria-current='date']::after {\n border-color: CanvasText;\n }\n .fs-calendar__cell--preview::before {\n border-color: Highlight;\n }\n }\n}\n";
|
package/dist/css-text/input.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default "/* Text input, textarea and select (spec 02 B). Usage: input.md. */\n@layer fs.components {\n .fs-input,\n .fs-textarea,\n .fs-select__control {\n box-sizing: border-box;\n width: 100%;\n margin: 0;\n padding: 0 var(--fs-pad-x);\n font: inherit;\n font-size: var(--fs-text-body-size);\n line-height: var(--fs-text-body-line);\n color: var(--fs-ink);\n background-color: var(--fs-bg-sunken);\n border: var(--fs-line-width) solid var(--fs-line-control);\n border-radius: var(--fs-radius-md);\n }\n .fs-input,\n .fs-select__control {\n height: var(--fs-control-h);\n }\n .fs-textarea {\n display: block;\n min-height: calc(var(--fs-text-body-line) * 3 + var(--fs-space-2) * 2);\n padding-block: var(--fs-space-2);\n resize: vertical;\n }\n /* A button that opens a picker (a tree, chips, a calendar) and shows the chosen value. */\n .fs-input--picker {\n display: flex;\n align-items: center;\n text-align: left;\n cursor: pointer;\n }\n .fs-input--num {\n text-align: right;\n font-variant-numeric: tabular-nums;\n }\n .fs-input::placeholder,\n .fs-textarea::placeholder {\n color: var(--fs-ink-muted);\n opacity: 1;\n }\n\n @media (hover: hover) {\n .fs-input:hover,\n .fs-textarea:hover,\n .fs-select__control:hover {\n border-color: var(--fs-ink-2);\n }\n }\n\n /* The ring recipe (D15). */\n .fs-input:focus-visible,\n .fs-textarea:focus-visible,\n .fs-select__control:focus-visible {\n outline: var(--fs-ring-width) solid var(--fs-ring);\n outline-offset: var(--fs-ring-halo-width);\n box-shadow: 0 0 0 var(--fs-ring-halo-width) var(--fs-ring-halo);\n }\n\n .fs-input[aria-invalid='true'],\n .fs-textarea[aria-invalid='true'],\n .fs-select__control[aria-invalid='true'] {\n border-color: var(--fs-danger-fill);\n }\n\n /* Read-only: no control edge, the value in full ink. */\n .fs-input:read-only,\n .fs-textarea:read-only {\n background-color: transparent;\n border-color: transparent;\n }\n .fs-textarea:read-only {\n resize: none;\n }\n\n /* Disabled last. opacity: 1 undoes Safari's own dimming. */\n .fs-input:disabled,\n .fs-textarea:disabled,\n .fs-select__control:disabled {\n color: var(--fs-ink-disabled);\n -webkit-text-fill-color: var(--fs-ink-disabled);\n background-color: var(--fs-bg-disabled);\n border-color: var(--fs-line);\n cursor: not-allowed;\n opacity: 1;\n }\n\n /* Select: a wrapper draws the chevron, since a <select> can't hold a pseudo-element. */\n .fs-select {\n position: relative;\n display: block;\n min-width: 0;\n color: var(--fs-ink-2);\n }\n .fs-select__control {\n appearance: none;\n padding-right: calc(var(--fs-pad-x) * 2 + 16px);\n cursor: pointer;\n }\n .fs-select::after {\n content: '';\n position: absolute;\n top: 0;\n right: var(--fs-pad-x);\n bottom: 0;\n width: 16px;\n margin: auto 0;\n height: 16px;\n background-color: currentColor;\n mask: url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.875' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E\")\n center / contain no-repeat;\n pointer-events: none;\n }\n .fs-select:has(:disabled) {\n color: var(--fs-ink-disabled);\n }\n}\n";
|
|
1
|
+
export default "/* Text input, textarea and select (spec 02 B). Usage: input.md. */\n@layer fs.components {\n .fs-input,\n .fs-textarea,\n .fs-select__control {\n box-sizing: border-box;\n width: 100%;\n margin: 0;\n padding: 0 var(--fs-pad-x);\n font: inherit;\n font-size: var(--fs-text-body-size);\n line-height: var(--fs-text-body-line);\n color: var(--fs-ink);\n background-color: var(--fs-bg-sunken);\n border: var(--fs-line-width) solid var(--fs-line-control);\n border-radius: var(--fs-radius-md);\n }\n .fs-input,\n .fs-select__control {\n height: var(--fs-control-h);\n }\n .fs-textarea {\n display: block;\n min-height: calc(var(--fs-text-body-line) * 3 + var(--fs-space-2) * 2);\n padding-block: var(--fs-space-2);\n resize: vertical;\n }\n /* A button that opens a picker (a tree, chips, a calendar) and shows the chosen value. */\n .fs-input--picker {\n display: flex;\n align-items: center;\n text-align: left;\n cursor: pointer;\n }\n .fs-input--num {\n text-align: right;\n font-variant-numeric: tabular-nums;\n }\n .fs-input::placeholder,\n .fs-textarea::placeholder {\n color: var(--fs-ink-muted);\n opacity: 1;\n }\n\n @media (hover: hover) {\n .fs-input:hover,\n .fs-textarea:hover,\n .fs-select__control:hover {\n border-color: var(--fs-ink-2);\n }\n }\n\n /* The ring recipe (D15). */\n .fs-input:focus-visible,\n .fs-textarea:focus-visible,\n .fs-select__control:focus-visible {\n outline: var(--fs-ring-width) solid var(--fs-ring);\n outline-offset: var(--fs-ring-halo-width);\n box-shadow: 0 0 0 var(--fs-ring-halo-width) var(--fs-ring-halo);\n }\n\n .fs-input[aria-invalid='true'],\n .fs-textarea[aria-invalid='true'],\n .fs-select__control[aria-invalid='true'] {\n border-color: var(--fs-danger-fill);\n }\n\n /* Read-only: no control edge, the value in full ink. `:read-only` matches anything not editable, a\n <button> too, so the picker button is left out (T84); `:where` keeps the specificity at (0,2,0), so\n disabled still wins. */\n .fs-input:where(:not(.fs-input--picker)):read-only,\n .fs-textarea:read-only {\n background-color: transparent;\n border-color: transparent;\n }\n .fs-textarea:read-only {\n resize: none;\n }\n\n /* Disabled last. opacity: 1 undoes Safari's own dimming. */\n .fs-input:disabled,\n .fs-textarea:disabled,\n .fs-select__control:disabled {\n color: var(--fs-ink-disabled);\n -webkit-text-fill-color: var(--fs-ink-disabled);\n background-color: var(--fs-bg-disabled);\n border-color: var(--fs-line);\n cursor: not-allowed;\n opacity: 1;\n }\n\n /* Select: a wrapper draws the chevron, since a <select> can't hold a pseudo-element. */\n .fs-select {\n position: relative;\n display: block;\n min-width: 0;\n color: var(--fs-ink-2);\n }\n .fs-select__control {\n appearance: none;\n padding-right: calc(var(--fs-pad-x) * 2 + 16px);\n cursor: pointer;\n }\n .fs-select::after {\n content: '';\n position: absolute;\n top: 0;\n right: var(--fs-pad-x);\n bottom: 0;\n width: 16px;\n margin: auto 0;\n height: 16px;\n background-color: currentColor;\n mask: url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.875' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E\")\n center / contain no-repeat;\n pointer-events: none;\n }\n .fs-select:has(:disabled) {\n color: var(--fs-ink-disabled);\n }\n}\n";
|
package/dist/css-text/kit.js
CHANGED
|
@@ -1372,6 +1372,273 @@ export default `@layer fs.tokens, fs.reset, fs.base, fs.components, fs.utilities
|
|
|
1372
1372
|
}
|
|
1373
1373
|
}
|
|
1374
1374
|
|
|
1375
|
+
/* Calendar (spec 02 B): year, month and day views; one value or a range (T85), one page or two.
|
|
1376
|
+
Usage: calendar.md. Behaviour: createCalendar, which renders the header and the grid into an empty
|
|
1377
|
+
.fs-calendar (D42). */
|
|
1378
|
+
@layer fs.components {
|
|
1379
|
+
.fs-calendar {
|
|
1380
|
+
/* One cell's width: seven make the calendar, so it follows the density. */
|
|
1381
|
+
--fs-calendar-cell: var(--fs-control-h);
|
|
1382
|
+
/* Between two pages side by side (months: 2). */
|
|
1383
|
+
--fs-calendar-gap: var(--fs-space-4);
|
|
1384
|
+
display: inline-flex;
|
|
1385
|
+
flex-direction: column;
|
|
1386
|
+
gap: var(--fs-space-1);
|
|
1387
|
+
box-sizing: content-box;
|
|
1388
|
+
width: calc(7 * var(--fs-calendar-cell));
|
|
1389
|
+
padding: var(--fs-space-2);
|
|
1390
|
+
font-size: var(--fs-text-body-size);
|
|
1391
|
+
line-height: var(--fs-text-body-line);
|
|
1392
|
+
color: var(--fs-ink);
|
|
1393
|
+
}
|
|
1394
|
+
|
|
1395
|
+
.fs-calendar__header {
|
|
1396
|
+
position: relative;
|
|
1397
|
+
display: flex;
|
|
1398
|
+
align-items: center;
|
|
1399
|
+
gap: var(--fs-space-1);
|
|
1400
|
+
height: var(--fs-control-h);
|
|
1401
|
+
}
|
|
1402
|
+
|
|
1403
|
+
/* Two pages side by side (months: 2): twice as wide in every view, so a popover never resizes. The
|
|
1404
|
+
higher views' one grid spans both columns. */
|
|
1405
|
+
.fs-calendar:has(> .fs-calendar__months) {
|
|
1406
|
+
width: calc(14 * var(--fs-calendar-cell) + var(--fs-calendar-gap));
|
|
1407
|
+
}
|
|
1408
|
+
.fs-calendar__months {
|
|
1409
|
+
display: grid;
|
|
1410
|
+
grid-template-columns: repeat(2, 1fr);
|
|
1411
|
+
column-gap: var(--fs-calendar-gap);
|
|
1412
|
+
}
|
|
1413
|
+
.fs-calendar__months > .fs-calendar__grid:only-child {
|
|
1414
|
+
grid-column: 1 / -1;
|
|
1415
|
+
}
|
|
1416
|
+
|
|
1417
|
+
/* The second page's heading, over its grid; the view button names the first. Not a control. */
|
|
1418
|
+
.fs-calendar__caption {
|
|
1419
|
+
position: absolute;
|
|
1420
|
+
inset-block: 0;
|
|
1421
|
+
inset-inline-start: calc(7 * var(--fs-calendar-cell) + var(--fs-calendar-gap));
|
|
1422
|
+
display: flex;
|
|
1423
|
+
align-items: center;
|
|
1424
|
+
padding: 0 var(--fs-pad-x);
|
|
1425
|
+
font-weight: var(--fs-weight-semibold);
|
|
1426
|
+
white-space: nowrap;
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1429
|
+
/* Shows the page's heading; steps up a view. In the top view it is the heading alone. */
|
|
1430
|
+
.fs-calendar__view {
|
|
1431
|
+
display: inline-flex;
|
|
1432
|
+
align-items: center;
|
|
1433
|
+
gap: var(--fs-space-1);
|
|
1434
|
+
box-sizing: border-box;
|
|
1435
|
+
min-width: 0;
|
|
1436
|
+
height: var(--fs-control-h);
|
|
1437
|
+
margin: 0 auto 0 0;
|
|
1438
|
+
padding: 0 var(--fs-pad-x);
|
|
1439
|
+
font: inherit;
|
|
1440
|
+
font-weight: var(--fs-weight-semibold);
|
|
1441
|
+
color: var(--fs-ink);
|
|
1442
|
+
white-space: nowrap;
|
|
1443
|
+
background: transparent;
|
|
1444
|
+
border: 0;
|
|
1445
|
+
border-radius: var(--fs-radius-sm);
|
|
1446
|
+
cursor: pointer;
|
|
1447
|
+
}
|
|
1448
|
+
.fs-calendar__view-icon {
|
|
1449
|
+
width: var(--fs-icon-size);
|
|
1450
|
+
height: var(--fs-icon-size);
|
|
1451
|
+
color: var(--fs-ink-2);
|
|
1452
|
+
}
|
|
1453
|
+
|
|
1454
|
+
.fs-calendar__grid {
|
|
1455
|
+
display: grid;
|
|
1456
|
+
align-content: start;
|
|
1457
|
+
/* A six-week month and the 4 × 3 month and year pages are the same height. */
|
|
1458
|
+
min-height: calc(7 * var(--fs-calendar-cell));
|
|
1459
|
+
}
|
|
1460
|
+
.fs-calendar__row {
|
|
1461
|
+
display: grid;
|
|
1462
|
+
grid-template-columns: repeat(3, 1fr);
|
|
1463
|
+
}
|
|
1464
|
+
.fs-calendar__grid--day .fs-calendar__row {
|
|
1465
|
+
grid-template-columns: repeat(7, 1fr);
|
|
1466
|
+
}
|
|
1467
|
+
|
|
1468
|
+
.fs-calendar__weekday {
|
|
1469
|
+
display: grid;
|
|
1470
|
+
place-items: center;
|
|
1471
|
+
height: var(--fs-calendar-cell);
|
|
1472
|
+
font-size: var(--fs-text-xs-size);
|
|
1473
|
+
line-height: var(--fs-text-xs-line);
|
|
1474
|
+
color: var(--fs-ink-muted);
|
|
1475
|
+
}
|
|
1476
|
+
|
|
1477
|
+
.fs-calendar__cell {
|
|
1478
|
+
position: relative;
|
|
1479
|
+
display: grid;
|
|
1480
|
+
place-items: center;
|
|
1481
|
+
box-sizing: border-box;
|
|
1482
|
+
min-width: 0;
|
|
1483
|
+
height: var(--fs-calendar-cell);
|
|
1484
|
+
margin: 0;
|
|
1485
|
+
padding: 0 2px;
|
|
1486
|
+
font: inherit;
|
|
1487
|
+
font-variant-numeric: tabular-nums;
|
|
1488
|
+
color: var(--fs-ink);
|
|
1489
|
+
white-space: nowrap;
|
|
1490
|
+
background: transparent;
|
|
1491
|
+
border: 0;
|
|
1492
|
+
border-radius: var(--fs-radius-sm);
|
|
1493
|
+
cursor: pointer;
|
|
1494
|
+
}
|
|
1495
|
+
.fs-calendar__grid--month .fs-calendar__cell,
|
|
1496
|
+
.fs-calendar__grid--year .fs-calendar__cell {
|
|
1497
|
+
height: calc(1.75 * var(--fs-calendar-cell));
|
|
1498
|
+
}
|
|
1499
|
+
|
|
1500
|
+
@media (hover: hover) {
|
|
1501
|
+
.fs-calendar__view:not([aria-disabled='true']):hover,
|
|
1502
|
+
.fs-calendar__cell:hover {
|
|
1503
|
+
background-color: var(--fs-bg-hover);
|
|
1504
|
+
}
|
|
1505
|
+
.fs-calendar__cell[aria-selected='true']:not([aria-disabled='true']):hover {
|
|
1506
|
+
background-color: var(--fs-primary-bg-hover);
|
|
1507
|
+
}
|
|
1508
|
+
.fs-calendar__cell--range[aria-selected='true']:not([aria-disabled='true']):hover {
|
|
1509
|
+
background-color: var(--fs-bg-hover);
|
|
1510
|
+
}
|
|
1511
|
+
}
|
|
1512
|
+
.fs-calendar__view:not([aria-disabled='true']):active,
|
|
1513
|
+
.fs-calendar__cell:active {
|
|
1514
|
+
background-color: var(--fs-bg-active);
|
|
1515
|
+
}
|
|
1516
|
+
|
|
1517
|
+
/* Today: an edge, not a fill, drawn inside so it never meets a neighbour's. */
|
|
1518
|
+
.fs-calendar__cell[aria-current='date']::after {
|
|
1519
|
+
content: '';
|
|
1520
|
+
position: absolute;
|
|
1521
|
+
inset: 2px;
|
|
1522
|
+
border: var(--fs-line-width) solid var(--fs-accent);
|
|
1523
|
+
border-radius: var(--fs-radius-sm);
|
|
1524
|
+
pointer-events: none;
|
|
1525
|
+
}
|
|
1526
|
+
|
|
1527
|
+
/* Selected: the accent fill and weight 600, so it never rests on colour alone. */
|
|
1528
|
+
.fs-calendar__cell[aria-selected='true'] {
|
|
1529
|
+
font-weight: var(--fs-weight-semibold);
|
|
1530
|
+
color: var(--fs-primary-ink);
|
|
1531
|
+
background-color: var(--fs-primary-bg);
|
|
1532
|
+
}
|
|
1533
|
+
.fs-calendar__cell[aria-selected='true'][aria-current='date']::after {
|
|
1534
|
+
border-color: var(--fs-primary-ink);
|
|
1535
|
+
}
|
|
1536
|
+
|
|
1537
|
+
/* A range (T85): start and end are filled as selected; the cells between are a band on the accent
|
|
1538
|
+
wash. Each end squares off where it meets the band, and the band's cells are square, so the band
|
|
1539
|
+
runs unbroken across a row. Start and end are also in the cells' names (cellLabel's range role). */
|
|
1540
|
+
.fs-calendar__cell--range-start {
|
|
1541
|
+
border-start-end-radius: 0;
|
|
1542
|
+
border-end-end-radius: 0;
|
|
1543
|
+
}
|
|
1544
|
+
.fs-calendar__cell--range-end {
|
|
1545
|
+
border-start-start-radius: 0;
|
|
1546
|
+
border-end-start-radius: 0;
|
|
1547
|
+
}
|
|
1548
|
+
.fs-calendar__cell--range[aria-selected='true'] {
|
|
1549
|
+
font-weight: inherit;
|
|
1550
|
+
color: var(--fs-ink);
|
|
1551
|
+
background-color: var(--fs-accent-wash);
|
|
1552
|
+
border-radius: 0;
|
|
1553
|
+
}
|
|
1554
|
+
.fs-calendar__cell--range[aria-selected='true'][aria-current='date']::after {
|
|
1555
|
+
border-color: var(--fs-accent);
|
|
1556
|
+
}
|
|
1557
|
+
|
|
1558
|
+
/* The preview, while only the start is picked: from the start to the hovered or focused cell, a
|
|
1559
|
+
dashed edge above and below, joined across the row. Not a fill: nothing is picked yet. */
|
|
1560
|
+
.fs-calendar__cell--preview::before {
|
|
1561
|
+
content: '';
|
|
1562
|
+
position: absolute;
|
|
1563
|
+
inset: 3px 0;
|
|
1564
|
+
border-block: var(--fs-line-width) dashed var(--fs-accent);
|
|
1565
|
+
pointer-events: none;
|
|
1566
|
+
}
|
|
1567
|
+
|
|
1568
|
+
/* The ring recipe (D15). The header's own button rings outside; cells touch, so theirs is inside. */
|
|
1569
|
+
.fs-calendar__view:focus-visible {
|
|
1570
|
+
outline: var(--fs-ring-width) solid var(--fs-ring);
|
|
1571
|
+
outline-offset: var(--fs-ring-halo-width);
|
|
1572
|
+
box-shadow: 0 0 0 var(--fs-ring-halo-width) var(--fs-ring-halo);
|
|
1573
|
+
}
|
|
1574
|
+
.fs-calendar__cell:focus-visible {
|
|
1575
|
+
z-index: 1;
|
|
1576
|
+
outline: var(--fs-ring-width) solid var(--fs-ring);
|
|
1577
|
+
outline-offset: calc(-1 * var(--fs-ring-width));
|
|
1578
|
+
box-shadow: inset 0 0 0 calc(var(--fs-ring-width) + var(--fs-ring-halo-width)) var(--fs-ring-halo);
|
|
1579
|
+
}
|
|
1580
|
+
|
|
1581
|
+
/* The top view's heading is not a control. */
|
|
1582
|
+
.fs-calendar__view[aria-disabled='true'] {
|
|
1583
|
+
cursor: default;
|
|
1584
|
+
}
|
|
1585
|
+
|
|
1586
|
+
/* Outside min and max: reachable, never pickable. Last, so it beats hover, press and selected. */
|
|
1587
|
+
.fs-calendar__cell[aria-disabled='true'] {
|
|
1588
|
+
color: var(--fs-ink-disabled);
|
|
1589
|
+
background-color: transparent;
|
|
1590
|
+
cursor: not-allowed;
|
|
1591
|
+
}
|
|
1592
|
+
|
|
1593
|
+
/* Forced colours: washes and fills are erased, so the selected cell keeps CanvasText on Canvas (Firefox
|
|
1594
|
+
and WebKit repaint the background but keep the ink, so a Highlight pair fails contrast: I15) and is
|
|
1595
|
+
marked by a 2px Highlight edge inside the cell, as the segmented control does. Today keeps its edge
|
|
1596
|
+
(borders survive, in the system's colour), inset further when the cell is selected too. Disabled is
|
|
1597
|
+
GrayText. */
|
|
1598
|
+
@media (forced-colors: active) {
|
|
1599
|
+
.fs-calendar__cell[aria-selected='true'] {
|
|
1600
|
+
color: CanvasText;
|
|
1601
|
+
background-color: Canvas;
|
|
1602
|
+
}
|
|
1603
|
+
.fs-calendar__cell[aria-selected='true']:not(.fs-calendar__cell--range)::before {
|
|
1604
|
+
content: '';
|
|
1605
|
+
position: absolute;
|
|
1606
|
+
inset: 0;
|
|
1607
|
+
border: 2px solid Highlight;
|
|
1608
|
+
border-radius: var(--fs-radius-sm);
|
|
1609
|
+
pointer-events: none;
|
|
1610
|
+
}
|
|
1611
|
+
.fs-calendar__cell[aria-current='date']::after {
|
|
1612
|
+
border-color: CanvasText;
|
|
1613
|
+
}
|
|
1614
|
+
.fs-calendar__cell[aria-selected='true'][aria-current='date']:not(.fs-calendar__cell--range)::after {
|
|
1615
|
+
inset: 4px;
|
|
1616
|
+
border-color: CanvasText;
|
|
1617
|
+
}
|
|
1618
|
+
.fs-calendar__cell[aria-disabled='true'] {
|
|
1619
|
+
color: GrayText;
|
|
1620
|
+
}
|
|
1621
|
+
/* The band keeps its shape as a Highlight edge above and below; start and end take the edge above. */
|
|
1622
|
+
.fs-calendar__cell--range[aria-selected='true'] {
|
|
1623
|
+
color: CanvasText;
|
|
1624
|
+
background-color: Canvas;
|
|
1625
|
+
}
|
|
1626
|
+
.fs-calendar__cell--range[aria-selected='true']::before {
|
|
1627
|
+
content: '';
|
|
1628
|
+
position: absolute;
|
|
1629
|
+
inset: 2px 0;
|
|
1630
|
+
border-block: var(--fs-line-width) solid Highlight;
|
|
1631
|
+
pointer-events: none;
|
|
1632
|
+
}
|
|
1633
|
+
.fs-calendar__cell--range[aria-selected='true'][aria-current='date']::after {
|
|
1634
|
+
border-color: CanvasText;
|
|
1635
|
+
}
|
|
1636
|
+
.fs-calendar__cell--preview::before {
|
|
1637
|
+
border-color: Highlight;
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1640
|
+
}
|
|
1641
|
+
|
|
1375
1642
|
/* Card: a whole panel that is one link or button (spec 02 D). Usage: card.md. */
|
|
1376
1643
|
@layer fs.components {
|
|
1377
1644
|
.fs-card {
|
|
@@ -3324,8 +3591,10 @@ export default `@layer fs.tokens, fs.reset, fs.base, fs.components, fs.utilities
|
|
|
3324
3591
|
border-color: var(--fs-danger-fill);
|
|
3325
3592
|
}
|
|
3326
3593
|
|
|
3327
|
-
/* Read-only: no control edge, the value in full ink.
|
|
3328
|
-
|
|
3594
|
+
/* Read-only: no control edge, the value in full ink. \`:read-only\` matches anything not editable, a
|
|
3595
|
+
<button> too, so the picker button is left out (T84); \`:where\` keeps the specificity at (0,2,0), so
|
|
3596
|
+
disabled still wins. */
|
|
3597
|
+
.fs-input:where(:not(.fs-input--picker)):read-only,
|
|
3329
3598
|
.fs-textarea:read-only {
|
|
3330
3599
|
background-color: transparent;
|
|
3331
3600
|
border-color: transparent;
|
|
@@ -4259,6 +4528,13 @@ export default `@layer fs.tokens, fs.reset, fs.base, fs.components, fs.utilities
|
|
|
4259
4528
|
margin-top: var(--fs-space-3);
|
|
4260
4529
|
}
|
|
4261
4530
|
|
|
4531
|
+
/* Fits its content and leaves the padding to it: a picker's calendar (T84). */
|
|
4532
|
+
.fs-popover--fit {
|
|
4533
|
+
width: max-content;
|
|
4534
|
+
max-width: calc(100vw - 16px);
|
|
4535
|
+
padding: 0;
|
|
4536
|
+
}
|
|
4537
|
+
|
|
4262
4538
|
/* The ring recipe (D15), when the panel itself takes focus. */
|
|
4263
4539
|
.fs-popover:focus-visible {
|
|
4264
4540
|
outline: var(--fs-ring-width) solid var(--fs-ring);
|
package/dist/css-text/popover.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default "/* Popover (spec 02 D). Usage: popover.md. Behaviour: createPopover. */\n@layer fs.components {\n .fs-popover {\n box-sizing: border-box;\n width: min(var(--fs-size-popover), calc(100vw - 16px));\n inset: auto;\n z-index: var(--fs-z-dropdown);\n margin: 0;\n padding: var(--fs-space-4);\n font-size: var(--fs-text-body-size);\n line-height: var(--fs-text-body-line);\n color: var(--fs-ink);\n background: var(--fs-bg-surface);\n border: var(--fs-line-width) solid var(--fs-line-strong);\n border-radius: var(--fs-radius-md);\n box-shadow: var(--fs-shadow-2);\n }\n .fs-popover__kicker {\n display: block;\n font-size: var(--fs-text-body-size);\n line-height: var(--fs-text-body-line);\n font-weight: var(--fs-weight-semibold);\n letter-spacing: var(--fs-tracking-caps);\n text-transform: uppercase;\n color: var(--fs-ink-2);\n }\n .fs-popover__title {\n display: flex;\n align-items: center;\n gap: var(--fs-space-2);\n margin: var(--fs-space-1) 0 var(--fs-space-2);\n font-size: var(--fs-text-body-size);\n line-height: var(--fs-text-body-line);\n font-weight: var(--fs-weight-semibold);\n color: var(--fs-ink-2);\n }\n .fs-popover__body {\n display: grid;\n gap: var(--fs-space-2);\n color: var(--fs-ink-2);\n }\n .fs-popover__actions {\n display: flex;\n justify-content: flex-end;\n gap: var(--fs-space-2);\n margin-top: var(--fs-space-3);\n }\n\n /* The ring recipe (D15), when the panel itself takes focus. */\n .fs-popover:focus-visible {\n outline: var(--fs-ring-width) solid var(--fs-ring);\n outline-offset: var(--fs-ring-halo-width);\n box-shadow: 0 0 0 var(--fs-ring-halo-width) var(--fs-ring-halo);\n }\n}\n";
|
|
1
|
+
export default "/* Popover (spec 02 D). Usage: popover.md. Behaviour: createPopover. */\n@layer fs.components {\n .fs-popover {\n box-sizing: border-box;\n width: min(var(--fs-size-popover), calc(100vw - 16px));\n inset: auto;\n z-index: var(--fs-z-dropdown);\n margin: 0;\n padding: var(--fs-space-4);\n font-size: var(--fs-text-body-size);\n line-height: var(--fs-text-body-line);\n color: var(--fs-ink);\n background: var(--fs-bg-surface);\n border: var(--fs-line-width) solid var(--fs-line-strong);\n border-radius: var(--fs-radius-md);\n box-shadow: var(--fs-shadow-2);\n }\n .fs-popover__kicker {\n display: block;\n font-size: var(--fs-text-body-size);\n line-height: var(--fs-text-body-line);\n font-weight: var(--fs-weight-semibold);\n letter-spacing: var(--fs-tracking-caps);\n text-transform: uppercase;\n color: var(--fs-ink-2);\n }\n .fs-popover__title {\n display: flex;\n align-items: center;\n gap: var(--fs-space-2);\n margin: var(--fs-space-1) 0 var(--fs-space-2);\n font-size: var(--fs-text-body-size);\n line-height: var(--fs-text-body-line);\n font-weight: var(--fs-weight-semibold);\n color: var(--fs-ink-2);\n }\n .fs-popover__body {\n display: grid;\n gap: var(--fs-space-2);\n color: var(--fs-ink-2);\n }\n .fs-popover__actions {\n display: flex;\n justify-content: flex-end;\n gap: var(--fs-space-2);\n margin-top: var(--fs-space-3);\n }\n\n /* Fits its content and leaves the padding to it: a picker's calendar (T84). */\n .fs-popover--fit {\n width: max-content;\n max-width: calc(100vw - 16px);\n padding: 0;\n }\n\n /* The ring recipe (D15), when the panel itself takes focus. */\n .fs-popover:focus-visible {\n outline: var(--fs-ring-width) solid var(--fs-ring);\n outline-offset: var(--fs-ring-halo-width);\n box-shadow: 0 0 0 var(--fs-ring-halo-width) var(--fs-ring-halo);\n }\n}\n";
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export type Granularity = 'month' | 'day';
|
|
2
|
+
export interface YMD {
|
|
3
|
+
year: number;
|
|
4
|
+
month: number;
|
|
5
|
+
day: number;
|
|
6
|
+
}
|
|
7
|
+
export declare function isLeapYear(year: number): boolean;
|
|
8
|
+
/** Days in a month (1–12). */
|
|
9
|
+
export declare function daysInMonth(year: number, month: number): number;
|
|
10
|
+
export declare const formatMonth: (year: number, month: number) => string;
|
|
11
|
+
export declare const formatDay: (year: number, month: number, day: number) => string;
|
|
12
|
+
/** `YYYY-MM` to its parts, or null when malformed or out of range. */
|
|
13
|
+
export declare function parseMonth(iso: string): {
|
|
14
|
+
year: number;
|
|
15
|
+
month: number;
|
|
16
|
+
} | null;
|
|
17
|
+
/** `YYYY-MM-DD` to its parts, or null when malformed or not a real day. */
|
|
18
|
+
export declare function parseDay(iso: string): YMD | null;
|
|
19
|
+
/** The weekday of a day, 0 = Sunday. */
|
|
20
|
+
export declare function weekday(year: number, month: number, day: number): number;
|
|
21
|
+
/** A day `n` days on (or back), held inside years 1–9999. */
|
|
22
|
+
export declare function addDays(iso: string, n: number): string;
|
|
23
|
+
/** A month or day `n` months on; a day keeps its number, clamped to the month's length. */
|
|
24
|
+
export declare function addMonths(iso: string, n: number): string;
|
|
25
|
+
export declare const addYears: (iso: string, n: number) => string;
|
|
26
|
+
/**
|
|
27
|
+
* Holds `iso` between `min` and `max` (either may be missing). Same-form ISO strings sort as
|
|
28
|
+
* text, because years are always four digits.
|
|
29
|
+
*/
|
|
30
|
+
export declare function clampIso(iso: string, min?: string, max?: string): string;
|
|
31
|
+
/**
|
|
32
|
+
* A month in weeks of seven, starting on `weekStart` (0 = Sunday): each entry is the day number,
|
|
33
|
+
* or null for a day of a neighbouring month.
|
|
34
|
+
*/
|
|
35
|
+
export declare function monthGrid(year: number, month: number, weekStart: number): (number | null)[][];
|
|
36
|
+
/** The page of twelve years that holds `year`: pages start at multiples of 12 (2016–2027). */
|
|
37
|
+
export declare function yearPage(year: number): {
|
|
38
|
+
from: number;
|
|
39
|
+
to: number;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Today in the user's own time zone, as a month or a day. The one place the calendar reads the
|
|
43
|
+
* clock, and only when the product passes no `today`.
|
|
44
|
+
*/
|
|
45
|
+
export declare function localToday(granularity: Granularity, now?: Date): string;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
// Date arithmetic for the calendar (D42; spec 03 §3.2), on ISO strings: `YYYY-MM` for a month,
|
|
2
|
+
// `YYYY-MM-DD` for a day. No `Date` is ever made from a value, so no time zone can move one by a
|
|
3
|
+
// day. Months are 1–12, weekdays 0 (Sunday) to 6, years 1–9999.
|
|
4
|
+
const MIN_YEAR = 1;
|
|
5
|
+
const MAX_YEAR = 9999;
|
|
6
|
+
const pad = (n, width) => String(n).padStart(width, '0');
|
|
7
|
+
const mod = (a, b) => ((a % b) + b) % b;
|
|
8
|
+
export function isLeapYear(year) {
|
|
9
|
+
return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
|
|
10
|
+
}
|
|
11
|
+
/** Days in a month (1–12). */
|
|
12
|
+
export function daysInMonth(year, month) {
|
|
13
|
+
return month === 2 ? (isLeapYear(year) ? 29 : 28) : [4, 6, 9, 11].includes(month) ? 30 : 31;
|
|
14
|
+
}
|
|
15
|
+
export const formatMonth = (year, month) => `${pad(year, 4)}-${pad(month, 2)}`;
|
|
16
|
+
export const formatDay = (year, month, day) => `${formatMonth(year, month)}-${pad(day, 2)}`;
|
|
17
|
+
/** `YYYY-MM` to its parts, or null when malformed or out of range. */
|
|
18
|
+
export function parseMonth(iso) {
|
|
19
|
+
const m = /^(\d{4})-(\d{2})$/.exec(iso);
|
|
20
|
+
if (!m)
|
|
21
|
+
return null;
|
|
22
|
+
const year = Number(m[1]);
|
|
23
|
+
const month = Number(m[2]);
|
|
24
|
+
return year >= MIN_YEAR && month >= 1 && month <= 12 ? { year, month } : null;
|
|
25
|
+
}
|
|
26
|
+
/** `YYYY-MM-DD` to its parts, or null when malformed or not a real day. */
|
|
27
|
+
export function parseDay(iso) {
|
|
28
|
+
const m = /^(\d{4}-\d{2})-(\d{2})$/.exec(iso);
|
|
29
|
+
const ym = m && parseMonth(m[1]);
|
|
30
|
+
if (!ym)
|
|
31
|
+
return null;
|
|
32
|
+
const day = Number(m[2]);
|
|
33
|
+
return day >= 1 && day <= daysInMonth(ym.year, ym.month) ? { ...ym, day } : null;
|
|
34
|
+
}
|
|
35
|
+
/** Parses either form, by length; a month comes back as its first day. */
|
|
36
|
+
function parts(iso) {
|
|
37
|
+
const d = iso.length > 7 ? parseDay(iso) : null;
|
|
38
|
+
if (d)
|
|
39
|
+
return d;
|
|
40
|
+
const m = parseMonth(iso.slice(0, 7));
|
|
41
|
+
if (!m)
|
|
42
|
+
throw new RangeError(`[fs] not an ISO month or day: "${iso}"`);
|
|
43
|
+
return { ...m, day: 1 };
|
|
44
|
+
}
|
|
45
|
+
// Days since 1970-01-01 and back (H. Hinnant's civil-from-days), so adding days never builds a Date.
|
|
46
|
+
function toDayNumber({ year, month, day }) {
|
|
47
|
+
const y = month <= 2 ? year - 1 : year;
|
|
48
|
+
const era = Math.floor(y / 400);
|
|
49
|
+
const yoe = y - era * 400;
|
|
50
|
+
const doy = Math.floor((153 * (month + (month > 2 ? -3 : 9)) + 2) / 5) + day - 1;
|
|
51
|
+
const doe = yoe * 365 + Math.floor(yoe / 4) - Math.floor(yoe / 100) + doy;
|
|
52
|
+
return era * 146097 + doe - 719468;
|
|
53
|
+
}
|
|
54
|
+
function fromDayNumber(n) {
|
|
55
|
+
const z = n + 719468;
|
|
56
|
+
const era = Math.floor(z / 146097);
|
|
57
|
+
const doe = z - era * 146097;
|
|
58
|
+
const yoe = Math.floor((doe - Math.floor(doe / 1460) + Math.floor(doe / 36524) - Math.floor(doe / 146096)) / 365);
|
|
59
|
+
const doy = doe - (365 * yoe + Math.floor(yoe / 4) - Math.floor(yoe / 100));
|
|
60
|
+
const mp = Math.floor((5 * doy + 2) / 153);
|
|
61
|
+
const day = doy - Math.floor((153 * mp + 2) / 5) + 1;
|
|
62
|
+
const month = mp < 10 ? mp + 3 : mp - 9;
|
|
63
|
+
return { year: yoe + era * 400 + (month <= 2 ? 1 : 0), month, day };
|
|
64
|
+
}
|
|
65
|
+
/** The weekday of a day, 0 = Sunday. */
|
|
66
|
+
export function weekday(year, month, day) {
|
|
67
|
+
return mod(toDayNumber({ year, month, day }) + 4, 7); // 1970-01-01 was a Thursday
|
|
68
|
+
}
|
|
69
|
+
/** A day `n` days on (or back), held inside years 1–9999. */
|
|
70
|
+
export function addDays(iso, n) {
|
|
71
|
+
const first = toDayNumber({ year: MIN_YEAR, month: 1, day: 1 });
|
|
72
|
+
const last = toDayNumber({ year: MAX_YEAR, month: 12, day: 31 });
|
|
73
|
+
const { year, month, day } = fromDayNumber(Math.min(Math.max(toDayNumber(parts(iso)) + n, first), last));
|
|
74
|
+
return formatDay(year, month, day);
|
|
75
|
+
}
|
|
76
|
+
/** A month or day `n` months on; a day keeps its number, clamped to the month's length. */
|
|
77
|
+
export function addMonths(iso, n) {
|
|
78
|
+
const p = parts(iso);
|
|
79
|
+
const index = Math.min(Math.max(p.year * 12 + p.month - 1 + n, MIN_YEAR * 12), MAX_YEAR * 12 + 11);
|
|
80
|
+
const year = Math.floor(index / 12);
|
|
81
|
+
const month = (index % 12) + 1;
|
|
82
|
+
if (iso.length <= 7)
|
|
83
|
+
return formatMonth(year, month);
|
|
84
|
+
// Clamped at either end of time, the day goes to that end too.
|
|
85
|
+
const atEdge = index !== p.year * 12 + p.month - 1 + n;
|
|
86
|
+
const day = atEdge ? (n < 0 ? 1 : daysInMonth(year, month)) : Math.min(p.day, daysInMonth(year, month));
|
|
87
|
+
return formatDay(year, month, day);
|
|
88
|
+
}
|
|
89
|
+
export const addYears = (iso, n) => addMonths(iso, n * 12);
|
|
90
|
+
/**
|
|
91
|
+
* Holds `iso` between `min` and `max` (either may be missing). Same-form ISO strings sort as
|
|
92
|
+
* text, because years are always four digits.
|
|
93
|
+
*/
|
|
94
|
+
export function clampIso(iso, min, max) {
|
|
95
|
+
if (min !== undefined && iso < min)
|
|
96
|
+
return min;
|
|
97
|
+
if (max !== undefined && iso > max)
|
|
98
|
+
return max;
|
|
99
|
+
return iso;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* A month in weeks of seven, starting on `weekStart` (0 = Sunday): each entry is the day number,
|
|
103
|
+
* or null for a day of a neighbouring month.
|
|
104
|
+
*/
|
|
105
|
+
export function monthGrid(year, month, weekStart) {
|
|
106
|
+
const lead = mod(weekday(year, month, 1) - weekStart, 7);
|
|
107
|
+
const cells = [...Array(lead).fill(null)];
|
|
108
|
+
for (let d = 1; d <= daysInMonth(year, month); d++)
|
|
109
|
+
cells.push(d);
|
|
110
|
+
while (cells.length % 7)
|
|
111
|
+
cells.push(null);
|
|
112
|
+
const weeks = [];
|
|
113
|
+
for (let i = 0; i < cells.length; i += 7)
|
|
114
|
+
weeks.push(cells.slice(i, i + 7));
|
|
115
|
+
return weeks;
|
|
116
|
+
}
|
|
117
|
+
/** The page of twelve years that holds `year`: pages start at multiples of 12 (2016–2027). */
|
|
118
|
+
export function yearPage(year) {
|
|
119
|
+
const from = year - mod(year, 12);
|
|
120
|
+
return { from, to: from + 11 };
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Today in the user's own time zone, as a month or a day. The one place the calendar reads the
|
|
124
|
+
* clock, and only when the product passes no `today`.
|
|
125
|
+
*/
|
|
126
|
+
export function localToday(granularity, now = new Date()) {
|
|
127
|
+
const month = formatMonth(now.getFullYear(), now.getMonth() + 1);
|
|
128
|
+
return granularity === 'month' ? month : `${month}-${pad(now.getDate(), 2)}`;
|
|
129
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { type Granularity } from './calendar-dates.ts';
|
|
2
|
+
export type { Granularity };
|
|
3
|
+
export type CalendarView = 'year' | 'month' | 'day';
|
|
4
|
+
/** What a page of the calendar shows, for the heading. Months are 1–12. */
|
|
5
|
+
export type CalendarPage = {
|
|
6
|
+
view: 'day';
|
|
7
|
+
year: number;
|
|
8
|
+
month: number;
|
|
9
|
+
} | {
|
|
10
|
+
view: 'month';
|
|
11
|
+
year: number;
|
|
12
|
+
} | {
|
|
13
|
+
view: 'year';
|
|
14
|
+
from: number;
|
|
15
|
+
to: number;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* A day cell, for its accessible name: `value` is `YYYY-MM-DD`, `weekday` 0 (Sunday) to 6. Only day
|
|
19
|
+
* cells take a name: a month or year cell is named by its visible text, and the grid by the heading,
|
|
20
|
+
* which carries the year (WCAG 2.5.3: a short "Jan" must not hide behind "January 2026").
|
|
21
|
+
*/
|
|
22
|
+
export interface CalendarDay {
|
|
23
|
+
value: string;
|
|
24
|
+
year: number;
|
|
25
|
+
month: number;
|
|
26
|
+
day: number;
|
|
27
|
+
weekday: number;
|
|
28
|
+
}
|
|
29
|
+
export interface CalendarLabels {
|
|
30
|
+
/** The previous-page button's name in each view ("Előző hónap", "Előző év", "Előző 12 év"). */
|
|
31
|
+
prev: Record<CalendarView, string>;
|
|
32
|
+
/** The next-page button's name in each view. */
|
|
33
|
+
next: Record<CalendarView, string>;
|
|
34
|
+
/** Optional: said after the heading in the view button's name ("2026. november, hónap választása"). */
|
|
35
|
+
up?: Partial<Record<'day' | 'month', string>>;
|
|
36
|
+
/** Range mode (required there): said after a range's first cell's name ("kezdete"). */
|
|
37
|
+
rangeStart?: string;
|
|
38
|
+
/** Range mode (required there): said after a range's last cell's name ("vége"). */
|
|
39
|
+
rangeEnd?: string;
|
|
40
|
+
}
|
|
41
|
+
/** A range calendar's labels: the start and end words are required. */
|
|
42
|
+
export interface CalendarRangeLabels extends CalendarLabels {
|
|
43
|
+
rangeStart: string;
|
|
44
|
+
rangeEnd: string;
|
|
45
|
+
}
|
|
46
|
+
/** The options both modes take. */
|
|
47
|
+
interface CalendarBaseOptions {
|
|
48
|
+
/** The first and last pickable day or month; either form is read at the granularity. */
|
|
49
|
+
min?: string;
|
|
50
|
+
max?: string;
|
|
51
|
+
/** Default: the local date, read from the clock once. */
|
|
52
|
+
today?: string;
|
|
53
|
+
/** The lowest view, and the form of the value. Default `day`. */
|
|
54
|
+
granularity?: Granularity;
|
|
55
|
+
/** The first column, 0 = Sunday. Default 1 (Monday). */
|
|
56
|
+
weekStart?: number;
|
|
57
|
+
/**
|
|
58
|
+
* Pages of the lowest view side by side, paging together: 2 shows two months in a day calendar,
|
|
59
|
+
* two years in a month calendar. The higher views stay one page, as wide. Default 1.
|
|
60
|
+
*/
|
|
61
|
+
months?: 1 | 2;
|
|
62
|
+
/** Twelve names the month cells show, January first. Short forms fit ("jan.", "febr."). */
|
|
63
|
+
monthNames: readonly string[];
|
|
64
|
+
/** Seven column headers, Sunday first whatever the week start ("V", "H", "K", "Sze", …). */
|
|
65
|
+
weekdayNames: readonly string[];
|
|
66
|
+
/** The heading of a page: "2026. november", "2026", "2016–2027". */
|
|
67
|
+
heading(page: CalendarPage): string;
|
|
68
|
+
/** A day cell's full accessible name, which must contain the day number: "2026. november 9., hétfő". */
|
|
69
|
+
cellLabel(day: CalendarDay): string;
|
|
70
|
+
labels: CalendarLabels;
|
|
71
|
+
/** The host's live region (CE §7). Without one the calendar keeps its own, visually hidden. */
|
|
72
|
+
announcer?: HTMLElement;
|
|
73
|
+
}
|
|
74
|
+
export interface CalendarOptions extends CalendarBaseOptions {
|
|
75
|
+
/** One value (the default). */
|
|
76
|
+
mode?: 'single';
|
|
77
|
+
/** The picked day (`YYYY-MM-DD`) or month (`YYYY-MM`), or null. */
|
|
78
|
+
value?: string | null;
|
|
79
|
+
}
|
|
80
|
+
/** A range at the granularity. While the second pick is pending, `end` is null. */
|
|
81
|
+
export interface CalendarRange {
|
|
82
|
+
start: string | null;
|
|
83
|
+
end: string | null;
|
|
84
|
+
}
|
|
85
|
+
export interface RangeCalendarOptions extends CalendarBaseOptions {
|
|
86
|
+
/** A start and an end (T85): the first pick sets the start, the second the end. Fixed at creation. */
|
|
87
|
+
mode: 'range';
|
|
88
|
+
labels: CalendarRangeLabels;
|
|
89
|
+
/** The range, or null. Read leniently: ends in either order; a month as a day calendar's end is its last day. */
|
|
90
|
+
value?: CalendarRange | null;
|
|
91
|
+
}
|
|
92
|
+
export interface CalendarChangeDetail {
|
|
93
|
+
value: string;
|
|
94
|
+
}
|
|
95
|
+
/** A range calendar's `fs-change`: only when both ends are set, `start` ≤ `end`. */
|
|
96
|
+
export interface CalendarRangeChangeDetail {
|
|
97
|
+
start: string;
|
|
98
|
+
end: string;
|
|
99
|
+
}
|
|
100
|
+
export interface Calendar {
|
|
101
|
+
readonly value: string | null;
|
|
102
|
+
readonly view: CalendarView;
|
|
103
|
+
/** Sets the value and shows its page, without an `fs-change` event; null clears it. */
|
|
104
|
+
setValue(value: string | null): void;
|
|
105
|
+
/** Shows a view (not one below the granularity). */
|
|
106
|
+
setView(view: CalendarView): void;
|
|
107
|
+
/** Focuses the grid's one tab stop. */
|
|
108
|
+
focus(): void;
|
|
109
|
+
/** Takes new options; a `value` among them moves to its page as `setValue` does. */
|
|
110
|
+
update(options: Partial<CalendarOptions>): void;
|
|
111
|
+
/** Removes every listener and empties the root. */
|
|
112
|
+
destroy(): void;
|
|
113
|
+
}
|
|
114
|
+
export interface RangeCalendar extends Omit<Calendar, 'value' | 'setValue' | 'update'> {
|
|
115
|
+
/** The range shown, `end` null while the second pick is pending; null when there is none. */
|
|
116
|
+
readonly value: CalendarRange | null;
|
|
117
|
+
/** Sets the range (dropping a pending start) and shows its start's page, without an event. */
|
|
118
|
+
setValue(value: CalendarRange | null): void;
|
|
119
|
+
/** Takes new options; a `value` among them moves to its page as `setValue` does. */
|
|
120
|
+
update(options: Partial<Omit<RangeCalendarOptions, 'mode'>>): void;
|
|
121
|
+
}
|
|
122
|
+
/** `root` is an empty `.fs-calendar` element; the helper renders the header and the grid into it. */
|
|
123
|
+
export declare function createCalendar(root: HTMLElement, options: RangeCalendarOptions): RangeCalendar;
|
|
124
|
+
export declare function createCalendar(root: HTMLElement, options: CalendarOptions): Calendar;
|