@finstack-com-public/design 0.7.1 → 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/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
- .fs-input:read-only,
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);
@@ -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>>;
@@ -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,55 @@ 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
+ * The calendar (D42): renders the empty `.fs-calendar` root and runs `createCalendar` on mount, which
72
+ * renders the header and the grid. On the server it is the empty root. Every name is a required prop.
73
+ */
74
+ export const Calendar = forwardRef(function Calendar({ value, defaultValue, onChange, min, max, today, granularity, weekStart, monthNames, weekdayNames, heading, cellLabel, labels, announcer, autoFocus, className, ...rest }, ref) {
75
+ const own = useRef(null);
76
+ const ctl = useRef(null);
77
+ // The helper calls these through the latest props, so new functions on each render cost nothing.
78
+ const names = useLatest({ heading, cellLabel });
79
+ const latestValue = useLatest(value);
80
+ const set = (o) => Object.fromEntries(Object.entries(o).filter(([, v]) => v !== undefined));
81
+ const options = () => ({
82
+ // Undefined clears a bound or today; granularity and weekStart keep their defaults.
83
+ min,
84
+ max,
85
+ today,
86
+ ...set({ granularity, weekStart }),
87
+ monthNames,
88
+ weekdayNames,
89
+ labels,
90
+ heading: (page) => names.current.heading(page),
91
+ cellLabel: (cell) => names.current.cellLabel(cell),
92
+ announcer: announcer?.current ?? undefined,
93
+ });
94
+ useIsoLayoutEffect(() => {
95
+ ctl.current = createCalendar(own.current, { ...options(), value: value === undefined ? defaultValue : value });
96
+ if (autoFocus)
97
+ ctl.current.focus();
98
+ return () => {
99
+ ctl.current?.destroy();
100
+ ctl.current = null;
101
+ };
102
+ }, []);
103
+ // New bounds, names or granularity: re-render in place, keeping the page and the focus.
104
+ useIsoLayoutEffect(() => {
105
+ ctl.current?.update(options());
106
+ }, [min, max, today, granularity, weekStart, monthNames, weekdayNames, labels, heading, cellLabel, announcer]);
107
+ useIsoLayoutEffect(() => {
108
+ if (value !== undefined && ctl.current && ctl.current.value !== value)
109
+ ctl.current.setValue(value);
110
+ }, [value]);
111
+ useFsEvent(own, 'fs-change', ({ value: picked }) => {
112
+ onChange?.(picked);
113
+ // A controlled value the parent didn't take is put back.
114
+ queueMicrotask(() => {
115
+ const held = latestValue.current;
116
+ if (held !== undefined && ctl.current && ctl.current.value !== held)
117
+ ctl.current.setValue(held);
118
+ });
119
+ });
120
+ return _jsx("div", { ref: useMergedRef(own, ref), className: cx('fs-calendar', className), ...rest });
121
+ });
@@ -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 | "true" | "false") | "inherit" | "plaintext-only" | undefined;
18
+ contentEditable?: (boolean | "false" | "true") | "inherit" | "plaintext-only" | undefined;
19
19
  contextMenu?: string | undefined;
20
20
  dir?: string | undefined;
21
- draggable?: (boolean | "true" | "false") | undefined;
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 | "true" | "false") | undefined;
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 | "true" | "false") | undefined;
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 | "true" | "false") | undefined;
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 | "true" | "false") | undefined;
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 | "true" | "false") | undefined;
84
+ "aria-expanded"?: (boolean | "false" | "true") | undefined;
85
85
  "aria-flowto"?: string | undefined;
86
- "aria-grabbed"?: (boolean | "true" | "false") | undefined;
86
+ "aria-grabbed"?: (boolean | "false" | "true") | undefined;
87
87
  "aria-haspopup"?: boolean | "false" | "true" | "menu" | "listbox" | "tree" | "grid" | "dialog" | undefined;
88
- "aria-hidden"?: (boolean | "true" | "false") | undefined;
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 | "true" | "false") | undefined;
96
- "aria-multiline"?: (boolean | "true" | "false") | undefined;
97
- "aria-multiselectable"?: (boolean | "true" | "false") | undefined;
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 | "true" | "false") | undefined;
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 | "true" | "false") | undefined;
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 | "true" | "false") | undefined;
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@finstack-com-public/design",
3
- "version": "0.7.1",
3
+ "version": "0.8.0",
4
4
  "description": "Design kit: tokens, icons, components and a chart theme, shared by Grizzbi, BI App and the calculation engine.",
5
5
  "license": "MIT",
6
6
  "author": "Finstack",