@usableapp/cardds 0.7.174 → 0.7.176

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.
@@ -37,9 +37,29 @@ export interface CalendarProps extends Omit<ComponentProps<'div'>, 'title' | 'on
37
37
  weekdays?: string[];
38
38
  /** replace the default prev/next icon buttons */
39
39
  nav?: ReactNode;
40
+ /** the year shown beside `title` ("2024", "2567"): the app gives the number, in its own calendar. Given, the head is two words, month and year */
41
+ year?: ReactNode;
42
+ /** the 12 month names in order. Given (with `onMonthChange`), a tap on `title` swaps the day grid for a panel of 12 chips; a tap on one returns to the days */
43
+ months?: ReactNode[];
44
+ /** the month shown, 0–11 (January = 0): which month chip is picked in the panel. The app owns it, as `title` */
45
+ month?: number;
46
+ /** a month chip was tapped: its index 0–11. The app turns the month (it owns `title`, `days`, `start`) */
47
+ onMonthChange?: (month: number) => void;
48
+ /** the years the panel lists, in order (the app says the range): `value` is what `onYearChange` hands back, `label` the words ("2567"). Given (with `onYearChange`), a tap on `year` swaps the day grid for a panel of chips that scrolls */
49
+ years?: {
50
+ value: number;
51
+ label: ReactNode;
52
+ }[];
53
+ /** the `value` of the year shown: which year chip is picked in the panel. The app owns it, as `year` */
54
+ yearValue?: number;
55
+ /** a year chip was tapped: its `value`. The app turns the year (it owns `year`, `title`, `days`, `start`) */
56
+ onYearChange?: (year: number) => void;
40
57
  }
41
58
  /** Calendar — a month grid of 44px round cells: one accent day, optional marks; prev/next in the head. It shows ONE month and knows no dates:
42
59
  * the app owns which month (`title`, `days`, `start` + `onPrev` / `onNext`) and which day (`selected` + `onSelect`, or `defaultSelected`).
43
60
  * A run of days instead of one (the asker says from when to when, Lh 2026-10-21): `span` + `onSpanChange`, or `defaultSpan` — a drag across
44
- * the days covers them, or a tap on the first day and a tap on the last; the whole run is one highlight, as a finger drags over words. On a sheet, never in a Card: the sheet is the paper the member fills in (Lh 2026-10-18). */
45
- export declare function Calendar({ title, days, start, selected, defaultSelected, onSelect, span, defaultSpan, onSpanChange, onPrev, onNext, prevLabel, nextLabel, marks, marks2, disabled, weekdays, nav, className, ...rest }: CalendarProps): import("react").JSX.Element;
61
+ * the days covers them, or a tap on the first day and a tap on the last; the whole run is one highlight, as a finger drags over words. On a sheet, never in a Card: the sheet is the paper the member fills in (Lh 2026-10-18).
62
+ * A far month or year (a birthday, Lh 2026-11-08): give `year` and `months` + `onMonthChange` and / or `years` + `onYearChange` — the head's month and year become
63
+ * two buttons; a tap on one swaps the day grid for a panel of chips (the 12 months, or the years in a list that scrolls), a tap on a chip returns to the days.
64
+ * While a panel is open the prev / next buttons are gone. The app still owns the month and year shown and any numbers (a Buddhist year is the app's label); with none of these props the head is as before. */
65
+ export declare function Calendar({ title, days, start, selected, defaultSelected, onSelect, span, defaultSpan, onSpanChange, onPrev, onNext, prevLabel, nextLabel, marks, marks2, disabled, weekdays, nav, year, months, month, onMonthChange, years, yearValue, onYearChange, className, ...rest }: CalendarProps): import("react").JSX.Element;
@@ -1,15 +1,31 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useLayoutEffect, useRef, useState } from 'react';
2
3
  import { useControlled } from '../state.js';
3
4
  import { cx } from '../cx.js';
4
5
  import { Btn } from '../actions/Btn.js';
6
+ import { Chip, ChipGrid } from '../actions/Chip.js';
5
7
  import { word } from '../words.js';
6
8
  import { calendarDay } from './calendarDay.js';
7
9
  import { useSpan } from './span.js';
8
10
  /** Calendar — a month grid of 44px round cells: one accent day, optional marks; prev/next in the head. It shows ONE month and knows no dates:
9
11
  * the app owns which month (`title`, `days`, `start` + `onPrev` / `onNext`) and which day (`selected` + `onSelect`, or `defaultSelected`).
10
12
  * A run of days instead of one (the asker says from when to when, Lh 2026-10-21): `span` + `onSpanChange`, or `defaultSpan` — a drag across
11
- * the days covers them, or a tap on the first day and a tap on the last; the whole run is one highlight, as a finger drags over words. On a sheet, never in a Card: the sheet is the paper the member fills in (Lh 2026-10-18). */
12
- export function Calendar({ title, days = 30, start = 1, selected, defaultSelected, onSelect, span, defaultSpan, onSpanChange, onPrev, onNext, prevLabel = word('previous'), nextLabel = word('next'), marks = [], marks2 = [], disabled = [], weekdays = ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'], nav, className, ...rest }) {
13
+ * the days covers them, or a tap on the first day and a tap on the last; the whole run is one highlight, as a finger drags over words. On a sheet, never in a Card: the sheet is the paper the member fills in (Lh 2026-10-18).
14
+ * A far month or year (a birthday, Lh 2026-11-08): give `year` and `months` + `onMonthChange` and / or `years` + `onYearChange` — the head's month and year become
15
+ * two buttons; a tap on one swaps the day grid for a panel of chips (the 12 months, or the years in a list that scrolls), a tap on a chip returns to the days.
16
+ * While a panel is open the prev / next buttons are gone. The app still owns the month and year shown and any numbers (a Buddhist year is the app's label); with none of these props the head is as before. */
17
+ export function Calendar({ title, days = 30, start = 1, selected, defaultSelected, onSelect, span, defaultSpan, onSpanChange, onPrev, onNext, prevLabel = word('previous'), nextLabel = word('next'), marks = [], marks2 = [], disabled = [], weekdays = ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'], nav, year, months, month, onMonthChange, years, yearValue, onYearChange, className, ...rest }) {
18
+ const [view, setView] = useState('days');
19
+ const panel = useRef(null);
20
+ const pickMonth = !!months && !!onMonthChange;
21
+ const pickYear = !!years && !!onYearChange;
22
+ const open = view === 'months' && pickMonth ? 'months' : view === 'years' && pickYear ? 'years' : 'days';
23
+ // a panel opens with the picked chip in the middle of its sight
24
+ useLayoutEffect(() => {
25
+ const box = panel.current, on = box?.querySelector('[aria-pressed="true"]');
26
+ if (box && on)
27
+ box.scrollTop = on.offsetTop - (box.clientHeight - on.offsetHeight) / 2;
28
+ }, [open]);
13
29
  const [day, pick] = useControlled(selected, defaultSelected, onSelect);
14
30
  const spanning = span !== undefined || defaultSpan !== undefined || onSpanChange !== undefined;
15
31
  // the hook counts cells from 0; the app counts days from 1
@@ -18,7 +34,13 @@ export function Calendar({ title, days = 30, start = 1, selected, defaultSelecte
18
34
  onSpanChange: onSpanChange && ((s) => onSpanChange([s[0] + 1, s[1] + 1])),
19
35
  blocked: (i) => i < 0 || i >= days || disabled.includes(i + 1),
20
36
  });
21
- return (_jsxs("div", { className: cx('calendar', spanning && 'calendar--span', className), ...rest, children: [_jsxs("div", { className: "calendar__head", children: [_jsx("span", { className: "t-title", children: title }), nav ?? (_jsxs("span", { className: "icon-row", children: [_jsx(Btn, { shape: "round", size: "sm", icon: "chevron-left", label: prevLabel, onClick: onPrev }), _jsx(Btn, { shape: "round", size: "sm", icon: "chevron-right", label: nextLabel, onClick: onNext })] }))] }), _jsxs("div", { className: "calendar__grid", ...(spanning ? run.box : {}), children: [weekdays.map((d) => _jsx("span", { className: "calendar__wd", children: d }, d)), Array.from({ length: days }, (_, i) => i + 1).map((d) => (calendarDay({
37
+ return (_jsxs("div", { className: cx('calendar', spanning && 'calendar--span', className), ...rest, children: [_jsxs("div", { className: "calendar__head", children: [pickMonth || pickYear || year != null ? (_jsxs("span", { className: "calendar__picks t-title", children: [pickMonth
38
+ ? _jsx("button", { type: "button", className: "calendar__pick", "aria-expanded": open === 'months', onClick: () => setView(open === 'months' ? 'days' : 'months'), children: title })
39
+ : _jsx("span", { children: title }), pickYear
40
+ ? _jsx("button", { type: "button", className: "calendar__pick", "aria-expanded": open === 'years', onClick: () => setView(open === 'years' ? 'days' : 'years'), children: year })
41
+ : year != null && _jsx("span", { children: year })] })) : _jsx("span", { className: "t-title", children: title }), open === 'days' && (nav ?? (_jsxs("span", { className: "icon-row", children: [_jsx(Btn, { shape: "round", size: "sm", icon: "chevron-left", label: prevLabel, onClick: onPrev }), _jsx(Btn, { shape: "round", size: "sm", icon: "chevron-right", label: nextLabel, onClick: onNext })] })))] }), open !== 'days' && (_jsx("div", { ref: panel, className: "calendar__panel", children: _jsx(ChipGrid, { children: open === 'months'
42
+ ? months.map((m, i) => (_jsx(Chip, { as: "button", on: i === month, "aria-pressed": i === month, onClick: () => { onMonthChange(i); setView('days'); }, children: m }, i)))
43
+ : years.map((y) => (_jsx(Chip, { as: "button", on: y.value === yearValue, "aria-pressed": y.value === yearValue, onClick: () => { onYearChange(y.value); setView('days'); }, children: y.label }, y.value))) }) })), open === 'days' && _jsxs("div", { className: "calendar__grid", ...(spanning ? run.box : {}), children: [weekdays.map((d) => _jsx("span", { className: "calendar__wd", children: d }, d)), Array.from({ length: days }, (_, i) => i + 1).map((d) => (calendarDay({
22
44
  key: d, num: d, mark: marks.includes(d), mark2: marks2.includes(d), selected: !spanning && d === day, disabled: disabled.includes(d),
23
45
  style: d === 1 ? { '--start': start } : undefined,
24
46
  onPick: () => (spanning ? run.tap(d - 1) : pick(d)),
package/docs/reference.md CHANGED
@@ -870,6 +870,19 @@ between at 40% down the screen (see *Anatomy*, "Where the centre is"):
870
870
  strings, so keys sort as their days do (ISO `2026-06-05`). Given `ranges`,
871
871
  `span` and `selected` are not read
872
872
  (gallery `CalendarWeeks/Ranges`).
873
+ - **Calendar picks a far month or year from its head** (a birthday, Lh 2026-11-08).
874
+ Give `year` (the app's number: a Buddhist year is its label, never the
875
+ component's maths) and `months` + `month` + `onMonthChange`, and / or
876
+ `years` + `yearValue` + `onYearChange`: the head's month and year become two
877
+ buttons. A tap on the month swaps the day grid for 12 chips; a tap on the
878
+ year swaps it for a list of year chips that scrolls (the app says the range;
879
+ the panel opens with the shown year in the middle). A tap on a chip hands
880
+ back its index or value and returns to the days; a second tap on the head's
881
+ word closes the panel unchanged. While a panel is open the prev / next
882
+ buttons are gone. The calendar still knows no dates: the app owns month,
883
+ year, `days` and `start` (a leap February is its `days`) and clears the day
884
+ when it turns month or year. Without these props the head and markup are
885
+ as before (gallery `Calendar/Birthday`).
873
886
  - **Two sheet systems, one material.** *Sheet single* (`.sheet`, `sheet.css`)
874
887
  is ONE sheet the member acts in, whatever it holds: a short entry in front
875
888
  of a step's card, a place on a map, a payment on a dim page — in a `.step`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usableapp/cardds",
3
- "version": "0.7.174",
3
+ "version": "0.7.176",
4
4
  "license": "UNLICENSED",
5
5
  "type": "module",
6
6
  "description": "card-first mobile design system, React-first: the components in src/ are thin wrappers over the CSS contract (css/*.css stays the only truth); gallery/ shows every story live (npm run dev).",