@finstack-com-public/design 0.8.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/kit.css CHANGED
@@ -1372,12 +1372,15 @@
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). */
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). */
1377
1378
  @layer fs.components {
1378
1379
  .fs-calendar {
1379
1380
  /* One cell's width: seven make the calendar, so it follows the density. */
1380
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);
1381
1384
  display: inline-flex;
1382
1385
  flex-direction: column;
1383
1386
  gap: var(--fs-space-1);
@@ -1390,12 +1393,39 @@
1390
1393
  }
1391
1394
 
1392
1395
  .fs-calendar__header {
1396
+ position: relative;
1393
1397
  display: flex;
1394
1398
  align-items: center;
1395
1399
  gap: var(--fs-space-1);
1396
1400
  height: var(--fs-control-h);
1397
1401
  }
1398
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
+
1399
1429
  /* Shows the page's heading; steps up a view. In the top view it is the heading alone. */
1400
1430
  .fs-calendar__view {
1401
1431
  display: inline-flex;
@@ -1475,6 +1505,9 @@
1475
1505
  .fs-calendar__cell[aria-selected='true']:not([aria-disabled='true']):hover {
1476
1506
  background-color: var(--fs-primary-bg-hover);
1477
1507
  }
1508
+ .fs-calendar__cell--range[aria-selected='true']:not([aria-disabled='true']):hover {
1509
+ background-color: var(--fs-bg-hover);
1510
+ }
1478
1511
  }
1479
1512
  .fs-calendar__view:not([aria-disabled='true']):active,
1480
1513
  .fs-calendar__cell:active {
@@ -1501,6 +1534,37 @@
1501
1534
  border-color: var(--fs-primary-ink);
1502
1535
  }
1503
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
+
1504
1568
  /* The ring recipe (D15). The header's own button rings outside; cells touch, so theirs is inside. */
1505
1569
  .fs-calendar__view:focus-visible {
1506
1570
  outline: var(--fs-ring-width) solid var(--fs-ring);
@@ -1526,22 +1590,52 @@
1526
1590
  cursor: not-allowed;
1527
1591
  }
1528
1592
 
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. */
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. */
1531
1598
  @media (forced-colors: active) {
1532
1599
  .fs-calendar__cell[aria-selected='true'] {
1533
- color: HighlightText;
1534
- background-color: Highlight;
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;
1535
1610
  }
1536
1611
  .fs-calendar__cell[aria-current='date']::after {
1537
1612
  border-color: CanvasText;
1538
1613
  }
1539
- .fs-calendar__cell[aria-selected='true'][aria-current='date']::after {
1540
- border-color: HighlightText;
1614
+ .fs-calendar__cell[aria-selected='true'][aria-current='date']:not(.fs-calendar__cell--range)::after {
1615
+ inset: 4px;
1616
+ border-color: CanvasText;
1541
1617
  }
1542
1618
  .fs-calendar__cell[aria-disabled='true'] {
1543
1619
  color: GrayText;
1544
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
+ }
1545
1639
  }
1546
1640
  }
1547
1641
 
@@ -1,5 +1,5 @@
1
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
+ import { type CalendarOptions, type CalendarRange, type CalendarRangeChangeDetail, type CalendarRangeLabels } from '../dom/calendar.ts';
3
3
  type Tone = 'neutral' | 'caution' | 'warning' | 'danger';
4
4
  /** What Field hands its control: spread it onto the input. */
5
5
  export interface FieldControlProps {
@@ -77,14 +77,9 @@ export declare const ReadonlyValue: import("react").ForwardRefExoticComponent<HT
77
77
  export declare const ComputedValue: import("react").ForwardRefExoticComponent<OutputHTMLAttributes<HTMLOutputElement> & import("react").RefAttributes<HTMLOutputElement>>;
78
78
  /** A figure that is a button: every explainable value is keyboard-reachable (GZ §6.3). */
79
79
  export declare const ExplainableValue: import("react").ForwardRefExoticComponent<ButtonHTMLAttributes<HTMLButtonElement> & import("react").RefAttributes<HTMLButtonElement>>;
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;
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'> & {
88
83
  /** The host's one live region (CE §7); without it the calendar keeps its own. */
89
84
  announcer?: RefObject<HTMLElement | null>;
90
85
  /**
@@ -92,9 +87,32 @@ export interface CalendarProps extends Omit<HTMLAttributes<HTMLDivElement>, 'onC
92
87
  * calendar on each open (a new `key`) to start there.
93
88
  */
94
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;
95
98
  }
96
99
  /**
97
100
  * The calendar (D42): renders the empty `.fs-calendar` root and runs `createCalendar` on mount, which
98
101
  * renders the header and the grid. On the server it is the empty root. Every name is a required prop.
99
102
  */
100
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>>;
@@ -68,22 +68,20 @@ export const ExplainableValue = forwardRef(function ExplainableValue({ className
68
68
  return _jsx("button", { ref: ref, type: type, className: cx('fs-value', 'fs-value--explainable', className), ...rest });
69
69
  });
70
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.
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.
73
74
  */
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);
75
+ function useCalendarHelper(own, { min, max, today, granularity, weekStart, months, monthNames, weekdayNames, heading, cellLabel, labels, announcer, autoFocus, }, create) {
76
76
  const ctl = useRef(null);
77
- // The helper calls these through the latest props, so new functions on each render cost nothing.
78
77
  const names = useLatest({ heading, cellLabel });
79
- const latestValue = useLatest(value);
80
78
  const set = (o) => Object.fromEntries(Object.entries(o).filter(([, v]) => v !== undefined));
81
79
  const options = () => ({
82
- // Undefined clears a bound or today; granularity and weekStart keep their defaults.
80
+ // Undefined clears a bound or today; granularity, weekStart and months keep their defaults.
83
81
  min,
84
82
  max,
85
83
  today,
86
- ...set({ granularity, weekStart }),
84
+ ...set({ granularity, weekStart, months }),
87
85
  monthNames,
88
86
  weekdayNames,
89
87
  labels,
@@ -92,7 +90,7 @@ export const Calendar = forwardRef(function Calendar({ value, defaultValue, onCh
92
90
  announcer: announcer?.current ?? undefined,
93
91
  });
94
92
  useIsoLayoutEffect(() => {
95
- ctl.current = createCalendar(own.current, { ...options(), value: value === undefined ? defaultValue : value });
93
+ ctl.current = create(own.current, options());
96
94
  if (autoFocus)
97
95
  ctl.current.focus();
98
96
  return () => {
@@ -100,10 +98,46 @@ export const Calendar = forwardRef(function Calendar({ value, defaultValue, onCh
100
98
  ctl.current = null;
101
99
  };
102
100
  }, []);
103
- // New bounds, names or granularity: re-render in place, keeping the page and the focus.
104
101
  useIsoLayoutEffect(() => {
102
+ // A range calendar's labels are the props' own, so they carry its start and end words.
105
103
  ctl.current?.update(options());
106
- }, [min, max, today, granularity, weekStart, monthNames, weekdayNames, labels, heading, cellLabel, announcer]);
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 }));
107
141
  useIsoLayoutEffect(() => {
108
142
  if (value !== undefined && ctl.current && ctl.current.value !== value)
109
143
  ctl.current.setValue(value);
@@ -119,3 +153,43 @@ export const Calendar = forwardRef(function Calendar({ value, defaultValue, onCh
119
153
  });
120
154
  return _jsx("div", { ref: useMergedRef(own, ref), className: cx('fs-calendar', className), ...rest });
121
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@finstack-com-public/design",
3
- "version": "0.8.0",
3
+ "version": "0.9.1",
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",