@usableapp/cardds 0.7.158 → 0.7.159

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.
@@ -33,6 +33,18 @@ export interface FieldProps extends Omit<ComponentProps<'input'>, 'className' |
33
33
  className?: string;
34
34
  /** inline style for the label wrapper, not the input */
35
35
  style?: React.CSSProperties;
36
+ /** FOLDED into a button (Lh 2026-10-28): the words of the button the field stands as until it is wanted — its `icon` leads them
37
+ * (`<Field fold="ค้นหาสถานที่" icon="search" action={…} />`). A tap on the button OPENS the field out of it, the cursor in it, the
38
+ * keyboard up; Escape, or leaving it EMPTY, asks to fold it back. In a `CtaPack` the button stands at the line's end and the open
39
+ * field takes the whole line over what stands beside it. Rows of offers under it (`Rows`) are the app's, as with any field. One line
40
+ * only: with `rows` it is ignored */
41
+ fold?: ReactNode;
42
+ /** with `fold`: the field is out (true) or folded into its button (false). Pair of `onOpenChange` */
43
+ open?: boolean;
44
+ /** with `fold`, UNCONTROLLED: out at first; the field then keeps its own */
45
+ defaultOpen?: boolean;
46
+ /** with `fold`: asks the app — true on the button's tap, false on Escape or on leaving the field empty */
47
+ onOpenChange?: (open: boolean) => void;
36
48
  }
37
49
  /** the digits of `v`, written into `mask`; a mark is written only when a digit comes after it */
38
50
  export declare function applyMask(v: string, mask: string): string;
@@ -45,4 +57,4 @@ export declare function applyMask(v: string, mask: string): string;
45
57
  * sheet: `<Field rows={4} />` over `<Field rows={2} />`). A frame says "tap me", so a framed write-in is a Field, never a Composer:
46
58
  * the Composer is the one big write-in on the paper, bare (Lh 2026-10-19, timebank's ask sheet).
47
59
  */
48
- export declare function Field({ icon, action, label, error, format: formatProp, digits: digitsProp, formatError, mask: maskProp, rows, className, style, onBlur, onInput, onChange, ...input }: FieldProps): import("react").JSX.Element;
60
+ export declare function Field({ icon, action, label, error, format: formatProp, digits: digitsProp, formatError, mask: maskProp, rows, fold: foldProp, open, defaultOpen, onOpenChange, className, style, onBlur, onInput, onChange, onKeyDown, ...input }: FieldProps): import("react").JSX.Element;
@@ -1,6 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useEffect, useLayoutEffect, useRef, useState } from 'react';
3
- import { warnOnce, watchSize } from '../state.js';
3
+ import { flushSync } from 'react-dom';
4
+ import { useControlled, warnOnce, watchSize } from '../state.js';
4
5
  import { formatOk, useCheck } from './check.js';
5
6
  import { cx } from '../cx.js';
6
7
  import { Icon } from '../type/Icon.js';
@@ -28,8 +29,16 @@ export function applyMask(v, mask) {
28
29
  * sheet: `<Field rows={4} />` over `<Field rows={2} />`). A frame says "tap me", so a framed write-in is a Field, never a Composer:
29
30
  * the Composer is the one big write-in on the paper, bare (Lh 2026-10-19, timebank's ask sheet).
30
31
  */
31
- export function Field({ icon, action, label, error, format: formatProp, digits: digitsProp, formatError, mask: maskProp, rows, className, style, onBlur, onInput, onChange, ...input }) {
32
+ export function Field({ icon, action, label, error, format: formatProp, digits: digitsProp, formatError, mask: maskProp, rows, fold: foldProp, open, defaultOpen = false, onOpenChange, className, style, onBlur, onInput, onChange, onKeyDown, ...input }) {
32
33
  const lines = rows != null;
34
+ if (lines && foldProp != null)
35
+ warnOnce('field-rows-fold', 'cardds Field: `fold` is for one line — with `rows` it is ignored');
36
+ const fold = lines ? undefined : foldProp;
37
+ const [out, ask] = useControlled(open, defaultOpen, onOpenChange);
38
+ const box = useRef(null);
39
+ const btn = useRef(null);
40
+ const wide = useRef(0); // the button's width with its words, read while they show
41
+ const [tight, setTight] = useState(false); // no room for the words beside the line's other controls: the icon alone
33
42
  if (lines && (formatProp != null || digitsProp != null || maskProp != null))
34
43
  warnOnce('field-rows-one-line', 'cardds Field: `mask`, `format` and `digits` are for one line — with `rows` they are ignored');
35
44
  const [format, digits, mask] = lines ? [undefined, undefined, undefined] : [formatProp, digitsProp, maskProp];
@@ -74,6 +83,28 @@ export function Field({ icon, action, label, error, format: formatProp, digits:
74
83
  document.fonts?.ready.then(fit);
75
84
  return watchSize([el], fit);
76
85
  }, [input.placeholder, lines]);
86
+ /* folded: the open field grows out of the button's own box — its width (`--_fold-w`) and, in a CtaPack, the line it stands on (`--_fold-y`) */
87
+ useLayoutEffect(() => {
88
+ const el = box.current, b = btn.current;
89
+ if (!el || !b)
90
+ return;
91
+ const fit = () => {
92
+ if (!el.classList.contains('field-fold--tight'))
93
+ wide.current = b.offsetWidth;
94
+ setTight(el.clientWidth < wide.current);
95
+ el.style.setProperty('--_fold-w', `${b.offsetWidth}px`);
96
+ el.style.setProperty('--_fold-y', `${el.offsetTop}px`);
97
+ el.style.setProperty('--_fold-h', `${el.offsetHeight}px`);
98
+ };
99
+ fit();
100
+ return watchSize([b, el], fit);
101
+ }, [fold != null, tight]);
102
+ /* the tap opens it INSIDE the finger's own event (flushSync), so the cursor goes in while the phone still lets a keyboard come up */
103
+ const unfold = () => {
104
+ flushSync(() => ask(true));
105
+ ref.current?.focus();
106
+ };
107
+ const refold = () => { ask(false); btn.current?.focus(); };
77
108
  useEffect(() => {
78
109
  if (wrong) {
79
110
  ref.current?.focus();
@@ -81,8 +112,16 @@ export function Field({ icon, action, label, error, format: formatProp, digits:
81
112
  }
82
113
  // eslint-disable-next-line react-hooks/exhaustive-deps -- when the app's error comes or changes
83
114
  }, [error]);
84
- const onBlurField = (e) => { onBlur?.(e); if (!checked)
85
- return; const w = verdict(false); setBad(w != null); say(w); };
115
+ const onBlurField = (e) => {
116
+ onBlur?.(e);
117
+ if (fold != null && out && !e.currentTarget.value && !box.current?.contains(e.relatedTarget))
118
+ ask(false); // left empty: back into its button
119
+ if (!checked)
120
+ return;
121
+ const w = verdict(false);
122
+ setBad(w != null);
123
+ say(w);
124
+ };
86
125
  const onInputField = (e) => { onInput?.(e); if (bad && verdict(false) == null) {
87
126
  setBad(false);
88
127
  say(null);
@@ -102,6 +141,16 @@ export function Field({ icon, action, label, error, format: formatProp, digits:
102
141
  }
103
142
  onChange?.(e);
104
143
  };
105
- const shared = { ref, 'aria-label': label, 'aria-invalid': wrong || undefined, ...input, ...cursor, onBlur: onBlurField, onInput: onInputField, onChange: onChangeField };
106
- return (_jsxs("label", { className: cx('field', lines && 'field--rows', action != null && 'field--action', wrong && 'field--error', className), style: style, children: [icon && _jsx(Icon, { name: icon, size: "sm" }), lines ? _jsx("textarea", { rows: rows, ...shared }) : _jsx("input", { ...shared }), action] }));
144
+ const onKeyDownField = (e) => {
145
+ onKeyDown?.(e);
146
+ if (fold != null && e.key === 'Escape' && !e.defaultPrevented) {
147
+ e.preventDefault();
148
+ refold();
149
+ }
150
+ };
151
+ const shared = { ref, 'aria-label': label, 'aria-invalid': wrong || undefined, ...input, ...cursor, onBlur: onBlurField, onInput: onInputField, onChange: onChangeField, onKeyDown: onKeyDownField };
152
+ const field = (_jsxs("label", { className: cx('field', lines && 'field--rows', action != null && 'field--action', wrong && 'field--error', fold == null && className), style: fold == null ? style : undefined, inert: fold != null && !out ? true : undefined, children: [icon && _jsx(Icon, { name: icon, size: "sm" }), lines ? _jsx("textarea", { rows: rows, ...shared }) : _jsx("input", { ...shared }), action] }));
153
+ if (fold == null)
154
+ return field;
155
+ return (_jsxs("div", { ref: box, className: cx('field-fold', out && 'field-fold--open', tight && 'field-fold--tight', className), style: style, children: [_jsxs("button", { ref: btn, type: "button", className: "btn field-fold__btn", "aria-expanded": out, inert: out || undefined, onClick: unfold, children: [icon && _jsx(Icon, { name: icon, size: "xs" }), _jsx("span", { className: "field-fold__words", children: fold })] }), field] }));
107
156
  }
@@ -12,5 +12,7 @@ export interface PageProps extends ComponentProps<'section'> {
12
12
  export declare function Page({ bleed, className, ...rest }: PageProps): import("react").JSX.Element;
13
13
  export interface CtaPackProps extends ComponentProps<'div'> {
14
14
  }
15
- /** CtaPack — the buttons under a Page's words, wrapping on one line. In a Step it holds ways in (each opens a sheet — the app wires that); the Step's own move is never here. */
15
+ /** CtaPack — controls on ONE line, each as wide as its words, wrapping when they do not fit: the buttons under a Page's words (in a Step,
16
+ * ways in — each opens a sheet, the app wires that; the Step's own move is never here), or in a `SheetStep` a pick and a tool side by
17
+ * side (`<BtnGroup look="choice" form>` and a `<Field fold>`, which stands at the line's end and opens over the whole line — Lh 2026-10-28). */
16
18
  export declare function CtaPack({ className, ...rest }: CtaPackProps): import("react").JSX.Element;
@@ -9,7 +9,9 @@ import { cx } from '../cx.js';
9
9
  export function Page({ bleed, className, ...rest }) {
10
10
  return _jsx("section", { className: cx('page', bleed && 'page--bleed', className), ...rest });
11
11
  }
12
- /** CtaPack — the buttons under a Page's words, wrapping on one line. In a Step it holds ways in (each opens a sheet — the app wires that); the Step's own move is never here. */
12
+ /** CtaPack — controls on ONE line, each as wide as its words, wrapping when they do not fit: the buttons under a Page's words (in a Step,
13
+ * ways in — each opens a sheet, the app wires that; the Step's own move is never here), or in a `SheetStep` a pick and a tool side by
14
+ * side (`<BtnGroup look="choice" form>` and a `<Field fold>`, which stands at the line's end and opens over the whole line — Lh 2026-10-28). */
13
15
  export function CtaPack({ className, ...rest }) {
14
16
  return _jsx("div", { className: cx('cta-pack', className), ...rest });
15
17
  }
@@ -198,9 +198,9 @@ export function SheetStep({ title, summary, skippable, skipLabel = word('skip'),
198
198
  /* Enter on the keyboard in a field of the step = a press on the step's button (the phone's "go"/"next" key, a desktop's Enter);
199
199
  the press goes through the step's checks like a tap (Lh 2026-09-25) */
200
200
  const enter = (e) => {
201
- if (e.key !== 'Enter' || e.nativeEvent.isComposing || !(e.target instanceof HTMLInputElement))
202
- return;
203
- const btn = e.currentTarget.querySelector('button.btn:not(:disabled)');
201
+ if (e.key !== 'Enter' || e.defaultPrevented || e.nativeEvent.isComposing || !(e.target instanceof HTMLInputElement))
202
+ return; // a field that answers its own Enter (a search) keeps it
203
+ const btn = e.currentTarget.querySelector('button.btn:not(:disabled):not([aria-expanded])'); // a button that opens something (a folded Field) is not the step's move
204
204
  if (btn) {
205
205
  e.preventDefault();
206
206
  btn.click();
@@ -33,7 +33,8 @@ export interface StampProps extends Omit<ComponentProps<'span'>, 'onClick'> {
33
33
  * Every stamp is ONE size wherever it stands (`--stamp-size`, two taps wide: 96 × 120) — what holds it only places it; a holder narrower than that shows it whole, smaller.
34
34
  * The one small stamp is a stamp stuck on something (`StampOn`); `xs` is the inline one, beside a status line's words. Every inner length follows the stamp's width.
35
35
  * The outer box holds the size and the shadow; the paper inside is the one whose edge is punched (a mask would cut the shadow too).
36
- * Every stamp, at every size and wherever it stands, has a thin contact shadow (`--stamp-shadow`): its edge shows on any ground, a white one too.
36
+ * Every stamp, at every size and wherever it stands, has a thin contact shadow: its edge shows on any ground, a white one too. A framed stamp's is black (`--stamp-shadow`);
37
+ * a `frame={false}` stamp's is its own tone made dusky, a grey laid over the tone (`--stamp-tone-shadow-bg`).
37
38
  * With `arrive` the stamp that stands in its place (the head of a card, `end={<Stamp arrive …/>}`) is struck onto it when the member sends, and `onArrived` tells
38
39
  * the app it has landed, so it sends. The strike scales it down from twice its size, so it never moves the layout (it may cover its neighbours for a moment);
39
40
  * a `tilt` is kept, the stamp ends at its turn. Afterwards the same stamp stands in the same place with no strike: drop `arrive` or keep it, nothing is struck twice.
@@ -7,7 +7,8 @@ import { useStrike } from './useStrike.js';
7
7
  * Every stamp is ONE size wherever it stands (`--stamp-size`, two taps wide: 96 × 120) — what holds it only places it; a holder narrower than that shows it whole, smaller.
8
8
  * The one small stamp is a stamp stuck on something (`StampOn`); `xs` is the inline one, beside a status line's words. Every inner length follows the stamp's width.
9
9
  * The outer box holds the size and the shadow; the paper inside is the one whose edge is punched (a mask would cut the shadow too).
10
- * Every stamp, at every size and wherever it stands, has a thin contact shadow (`--stamp-shadow`): its edge shows on any ground, a white one too.
10
+ * Every stamp, at every size and wherever it stands, has a thin contact shadow: its edge shows on any ground, a white one too. A framed stamp's is black (`--stamp-shadow`);
11
+ * a `frame={false}` stamp's is its own tone made dusky, a grey laid over the tone (`--stamp-tone-shadow-bg`).
11
12
  * With `arrive` the stamp that stands in its place (the head of a card, `end={<Stamp arrive …/>}`) is struck onto it when the member sends, and `onArrived` tells
12
13
  * the app it has landed, so it sends. The strike scales it down from twice its size, so it never moves the layout (it may cover its neighbours for a moment);
13
14
  * a `tilt` is kept, the stamp ends at its turn. Afterwards the same stamp stands in the same place with no strike: drop `arrive` or keep it, nothing is struck twice.
@@ -16,7 +17,7 @@ export function Stamp({ pictures, tone = 'custard', name, words, bare, xs, frame
16
17
  const shown = pictures.slice(0, 4);
17
18
  const { struck } = useStrike(arrive, onArrived, onAnimationEnd);
18
19
  const { tap, Box, boxProps } = pressable(onClick, 'span', rest);
19
- return (_jsx(Box, { className: cx('stamp', `stamp--${shown.length}`, bare && 'stamp--bare', xs && 'stamp--xs', !frame && 'stamp--frameless', held && 'stamp--held', under && 'stamp--under', tilt && `stamp--tilt-${tilt}`, tap && 'stamp--tap', arrive && 'stamp--arrive', className), onAnimationEnd: struck, "aria-hidden": held || undefined, ...boxProps, children: _jsx("span", { className: cx('stamp__paper', !frame && `sticky--${tone}`), children: _jsxs("span", { className: cx('stamp__pic', `sticky--${tone}`), children: [shown.map((picture, i) => _jsx("span", { className: "stamp__art", "aria-hidden": "true", children: picture }, i)), (name != null || words != null) && (_jsxs("span", { className: "stamp__cap", children: [words != null && _jsx("span", { className: "stamp__words", children: words }), name != null && _jsx("span", { className: "stamp__name", children: name })] }))] }) }) }));
20
+ return (_jsxs(Box, { className: cx('stamp', `stamp--${shown.length}`, bare && 'stamp--bare', xs && 'stamp--xs', !frame && 'stamp--frameless', held && 'stamp--held', under && 'stamp--under', tilt && `stamp--tilt-${tilt}`, tap && 'stamp--tap', arrive && 'stamp--arrive', className), onAnimationEnd: struck, "aria-hidden": held || undefined, ...boxProps, children: [!frame && _jsx("span", { className: "stamp__shade", "aria-hidden": "true", children: _jsx("span", { className: cx('stamp__paper', `sticky--${tone}`) }) }), _jsx("span", { className: cx('stamp__paper', !frame && `sticky--${tone}`), children: _jsxs("span", { className: cx('stamp__pic', `sticky--${tone}`), children: [shown.map((picture, i) => _jsx("span", { className: "stamp__art", "aria-hidden": "true", children: picture }, i)), (name != null || words != null) && (_jsxs("span", { className: "stamp__cap", children: [words != null && _jsx("span", { className: "stamp__words", children: words }), name != null && _jsx("span", { className: "stamp__name", children: name })] }))] }) })] }));
20
21
  }
21
22
  /**
22
23
  * StampPlace — an empty place for a stamp: a 4:5 frame of round dots the size a Stamp is (`--stamp-size`), a word or an Icon inside.
package/docs/reference.md CHANGED
@@ -926,7 +926,7 @@ ground of my own stamp.
926
926
  A stamp is a small paper picture a member keeps and sticks on a note or a postcard for a neighbour. Sending never uses
927
927
  it up. cardds draws the paper; the pictures, their words and which stamp a member owns are the app's.
928
928
 
929
- - **`Stamp`** — a perforated 4:5 stamp, always with teeth; `frame={false}` drops the white paper frame round the picture, so the tone runs out to the teeth (the same size, shadow and words), wherever a stamp goes (`xs`, `tilt`, `arrive`, `onClick`, a `StampOn`, a `StampBook`, an `AvatarStack`). `pictures` is one to four nodes, the app's own art (an svg, an img), in placement
929
+ - **`Stamp`** — a perforated 4:5 stamp, always with teeth; `frame={false}` drops the white paper frame round the picture, so the tone runs out to the teeth (the same size and words), no rim round the teeth (Lh 2026-10-28: a paper-coloured rim read as a white edge), and its contact shadow its own tone made dusky rather than black (Lh 2026-10-28: a grey laid over the tone, knob `--stamp-tone-shadow-bg`), wherever a stamp goes (`xs`, `tilt`, `arrive`, `onClick`, a `StampOn`, a `StampBook`, an `AvatarStack`). `pictures` is one to four nodes, the app's own art (an svg, an img), in placement
930
930
  order: the stamp places, sizes and turns them by how many there are. `tone` is the ground, one of `STICKY_TONES` (the
931
931
  same list and the same `--sticky-<tone>-bg` knobs as a note's paper). `name` is the big line on the picture's foot,
932
932
  `words` the small line above it. `tilt` turns it, `onClick` makes the whole stamp a button. Every inner length follows
@@ -946,8 +946,8 @@ it up. cardds draws the paper; the pictures, their words and which stamp a membe
946
946
  a `PostDesk`'s tray are the standard size. One exception, by the owner's decision: the stamp at a postcard's corner is
947
947
  the postcard's own size, 72 × 90 (`--post-corner-stamp-w`), in neither. `words` is not drawn on a stamp 96 wide or
948
948
  narrower, so at the standard size only `name` shows, and it is larger.
949
- - **Every stamp has a thin contact shadow** (2026-10-26): at every size, `xs` and a `StampOn` too, on a card or off it — paper a hair off
950
- its ground, so its edge shows on any ground, a white one included (knob `--stamp-shadow`, a hair lighter than `--shadow-contact`). By default it is
949
+ - **Every stamp has a thin contact shadow** (2026-10-26; darker and sharper, Lh 2026-10-28): at every size, `xs` and a `StampOn` too, on a card or off it — paper a hair off
950
+ its ground, so its edge shows on any ground, a white one included (knob `--stamp-shadow`; sharper and darker than `--shadow-contact`). A framed stamp's is black; a `frame={false}` stamp's is its own tone under a grey (`--stamp-tone-shadow-bg`), and black only if a theme sets `--stamp-shadow`. By default it is
951
951
  the only shadow a stamp has (Lh 2026-10-26: contact only); `--stamp-drop` adds a lift off a card, none by default. What follows is where a stamp gets more.
952
952
  - **A stamp on a card lies flat** (Lh 2026-10-24): no lift, only the contact shadow, at every size — a `FeedCard`'s lead, a
953
953
  `Foot` row's, `xs`. A stamp in a card's head is glued down (Lh 2026-10-25): plain, `under` or `sm`, a hair of shadow
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usableapp/cardds",
3
- "version": "0.7.158",
3
+ "version": "0.7.159",
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).",