shelving 1.294.0 → 1.295.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/package.json +1 -1
- package/ui/README.md +1 -1
- package/ui/block/Grid.d.ts +24 -0
- package/ui/block/Grid.js +14 -0
- package/ui/block/Grid.md +49 -0
- package/ui/block/Grid.tsx +39 -0
- package/ui/block/index.d.ts +1 -0
- package/ui/block/index.js +1 -0
- package/ui/block/index.ts +1 -0
- package/ui/inline/Link.d.ts +3 -1
- package/ui/inline/Link.js +2 -3
- package/ui/inline/Link.md +15 -1
- package/ui/inline/Link.module.css +10 -0
- package/ui/inline/Link.tsx +6 -5
- package/ui/input/DateInput.js +1 -1
- package/ui/input/DateInput.tsx +0 -1
- package/ui/input/FileInput.js +1 -1
- package/ui/input/FileInput.tsx +0 -1
- package/ui/input/Input.test.tsx +38 -0
- package/ui/input/NumberInput.js +1 -1
- package/ui/input/NumberInput.tsx +0 -1
- package/ui/input/SchemaInput.test.tsx +4 -4
- package/ui/input/TextInput.js +2 -2
- package/ui/input/TextInput.tsx +0 -2
- package/ui/style/Flex.module.css +2 -2
- package/ui/style/Grid.d.ts +27 -0
- package/ui/style/Grid.js +14 -0
- package/ui/style/Grid.module.css +60 -0
- package/ui/style/Grid.tsx +37 -0
- package/ui/style/TINT_CLASS.md +5 -2
- package/ui/style/Tint.d.ts +3 -1
- package/ui/style/Tint.module.css +3 -0
- package/ui/style/Tint.tsx +4 -1
- package/ui/style/Typography.d.ts +4 -2
- package/ui/style/Typography.js +1 -1
- package/ui/style/Typography.module.css +10 -0
- package/ui/style/Typography.tsx +4 -2
- package/ui/style/Width.js +1 -1
- package/ui/style/Width.module.css +1 -0
- package/ui/style/Width.tsx +1 -1
- package/ui/style/getGridClass.md +24 -0
- package/ui/style/getTypographyClass.md +3 -1
- package/ui/style/getWidthClass.md +5 -1
- package/ui/style/index.d.ts +1 -0
- package/ui/style/index.js +1 -0
- package/ui/style/index.ts +1 -0
- package/ui/style/layers.css +1 -1
- package/ui/util/css.test.ts +4 -3
package/package.json
CHANGED
package/ui/README.md
CHANGED
|
@@ -26,7 +26,7 @@ The styling system lives in `style/` and has four moving parts: design tokens, t
|
|
|
26
26
|
|
|
27
27
|
**Cascade layers.** Styles are ordered by `@layer`, lowest to highest priority: `defaults` (`:root` tokens, the tint ladder, body baseline) → `components` (the bulk of the CSS: `.card`, `.button`, …) → `variants` (cross-cutting opt-in modifiers, which always beat components) → `overrides` (top-priority structural fixes like `:first-child` / `:last-child` margin collapses). Unlayered rules beat all layered rules, so a theme should set tokens at `:root` or wrap its rules in `@layer`.
|
|
28
28
|
|
|
29
|
-
**Styling props.** The cross-cutting visual options are props, each backed by a helper in `style/` that maps the prop to a class. Colour and status move the tint anchor — `getColorClass()` and `getStatusClass()`; font size, weight, family, and case, plus text alignment, tint, and wrapping, all come from `getTypographyClass()`, which extends `ColorVariants` and composes `getColorClass()` so every typographic element also accepts `color` (use `getColorClass()` directly only for colour-without-typography, e.g. `<Icon>`); spacing, block-padding, inline-padding ("indent"), and gap from `getSpaceClass()`, `getPaddingClass()`, `getIndentClass()`, and `getGapClass()`; width constraints from `getWidthClass()`; flex layout from `getFlexClass()`; and opt-in scrolling from `getScrollClass()`. Each helper's page lists its exact prop values and what they set. A component opts into the props it wants by extending the matching `*Props` interfaces and composing the `getXxxClass(props)` calls.
|
|
29
|
+
**Styling props.** The cross-cutting visual options are props, each backed by a helper in `style/` that maps the prop to a class. Colour and status move the tint anchor — `getColorClass()` and `getStatusClass()`; font size, weight, family, and case, plus text alignment, tint, and wrapping, all come from `getTypographyClass()`, which extends `ColorVariants` and composes `getColorClass()` so every typographic element also accepts `color` (use `getColorClass()` directly only for colour-without-typography, e.g. `<Icon>`); spacing, block-padding, inline-padding ("indent"), and gap from `getSpaceClass()`, `getPaddingClass()`, `getIndentClass()`, and `getGapClass()`; width constraints from `getWidthClass()`; flex layout from `getFlexClass()`; grid layout from `getGridClass()`; and opt-in scrolling from `getScrollClass()`. Each helper's page lists its exact prop values and what they set. A component opts into the props it wants by extending the matching `*Props` interfaces and composing the `getXxxClass(props)` calls.
|
|
30
30
|
|
|
31
31
|
Each painting component also exposes per-property theme hooks (`--card-background`, `--card-radius`, …) for surgical overrides. To recolour a component or a whole region, apply `color=` / `status=` — on it or an ancestor scope — rather than a per-component tint hook; components no longer set the tint anchor themselves. Those hooks are documented in each component's own **Styling** section (see `<Card>` for the precedent).
|
|
32
32
|
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ReactElement } from "react";
|
|
2
|
+
import { type BlockVariants } from "../style/Block.js";
|
|
3
|
+
import { type GridVariants } from "../style/Grid.js";
|
|
4
|
+
import type { ClassProps, OptionalChildProps } from "../util/index.js";
|
|
5
|
+
import type { BlockElement } from "./Block.js";
|
|
6
|
+
/**
|
|
7
|
+
* Props for the `<Grid>` component.
|
|
8
|
+
*
|
|
9
|
+
* @see https://shelving.cc/ui/GridProps
|
|
10
|
+
*/
|
|
11
|
+
export interface GridProps extends BlockVariants, GridVariants, OptionalChildProps, ClassProps {
|
|
12
|
+
/**
|
|
13
|
+
* Element this `<Grid>` renders as, e.g. "ul" to output a "<ul>"
|
|
14
|
+
* @default "div"
|
|
15
|
+
*/
|
|
16
|
+
as?: BlockElement | "ul" | "ol" | undefined;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Grid container that arranges its children in equal-width columns.
|
|
20
|
+
*
|
|
21
|
+
* @kind component
|
|
22
|
+
* @see https://shelving.cc/ui/Grid
|
|
23
|
+
*/
|
|
24
|
+
export declare function Grid({ as: Element, children, className, ...props }: GridProps): ReactElement;
|
package/ui/block/Grid.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { getBlockClass } from "../style/Block.js";
|
|
3
|
+
import { getGridClass } from "../style/Grid.js";
|
|
4
|
+
import { getClass } from "../util/css.js";
|
|
5
|
+
/**
|
|
6
|
+
* Grid container that arranges its children in equal-width columns.
|
|
7
|
+
*
|
|
8
|
+
* @kind component
|
|
9
|
+
* @see https://shelving.cc/ui/Grid
|
|
10
|
+
*/
|
|
11
|
+
export function Grid({ as: Element = "div", children, className, ...props }) {
|
|
12
|
+
return (_jsx(Element, { className: getClass(getBlockClass(props), //
|
|
13
|
+
getGridClass(props), className), children: children }));
|
|
14
|
+
}
|
package/ui/block/Grid.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Grid
|
|
2
|
+
|
|
3
|
+
A grid container that arranges its children in equal-width columns. Renders a `<div>` by default. Use it for tiles, cards, badges, or a calendar of days. For one row or one column of items, use `<Row>` or `<Column>`.
|
|
4
|
+
|
|
5
|
+
**Things to know:**
|
|
6
|
+
|
|
7
|
+
- Set `columns` to `1` to `8`. The default is `2`. Each column has the same width, and long content cannot make one column wider.
|
|
8
|
+
- Set `gap` to change the space between cells. The grid sets the outer margin of each child to `0`, so a child's `space` variant has no effect.
|
|
9
|
+
- Pass `as` to render a different element. Use `as="ul"` or `as="ol"` for a list of items, and give each child as an `<li>`. The grid removes the list markers.
|
|
10
|
+
- It composes the standard block variants (`space`, `padding`, `indent`, `width`, `color`, and typography). See `getGridClass()` for the grid variants.
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
### Two columns of cards
|
|
15
|
+
|
|
16
|
+
```tsx
|
|
17
|
+
import { Card, Grid, Paragraph } from "shelving/ui";
|
|
18
|
+
|
|
19
|
+
<Grid gap="small">
|
|
20
|
+
<Card><Paragraph>Running</Paragraph></Card>
|
|
21
|
+
<Card><Paragraph>Cycling</Paragraph></Card>
|
|
22
|
+
<Card><Paragraph>Swimming</Paragraph></Card>
|
|
23
|
+
<Card><Paragraph>Rowing</Paragraph></Card>
|
|
24
|
+
</Grid>
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### A list of tiles
|
|
28
|
+
|
|
29
|
+
```tsx
|
|
30
|
+
import { Grid } from "shelving/ui";
|
|
31
|
+
|
|
32
|
+
<Grid as="ul" columns={3} gap="normal">
|
|
33
|
+
{badges.map(badge => <li key={badge.id}>{badge.name}</li>)}
|
|
34
|
+
</Grid>
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Days of the week
|
|
38
|
+
|
|
39
|
+
```tsx
|
|
40
|
+
import { Grid } from "shelving/ui";
|
|
41
|
+
|
|
42
|
+
<Grid as="ol" columns={7} gap="xsmall">
|
|
43
|
+
{days.map(day => <li key={day.date}>{day.label}</li>)}
|
|
44
|
+
</Grid>
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Styling
|
|
48
|
+
|
|
49
|
+
`Grid` has no own hooks. It reads `--grid-gap` from `getGridClass()` (the space between cells, default `var(--space-small)`), and the block variants from `getBlockClass()`.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { ReactElement } from "react";
|
|
2
|
+
import { type BlockVariants, getBlockClass } from "../style/Block.js";
|
|
3
|
+
import { type GridVariants, getGridClass } from "../style/Grid.js";
|
|
4
|
+
import { getClass } from "../util/css.js";
|
|
5
|
+
import type { ClassProps, OptionalChildProps } from "../util/index.js";
|
|
6
|
+
import type { BlockElement } from "./Block.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Props for the `<Grid>` component.
|
|
10
|
+
*
|
|
11
|
+
* @see https://shelving.cc/ui/GridProps
|
|
12
|
+
*/
|
|
13
|
+
export interface GridProps extends BlockVariants, GridVariants, OptionalChildProps, ClassProps {
|
|
14
|
+
/**
|
|
15
|
+
* Element this `<Grid>` renders as, e.g. "ul" to output a "<ul>"
|
|
16
|
+
* @default "div"
|
|
17
|
+
*/
|
|
18
|
+
as?: BlockElement | "ul" | "ol" | undefined;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Grid container that arranges its children in equal-width columns.
|
|
23
|
+
*
|
|
24
|
+
* @kind component
|
|
25
|
+
* @see https://shelving.cc/ui/Grid
|
|
26
|
+
*/
|
|
27
|
+
export function Grid({ as: Element = "div", children, className, ...props }: GridProps): ReactElement {
|
|
28
|
+
return (
|
|
29
|
+
<Element
|
|
30
|
+
className={getClass(
|
|
31
|
+
getBlockClass(props), //
|
|
32
|
+
getGridClass(props),
|
|
33
|
+
className,
|
|
34
|
+
)}
|
|
35
|
+
>
|
|
36
|
+
{children}
|
|
37
|
+
</Element>
|
|
38
|
+
);
|
|
39
|
+
}
|
package/ui/block/index.d.ts
CHANGED
package/ui/block/index.js
CHANGED
package/ui/block/index.ts
CHANGED
package/ui/inline/Link.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ import type { ClassProps } from "../util/props.js";
|
|
|
8
8
|
* @see https://shelving.cc/ui/LinkProps
|
|
9
9
|
*/
|
|
10
10
|
export interface LinkProps extends ClickableProps, TypographyVariants, ClassProps {
|
|
11
|
+
/** Remove the link colour, weight, and underline, e.g. for a link around a block of content. */
|
|
12
|
+
plain?: boolean | undefined;
|
|
11
13
|
}
|
|
12
14
|
/**
|
|
13
15
|
* Inline link — delegates to `<Clickable>`, rendering an `<a>` (when `href` is set) or `<button>` (when `onClick` is set).
|
|
@@ -15,4 +17,4 @@ export interface LinkProps extends ClickableProps, TypographyVariants, ClassProp
|
|
|
15
17
|
* @kind component
|
|
16
18
|
* @see https://shelving.cc/ui/Link
|
|
17
19
|
*/
|
|
18
|
-
export declare function Link({ className, ...props }: LinkProps): ReactElement;
|
|
20
|
+
export declare function Link({ className, plain, ...props }: LinkProps): ReactElement;
|
package/ui/inline/Link.js
CHANGED
|
@@ -3,14 +3,13 @@ import { Clickable } from "../button/Clickable.js";
|
|
|
3
3
|
import { getTypographyClass } from "../style/Typography.js";
|
|
4
4
|
import { getClass, getModuleClass } from "../util/css.js";
|
|
5
5
|
import LINK_CSS from "./Link.module.css";
|
|
6
|
-
const LINK_CLASS = getModuleClass(LINK_CSS, "link");
|
|
7
6
|
/**
|
|
8
7
|
* Inline link — delegates to `<Clickable>`, rendering an `<a>` (when `href` is set) or `<button>` (when `onClick` is set).
|
|
9
8
|
*
|
|
10
9
|
* @kind component
|
|
11
10
|
* @see https://shelving.cc/ui/Link
|
|
12
11
|
*/
|
|
13
|
-
export function Link({ className, ...props }) {
|
|
14
|
-
return (_jsx(Clickable, { ...props, className: getClass(
|
|
12
|
+
export function Link({ className, plain, ...props }) {
|
|
13
|
+
return (_jsx(Clickable, { ...props, className: getClass(getModuleClass(LINK_CSS, "link", { plain }), //
|
|
15
14
|
getTypographyClass(props), className) }));
|
|
16
15
|
}
|
package/ui/inline/Link.md
CHANGED
|
@@ -7,6 +7,7 @@ An inline link or action. Delegates to `<Clickable>`, rendering an `<a>` when `h
|
|
|
7
7
|
- It handles busy state, URL resolution, and active-page highlighting automatically via the shared `<Clickable>` helper.
|
|
8
8
|
- An `<a>` (any actual link) shows an underline that disappears on hover; a `<button>` variant carries no underline.
|
|
9
9
|
- Reach for `Link` for inline text links; for standalone calls to action use a button-styled component instead.
|
|
10
|
+
- Set `plain` to remove the link colour, weight, and underline. Use it for a link around a block of content, such as a card or a profile row. The link keeps URL resolution and active-page highlighting.
|
|
10
11
|
- Inside `<Prose>` a raw `<a>` picks up the same styling, so Markdown-rendered links match component ones.
|
|
11
12
|
|
|
12
13
|
## Usage
|
|
@@ -29,9 +30,22 @@ import { Link } from "shelving/ui";
|
|
|
29
30
|
<Link onClick={() => save()}>Save now</Link>
|
|
30
31
|
```
|
|
31
32
|
|
|
33
|
+
### Plain link around a block
|
|
34
|
+
|
|
35
|
+
```tsx
|
|
36
|
+
import { Link, Row, Span } from "shelving/ui";
|
|
37
|
+
|
|
38
|
+
<Link plain href="/jane">
|
|
39
|
+
<Row left>
|
|
40
|
+
<Span weight="strong">Jane Smith</Span>
|
|
41
|
+
<Span tint="60">@jane</Span>
|
|
42
|
+
</Row>
|
|
43
|
+
</Link>
|
|
44
|
+
```
|
|
45
|
+
|
|
32
46
|
## Styling
|
|
33
47
|
|
|
34
|
-
`Link` colours itself from the global `--color-link` token by default. Inside a tinted scope (`color=` / `status=` on an ancestor) `--color-link` resolves to `inherit`, so links adopt the surrounding tinted text colour. Override `--link-color` to set it directly.
|
|
48
|
+
`Link` colours itself from the global `--color-link` token by default. Inside a tinted scope (`color=` / `status=` on an ancestor) `--color-link` resolves to `inherit`, so links adopt the surrounding tinted text colour. Override `--link-color` to set it directly. A `plain` link ignores both hooks and inherits the colour and weight of its parent.
|
|
35
49
|
|
|
36
50
|
| Variable | Styles | Default |
|
|
37
51
|
|---|---|---|
|
|
@@ -22,5 +22,15 @@
|
|
|
22
22
|
text-decoration: none;
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
+
|
|
26
|
+
/* Plain: no link colour, weight, or underline, for a link around a block of content. */
|
|
27
|
+
&.plain {
|
|
28
|
+
color: inherit;
|
|
29
|
+
font-weight: inherit;
|
|
30
|
+
|
|
31
|
+
&:any-link {
|
|
32
|
+
text-decoration: none;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
25
35
|
}
|
|
26
36
|
}
|
package/ui/inline/Link.tsx
CHANGED
|
@@ -5,14 +5,15 @@ import { getClass, getModuleClass } from "../util/css.js";
|
|
|
5
5
|
import type { ClassProps } from "../util/props.js";
|
|
6
6
|
import LINK_CSS from "./Link.module.css";
|
|
7
7
|
|
|
8
|
-
const LINK_CLASS = getModuleClass(LINK_CSS, "link");
|
|
9
|
-
|
|
10
8
|
/**
|
|
11
9
|
* Props for `Link` — `ClickableProps` (`href` for navigation or `onClick` for actions) plus colour and typography variants.
|
|
12
10
|
*
|
|
13
11
|
* @see https://shelving.cc/ui/LinkProps
|
|
14
12
|
*/
|
|
15
|
-
export interface LinkProps extends ClickableProps, TypographyVariants, ClassProps {
|
|
13
|
+
export interface LinkProps extends ClickableProps, TypographyVariants, ClassProps {
|
|
14
|
+
/** Remove the link colour, weight, and underline, e.g. for a link around a block of content. */
|
|
15
|
+
plain?: boolean | undefined;
|
|
16
|
+
}
|
|
16
17
|
|
|
17
18
|
/**
|
|
18
19
|
* Inline link — delegates to `<Clickable>`, rendering an `<a>` (when `href` is set) or `<button>` (when `onClick` is set).
|
|
@@ -20,12 +21,12 @@ export interface LinkProps extends ClickableProps, TypographyVariants, ClassProp
|
|
|
20
21
|
* @kind component
|
|
21
22
|
* @see https://shelving.cc/ui/Link
|
|
22
23
|
*/
|
|
23
|
-
export function Link({ className, ...props }: LinkProps): ReactElement {
|
|
24
|
+
export function Link({ className, plain, ...props }: LinkProps): ReactElement {
|
|
24
25
|
return (
|
|
25
26
|
<Clickable
|
|
26
27
|
{...props}
|
|
27
28
|
className={getClass(
|
|
28
|
-
|
|
29
|
+
getModuleClass(LINK_CSS, "link", { plain }), //
|
|
29
30
|
getTypographyClass(props),
|
|
30
31
|
className,
|
|
31
32
|
)}
|
package/ui/input/DateInput.js
CHANGED
|
@@ -23,5 +23,5 @@ required = false, disabled = false, message = "", value, onValue, min, max, inpu
|
|
|
23
23
|
onValue?.(e.currentTarget.value ?? undefined);
|
|
24
24
|
};
|
|
25
25
|
const dateToString = _DATE_TO_STRING[input];
|
|
26
|
-
return (_jsx("input", { name: name, type: input, min: dateToString(min), max: dateToString(max), disabled: disabled, required: required, defaultValue: dateToString(value), placeholder: placeholder || " ", className: getClass(getInputClass(variants), getModuleClass(INPUT_CSS, "text"), className), onChange: onChange,
|
|
26
|
+
return (_jsx("input", { name: name, type: input, min: dateToString(min), max: dateToString(max), disabled: disabled, required: required, defaultValue: dateToString(value), placeholder: placeholder || " ", className: getClass(getInputClass(variants), getModuleClass(INPUT_CSS, "text"), className), onChange: onChange, title: message, "aria-invalid": !!message, step: step }));
|
|
27
27
|
}
|
package/ui/input/DateInput.tsx
CHANGED
|
@@ -66,7 +66,6 @@ export function DateInput({
|
|
|
66
66
|
placeholder={placeholder || " "}
|
|
67
67
|
className={getClass(getInputClass(variants), getModuleClass(INPUT_CSS, "text"), className)}
|
|
68
68
|
onChange={onChange}
|
|
69
|
-
onInput={onChange}
|
|
70
69
|
title={message}
|
|
71
70
|
aria-invalid={!!message}
|
|
72
71
|
step={step}
|
package/ui/input/FileInput.js
CHANGED
|
@@ -18,5 +18,5 @@ onValue, types = {}, className, ...variants }) {
|
|
|
18
18
|
for (const file of files)
|
|
19
19
|
onValue(file);
|
|
20
20
|
};
|
|
21
|
-
return (_jsx("input", { name: name, type: "file", accept: Object.values(types).join(","), required: required, disabled: disabled, placeholder: placeholder, className: getClass(getInputClass(variants), className), onChange: onChange,
|
|
21
|
+
return (_jsx("input", { name: name, type: "file", accept: Object.values(types).join(","), required: required, disabled: disabled, placeholder: placeholder, className: getClass(getInputClass(variants), className), onChange: onChange, multiple: false, title: message, "aria-invalid": !!message }));
|
|
22
22
|
}
|
package/ui/input/FileInput.tsx
CHANGED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import type { ReactElement } from "react";
|
|
3
|
+
import { DateInput, FileInput, NumberInput, TextInput } from "shelving/ui";
|
|
4
|
+
import { PASSTHROUGH } from "shelving/util/function";
|
|
5
|
+
|
|
6
|
+
/** The props of the rendered element that the tests read. */
|
|
7
|
+
interface _ElementProps {
|
|
8
|
+
readonly onInput?: unknown;
|
|
9
|
+
readonly onChange?: unknown;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
describe("value inputs", () => {
|
|
13
|
+
// React's `onChange` already fires for each native `input` event, so a second `onInput` handler would call `onValue()` twice.
|
|
14
|
+
const elements: [string, ReactElement][] = [
|
|
15
|
+
["TextInput", TextInput({ name: "x", onValue: PASSTHROUGH })],
|
|
16
|
+
["TextInput (multiline)", TextInput({ name: "x", rows: 3, onValue: PASSTHROUGH })],
|
|
17
|
+
["NumberInput", NumberInput({ name: "x", onValue: PASSTHROUGH })],
|
|
18
|
+
["DateInput", DateInput({ name: "x", onValue: PASSTHROUGH })],
|
|
19
|
+
["FileInput", FileInput({ name: "x", onValue: PASSTHROUGH })],
|
|
20
|
+
];
|
|
21
|
+
for (const [label, element] of elements) {
|
|
22
|
+
test(`${label} listens to change only, so it calls onValue once per edit`, () => {
|
|
23
|
+
const props = element.props as _ElementProps;
|
|
24
|
+
expect(props.onChange).toBeFunction();
|
|
25
|
+
expect(props.onInput).toBeUndefined();
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
describe("FileInput", () => {
|
|
31
|
+
test("calls onValue once for the picked file", () => {
|
|
32
|
+
const values: (string | File | undefined)[] = [];
|
|
33
|
+
const file = new File(["abc"], "a.txt");
|
|
34
|
+
const element = FileInput({ name: "x", onValue: v => void values.push(v) });
|
|
35
|
+
(element.props as { onChange(e: { currentTarget: { files: File[] } }): void }).onChange({ currentTarget: { files: [file] } });
|
|
36
|
+
expect(values).toEqual([file]);
|
|
37
|
+
});
|
|
38
|
+
});
|
package/ui/input/NumberInput.js
CHANGED
|
@@ -24,5 +24,5 @@ formatter = formatNumber, className, ...variants }) {
|
|
|
24
24
|
const num = getNumber(currentTarget.value);
|
|
25
25
|
currentTarget.value = num !== undefined ? formatter(num) : "";
|
|
26
26
|
};
|
|
27
|
-
return (_jsx("input", { name: name, type: "text", inputMode: "decimal", defaultValue: value !== undefined ? formatter(value) : "", required: required, disabled: disabled, placeholder: placeholder || " ", className: getClass(getInputClass(variants), getModuleClass(INPUT_CSS, "text"), className), onChange: onChange,
|
|
27
|
+
return (_jsx("input", { name: name, type: "text", inputMode: "decimal", defaultValue: value !== undefined ? formatter(value) : "", required: required, disabled: disabled, placeholder: placeholder || " ", className: getClass(getInputClass(variants), getModuleClass(INPUT_CSS, "text"), className), onChange: onChange, onBlur: onBlur, title: message, "aria-invalid": !!message }));
|
|
28
28
|
}
|
package/ui/input/NumberInput.tsx
CHANGED
|
@@ -62,7 +62,6 @@ export function NumberInput({
|
|
|
62
62
|
placeholder={placeholder || " "}
|
|
63
63
|
className={getClass(getInputClass(variants), getModuleClass(INPUT_CSS, "text"), className)}
|
|
64
64
|
onChange={onChange}
|
|
65
|
-
onInput={onChange}
|
|
66
65
|
onBlur={onBlur}
|
|
67
66
|
title={message}
|
|
68
67
|
aria-invalid={!!message}
|
|
@@ -25,7 +25,7 @@ function _getInputProps(schema: StringSchema, onValue: (value: string | undefine
|
|
|
25
25
|
interface _InputProps {
|
|
26
26
|
readonly type?: string;
|
|
27
27
|
readonly defaultValue?: string;
|
|
28
|
-
|
|
28
|
+
onChange(e: { currentTarget: { value: string } }): void;
|
|
29
29
|
onBlur(e: { currentTarget: { value: string } }): void;
|
|
30
30
|
}
|
|
31
31
|
|
|
@@ -58,7 +58,7 @@ describe("StringSchemaInput", () => {
|
|
|
58
58
|
// `format()` is for display only — the store must receive a value that re-validates.
|
|
59
59
|
const values: (string | undefined)[] = [];
|
|
60
60
|
const input = _getInputProps(new BracketSchema({}), v => void values.push(v));
|
|
61
|
-
input.
|
|
61
|
+
input.onChange({ currentTarget: { value: " abc " } });
|
|
62
62
|
|
|
63
63
|
expect(values).toEqual(["abc"]);
|
|
64
64
|
});
|
|
@@ -77,7 +77,7 @@ describe("StringSchemaInput", () => {
|
|
|
77
77
|
// A `PasswordSchema` field must submit the typed password; masking is the `type="password"` input's job.
|
|
78
78
|
const values: (string | undefined)[] = [];
|
|
79
79
|
const input = _getInputProps(PASSWORD, v => void values.push(v), "hunter2");
|
|
80
|
-
input.
|
|
80
|
+
input.onChange({ currentTarget: { value: "hunter22" } });
|
|
81
81
|
const currentTarget = { value: "hunter22" };
|
|
82
82
|
input.onBlur({ currentTarget });
|
|
83
83
|
|
|
@@ -91,7 +91,7 @@ describe("StringSchemaInput", () => {
|
|
|
91
91
|
// `URLSchema.format()` strips the scheme for display; publishing that form would fail re-validation.
|
|
92
92
|
const values: (string | undefined)[] = [];
|
|
93
93
|
const input = _getInputProps(URL_SCHEMA, v => void values.push(v));
|
|
94
|
-
input.
|
|
94
|
+
input.onChange({ currentTarget: { value: " https://example.com/path " } });
|
|
95
95
|
const currentTarget = { value: "https://example.com/path" };
|
|
96
96
|
input.onBlur({ currentTarget });
|
|
97
97
|
|
package/ui/input/TextInput.js
CHANGED
|
@@ -22,12 +22,12 @@ required = false, disabled = false, message = "", value, onValue, input = "text"
|
|
|
22
22
|
onValue?.(e.currentTarget.value);
|
|
23
23
|
_resize(e.currentTarget, rows);
|
|
24
24
|
};
|
|
25
|
-
return (_jsx("textarea", { ref: el => void (el && _resize(el, rows)), name: name, defaultValue: value !== undefined ? formatter(value) : "", minLength: Number.isFinite(min) ? min : 0, maxLength: Number.isFinite(max) ? max : undefined, rows: rows, required: required && min > 0, disabled: disabled, placeholder: placeholder || " ", className: getClass(getInputClass(variants), getModuleClass(INPUT_CSS, "text"), getModuleClass(INPUT_CSS, "multiline"), className),
|
|
25
|
+
return (_jsx("textarea", { ref: el => void (el && _resize(el, rows)), name: name, defaultValue: value !== undefined ? formatter(value) : "", minLength: Number.isFinite(min) ? min : 0, maxLength: Number.isFinite(max) ? max : undefined, rows: rows, required: required && min > 0, disabled: disabled, placeholder: placeholder || " ", className: getClass(getInputClass(variants), getModuleClass(INPUT_CSS, "text"), getModuleClass(INPUT_CSS, "multiline"), className), onChange: onChange, onBlur: onBlur, title: message, "aria-invalid": !!message }));
|
|
26
26
|
}
|
|
27
27
|
const onChange = (e) => {
|
|
28
28
|
onValue?.(e.currentTarget.value);
|
|
29
29
|
};
|
|
30
|
-
return (_jsx("input", { name: name, type: input, defaultValue: value !== undefined ? formatter(value) : "", minLength: Number.isFinite(min) ? min : 0, maxLength: Number.isFinite(max) ? max : undefined, required: required && min > 0, disabled: disabled, placeholder: placeholder || " ", className: getClass(getInputClass(variants), getModuleClass(INPUT_CSS, "text"), className),
|
|
30
|
+
return (_jsx("input", { name: name, type: input, defaultValue: value !== undefined ? formatter(value) : "", minLength: Number.isFinite(min) ? min : 0, maxLength: Number.isFinite(max) ? max : undefined, required: required && min > 0, disabled: disabled, placeholder: placeholder || " ", className: getClass(getInputClass(variants), getModuleClass(INPUT_CSS, "text"), className), onChange: onChange, onBlur: onBlur, title: message, "aria-invalid": !!message }));
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
33
33
|
* @todo This can be removed when Firefox supports `field-sizing:` in CSS.
|
package/ui/input/TextInput.tsx
CHANGED
|
@@ -70,7 +70,6 @@ export function TextInput({
|
|
|
70
70
|
disabled={disabled}
|
|
71
71
|
placeholder={placeholder || " "}
|
|
72
72
|
className={getClass(getInputClass(variants), getModuleClass(INPUT_CSS, "text"), getModuleClass(INPUT_CSS, "multiline"), className)}
|
|
73
|
-
onInput={onChange}
|
|
74
73
|
onChange={onChange}
|
|
75
74
|
onBlur={onBlur}
|
|
76
75
|
title={message}
|
|
@@ -94,7 +93,6 @@ export function TextInput({
|
|
|
94
93
|
disabled={disabled}
|
|
95
94
|
placeholder={placeholder || " "}
|
|
96
95
|
className={getClass(getInputClass(variants), getModuleClass(INPUT_CSS, "text"), className)}
|
|
97
|
-
onInput={onChange}
|
|
98
96
|
onChange={onChange}
|
|
99
97
|
onBlur={onBlur}
|
|
100
98
|
title={message}
|
package/ui/style/Flex.module.css
CHANGED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type GapVariants } from "./Gap.js";
|
|
2
|
+
/**
|
|
3
|
+
* Number of equal-width columns selectable via the `columns` variant prop.
|
|
4
|
+
*
|
|
5
|
+
* @see https://shelving.cc/ui/ColumnsVariant
|
|
6
|
+
*/
|
|
7
|
+
export type ColumnsVariant = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8;
|
|
8
|
+
/**
|
|
9
|
+
* Variant props for grid layout, e.g. `columns={3} gap="normal"`.
|
|
10
|
+
*
|
|
11
|
+
* @see https://shelving.cc/ui/GridVariants
|
|
12
|
+
*/
|
|
13
|
+
export interface GridVariants extends GapVariants {
|
|
14
|
+
/**
|
|
15
|
+
* Number of equal-width columns.
|
|
16
|
+
* @default 2
|
|
17
|
+
*/
|
|
18
|
+
columns?: ColumnsVariant | undefined;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Get the grid layout class for a component from its grid variant props.
|
|
22
|
+
*
|
|
23
|
+
* @returns The combined grid + gap class string.
|
|
24
|
+
* @example getGridClass({ columns: 3, gap: "normal" })
|
|
25
|
+
* @see https://shelving.cc/ui/getGridClass
|
|
26
|
+
*/
|
|
27
|
+
export declare function getGridClass({ columns, ...variants }: GridVariants): string;
|
package/ui/style/Grid.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { getClass, getModuleClass } from "../util/css.js";
|
|
2
|
+
import { getGapClass } from "./Gap.js";
|
|
3
|
+
import GRID_CSS from "./Grid.module.css";
|
|
4
|
+
/**
|
|
5
|
+
* Get the grid layout class for a component from its grid variant props.
|
|
6
|
+
*
|
|
7
|
+
* @returns The combined grid + gap class string.
|
|
8
|
+
* @example getGridClass({ columns: 3, gap: "normal" })
|
|
9
|
+
* @see https://shelving.cc/ui/getGridClass
|
|
10
|
+
*/
|
|
11
|
+
export function getGridClass({ columns = 2, ...variants }) {
|
|
12
|
+
return getClass(getModuleClass(GRID_CSS, "grid", `columns-${columns}`), //
|
|
13
|
+
getGapClass(variants));
|
|
14
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
@import url("layers.css");
|
|
2
|
+
@import url("Space.module.css");
|
|
3
|
+
|
|
4
|
+
@layer defaults {
|
|
5
|
+
.grid {
|
|
6
|
+
/* Contents */
|
|
7
|
+
gap: var(--grid-gap, var(--space-small));
|
|
8
|
+
|
|
9
|
+
/* Allow `as="ul"` and `as="ol"` without list markers. */
|
|
10
|
+
list-style: none;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
@layer variants {
|
|
15
|
+
.grid {
|
|
16
|
+
/* Box */
|
|
17
|
+
display: grid;
|
|
18
|
+
|
|
19
|
+
/* Contents */
|
|
20
|
+
grid-template-columns: repeat(var(--grid-columns), minmax(0, 1fr));
|
|
21
|
+
|
|
22
|
+
/* Children (doubled class, so it beats a child's `space` variant in the same layer in any bundle order). */
|
|
23
|
+
&& > * {
|
|
24
|
+
margin: 0;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/* Columns. */
|
|
29
|
+
.columns-1 {
|
|
30
|
+
--grid-columns: 1;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.columns-2 {
|
|
34
|
+
--grid-columns: 2;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.columns-3 {
|
|
38
|
+
--grid-columns: 3;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.columns-4 {
|
|
42
|
+
--grid-columns: 4;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.columns-5 {
|
|
46
|
+
--grid-columns: 5;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.columns-6 {
|
|
50
|
+
--grid-columns: 6;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.columns-7 {
|
|
54
|
+
--grid-columns: 7;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.columns-8 {
|
|
58
|
+
--grid-columns: 8;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { getClass, getModuleClass } from "../util/css.js";
|
|
2
|
+
import { type GapVariants, getGapClass } from "./Gap.js";
|
|
3
|
+
import GRID_CSS from "./Grid.module.css";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Number of equal-width columns selectable via the `columns` variant prop.
|
|
7
|
+
*
|
|
8
|
+
* @see https://shelving.cc/ui/ColumnsVariant
|
|
9
|
+
*/
|
|
10
|
+
export type ColumnsVariant = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Variant props for grid layout, e.g. `columns={3} gap="normal"`.
|
|
14
|
+
*
|
|
15
|
+
* @see https://shelving.cc/ui/GridVariants
|
|
16
|
+
*/
|
|
17
|
+
export interface GridVariants extends GapVariants {
|
|
18
|
+
/**
|
|
19
|
+
* Number of equal-width columns.
|
|
20
|
+
* @default 2
|
|
21
|
+
*/
|
|
22
|
+
columns?: ColumnsVariant | undefined;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Get the grid layout class for a component from its grid variant props.
|
|
27
|
+
*
|
|
28
|
+
* @returns The combined grid + gap class string.
|
|
29
|
+
* @example getGridClass({ columns: 3, gap: "normal" })
|
|
30
|
+
* @see https://shelving.cc/ui/getGridClass
|
|
31
|
+
*/
|
|
32
|
+
export function getGridClass({ columns = 2, ...variants }: GridVariants): string {
|
|
33
|
+
return getClass(
|
|
34
|
+
getModuleClass(GRID_CSS, "grid", `columns-${columns}`), //
|
|
35
|
+
getGapClass(variants),
|
|
36
|
+
);
|
|
37
|
+
}
|
package/ui/style/TINT_CLASS.md
CHANGED
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
All colour in the library flows from a single anchor variable, **`--tint-50`**, defined in `Tint.module.css`. From that one hue a 21-step ladder — `--tint-00`, `--tint-05`, … `--tint-95`, `--tint-100` — is computed with `color-mix()` in OKLCH: `--tint-00` is black, `--tint-50` is the anchor hue itself, `--tint-100` is white, and every step in between mixes the anchor toward one extreme or the other.
|
|
4
4
|
|
|
5
|
+
One more step, `--tint-contrast`, is black or white, whichever reads better on `--tint-50`. It picks white when the anchor is dark and black when the anchor is light (yellow, for example). Use it for text on a `--tint-50` background when the anchor can be any colour. It uses relative colour syntax (`oklch(from …)`), so it needs Safari 18 or later.
|
|
6
|
+
|
|
5
7
|
The anchor defaults to `--color-gray`, so the default ladder is a neutral grey ramp — grey is just the colour you get when nothing moves the anchor. The page baseline paints from the extremes: `body { color: var(--tint-00); background: var(--tint-100); }`.
|
|
6
8
|
|
|
7
9
|
## The recompute trick
|
|
8
10
|
|
|
9
|
-
The ladder is computed at `:root` and *recomputed* under `TINT_CLASS` (the `.tint` class). That recomputation is the whole trick: move the anchor at any scope, apply `TINT_CLASS`, and all 21 shades rebuild from the new hue at that scope. Colour and status classes are exactly that — they only move the anchor:
|
|
11
|
+
The ladder is computed at `:root` and *recomputed* under `TINT_CLASS` (the `.tint` class). That recomputation is the whole trick: move the anchor at any scope, apply `TINT_CLASS`, and all 21 shades (and `--tint-contrast`) rebuild from the new hue at that scope. Colour and status classes are exactly that — they only move the anchor:
|
|
10
12
|
|
|
11
13
|
```css
|
|
12
14
|
/* Color.module.css — a colour variant just moves the anchor. */
|
|
@@ -34,8 +36,9 @@ Components paint from the ladder by convention:
|
|
|
34
36
|
| `--tint-90` | Surfaces — `<Card>`, `Preformatted` backgrounds |
|
|
35
37
|
| `--tint-95` | Hover state of those surfaces |
|
|
36
38
|
| `--tint-100` | The page background; text on `--tint-50` backgrounds |
|
|
39
|
+
| `--tint-contrast` | Text on `--tint-50` backgrounds when the anchor can be light or dark |
|
|
37
40
|
|
|
38
|
-
Pairings follow contrast: long text reads at `00`-on-`90` or `00`-on-`100`; short labels read at `100`-on-`50
|
|
41
|
+
Pairings follow contrast: long text reads at `00`-on-`90` or `00`-on-`100`; short labels read at `100`-on-`50`, or at `contrast`-on-`50` when the anchor can be light.
|
|
39
42
|
|
|
40
43
|
## Theming
|
|
41
44
|
|
package/ui/style/Tint.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Shades of the currently selected tint color, from `"00"` (black) through `"50"` (the hue itself) to `"100"` (white).
|
|
3
3
|
*
|
|
4
|
+
* - `"contrast"` is black or white, whichever reads better on `"50"`.
|
|
5
|
+
*
|
|
4
6
|
* @see https://shelving.cc/ui/TintVariant
|
|
5
7
|
*/
|
|
6
|
-
export type TintVariant = "00" | "05" | "10" | "15" | "20" | "25" | "30" | "35" | "40" | "45" | "50" | "55" | "60" | "65" | "70" | "75" | "80" | "85" | "90" | "95" | "100";
|
|
8
|
+
export type TintVariant = "00" | "05" | "10" | "15" | "20" | "25" | "30" | "35" | "40" | "45" | "50" | "55" | "60" | "65" | "70" | "75" | "80" | "85" | "90" | "95" | "100" | "contrast";
|
|
7
9
|
/**
|
|
8
10
|
* CSS class that (re)calculates the full ladder of tint shades from the current global tint colour.
|
|
9
11
|
*
|
package/ui/style/Tint.module.css
CHANGED
|
@@ -33,6 +33,9 @@
|
|
|
33
33
|
--tint-90: color-mix(in oklch, var(--tint-50), white 80%);
|
|
34
34
|
--tint-95: color-mix(in oklch, var(--tint-50), white 90%);
|
|
35
35
|
--tint-100: white;
|
|
36
|
+
|
|
37
|
+
/* Black or white, whichever reads better on `--tint-50`. */
|
|
38
|
+
--tint-contrast: oklch(from var(--tint-50) calc(clamp(0, (0.72 - l) * 1000, 1)) 0 0deg);
|
|
36
39
|
}
|
|
37
40
|
|
|
38
41
|
.tint {
|
package/ui/style/Tint.tsx
CHANGED
|
@@ -4,6 +4,8 @@ import THEME_CSS from "./Tint.module.css";
|
|
|
4
4
|
/**
|
|
5
5
|
* Shades of the currently selected tint color, from `"00"` (black) through `"50"` (the hue itself) to `"100"` (white).
|
|
6
6
|
*
|
|
7
|
+
* - `"contrast"` is black or white, whichever reads better on `"50"`.
|
|
8
|
+
*
|
|
7
9
|
* @see https://shelving.cc/ui/TintVariant
|
|
8
10
|
*/
|
|
9
11
|
export type TintVariant =
|
|
@@ -27,7 +29,8 @@ export type TintVariant =
|
|
|
27
29
|
| "85"
|
|
28
30
|
| "90"
|
|
29
31
|
| "95"
|
|
30
|
-
| "100"
|
|
32
|
+
| "100"
|
|
33
|
+
| "contrast";
|
|
31
34
|
|
|
32
35
|
/**
|
|
33
36
|
* CSS class that (re)calculates the full ladder of tint shades from the current global tint colour.
|
package/ui/style/Typography.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ export type CaseVariant = "title" | "body" | "label" | "code" | "upper" | "lower
|
|
|
25
25
|
*/
|
|
26
26
|
export type FontVariant = "title" | "body" | "label" | "code" | "serif" | "sans" | "monospace";
|
|
27
27
|
/**
|
|
28
|
-
* Typographic variant props — colour, font-family, weight, case, size, tint, alignment, and
|
|
28
|
+
* Typographic variant props — colour, font-family, weight, case, size, tint, alignment, wrap, and truncate, applied via `getTypographyClass()`
|
|
29
29
|
*
|
|
30
30
|
* - Extends `ColorVariants`, so anything that accepts typography also accepts the `color` variant.
|
|
31
31
|
*
|
|
@@ -52,11 +52,13 @@ export interface TypographyVariants extends ColorVariants {
|
|
|
52
52
|
wrap?: boolean | undefined;
|
|
53
53
|
/** Disable wrapping. */
|
|
54
54
|
nowrap?: boolean | undefined;
|
|
55
|
+
/** Cut overflowing text to one line with an ellipsis (on a block or a flex item). */
|
|
56
|
+
truncate?: boolean | undefined;
|
|
55
57
|
}
|
|
56
58
|
/**
|
|
57
59
|
* Get the typography class for a component from its typographic variant props.
|
|
58
60
|
*
|
|
59
|
-
* Maps the colour, size, weight, font, case, tint, alignment, and
|
|
61
|
+
* Maps the colour, size, weight, font, case, tint, alignment, wrap, and truncate variant props to their CSS classes — the `color` variant is composed in via `getColorClass()`.
|
|
60
62
|
*
|
|
61
63
|
* @returns The combined typography class string (empty when no variants apply).
|
|
62
64
|
* @example getTypographyClass({ font: "title", size: "large", center: true })
|
package/ui/style/Typography.js
CHANGED
|
@@ -4,7 +4,7 @@ import TYPOGRAPHY_CSS from "./Typography.module.css";
|
|
|
4
4
|
/**
|
|
5
5
|
* Get the typography class for a component from its typographic variant props.
|
|
6
6
|
*
|
|
7
|
-
* Maps the colour, size, weight, font, case, tint, alignment, and
|
|
7
|
+
* Maps the colour, size, weight, font, case, tint, alignment, wrap, and truncate variant props to their CSS classes — the `color` variant is composed in via `getColorClass()`.
|
|
8
8
|
*
|
|
9
9
|
* @returns The combined typography class string (empty when no variants apply).
|
|
10
10
|
* @example getTypographyClass({ font: "title", size: "large", center: true })
|
|
@@ -328,6 +328,10 @@
|
|
|
328
328
|
color: var(--tint-100);
|
|
329
329
|
}
|
|
330
330
|
|
|
331
|
+
.tint-contrast {
|
|
332
|
+
color: var(--tint-contrast);
|
|
333
|
+
}
|
|
334
|
+
|
|
331
335
|
/* Text-alignment variants. */
|
|
332
336
|
.left {
|
|
333
337
|
text-align: left;
|
|
@@ -349,4 +353,10 @@
|
|
|
349
353
|
.nowrap {
|
|
350
354
|
white-space: nowrap;
|
|
351
355
|
}
|
|
356
|
+
|
|
357
|
+
.truncate {
|
|
358
|
+
overflow: hidden;
|
|
359
|
+
white-space: nowrap;
|
|
360
|
+
text-overflow: ellipsis;
|
|
361
|
+
}
|
|
352
362
|
}
|
package/ui/style/Typography.tsx
CHANGED
|
@@ -50,7 +50,7 @@ export type CaseVariant = "title" | "body" | "label" | "code" | "upper" | "lower
|
|
|
50
50
|
export type FontVariant = "title" | "body" | "label" | "code" | "serif" | "sans" | "monospace";
|
|
51
51
|
|
|
52
52
|
/**
|
|
53
|
-
* Typographic variant props — colour, font-family, weight, case, size, tint, alignment, and
|
|
53
|
+
* Typographic variant props — colour, font-family, weight, case, size, tint, alignment, wrap, and truncate, applied via `getTypographyClass()`
|
|
54
54
|
*
|
|
55
55
|
* - Extends `ColorVariants`, so anything that accepts typography also accepts the `color` variant.
|
|
56
56
|
*
|
|
@@ -77,12 +77,14 @@ export interface TypographyVariants extends ColorVariants {
|
|
|
77
77
|
wrap?: boolean | undefined;
|
|
78
78
|
/** Disable wrapping. */
|
|
79
79
|
nowrap?: boolean | undefined;
|
|
80
|
+
/** Cut overflowing text to one line with an ellipsis (on a block or a flex item). */
|
|
81
|
+
truncate?: boolean | undefined;
|
|
80
82
|
}
|
|
81
83
|
|
|
82
84
|
/**
|
|
83
85
|
* Get the typography class for a component from its typographic variant props.
|
|
84
86
|
*
|
|
85
|
-
* Maps the colour, size, weight, font, case, tint, alignment, and
|
|
87
|
+
* Maps the colour, size, weight, font, case, tint, alignment, wrap, and truncate variant props to their CSS classes — the `color` variant is composed in via `getColorClass()`.
|
|
86
88
|
*
|
|
87
89
|
* @returns The combined typography class string (empty when no variants apply).
|
|
88
90
|
* @example getTypographyClass({ font: "title", size: "large", center: true })
|
package/ui/style/Width.js
CHANGED
|
@@ -9,5 +9,5 @@ import WIDTH_CSS from "./Width.module.css";
|
|
|
9
9
|
*/
|
|
10
10
|
export function getWidthClass({ width, grow }) {
|
|
11
11
|
if (width || grow)
|
|
12
|
-
return getModuleClass(WIDTH_CSS, "width", width && `width-${width}`, grow && "grow");
|
|
12
|
+
return getModuleClass(WIDTH_CSS, width && "width", width && `width-${width}`, grow && "grow");
|
|
13
13
|
}
|
|
@@ -107,6 +107,7 @@
|
|
|
107
107
|
/* Grow modifier — turn the chosen width into a floor and expand to fill (flex items + table columns). */
|
|
108
108
|
.grow {
|
|
109
109
|
flex-grow: 1;
|
|
110
|
+
min-inline-size: 0; /* Let long content shrink, so it can wrap or truncate. */
|
|
110
111
|
|
|
111
112
|
&:where(td, th) {
|
|
112
113
|
/* Table layouts don't grow unless forced with `width: 100%` */
|
package/ui/style/Width.tsx
CHANGED
|
@@ -52,5 +52,5 @@ export interface WidthVariants {
|
|
|
52
52
|
* @see https://shelving.cc/ui/getWidthClass
|
|
53
53
|
*/
|
|
54
54
|
export function getWidthClass({ width, grow }: WidthVariants): string | undefined {
|
|
55
|
-
if (width || grow) return getModuleClass(WIDTH_CSS, "width", width && `width-${width}`, grow && "grow");
|
|
55
|
+
if (width || grow) return getModuleClass(WIDTH_CSS, width && "width", width && `width-${width}`, grow && "grow");
|
|
56
56
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# getGridClass
|
|
2
|
+
|
|
3
|
+
The grid variant props lay out a component's children in equal-width columns — `<Grid columns={3}>`. Use them for tiles, cards, badges, or a calendar of days.
|
|
4
|
+
|
|
5
|
+
`getGridClass({ columns, gap })` maps the props to grid classes (e.g. `columns={3}` → `columns-3`) and composes `getGapClass()` for the `gap` prop.
|
|
6
|
+
|
|
7
|
+
**Values:**
|
|
8
|
+
|
|
9
|
+
- `columns` — `1` to `8` equal-width columns. The default is `2`.
|
|
10
|
+
- `gap` — the space between cells, from the same scale as `getGapClass()`. The default is `--space-small`.
|
|
11
|
+
|
|
12
|
+
**Things to know:**
|
|
13
|
+
|
|
14
|
+
- Each column is `minmax(0, 1fr)`, so long content cannot push a column wider than the others. Use `truncate` (see `getTypographyClass()`) or wrapping to fit long text.
|
|
15
|
+
- The grid sets the outer margin of each child to `0`, so a child's `space` variant has no effect inside the grid. Use `gap` to space the cells.
|
|
16
|
+
- The grid removes list markers, so you can render it as a `<ul>` or `<ol>` with `<li>` children.
|
|
17
|
+
|
|
18
|
+
## Styling
|
|
19
|
+
|
|
20
|
+
| Variable | Styles | Default |
|
|
21
|
+
|---|---|---|
|
|
22
|
+
| `--grid-gap` | Space between cells when no `gap` is set | `var(--space-small)` (12px) |
|
|
23
|
+
|
|
24
|
+
**Global tokens it reads:** `--space-small`, plus the `--space-*` token of the `gap` variant.
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
The typography variant props set an element's text styling from a single helper — `<Heading font="title" size="large">`, `<Paragraph weight="strong" center>`, `<Small case="upper">`. They're **overrides** for one-off changes; for an app-wide change, retune the variables below in a theme file.
|
|
4
4
|
|
|
5
|
-
`getTypographyClass({ color, size, weight, font, case, tint, left, center, right, wrap, nowrap })` maps each prop to a class (e.g. `size="large"` → `size-large`, `font="title"` → `font-title`, `weight="strong"` → `weight-strong`, `case="upper"` → `case-upper`), and combines them with text alignment, tint colour, and
|
|
5
|
+
`getTypographyClass({ color, size, weight, font, case, tint, left, center, right, wrap, nowrap, truncate })` maps each prop to a class (e.g. `size="large"` → `size-large`, `font="title"` → `font-title`, `weight="strong"` → `weight-strong`, `case="upper"` → `case-upper`), and combines them with text alignment, tint colour, wrapping, and truncation. `TypographyVariants` extends `ColorVariants`, so it also accepts `color` and composes [`getColorClass()`](/ui/getColorClass) internally — anything that opts into typography gets the `color` variant for free and no longer needs to extend `ColorVariants` or call `getColorClass()` separately. (`getColorClass()` stays exported for the rare element that wants colour without typography, such as `<Icon>`.) It also supersedes the former `getFontClass()`, `getSizeClass()`, and `getWeightClass()` helpers, which were merged into this module.
|
|
6
|
+
|
|
7
|
+
The `truncate` flag cuts overflowing text to one line and ends it with an ellipsis. It works on a block element or a flex item, not on inline text. When the text is inside a wrapper that is a flex item, give that wrapper `grow` (see `getWidthClass()`), so it can shrink below the width of the text.
|
|
6
8
|
|
|
7
9
|
The semantic faces, weights, sizes, and cases are aliases of the base values, so a theme usually only needs to move the small set of base variables.
|
|
8
10
|
|
|
@@ -11,7 +11,11 @@ The `width` variant prop sets a component's inline-size — `<Card width="narrow
|
|
|
11
11
|
- `fit` — shrink to the content's intrinsic width (`fit-content`).
|
|
12
12
|
- `1x` / `2x` / `3x` / `4x` / `5x` / `6x` / `7x` / `8x` / `10x` / `12x` / `16x` / `20x` / `24x` / `28x` / `32x` — fixed multiples of `--space-normal` (no per-step variables; calculated directly).
|
|
13
13
|
|
|
14
|
-
**The `grow` flag**
|
|
14
|
+
**The `grow` flag** lets the element expand past its `width`:
|
|
15
|
+
|
|
16
|
+
- On a flex item it adds `flex-grow: 1`, so the item fills the free space. It also sets `min-inline-size: 0`, so long content can shrink the item and wrap or truncate (see `truncate` in `getTypographyClass()`).
|
|
17
|
+
- `grow` works without `width`. On its own it adds only the grow class, so the element does not pick up a `--width` from an ancestor.
|
|
18
|
+
- On a `<Cell>` it turns the chosen `width` into a floor: it applies the value as `min-width`. Set `width="12x" grow` to give that column a 192px minimum that absorbs the remaining width and keeps the table from collapsing the column on a narrow viewport — cells honour `min-width`, so the table scrolls instead.
|
|
15
19
|
|
|
16
20
|
## Theme variables
|
|
17
21
|
|
package/ui/style/index.d.ts
CHANGED
package/ui/style/index.js
CHANGED
package/ui/style/index.ts
CHANGED
package/ui/style/layers.css
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* body baseline. Low-priority opt-in defaults.
|
|
10
10
|
* • `components` — component-defining CSS. The bulk of the codebase.
|
|
11
11
|
* • `variants` — cross-cutting opt-in modifiers (Color, Status, Space, Padding, Gap, Width, Typography,
|
|
12
|
-
* Flex, Scroll). Always beat components.
|
|
12
|
+
* Flex, Grid, Scroll). Always beat components.
|
|
13
13
|
* • `overrides` — top-priority structural overrides like `:first-child` / `:last-child` margin collapses,
|
|
14
14
|
* which must beat variant-set margins.
|
|
15
15
|
*
|
package/ui/util/css.test.ts
CHANGED
|
@@ -58,8 +58,8 @@ describe("Bun CSS modules", () => {
|
|
|
58
58
|
expect(css).toContain(`animation-name: ${name};`);
|
|
59
59
|
});
|
|
60
60
|
|
|
61
|
-
//
|
|
62
|
-
test("
|
|
61
|
+
// Before Bun 1.4.3, Bun hashed a class inside `::view-transition-*()` from the file basename but hashed exports from the path, so the two never matched in a real build. Bun 1.4.3 fixes it, so the view-transition classes can move into their `.module.css` files (see dhoulb/shelving#325).
|
|
62
|
+
test("hashes a view-transition class to match its export from Bun 1.4.3", async () => {
|
|
63
63
|
const dir = await mkdtemp(join(tmpdir(), "shelving-css-"));
|
|
64
64
|
try {
|
|
65
65
|
const path = join(dir, "sub", "canary.module.css");
|
|
@@ -68,7 +68,8 @@ describe("Bun CSS modules", () => {
|
|
|
68
68
|
expect(exports.plain).toBeString();
|
|
69
69
|
expect(exports.vt).toBeString();
|
|
70
70
|
expect(css).toContain(`.${exports.plain}`);
|
|
71
|
-
expect(css).
|
|
71
|
+
if (Bun.semver.satisfies(Bun.version, ">=1.4.3")) expect(css).toContain(`(.${exports.vt})`);
|
|
72
|
+
else expect(css).not.toContain(`(.${exports.vt})`);
|
|
72
73
|
} finally {
|
|
73
74
|
await rm(dir, { recursive: true, force: true });
|
|
74
75
|
}
|