shelving 1.293.0 → 1.295.0
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/button/Clickable.d.ts +3 -1
- package/ui/button/Clickable.js +2 -2
- package/ui/button/Clickable.tsx +4 -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/router/Navigation.d.ts +1 -1
- package/ui/router/Navigation.js +10 -8
- package/ui/router/Navigation.md +7 -2
- package/ui/router/Navigation.test.tsx +12 -1
- package/ui/router/Navigation.tsx +9 -9
- package/ui/router/NavigationStore.d.ts +15 -0
- package/ui/router/NavigationStore.js +20 -0
- package/ui/router/NavigationStore.md +1 -0
- package/ui/router/NavigationStore.tsx +23 -0
- 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/button/Clickable.d.ts
CHANGED
|
@@ -32,6 +32,8 @@ export interface ClickableProps extends OptionalChildProps {
|
|
|
32
32
|
title?: string | undefined;
|
|
33
33
|
/** Whether this is the selected item in a group. Sets `aria-pressed` on a `<button>`, or `aria-current` on an `<a>`. */
|
|
34
34
|
selected?: boolean | undefined;
|
|
35
|
+
/** If `href` is present, then `<Navigation>` opens the link with a back transition. Use it for a "back to" link. Sets `data-back` on the `<a>`. */
|
|
36
|
+
back?: boolean | undefined;
|
|
35
37
|
}
|
|
36
38
|
/**
|
|
37
39
|
* Props for a clickable that also accepts a `className` for styling.
|
|
@@ -59,7 +61,7 @@ export declare function Clickable(props: StylableClickableProps): ReactElement;
|
|
|
59
61
|
* @example <LinkClickable href="/about" className="link">About</LinkClickable>
|
|
60
62
|
* @see https://shelving.cc/ui/LinkClickable
|
|
61
63
|
*/
|
|
62
|
-
export declare function LinkClickable({ href, disabled, target, download, title, selected, children, className, }: StylableClickableProps): ReactElement;
|
|
64
|
+
export declare function LinkClickable({ href, disabled, target, download, title, selected, back, children, className, }: StylableClickableProps): ReactElement;
|
|
63
65
|
/**
|
|
64
66
|
* Render a `<button>` element that runs its `onClick` handler through a `BusyStore` and shows a loading spinner while busy.
|
|
65
67
|
* - Notifies the user of the handler's returned value (success) or thrown value (error).
|
package/ui/button/Clickable.js
CHANGED
|
@@ -29,13 +29,13 @@ export function Clickable(props) {
|
|
|
29
29
|
* @example <LinkClickable href="/about" className="link">About</LinkClickable>
|
|
30
30
|
* @see https://shelving.cc/ui/LinkClickable
|
|
31
31
|
*/
|
|
32
|
-
export function LinkClickable({ href, disabled = !href, target, download, title, selected, children = "Go", className, }) {
|
|
32
|
+
export function LinkClickable({ href, disabled = !href, target, download, title, selected, back, children = "Go", className, }) {
|
|
33
33
|
// Resolve `href` against the current page URL and site root so site-absolute paths (`/foo`) honour the base subfolder.
|
|
34
34
|
const { url, root } = requireMeta();
|
|
35
35
|
const link = disabled ? undefined : getLink(href, url, root);
|
|
36
36
|
// Is this link "active" compared to the current URL?
|
|
37
37
|
const active = isURLActive(link, url);
|
|
38
|
-
return (_jsx("a", { href: link?.href, title: title, download: download, target: target, className: getClass(className) || undefined, "aria-current": active ? "page" : selected ? "true" : undefined, children: children }));
|
|
38
|
+
return (_jsx("a", { href: link?.href, title: title, download: download, target: target, className: getClass(className) || undefined, "aria-current": active ? "page" : selected ? "true" : undefined, "data-back": back || undefined, children: children }));
|
|
39
39
|
}
|
|
40
40
|
/**
|
|
41
41
|
* Render a `<button>` element that runs its `onClick` handler through a `BusyStore` and shows a loading spinner while busy.
|
package/ui/button/Clickable.tsx
CHANGED
|
@@ -43,6 +43,8 @@ export interface ClickableProps extends OptionalChildProps {
|
|
|
43
43
|
title?: string | undefined;
|
|
44
44
|
/** Whether this is the selected item in a group. Sets `aria-pressed` on a `<button>`, or `aria-current` on an `<a>`. */
|
|
45
45
|
selected?: boolean | undefined;
|
|
46
|
+
/** If `href` is present, then `<Navigation>` opens the link with a back transition. Use it for a "back to" link. Sets `data-back` on the `<a>`. */
|
|
47
|
+
back?: boolean | undefined;
|
|
46
48
|
}
|
|
47
49
|
|
|
48
50
|
/**
|
|
@@ -87,6 +89,7 @@ export function LinkClickable({
|
|
|
87
89
|
download,
|
|
88
90
|
title,
|
|
89
91
|
selected,
|
|
92
|
+
back,
|
|
90
93
|
children = "Go",
|
|
91
94
|
className,
|
|
92
95
|
}: StylableClickableProps): ReactElement {
|
|
@@ -105,6 +108,7 @@ export function LinkClickable({
|
|
|
105
108
|
target={target}
|
|
106
109
|
className={getClass(className) || undefined}
|
|
107
110
|
aria-current={active ? "page" : selected ? "true" : undefined}
|
|
111
|
+
data-back={back || undefined}
|
|
108
112
|
>
|
|
109
113
|
{children}
|
|
110
114
|
</a>
|
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
|
)}
|
|
@@ -11,7 +11,7 @@ export interface NavigationProps extends PossibleMeta, OptionalChildProps {
|
|
|
11
11
|
/**
|
|
12
12
|
* Top-level navigation provider.
|
|
13
13
|
* - Owns a single `NavigationStore` initialised from the surrounding `<Meta>` url/base.
|
|
14
|
-
* - Intercepts same-origin anchor clicks (excluding `download` anchors) and turns them into `forward()` calls.
|
|
14
|
+
* - Intercepts same-origin anchor clicks (excluding `download` anchors) and turns them into `forward()` calls, or `back()` calls for an anchor with a `data-back` attribute.
|
|
15
15
|
* - Listens for `popstate` to sync the store with browser back/forward.
|
|
16
16
|
* - Publishes the live URL into the `Meta` context via `mergeMeta()`, so descendant `<Router>`s re-render on navigation and merge invariants hold (e.g. `root` defaults to the live URL's origin when unset).
|
|
17
17
|
* - Publishes each URL change inside `startTransition()` with a `"forward"` or `"back"` transition type, so a `<Transition>` around the routes runs a view transition.
|
package/ui/router/Navigation.js
CHANGED
|
@@ -9,7 +9,7 @@ import { NavigationStore } from "./NavigationStore.js";
|
|
|
9
9
|
/**
|
|
10
10
|
* Top-level navigation provider.
|
|
11
11
|
* - Owns a single `NavigationStore` initialised from the surrounding `<Meta>` url/base.
|
|
12
|
-
* - Intercepts same-origin anchor clicks (excluding `download` anchors) and turns them into `forward()` calls.
|
|
12
|
+
* - Intercepts same-origin anchor clicks (excluding `download` anchors) and turns them into `forward()` calls, or `back()` calls for an anchor with a `data-back` attribute.
|
|
13
13
|
* - Listens for `popstate` to sync the store with browser back/forward.
|
|
14
14
|
* - Publishes the live URL into the `Meta` context via `mergeMeta()`, so descendant `<Router>`s re-render on navigation and merge invariants hold (e.g. `root` defaults to the live URL's origin when unset).
|
|
15
15
|
* - Publishes each URL change inside `startTransition()` with a `"forward"` or `"back"` transition type, so a `<Transition>` around the routes runs a view transition.
|
|
@@ -31,12 +31,10 @@ export function Navigation({ children, ...meta }) {
|
|
|
31
31
|
useEffect(() => {
|
|
32
32
|
if (typeof document === "undefined" || typeof window === "undefined")
|
|
33
33
|
return;
|
|
34
|
-
//
|
|
35
|
-
// `null` means no transition, because the browser already animated the change (e.g. a swipe-back gesture).
|
|
36
|
-
let type = "forward";
|
|
34
|
+
// Read the transition type the store set for this change, then reset it.
|
|
37
35
|
const stop = nav.subscribe(value => {
|
|
38
|
-
const t =
|
|
39
|
-
|
|
36
|
+
const t = nav.transition;
|
|
37
|
+
nav.transition = "forward";
|
|
40
38
|
if (!t)
|
|
41
39
|
return setURL(value);
|
|
42
40
|
// React renders a transition that starts inside a `popstate` event as a sync update with no view transition, so leave the event first.
|
|
@@ -51,15 +49,19 @@ export function Navigation({ children, ...meta }) {
|
|
|
51
49
|
(!e.target.closest("button, label") && e.target.closest(".targeted")?.querySelector("a.target[href]"));
|
|
52
50
|
if (anchor instanceof HTMLAnchorElement && anchor.origin === window.location.origin && !anchor.hasAttribute("download")) {
|
|
53
51
|
e.preventDefault();
|
|
54
|
-
|
|
52
|
+
if (anchor.hasAttribute("data-back"))
|
|
53
|
+
nav.back(anchor.href);
|
|
54
|
+
else
|
|
55
|
+
nav.forward(anchor.href);
|
|
55
56
|
return false; // `return false` stops iOS web app opening every link in a new window.
|
|
56
57
|
}
|
|
57
58
|
}
|
|
58
59
|
};
|
|
59
60
|
const onPopState = (e) => {
|
|
60
61
|
const href = window.location.href;
|
|
62
|
+
// `"back"` for a `popstate`. `null` means no transition, because the browser already animated the change (e.g. a swipe-back gesture).
|
|
61
63
|
if (href !== nav.value.href)
|
|
62
|
-
|
|
64
|
+
nav.transition = e.hasUAVisualTransition ? null : "back";
|
|
63
65
|
nav.value = href;
|
|
64
66
|
};
|
|
65
67
|
document.addEventListener("click", onClick);
|
package/ui/router/Navigation.md
CHANGED
|
@@ -5,8 +5,9 @@ The top-level navigation provider for a client-side app. It owns a single `Navig
|
|
|
5
5
|
**Things to know:**
|
|
6
6
|
|
|
7
7
|
- Same-origin anchor clicks are intercepted automatically and turned into `forward()` calls. Add a `download` attribute to an anchor to opt out.
|
|
8
|
+
- An anchor with a `data-back` attribute calls `back()` instead, so the page slides back. Set it with the `back` prop on `<Button>` or `<Link>`, e.g. on a "Back to profile" button.
|
|
8
9
|
- It listens for `popstate` so the store stays in sync with browser back/forward.
|
|
9
|
-
- It publishes each page change inside `startTransition()`, so a `<Transition>` around the routes animates it. A link click, `NavigationStore.forward()` or `NavigationStore.redirect()` sets the `"forward"` transition type.
|
|
10
|
+
- It publishes each page change inside `startTransition()`, so a `<Transition>` around the routes animates it. A link click, `NavigationStore.forward()` or `NavigationStore.redirect()` sets the `"forward"` transition type. A `data-back` link click, `NavigationStore.back()`, and the browser back or forward button set `"back"` (`popstate` does not say which way it went).
|
|
10
11
|
- When the browser already animated the change, for example a swipe-back gesture on a phone, there is no view transition, so the page does not slide twice. The browser says so with `hasUAVisualTransition` on the `popstate` event. Other browsers still slide.
|
|
11
12
|
- The `popstate` update waits for the next task (`setTimeout()`). React renders a transition that starts inside `popstate` as a sync update with no view transition.
|
|
12
13
|
- It initialises the store from the surrounding `<Meta>` url/base, so set those on an ancestor `<App>` / `<HTML>` / `<Page>`. In the browser the store falls back to `window.location.href` when no url is set.
|
|
@@ -30,12 +31,15 @@ import { HTML, Navigation, Router } from "shelving/ui";
|
|
|
30
31
|
```tsx
|
|
31
32
|
import { HorizontalTransition, Navigation, Router } from "shelving/ui";
|
|
32
33
|
|
|
33
|
-
// Links slide right
|
|
34
|
+
// Links slide right. Back links and the browser back button slide left.
|
|
34
35
|
<Navigation>
|
|
35
36
|
<HorizontalTransition>
|
|
36
37
|
<Router routes={ROUTES}/>
|
|
37
38
|
</HorizontalTransition>
|
|
38
39
|
</Navigation>
|
|
40
|
+
|
|
41
|
+
// A "back to" link slides left too.
|
|
42
|
+
<Button href="/profile" back>Back to profile</Button>
|
|
39
43
|
```
|
|
40
44
|
|
|
41
45
|
### Imperative navigation
|
|
@@ -48,4 +52,5 @@ import { requireNavigation } from "shelving/ui";
|
|
|
48
52
|
const nav = requireNavigation();
|
|
49
53
|
nav.forward("/users/123"); // push a new history entry
|
|
50
54
|
nav.redirect("/login"); // replace the current history entry
|
|
55
|
+
nav.back("/users"); // push a new history entry that slides back
|
|
51
56
|
```
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { describe, expect, test } from "bun:test";
|
|
2
2
|
import type { ReactNode } from "react";
|
|
3
3
|
import { renderToStaticMarkup } from "react-dom/server";
|
|
4
|
-
import { Navigation, requireMetaURL } from "shelving/ui";
|
|
4
|
+
import { Button, Navigation, requireMetaURL } from "shelving/ui";
|
|
5
5
|
|
|
6
6
|
/** Render `requireMetaURL().path` from inside a component so its `use(MetaContext)` call is valid. */
|
|
7
7
|
function Probe(): ReactNode {
|
|
@@ -26,4 +26,15 @@ describe("Navigation", () => {
|
|
|
26
26
|
);
|
|
27
27
|
expect(html).toBe("/sub");
|
|
28
28
|
});
|
|
29
|
+
|
|
30
|
+
test("marks a back link with a data-back attribute", () => {
|
|
31
|
+
const html = renderToStaticMarkup(
|
|
32
|
+
<Navigation url="http://x.com/a">
|
|
33
|
+
<Button href="/b" back>
|
|
34
|
+
Back
|
|
35
|
+
</Button>
|
|
36
|
+
</Navigation>,
|
|
37
|
+
);
|
|
38
|
+
expect(html).toContain('data-back="true"');
|
|
39
|
+
});
|
|
29
40
|
});
|
package/ui/router/Navigation.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type ReactElement, startTransition, useEffect, useState } from "react";
|
|
2
2
|
import { useInstance } from "../../react/useInstance.js";
|
|
3
3
|
import { MetaContext, requireMeta } from "../misc/MetaContext.js";
|
|
4
|
-
import { setTransitionType
|
|
4
|
+
import { setTransitionType } from "../transition/util.js";
|
|
5
5
|
import { mergeMeta, type PossibleMeta } from "../util/index.js";
|
|
6
6
|
import type { OptionalChildProps } from "../util/props.js";
|
|
7
7
|
import { NavigationContext } from "./NavigationContext.js";
|
|
@@ -17,7 +17,7 @@ export interface NavigationProps extends PossibleMeta, OptionalChildProps {}
|
|
|
17
17
|
/**
|
|
18
18
|
* Top-level navigation provider.
|
|
19
19
|
* - Owns a single `NavigationStore` initialised from the surrounding `<Meta>` url/base.
|
|
20
|
-
* - Intercepts same-origin anchor clicks (excluding `download` anchors) and turns them into `forward()` calls.
|
|
20
|
+
* - Intercepts same-origin anchor clicks (excluding `download` anchors) and turns them into `forward()` calls, or `back()` calls for an anchor with a `data-back` attribute.
|
|
21
21
|
* - Listens for `popstate` to sync the store with browser back/forward.
|
|
22
22
|
* - Publishes the live URL into the `Meta` context via `mergeMeta()`, so descendant `<Router>`s re-render on navigation and merge invariants hold (e.g. `root` defaults to the live URL's origin when unset).
|
|
23
23
|
* - Publishes each URL change inside `startTransition()` with a `"forward"` or `"back"` transition type, so a `<Transition>` around the routes runs a view transition.
|
|
@@ -41,12 +41,10 @@ export function Navigation({ children, ...meta }: NavigationProps): ReactElement
|
|
|
41
41
|
useEffect(() => {
|
|
42
42
|
if (typeof document === "undefined" || typeof window === "undefined") return;
|
|
43
43
|
|
|
44
|
-
//
|
|
45
|
-
// `null` means no transition, because the browser already animated the change (e.g. a swipe-back gesture).
|
|
46
|
-
let type: TransitionType | null = "forward";
|
|
44
|
+
// Read the transition type the store set for this change, then reset it.
|
|
47
45
|
const stop = nav.subscribe(value => {
|
|
48
|
-
const t =
|
|
49
|
-
|
|
46
|
+
const t = nav.transition;
|
|
47
|
+
nav.transition = "forward";
|
|
50
48
|
if (!t) return setURL(value);
|
|
51
49
|
// React renders a transition that starts inside a `popstate` event as a sync update with no view transition, so leave the event first.
|
|
52
50
|
setTimeout(() =>
|
|
@@ -64,14 +62,16 @@ export function Navigation({ children, ...meta }: NavigationProps): ReactElement
|
|
|
64
62
|
(!e.target.closest("button, label") && e.target.closest(".targeted")?.querySelector<HTMLAnchorElement>("a.target[href]"));
|
|
65
63
|
if (anchor instanceof HTMLAnchorElement && anchor.origin === window.location.origin && !anchor.hasAttribute("download")) {
|
|
66
64
|
e.preventDefault();
|
|
67
|
-
nav.
|
|
65
|
+
if (anchor.hasAttribute("data-back")) nav.back(anchor.href);
|
|
66
|
+
else nav.forward(anchor.href);
|
|
68
67
|
return false; // `return false` stops iOS web app opening every link in a new window.
|
|
69
68
|
}
|
|
70
69
|
}
|
|
71
70
|
};
|
|
72
71
|
const onPopState = (e: PopStateEvent) => {
|
|
73
72
|
const href = window.location.href;
|
|
74
|
-
|
|
73
|
+
// `"back"` for a `popstate`. `null` means no transition, because the browser already animated the change (e.g. a swipe-back gesture).
|
|
74
|
+
if (href !== nav.value.href) nav.transition = e.hasUAVisualTransition ? null : "back";
|
|
75
75
|
nav.value = href;
|
|
76
76
|
};
|
|
77
77
|
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import { URLStore } from "../../store/URLStore.js";
|
|
2
2
|
import { type PossibleURL } from "../../util/url.js";
|
|
3
|
+
import type { TransitionType } from "../transition/util.js";
|
|
3
4
|
/**
|
|
4
5
|
* Store holding the current navigation URL and driving browser history.
|
|
5
6
|
*
|
|
6
7
|
* - Extends `URLStore`; the current location is its `value`.
|
|
7
8
|
* - `forward()` pushes a new history entry; `redirect()` replaces the current one.
|
|
9
|
+
* - `back()` pushes a new history entry like `forward()`, but `<Navigation>` animates it as a back transition.
|
|
8
10
|
* - TODO: switch to the browser Navigation API when broadly supported.
|
|
9
11
|
*
|
|
10
12
|
* @see https://shelving.cc/ui/NavigationStore
|
|
11
13
|
*/
|
|
12
14
|
export declare class NavigationStore extends URLStore {
|
|
15
|
+
/** Transition type of the next URL change. `null` means no transition. `<Navigation>` reads it, then sets it back to `"forward"`. */
|
|
16
|
+
transition: TransitionType | null;
|
|
13
17
|
constructor(url?: PossibleURL, base?: PossibleURL);
|
|
14
18
|
/**
|
|
15
19
|
* Navigate forward to a URL, pushing a new browser history entry.
|
|
@@ -29,4 +33,15 @@ export declare class NavigationStore extends URLStore {
|
|
|
29
33
|
* @see https://shelving.cc/ui/NavigationStore/redirect
|
|
30
34
|
*/
|
|
31
35
|
redirect(possible: PossibleURL): void;
|
|
36
|
+
/**
|
|
37
|
+
* Navigate back to a URL, pushing a new browser history entry with the `"back"` transition type.
|
|
38
|
+
* - Use it for a "back to" link, so the page slides back, not forward.
|
|
39
|
+
* - It does not go back in the browser history, so it also works when the page was opened directly.
|
|
40
|
+
*
|
|
41
|
+
* @param possible The destination URL, resolved against `base`.
|
|
42
|
+
* @throws RequiredError If `possible` cannot be resolved to a valid URL.
|
|
43
|
+
* @example nav.back("/profile");
|
|
44
|
+
* @see https://shelving.cc/ui/NavigationStore/back
|
|
45
|
+
*/
|
|
46
|
+
back(possible: PossibleURL): void;
|
|
32
47
|
}
|
|
@@ -5,11 +5,14 @@ import { requireURL } from "../../util/url.js";
|
|
|
5
5
|
*
|
|
6
6
|
* - Extends `URLStore`; the current location is its `value`.
|
|
7
7
|
* - `forward()` pushes a new history entry; `redirect()` replaces the current one.
|
|
8
|
+
* - `back()` pushes a new history entry like `forward()`, but `<Navigation>` animates it as a back transition.
|
|
8
9
|
* - TODO: switch to the browser Navigation API when broadly supported.
|
|
9
10
|
*
|
|
10
11
|
* @see https://shelving.cc/ui/NavigationStore
|
|
11
12
|
*/
|
|
12
13
|
export class NavigationStore extends URLStore {
|
|
14
|
+
/** Transition type of the next URL change. `null` means no transition. `<Navigation>` reads it, then sets it back to `"forward"`. */
|
|
15
|
+
transition = "forward";
|
|
13
16
|
constructor(url = typeof window === "undefined" ? "/" : window.location.href, base) {
|
|
14
17
|
super(url, base);
|
|
15
18
|
}
|
|
@@ -22,6 +25,7 @@ export class NavigationStore extends URLStore {
|
|
|
22
25
|
* @see https://shelving.cc/ui/NavigationStore/forward
|
|
23
26
|
*/
|
|
24
27
|
forward(possible) {
|
|
28
|
+
this.transition = "forward";
|
|
25
29
|
this.value = requireURL(possible, this.base, this.forward);
|
|
26
30
|
window.history.pushState(null, "", this.value);
|
|
27
31
|
}
|
|
@@ -34,7 +38,23 @@ export class NavigationStore extends URLStore {
|
|
|
34
38
|
* @see https://shelving.cc/ui/NavigationStore/redirect
|
|
35
39
|
*/
|
|
36
40
|
redirect(possible) {
|
|
41
|
+
this.transition = "forward";
|
|
37
42
|
this.value = requireURL(possible, this.base, this.redirect);
|
|
38
43
|
window.history.replaceState(null, "", this.value);
|
|
39
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Navigate back to a URL, pushing a new browser history entry with the `"back"` transition type.
|
|
47
|
+
* - Use it for a "back to" link, so the page slides back, not forward.
|
|
48
|
+
* - It does not go back in the browser history, so it also works when the page was opened directly.
|
|
49
|
+
*
|
|
50
|
+
* @param possible The destination URL, resolved against `base`.
|
|
51
|
+
* @throws RequiredError If `possible` cannot be resolved to a valid URL.
|
|
52
|
+
* @example nav.back("/profile");
|
|
53
|
+
* @see https://shelving.cc/ui/NavigationStore/back
|
|
54
|
+
*/
|
|
55
|
+
back(possible) {
|
|
56
|
+
this.transition = "back";
|
|
57
|
+
this.value = requireURL(possible, this.base, this.back);
|
|
58
|
+
window.history.pushState(null, "", this.value);
|
|
59
|
+
}
|
|
40
60
|
}
|
|
@@ -5,6 +5,7 @@ The store holding the current navigation URL and driving browser history. It ext
|
|
|
5
5
|
**Things to know:**
|
|
6
6
|
|
|
7
7
|
- `forward()` pushes a new browser history entry; `redirect()` replaces the current one. Both resolve the destination against the store's `base`.
|
|
8
|
+
- `back()` pushes a new browser history entry like `forward()`, but `<Navigation>` gives it the `"back"` transition type, so the page slides back. It does not go back in the browser history, so it works when the page was opened directly.
|
|
8
9
|
- It is a `shelving/store` `URLStore`, so components can subscribe to it for re-renders.
|
|
9
10
|
|
|
10
11
|
## Usage
|
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
import { URLStore } from "../../store/URLStore.js";
|
|
2
2
|
import { type PossibleURL, requireURL } from "../../util/url.js";
|
|
3
|
+
import type { TransitionType } from "../transition/util.js";
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Store holding the current navigation URL and driving browser history.
|
|
6
7
|
*
|
|
7
8
|
* - Extends `URLStore`; the current location is its `value`.
|
|
8
9
|
* - `forward()` pushes a new history entry; `redirect()` replaces the current one.
|
|
10
|
+
* - `back()` pushes a new history entry like `forward()`, but `<Navigation>` animates it as a back transition.
|
|
9
11
|
* - TODO: switch to the browser Navigation API when broadly supported.
|
|
10
12
|
*
|
|
11
13
|
* @see https://shelving.cc/ui/NavigationStore
|
|
12
14
|
*/
|
|
13
15
|
export class NavigationStore extends URLStore {
|
|
16
|
+
/** Transition type of the next URL change. `null` means no transition. `<Navigation>` reads it, then sets it back to `"forward"`. */
|
|
17
|
+
transition: TransitionType | null = "forward";
|
|
18
|
+
|
|
14
19
|
constructor(url: PossibleURL = typeof window === "undefined" ? "/" : window.location.href, base?: PossibleURL) {
|
|
15
20
|
super(url, base);
|
|
16
21
|
}
|
|
@@ -24,6 +29,7 @@ export class NavigationStore extends URLStore {
|
|
|
24
29
|
* @see https://shelving.cc/ui/NavigationStore/forward
|
|
25
30
|
*/
|
|
26
31
|
forward(possible: PossibleURL): void {
|
|
32
|
+
this.transition = "forward";
|
|
27
33
|
this.value = requireURL(possible, this.base, this.forward);
|
|
28
34
|
window.history.pushState(null, "", this.value);
|
|
29
35
|
}
|
|
@@ -37,7 +43,24 @@ export class NavigationStore extends URLStore {
|
|
|
37
43
|
* @see https://shelving.cc/ui/NavigationStore/redirect
|
|
38
44
|
*/
|
|
39
45
|
redirect(possible: PossibleURL): void {
|
|
46
|
+
this.transition = "forward";
|
|
40
47
|
this.value = requireURL(possible, this.base, this.redirect);
|
|
41
48
|
window.history.replaceState(null, "", this.value);
|
|
42
49
|
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Navigate back to a URL, pushing a new browser history entry with the `"back"` transition type.
|
|
53
|
+
* - Use it for a "back to" link, so the page slides back, not forward.
|
|
54
|
+
* - It does not go back in the browser history, so it also works when the page was opened directly.
|
|
55
|
+
*
|
|
56
|
+
* @param possible The destination URL, resolved against `base`.
|
|
57
|
+
* @throws RequiredError If `possible` cannot be resolved to a valid URL.
|
|
58
|
+
* @example nav.back("/profile");
|
|
59
|
+
* @see https://shelving.cc/ui/NavigationStore/back
|
|
60
|
+
*/
|
|
61
|
+
back(possible: PossibleURL): void {
|
|
62
|
+
this.transition = "back";
|
|
63
|
+
this.value = requireURL(possible, this.base, this.back);
|
|
64
|
+
window.history.pushState(null, "", this.value);
|
|
65
|
+
}
|
|
43
66
|
}
|
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
|
}
|