@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/kit.css
CHANGED
|
@@ -1372,6 +1372,273 @@
|
|
|
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 @@
|
|
|
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 @@
|
|
|
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/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, type CalendarRange, type CalendarRangeChangeDetail, type CalendarRangeLabels } 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,42 @@ 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, CalendarRange, CalendarRangeChangeDetail, CalendarRangeLabels, CalendarView, } from '../dom/calendar.ts';
|
|
81
|
+
/** The props both calendars take: the options but the value, plus the host's announcer and autoFocus. */
|
|
82
|
+
type CalendarCommonProps = Pick<CalendarOptions, 'min' | 'max' | 'today' | 'granularity' | 'weekStart' | 'months' | 'monthNames' | 'weekdayNames' | 'heading' | 'cellLabel' | 'labels'> & {
|
|
83
|
+
/** The host's one live region (CE §7); without it the calendar keeps its own. */
|
|
84
|
+
announcer?: RefObject<HTMLElement | null>;
|
|
85
|
+
/**
|
|
86
|
+
* Focuses the grid's tab stop (the value, else today) when it mounts. A picker remounts the
|
|
87
|
+
* calendar on each open (a new `key`) to start there.
|
|
88
|
+
*/
|
|
89
|
+
autoFocus?: boolean;
|
|
90
|
+
};
|
|
91
|
+
export interface CalendarProps extends Omit<HTMLAttributes<HTMLDivElement>, 'onChange' | 'defaultValue' | 'children'>, CalendarCommonProps {
|
|
92
|
+
/** Controlled: the picked day (`YYYY-MM-DD`) or month (`YYYY-MM`), or null. */
|
|
93
|
+
value?: string | null;
|
|
94
|
+
/** Uncontrolled: the first value. */
|
|
95
|
+
defaultValue?: string | null;
|
|
96
|
+
/** A lowest-view cell was picked: on every pick, the current value too. */
|
|
97
|
+
onChange?: (value: string) => void;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* The calendar (D42): renders the empty `.fs-calendar` root and runs `createCalendar` on mount, which
|
|
101
|
+
* renders the header and the grid. On the server it is the empty root. Every name is a required prop.
|
|
102
|
+
*/
|
|
103
|
+
export declare const Calendar: import("react").ForwardRefExoticComponent<CalendarProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
104
|
+
export interface DateRangeCalendarProps extends Omit<HTMLAttributes<HTMLDivElement>, 'onChange' | 'defaultValue' | 'children'>, Omit<CalendarCommonProps, 'labels'> {
|
|
105
|
+
/** As `Calendar`'s, plus the words said after a range's first and last cell (required). */
|
|
106
|
+
labels: CalendarRangeLabels;
|
|
107
|
+
/** Controlled: the range (`YYYY-MM-DD` or `YYYY-MM` ends), or null. */
|
|
108
|
+
value?: CalendarRange | null;
|
|
109
|
+
/** Uncontrolled: the first range. */
|
|
110
|
+
defaultValue?: CalendarRange | null;
|
|
111
|
+
/** The second pick set the end: both ends, in order. The first pick (the start) reports nothing. */
|
|
112
|
+
onChange?: (range: CalendarRangeChangeDetail) => void;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* The range calendar (T85): `createCalendar` in `mode: 'range'` (D42: one helper), on the same empty
|
|
116
|
+
* root. A pending start lives in the helper: a parent re-rendering the same range keeps it.
|
|
117
|
+
*/
|
|
118
|
+
export declare const DateRangeCalendar: import("react").ForwardRefExoticComponent<DateRangeCalendarProps & import("react").RefAttributes<HTMLDivElement>>;
|
package/dist/react/inputs.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
// React wrappers for spec 02 B: inputs.
|
|
3
|
-
import { forwardRef, useId, } from 'react';
|
|
3
|
+
import { forwardRef, useId, useRef, } from 'react';
|
|
4
|
+
import { createCalendar, } from "../dom/calendar.js";
|
|
4
5
|
import { Icon } from "./icon.js";
|
|
5
|
-
import { cx } from "./util.js";
|
|
6
|
+
import { cx, useFsEvent, useIsoLayoutEffect, useLatest, useMergedRef } from "./util.js";
|
|
6
7
|
const MESSAGE_ICON = { warning: 'triangle-alert', danger: 'circle-alert' };
|
|
7
8
|
export const Field = forwardRef(function Field({ label, layout = 'stacked', full, wrap, required, invalid, message, messageTone = 'neutral', mark, count, className, children, ...rest }, ref) {
|
|
8
9
|
const id = useId();
|
|
@@ -66,3 +67,129 @@ export const ComputedValue = forwardRef(function ComputedValue({ className, ...r
|
|
|
66
67
|
export const ExplainableValue = forwardRef(function ExplainableValue({ className, type = 'button', ...rest }, ref) {
|
|
67
68
|
return _jsx("button", { ref: ref, type: type, className: cx('fs-value', 'fs-value--explainable', className), ...rest });
|
|
68
69
|
});
|
|
70
|
+
/**
|
|
71
|
+
* Runs `createCalendar` on mount (D42) and `destroy` on unmount; new bounds, names, granularity or
|
|
72
|
+
* months re-render in place, keeping the page and the focus. `heading` and `cellLabel` are called
|
|
73
|
+
* through the latest props, so inline functions cost one grid re-render, not a reset.
|
|
74
|
+
*/
|
|
75
|
+
function useCalendarHelper(own, { min, max, today, granularity, weekStart, months, monthNames, weekdayNames, heading, cellLabel, labels, announcer, autoFocus, }, create) {
|
|
76
|
+
const ctl = useRef(null);
|
|
77
|
+
const names = useLatest({ heading, cellLabel });
|
|
78
|
+
const set = (o) => Object.fromEntries(Object.entries(o).filter(([, v]) => v !== undefined));
|
|
79
|
+
const options = () => ({
|
|
80
|
+
// Undefined clears a bound or today; granularity, weekStart and months keep their defaults.
|
|
81
|
+
min,
|
|
82
|
+
max,
|
|
83
|
+
today,
|
|
84
|
+
...set({ granularity, weekStart, months }),
|
|
85
|
+
monthNames,
|
|
86
|
+
weekdayNames,
|
|
87
|
+
labels,
|
|
88
|
+
heading: (page) => names.current.heading(page),
|
|
89
|
+
cellLabel: (cell) => names.current.cellLabel(cell),
|
|
90
|
+
announcer: announcer?.current ?? undefined,
|
|
91
|
+
});
|
|
92
|
+
useIsoLayoutEffect(() => {
|
|
93
|
+
ctl.current = create(own.current, options());
|
|
94
|
+
if (autoFocus)
|
|
95
|
+
ctl.current.focus();
|
|
96
|
+
return () => {
|
|
97
|
+
ctl.current?.destroy();
|
|
98
|
+
ctl.current = null;
|
|
99
|
+
};
|
|
100
|
+
}, []);
|
|
101
|
+
useIsoLayoutEffect(() => {
|
|
102
|
+
// A range calendar's labels are the props' own, so they carry its start and end words.
|
|
103
|
+
ctl.current?.update(options());
|
|
104
|
+
}, [
|
|
105
|
+
min,
|
|
106
|
+
max,
|
|
107
|
+
today,
|
|
108
|
+
granularity,
|
|
109
|
+
weekStart,
|
|
110
|
+
months,
|
|
111
|
+
monthNames,
|
|
112
|
+
weekdayNames,
|
|
113
|
+
labels,
|
|
114
|
+
heading,
|
|
115
|
+
cellLabel,
|
|
116
|
+
announcer,
|
|
117
|
+
]);
|
|
118
|
+
return ctl;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* The calendar (D42): renders the empty `.fs-calendar` root and runs `createCalendar` on mount, which
|
|
122
|
+
* renders the header and the grid. On the server it is the empty root. Every name is a required prop.
|
|
123
|
+
*/
|
|
124
|
+
export const Calendar = forwardRef(function Calendar({ value, defaultValue, onChange, min, max, today, granularity, weekStart, months, monthNames, weekdayNames, heading, cellLabel, labels, announcer, autoFocus, className, ...rest }, ref) {
|
|
125
|
+
const own = useRef(null);
|
|
126
|
+
const latestValue = useLatest(value);
|
|
127
|
+
const common = {
|
|
128
|
+
min,
|
|
129
|
+
max,
|
|
130
|
+
today,
|
|
131
|
+
granularity,
|
|
132
|
+
weekStart,
|
|
133
|
+
months,
|
|
134
|
+
monthNames,
|
|
135
|
+
weekdayNames,
|
|
136
|
+
heading,
|
|
137
|
+
cellLabel,
|
|
138
|
+
labels,
|
|
139
|
+
};
|
|
140
|
+
const ctl = useCalendarHelper(own, { ...common, announcer, autoFocus }, (root, options) => createCalendar(root, { ...options, value: value === undefined ? defaultValue : value }));
|
|
141
|
+
useIsoLayoutEffect(() => {
|
|
142
|
+
if (value !== undefined && ctl.current && ctl.current.value !== value)
|
|
143
|
+
ctl.current.setValue(value);
|
|
144
|
+
}, [value]);
|
|
145
|
+
useFsEvent(own, 'fs-change', ({ value: picked }) => {
|
|
146
|
+
onChange?.(picked);
|
|
147
|
+
// A controlled value the parent didn't take is put back.
|
|
148
|
+
queueMicrotask(() => {
|
|
149
|
+
const held = latestValue.current;
|
|
150
|
+
if (held !== undefined && ctl.current && ctl.current.value !== held)
|
|
151
|
+
ctl.current.setValue(held);
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
return _jsx("div", { ref: useMergedRef(own, ref), className: cx('fs-calendar', className), ...rest });
|
|
155
|
+
});
|
|
156
|
+
const sameRange = (a, b) => (a?.start ?? null) === (b?.start ?? null) && (a?.end ?? null) === (b?.end ?? null);
|
|
157
|
+
/**
|
|
158
|
+
* The range calendar (T85): `createCalendar` in `mode: 'range'` (D42: one helper), on the same empty
|
|
159
|
+
* root. A pending start lives in the helper: a parent re-rendering the same range keeps it.
|
|
160
|
+
*/
|
|
161
|
+
export const DateRangeCalendar = forwardRef(function DateRangeCalendar({ value, defaultValue, onChange, min, max, today, granularity, weekStart, months, monthNames, weekdayNames, heading, cellLabel, labels, announcer, autoFocus, className, ...rest }, ref) {
|
|
162
|
+
const own = useRef(null);
|
|
163
|
+
const latestValue = useLatest(value);
|
|
164
|
+
const common = {
|
|
165
|
+
min,
|
|
166
|
+
max,
|
|
167
|
+
today,
|
|
168
|
+
granularity,
|
|
169
|
+
weekStart,
|
|
170
|
+
months,
|
|
171
|
+
monthNames,
|
|
172
|
+
weekdayNames,
|
|
173
|
+
heading,
|
|
174
|
+
cellLabel,
|
|
175
|
+
labels,
|
|
176
|
+
};
|
|
177
|
+
const ctl = useCalendarHelper(own, { ...common, announcer, autoFocus }, (root, options) => createCalendar(root, { ...options, labels, mode: 'range', value: value === undefined ? defaultValue : value }));
|
|
178
|
+
// Only a new range in the prop resets the helper: an equal one keeps a pending start.
|
|
179
|
+
const start = value === undefined ? undefined : (value?.start ?? null);
|
|
180
|
+
const end = value === undefined ? undefined : (value?.end ?? null);
|
|
181
|
+
useIsoLayoutEffect(() => {
|
|
182
|
+
if (value !== undefined && ctl.current && !sameRange(ctl.current.value, value))
|
|
183
|
+
ctl.current.setValue(value);
|
|
184
|
+
}, [start, end]);
|
|
185
|
+
useFsEvent(own, 'fs-change', (picked) => {
|
|
186
|
+
onChange?.({ start: picked.start, end: picked.end });
|
|
187
|
+
// A controlled range the parent didn't take is put back.
|
|
188
|
+
queueMicrotask(() => {
|
|
189
|
+
const held = latestValue.current;
|
|
190
|
+
if (held !== undefined && ctl.current && !sameRange(ctl.current.value, held))
|
|
191
|
+
ctl.current.setValue(held);
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
return _jsx("div", { ref: useMergedRef(own, ref), className: cx('fs-calendar', className), ...rest });
|
|
195
|
+
});
|
package/dist/react/overlays.d.ts
CHANGED
|
@@ -15,17 +15,17 @@ export declare function Heading({ level, ...rest }: HTMLAttributes<HTMLHeadingEl
|
|
|
15
15
|
autoCapitalize?: "off" | "none" | "on" | "sentences" | "words" | "characters" | undefined | (string & {});
|
|
16
16
|
autoFocus?: boolean | undefined;
|
|
17
17
|
className?: string | undefined;
|
|
18
|
-
contentEditable?: (boolean | "
|
|
18
|
+
contentEditable?: (boolean | "false" | "true") | "inherit" | "plaintext-only" | undefined;
|
|
19
19
|
contextMenu?: string | undefined;
|
|
20
20
|
dir?: string | undefined;
|
|
21
|
-
draggable?: (boolean | "
|
|
21
|
+
draggable?: (boolean | "false" | "true") | undefined;
|
|
22
22
|
enterKeyHint?: "enter" | "done" | "go" | "next" | "previous" | "search" | "send" | undefined;
|
|
23
23
|
hidden?: boolean | undefined;
|
|
24
24
|
id?: string | undefined;
|
|
25
25
|
lang?: string | undefined;
|
|
26
26
|
nonce?: string | undefined;
|
|
27
27
|
slot?: string | undefined;
|
|
28
|
-
spellCheck?: (boolean | "
|
|
28
|
+
spellCheck?: (boolean | "false" | "true") | undefined;
|
|
29
29
|
style?: import("react").CSSProperties | undefined;
|
|
30
30
|
tabIndex?: number | undefined;
|
|
31
31
|
title?: string | undefined;
|
|
@@ -63,11 +63,11 @@ export declare function Heading({ level, ...rest }: HTMLAttributes<HTMLHeadingEl
|
|
|
63
63
|
exportparts?: string | undefined;
|
|
64
64
|
part?: string | undefined;
|
|
65
65
|
"aria-activedescendant"?: string | undefined;
|
|
66
|
-
"aria-atomic"?: (boolean | "
|
|
66
|
+
"aria-atomic"?: (boolean | "false" | "true") | undefined;
|
|
67
67
|
"aria-autocomplete"?: "none" | "inline" | "list" | "both" | undefined;
|
|
68
68
|
"aria-braillelabel"?: string | undefined;
|
|
69
69
|
"aria-brailleroledescription"?: string | undefined;
|
|
70
|
-
"aria-busy"?: (boolean | "
|
|
70
|
+
"aria-busy"?: (boolean | "false" | "true") | undefined;
|
|
71
71
|
"aria-checked"?: boolean | "false" | "mixed" | "true" | undefined;
|
|
72
72
|
"aria-colcount"?: number | undefined;
|
|
73
73
|
"aria-colindex"?: number | undefined;
|
|
@@ -78,37 +78,37 @@ export declare function Heading({ level, ...rest }: HTMLAttributes<HTMLHeadingEl
|
|
|
78
78
|
"aria-describedby"?: string | undefined;
|
|
79
79
|
"aria-description"?: string | undefined;
|
|
80
80
|
"aria-details"?: string | undefined;
|
|
81
|
-
"aria-disabled"?: (boolean | "
|
|
81
|
+
"aria-disabled"?: (boolean | "false" | "true") | undefined;
|
|
82
82
|
"aria-dropeffect"?: "none" | "copy" | "execute" | "link" | "move" | "popup" | undefined;
|
|
83
83
|
"aria-errormessage"?: string | undefined;
|
|
84
|
-
"aria-expanded"?: (boolean | "
|
|
84
|
+
"aria-expanded"?: (boolean | "false" | "true") | undefined;
|
|
85
85
|
"aria-flowto"?: string | undefined;
|
|
86
|
-
"aria-grabbed"?: (boolean | "
|
|
86
|
+
"aria-grabbed"?: (boolean | "false" | "true") | undefined;
|
|
87
87
|
"aria-haspopup"?: boolean | "false" | "true" | "menu" | "listbox" | "tree" | "grid" | "dialog" | undefined;
|
|
88
|
-
"aria-hidden"?: (boolean | "
|
|
88
|
+
"aria-hidden"?: (boolean | "false" | "true") | undefined;
|
|
89
89
|
"aria-invalid"?: boolean | "false" | "true" | "grammar" | "spelling" | undefined;
|
|
90
90
|
"aria-keyshortcuts"?: string | undefined;
|
|
91
91
|
"aria-label"?: string | undefined;
|
|
92
92
|
"aria-labelledby"?: string | undefined;
|
|
93
93
|
"aria-level"?: number | undefined;
|
|
94
94
|
"aria-live"?: "off" | "assertive" | "polite" | undefined;
|
|
95
|
-
"aria-modal"?: (boolean | "
|
|
96
|
-
"aria-multiline"?: (boolean | "
|
|
97
|
-
"aria-multiselectable"?: (boolean | "
|
|
95
|
+
"aria-modal"?: (boolean | "false" | "true") | undefined;
|
|
96
|
+
"aria-multiline"?: (boolean | "false" | "true") | undefined;
|
|
97
|
+
"aria-multiselectable"?: (boolean | "false" | "true") | undefined;
|
|
98
98
|
"aria-orientation"?: "horizontal" | "vertical" | undefined;
|
|
99
99
|
"aria-owns"?: string | undefined;
|
|
100
100
|
"aria-placeholder"?: string | undefined;
|
|
101
101
|
"aria-posinset"?: number | undefined;
|
|
102
102
|
"aria-pressed"?: boolean | "false" | "mixed" | "true" | undefined;
|
|
103
|
-
"aria-readonly"?: (boolean | "
|
|
103
|
+
"aria-readonly"?: (boolean | "false" | "true") | undefined;
|
|
104
104
|
"aria-relevant"?: "additions" | "additions removals" | "additions text" | "all" | "removals" | "removals additions" | "removals text" | "text" | "text additions" | "text removals" | undefined;
|
|
105
|
-
"aria-required"?: (boolean | "
|
|
105
|
+
"aria-required"?: (boolean | "false" | "true") | undefined;
|
|
106
106
|
"aria-roledescription"?: string | undefined;
|
|
107
107
|
"aria-rowcount"?: number | undefined;
|
|
108
108
|
"aria-rowindex"?: number | undefined;
|
|
109
109
|
"aria-rowindextext"?: string | undefined;
|
|
110
110
|
"aria-rowspan"?: number | undefined;
|
|
111
|
-
"aria-selected"?: (boolean | "
|
|
111
|
+
"aria-selected"?: (boolean | "false" | "true") | undefined;
|
|
112
112
|
"aria-setsize"?: number | undefined;
|
|
113
113
|
"aria-sort"?: "none" | "ascending" | "descending" | "other" | undefined;
|
|
114
114
|
"aria-valuemax"?: number | undefined;
|
package/package.json
CHANGED