@usableapp/cardds 0.7.160 → 0.7.161
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 +11 -0
- package/css/actions.css +11 -0
- package/css/parts.css +39 -19
- package/dist/actions/LinkBlock.d.ts +3 -2
- package/dist/actions/LinkBlock.js +5 -3
- package/dist/cardds.css +50 -19
- package/dist/catalog.json +1 -1
- package/dist/lists/Row.js +5 -2
- package/dist/parts/Head.d.ts +1 -0
- package/dist/parts/Head.js +5 -1
- package/dist/parts/Words.d.ts +2 -1
- package/dist/parts/Words.js +8 -3
- package/dist/parts/endRoom.d.ts +9 -0
- package/dist/parts/endRoom.js +35 -0
- package/package.json +1 -1
package/dist/lists/Row.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { cloneElement, createElement, isValidElement, useId, useLayoutEffect, useRef } from 'react';
|
|
2
|
+
import { cloneElement, createElement, isValidElement, useContext, useId, useLayoutEffect, useRef } from 'react';
|
|
3
3
|
import { cx } from '../cx.js';
|
|
4
4
|
import { Icon } from '../type/Icon.js';
|
|
5
5
|
import { glide, reducedMotion, setRefs, stopMoves, useDisclosure } from '../state.js';
|
|
6
|
+
import { RowEndRoomCtx, withEndRoom } from '../parts/endRoom.js';
|
|
7
|
+
import { Words } from '../parts/Words.js';
|
|
6
8
|
/**
|
|
7
9
|
* Row — a frameless row inside a card: lead · words · end, its children in that order. 48px+ tall, a tap target.
|
|
8
10
|
* The lead is a `Lead` box, or a bare Avatar / AvatarStack; the words are a `Words`; the end is an `End` (a value and its caption)
|
|
@@ -14,8 +16,9 @@ import { glide, reducedMotion, setRefs, stopMoves, useDisclosure } from '../stat
|
|
|
14
16
|
*/
|
|
15
17
|
export function Row({ lg, done, as, href, more, open, defaultOpen, onOpenChange, className, children, ...rest }) {
|
|
16
18
|
const disclosure = useDisclosure(open, defaultOpen, onOpenChange);
|
|
19
|
+
const kids = (useContext(RowEndRoomCtx) && withEndRoom(children, Words)) || children; // in a LinkBlock: the title's later lines run under the ends
|
|
17
20
|
const el = more !== undefined ? 'summary' : as ?? (href ? 'a' : 'div');
|
|
18
|
-
const row = createElement(el, { href, className: cx('row', lg && 'row--lg', done && 'row--done', className), 'aria-disabled': done || undefined, ...(more === undefined ? rest : {}) },
|
|
21
|
+
const row = createElement(el, { href, className: cx('row', lg && 'row--lg', done && 'row--done', className), 'aria-disabled': done || undefined, ...(more === undefined ? rest : {}) }, kids, done && _jsx("span", { className: "row__done", children: _jsx(Icon, { name: "check", size: "sm" }) }));
|
|
19
22
|
if (more === undefined)
|
|
20
23
|
return row;
|
|
21
24
|
return (_jsxs("details", { className: "row-expand", ...rest, ...disclosure, children: [row, _jsx("div", { className: "row-expand__more", children: more })] }));
|
package/dist/parts/Head.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export interface HeadProps extends ComponentProps<'div'> {
|
|
|
11
11
|
* Head — the first row of a card, a sheet or a stack sheet: what this is, and the one thing beside it. Its children are, in order, an optional
|
|
12
12
|
* lead (a `Lead`, a `StackBack`, a `JourneyBadge`), the `Words` (the title takes the room, its meta under it), chips, and an end (an `IconBtn`, a `Chip`, an `End`).
|
|
13
13
|
* A `Lead`, an `Avatar` or an `AvatarStack` first, the `Words` next: the lead at the left, the title over its meta as one block beside it, the end at the right.
|
|
14
|
+
* With a meta, whatever follows the `Words` (an `End`, a `Btn sm`, `IconBtn`s, up to four) stands in the top-right corner and the title's later lines run under it.
|
|
14
15
|
* Never put buttons here that finish the card: they go in the foot. A `Card` finds its `Head` by type, so a consumer's own component that wraps a `Head` is not found.
|
|
15
16
|
*/
|
|
16
17
|
export declare function Head({ top, centre, long, className, children, ...rest }: HeadProps): import("react").JSX.Element;
|
package/dist/parts/Head.js
CHANGED
|
@@ -4,6 +4,8 @@ import { cx } from '../cx.js';
|
|
|
4
4
|
import { Text } from '../type/Text.js';
|
|
5
5
|
import { StackHeadCtx } from '../sheets/stackCard.js';
|
|
6
6
|
import { HeadCtx, onTitleKey } from './headCtx.js';
|
|
7
|
+
import { withEndRoom } from './endRoom.js';
|
|
8
|
+
import { Words } from './Words.js';
|
|
7
9
|
/** a title written by hand (a `Text` h1/h2/display, a bare h1-h3) is the stack's keyboard way in as a `Words` title is. The head renders the tab stop and, when
|
|
8
10
|
* the sheet measured it long, `.is-long`. Nothing sets either on the node afterwards */
|
|
9
11
|
function markTitle(node, tab, long) {
|
|
@@ -27,9 +29,11 @@ function markTitle(node, tab, long) {
|
|
|
27
29
|
* Head — the first row of a card, a sheet or a stack sheet: what this is, and the one thing beside it. Its children are, in order, an optional
|
|
28
30
|
* lead (a `Lead`, a `StackBack`, a `JourneyBadge`), the `Words` (the title takes the room, its meta under it), chips, and an end (an `IconBtn`, a `Chip`, an `End`).
|
|
29
31
|
* A `Lead`, an `Avatar` or an `AvatarStack` first, the `Words` next: the lead at the left, the title over its meta as one block beside it, the end at the right.
|
|
32
|
+
* With a meta, whatever follows the `Words` (an `End`, a `Btn sm`, `IconBtn`s, up to four) stands in the top-right corner and the title's later lines run under it.
|
|
30
33
|
* Never put buttons here that finish the card: they go in the foot. A `Card` finds its `Head` by type, so a consumer's own component that wraps a `Head` is not found.
|
|
31
34
|
*/
|
|
32
35
|
export function Head({ top, centre, long, className, children, ...rest }) {
|
|
33
36
|
const tab = useContext(StackHeadCtx);
|
|
34
|
-
|
|
37
|
+
const kids = withEndRoom(children, Words) ?? children;
|
|
38
|
+
return (_jsx("div", { className: cx('head', top && 'head--top', centre && 'head--centre', className), ...rest, children: _jsx(HeadCtx.Provider, { value: { tab, long: !!long }, children: tab == null && !long ? kids : Children.map(kids, (c) => markTitle(c, tab, !!long)) }) }));
|
|
35
39
|
}
|
package/dist/parts/Words.d.ts
CHANGED
|
@@ -12,5 +12,6 @@ export interface WordsProps extends Omit<ComponentProps<'span'>, 'title'> {
|
|
|
12
12
|
}
|
|
13
13
|
/** Words — the words of a line, filling the room between the lead and the end: a `title` over a `meta` caption, maybe under an `over` caption;
|
|
14
14
|
* its children come under them, or instead of them (a Wave for a voice note). In a `Head` there is no box round them: the title and the meta
|
|
15
|
-
* stand in the head, and a `className`, an `id` or any other attribute goes on the title.
|
|
15
|
+
* stand in the head, and a `className`, an `id` or any other attribute goes on the title. After a lead, with a meta, in a `Head` or a `LinkBlock`'s
|
|
16
|
+
* `Row`: the title's later lines run UNDER the ends at full width (the line hands it their room). */
|
|
16
17
|
export declare function Words({ title, meta, over, level, className, children, ...rest }: WordsProps): import("react").JSX.Element;
|
package/dist/parts/Words.js
CHANGED
|
@@ -2,20 +2,25 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
2
2
|
import { useContext } from 'react';
|
|
3
3
|
import { cx } from '../cx.js';
|
|
4
4
|
import { HeadCtx, onTitleKey } from './headCtx.js';
|
|
5
|
+
import { EndRoomCtx } from './endRoom.js';
|
|
5
6
|
/** Words — the words of a line, filling the room between the lead and the end: a `title` over a `meta` caption, maybe under an `over` caption;
|
|
6
7
|
* its children come under them, or instead of them (a Wave for a voice note). In a `Head` there is no box round them: the title and the meta
|
|
7
|
-
* stand in the head, and a `className`, an `id` or any other attribute goes on the title.
|
|
8
|
+
* stand in the head, and a `className`, an `id` or any other attribute goes on the title. After a lead, with a meta, in a `Head` or a `LinkBlock`'s
|
|
9
|
+
* `Row`: the title's later lines run UNDER the ends at full width (the line hands it their room). */
|
|
8
10
|
export function Words({ title, meta, over, level, className, children, ...rest }) {
|
|
9
11
|
const head = useContext(HeadCtx);
|
|
12
|
+
const ends = useContext(EndRoomCtx);
|
|
13
|
+
// the room the line's ends take at the title's first line: their unseen, inert copies (endRoom.ts), read by nobody
|
|
14
|
+
const room = ends != null && _jsx("span", { className: "words__room", "aria-hidden": true, inert: true, children: _jsx(EndRoomCtx.Provider, { value: null, children: ends }) });
|
|
10
15
|
if (head) {
|
|
11
16
|
const as = level ?? 'h2';
|
|
12
17
|
const Title = as === 'h1' ? 'h1' : 'h2';
|
|
13
18
|
const { onKeyDown, ...own } = rest;
|
|
14
19
|
const attrs = head.tab != null ? { tabIndex: head.tab, onKeyDown: (e) => { onKeyDown?.(e); if (!e.defaultPrevented)
|
|
15
20
|
onTitleKey(e); } } : { onKeyDown };
|
|
16
|
-
const titled = title != null &&
|
|
21
|
+
const titled = title != null && _jsxs(Title, { className: cx('words__title', `t-${as}`, head.long && 'is-long', className), ...own, ...attrs, children: [room, title] });
|
|
17
22
|
return (_jsxs(_Fragment, { children: [over != null ? _jsxs("div", { className: "words__over-title", children: [_jsx("span", { className: "words__over t-caption", children: over }), titled] }) : titled, meta != null && _jsx("span", { className: "words__meta t-caption t-muted", children: meta }), children] }));
|
|
18
23
|
}
|
|
19
24
|
const Title = level === 'h1' ? 'h1' : level ? 'h2' : 'span';
|
|
20
|
-
return (_jsxs("span", { className: cx('words', className), ...rest, children: [over != null && _jsx("span", { className: "words__over t-caption", children: over }), title != null &&
|
|
25
|
+
return (_jsxs("span", { className: cx('words', className), ...rest, children: [over != null && _jsx("span", { className: "words__over t-caption", children: over }), title != null && _jsxs(Title, { className: cx('words__title', level && `t-${level}`), children: [room, title] }), meta != null && _jsx("span", { className: "words__meta", children: meta }), children] }));
|
|
21
26
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type ElementType, type ReactNode } from 'react';
|
|
2
|
+
/** the ends a `Words` title keeps room for at its first line's end: unseen copies of them, which the title floats so its later lines run under
|
|
3
|
+
* the real ends at full width (parts.css "the ends' room"). `null`: no room */
|
|
4
|
+
export declare const EndRoomCtx: import("react").Context<ReactNode>;
|
|
5
|
+
/** set by a holder (a `LinkBlock`) whose `Row`s keep that room; a list's rows keep none */
|
|
6
|
+
export declare const RowEndRoomCtx: import("react").Context<boolean>;
|
|
7
|
+
/** a line's children with its `Words` given room for the ends that follow it, or `null` when the line has no such room: a `Lead`, an `Avatar` or
|
|
8
|
+
* an `AvatarStack` first, the `Words` next, a title over a meta (no `over`, no children), and one to four elements after it (the grid's spare columns) */
|
|
9
|
+
export declare function withEndRoom(children: ReactNode, words: ElementType): ReactNode[] | null;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Children, cloneElement, createContext, createElement, isValidElement } from 'react';
|
|
2
|
+
import { Lead } from './Lead.js';
|
|
3
|
+
import { Avatar, AvatarStack } from '../people/Avatar.js';
|
|
4
|
+
/** what may lead a line that keeps the room (the CSS's .lead, .avatar, .avatar-stack) */
|
|
5
|
+
const LEADS = [Lead, Avatar, AvatarStack];
|
|
6
|
+
/** the ends a `Words` title keeps room for at its first line's end: unseen copies of them, which the title floats so its later lines run under
|
|
7
|
+
* the real ends at full width (parts.css "the ends' room"). `null`: no room */
|
|
8
|
+
export const EndRoomCtx = createContext(null);
|
|
9
|
+
/** set by a holder (a `LinkBlock`) whose `Row`s keep that room; a list's rows keep none */
|
|
10
|
+
export const RowEndRoomCtx = createContext(false);
|
|
11
|
+
/** an end's copy, sized as the end is and doing nothing: no id, no name, no ref, no handler that could fire without a touch, not sending.
|
|
12
|
+
* `onChange` stays so a controlled input's copy is still controlled (the copy is inert: it never changes) */
|
|
13
|
+
function copyOf(end) {
|
|
14
|
+
const off = { id: undefined, name: undefined, ref: null, sending: undefined, autoFocus: undefined };
|
|
15
|
+
for (const k of Object.keys(end.props))
|
|
16
|
+
if (/^on[A-Z]/.test(k) && k !== 'onChange')
|
|
17
|
+
off[k] = undefined;
|
|
18
|
+
return cloneElement(end, off);
|
|
19
|
+
}
|
|
20
|
+
/** a line's children with its `Words` given room for the ends that follow it, or `null` when the line has no such room: a `Lead`, an `Avatar` or
|
|
21
|
+
* an `AvatarStack` first, the `Words` next, a title over a meta (no `over`, no children), and one to four elements after it (the grid's spare columns) */
|
|
22
|
+
export function withEndRoom(children, words) {
|
|
23
|
+
const list = Children.toArray(children);
|
|
24
|
+
const at = list.findIndex((c) => isValidElement(c) && c.type === words);
|
|
25
|
+
if (at !== 1 || !isValidElement(list[0]) || !LEADS.includes(list[0].type))
|
|
26
|
+
return null;
|
|
27
|
+
const w = list[at];
|
|
28
|
+
if (w.props.title == null || w.props.meta == null || w.props.over != null || w.props.children != null)
|
|
29
|
+
return null;
|
|
30
|
+
const ends = list.slice(at + 1);
|
|
31
|
+
if (ends.length < 1 || ends.length > 4 || !ends.every(isValidElement))
|
|
32
|
+
return null;
|
|
33
|
+
list[at] = createElement(EndRoomCtx.Provider, { key: w.key, value: ends.map(copyOf) }, w);
|
|
34
|
+
return list;
|
|
35
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usableapp/cardds",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.161",
|
|
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).",
|