@slashsuite/ui-react 0.13.0 → 0.13.2

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.
@@ -82,6 +82,6 @@ Left out, the part takes the nearest loading layout's or part's; `false` opts it
82
82
  - FlowDirection: `"down" | "right"`. `down` reads from the top, `right` from the start edge.
83
83
  - FlowLayout: `{ width: number; height: number; nodes: readonly FlowNodeBox[]; groups: readonly (FlowBox & { name: string })[]; edges: readonly FlowEdgePath[] }`. The whole diagram as laid out, in one coordinate space: `width` and `height`, a box per node and per group, and a path per arrow. `FlowDiagram` hands it to `overlay`.
84
84
  - FlowNodeBox: `{ x: number; y: number; width: number; height: number; id: string }`. A node as laid out: its `id` and its box. A group's box (`group`) is the frame round its nodes.
85
- - FlowEdgePath: `{ from: string; to: string; index: number; points: readonly FlowPoint[]; path: string; labelAt: FlowPoint | null }`. An arrow as laid out: the `from` and `to` ids, its place in `edges` (`index`), the points dagre routed it through, the SVG path drawn through them (it ends on the target's edge, at the arrowhead's tip) and its label's centre when it has one.
85
+ - FlowEdgePath: `{ from: string; to: string; index: number; points: readonly FlowPoint[]; path: string; labelAt: FlowPoint | null }`. An arrow as laid out: the `from` and `to` ids, its place in `edges` (`index`), the corners of its square route (it leaves the source's side facing the way it goes, turns only between ranks, and ends on the target's edge, at the arrowhead's tip), the SVG path through them and its label's centre when it has one.
86
86
  - FlowBox: `{ x: number; y: number; width: number; height: number }`. Where a node or a group sits, its top left corner and its size, in CSS pixels.
87
87
  - FlowPoint: `{ x: number; y: number }`. A point in the diagram's own space, in CSS pixels from its top left corner.
package/dist/Button.d.ts CHANGED
@@ -12,9 +12,10 @@ export type ButtonSize = Size;
12
12
  export type ButtonTone = Extract<Tone, "neutral" | "positive" | "danger">;
13
13
  /** The padding table and its `md:` twin, for the data test. */
14
14
  export declare const buttonSizeTables: {
15
- box: Record<Size, string>;
16
- boxMd: Record<Size, string>;
15
+ box: Record<import("./core/index.js").ButtonSize, string>;
16
+ boxMd: Record<import("./core/index.js").ButtonSize, string>;
17
17
  };
18
+ /** The count chip's classes (a Badge's size, in the button's own text colour). */
18
19
  export declare const COUNT = "inline-flex min-h-4 min-w-4 items-center justify-center rounded-full border border-current px-1 text-[0.625rem]/[1.4] font-semibold tabular-nums";
19
20
  /** Size, tone and variant: the look of a button, apart from its state. */
20
21
  type ButtonLook = {
package/dist/Button.js CHANGED
@@ -1,102 +1,23 @@
1
1
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { BUTTON_BLOCKED, BUTTON_BLOCKED_BY_VARIANT, BUTTON_BOX, BUTTON_BOX_MD, BUTTON_BUSY, BUTTON_COUNT, BUTTON_DASHED_BOX, BUTTON_DISABLED_PLAIN, BUTTON_LINK_GAP, BUTTON_SHAPE, buttonLook, } from "./core/index.js";
2
3
  import { cx, focusRing } from "./cx.js";
3
4
  import { controlText, useResponsiveDensity, useTypeStep } from "./density.js";
4
5
  import { Icon } from "./Icon.js";
5
6
  import { hasReason, useBlocked } from "./blocked.js";
6
7
  import { renderLink } from "./link.js";
7
8
  import { sizeClass } from "./size.js";
8
- const SHAPE = "inline-flex items-center justify-center rounded-lg border font-medium transition";
9
- // Size sets the padding; the text is `controlText`'s, from the size and the type step. The link
10
- // variant has no box, so it takes the text size only.
11
- const BOX = {
12
- sm: "gap-1.5 px-2.5 py-1",
13
- md: "gap-2 px-4 py-2",
14
- lg: "gap-2 px-5 py-2.5",
15
- };
16
- // `BOX` from the `md` breakpoint up, for a responsive size, every class written out in full.
17
- const BOX_MD = {
18
- sm: "md:gap-1.5 md:px-2.5 md:py-1",
19
- md: "md:gap-2 md:px-4 md:py-2",
20
- lg: "md:gap-2 md:px-5 md:py-2.5",
21
- };
22
9
  /** The padding table and its `md:` twin, for the data test. */
23
- export const buttonSizeTables = { box: BOX, boxMd: BOX_MD };
24
- // A plain `disabled` washes out and ignores the pointer. A busy button is disabled too, but keeps
25
- // pointer events (the cursor says why) and does not take this; a blocked one is `aria-disabled`.
26
- const DISABLED_PLAIN = "disabled:pointer-events-none disabled:opacity-50";
27
- const LINK = "underline-offset-2";
28
- const TONE = {
29
- neutral: {
30
- primary: {
31
- color: "border-violet-600 bg-violet-600 text-violet-50",
32
- hover: "hover:bg-violet-700",
33
- },
34
- outline: { color: "border-violet-600 text-violet-600", hover: "hover:bg-violet-50" },
35
- ghost: { color: "border-transparent text-slate-600", hover: "hover:bg-slate-100" },
36
- link: {
37
- color: `border-transparent text-violet-600 ${LINK}`,
38
- hover: "hover:text-violet-700 hover:underline",
39
- },
40
- },
41
- positive: {
42
- primary: {
43
- color: "border-emerald-600 bg-emerald-600 text-emerald-50",
44
- hover: "hover:bg-emerald-700",
45
- },
46
- outline: { color: "border-emerald-200 text-emerald-700", hover: "hover:bg-emerald-50" },
47
- ghost: { color: "border-transparent text-emerald-700", hover: "hover:bg-emerald-50" },
48
- link: { color: `border-transparent text-emerald-700 ${LINK}`, hover: "hover:underline" },
49
- },
50
- danger: {
51
- primary: { color: "border-red-600 bg-red-600 text-red-50", hover: "hover:bg-red-700" },
52
- outline: { color: "border-red-200 text-red-700", hover: "hover:bg-red-50" },
53
- ghost: { color: "border-transparent text-red-700", hover: "hover:bg-red-50" },
54
- link: { color: `border-transparent text-red-700 ${LINK}`, hover: "hover:underline" },
55
- },
56
- };
57
- // The add row: Card dashed's outline and muted text, lit with the accent on hover. One look, so
58
- // `tone` does not apply to it.
59
- const DASHED = {
60
- color: "border-slate-300 text-slate-500",
61
- hover: "hover:border-violet-400 hover:text-violet-700",
62
- };
63
- // An outline or ghost Button with `pressed` set is a toggle, such as a filter chip: off is neutral
64
- // (the surface, a hairline, muted text, lit with the accent on hover), on is the tone's primary
65
- // fill, so the selected one stands out in every theme. A primary is already filled, and link and
66
- // dashed have no selected state; with `pressed` left out, outline and ghost keep their own look.
67
- const TOGGLE_OFF = {
68
- color: "border-slate-200 bg-white text-slate-600",
69
- hover: "hover:border-violet-400",
70
- };
71
- // The count chip: a pill in the button's own text colour (a hairline of `currentColor`), so it reads
72
- // on every variant and tone and needs no palette entry. The size is a Badge's: rem text and a
73
- // min-height, so the chip grows with the reader's text size.
74
- export const COUNT = "inline-flex min-h-4 min-w-4 items-center justify-center rounded-full border border-current px-1 text-[0.625rem]/[1.4] font-semibold tabular-nums";
10
+ export const buttonSizeTables = { box: BUTTON_BOX, boxMd: BUTTON_BOX_MD };
11
+ /** The count chip's classes (a Badge's size, in the button's own text colour). */
12
+ export const COUNT = BUTTON_COUNT;
75
13
  /** The label, then the count chip. The comma is for a screen reader only, so the name reads "Splits, 3". */
76
14
  function withCount(children, count) {
77
15
  if (count === undefined)
78
16
  return children;
79
17
  return (_jsxs(_Fragment, { children: [children, _jsx("span", { className: "sr-only", children: ", " }), _jsx("span", { className: COUNT, children: count })] }));
80
18
  }
81
- function lookOf(variant, tone, pressed) {
82
- if (variant === "dashed")
83
- return DASHED;
84
- if (pressed !== undefined && (variant === "outline" || variant === "ghost")) {
85
- return pressed ? TONE[tone].primary : TOGGLE_OFF;
86
- }
87
- return TONE[tone][variant];
88
- }
89
- // Blocked replaces the variant's colour and hover rather than overriding them, so no `!` is needed.
90
- const BLOCKED = "cursor-not-allowed border-slate-200 bg-slate-100 text-slate-400";
91
- const BLOCKED_DASHED = "cursor-not-allowed border-slate-200 text-slate-400";
92
- const BLOCKED_LINK = "cursor-not-allowed border-transparent text-slate-400";
93
- const BLOCKED_BY_VARIANT = {
94
- link: BLOCKED_LINK,
95
- dashed: BLOCKED_DASHED,
96
- };
97
- const BUSY = "cursor-progress opacity-85";
98
19
  function shape(variant, size, step) {
99
- return cx(SHAPE, variant !== "link" && sizeClass(BOX, BOX_MD, size), variant === "link" && "gap-1.5", variant === "dashed" && "w-full border-dashed", controlText(size, step, false), focusRing);
20
+ return cx(BUTTON_SHAPE, variant !== "link" && sizeClass(BUTTON_BOX, BUTTON_BOX_MD, size), variant === "link" && BUTTON_LINK_GAP, variant === "dashed" && BUTTON_DASHED_BOX, controlText(size, step, false), focusRing);
100
21
  }
101
22
  /** The classes of an idle Button: what `href` draws, and what the tests compare against. */
102
23
  export function buttonClass(variant = "primary", { size = "md", tone = "neutral" } = {}, step) {
@@ -110,8 +31,8 @@ export function blockedButtonClass(variant = "primary", { size = "md" } = {}, st
110
31
  return stateClass({ variant, size }, "blocked", undefined, step);
111
32
  }
112
33
  function idleClass(variant, size, tone, { step, pressed }) {
113
- const look = lookOf(variant, tone, pressed);
114
- return cx(shape(variant, size, step), "cursor-pointer", DISABLED_PLAIN, look.color, look.hover);
34
+ const look = buttonLook(variant, tone, pressed);
35
+ return cx(shape(variant, size, step), "cursor-pointer", BUTTON_DISABLED_PLAIN, look.color, look.hover);
115
36
  }
116
37
  function isLink(props) {
117
38
  return props.href !== undefined;
@@ -125,10 +46,10 @@ function stateOf(busy, disabledReason) {
125
46
  /** The classes of a Button in a given state: blocked swaps the colour out, busy keeps it. */
126
47
  function stateClass({ variant = "primary", size = "md", tone = "neutral" }, state, pressed, step) {
127
48
  if (state === "blocked") {
128
- return cx(shape(variant, size, step), BLOCKED_BY_VARIANT[variant] ?? BLOCKED);
49
+ return cx(shape(variant, size, step), BUTTON_BLOCKED_BY_VARIANT[variant] ?? BUTTON_BLOCKED);
129
50
  }
130
51
  if (state === "busy") {
131
- return cx(shape(variant, size, step), lookOf(variant, tone, pressed).color, BUSY);
52
+ return cx(shape(variant, size, step), buttonLook(variant, tone, pressed).color, BUTTON_BUSY);
132
53
  }
133
54
  return idleClass(variant, size, tone, { step, pressed });
134
55
  }
@@ -3,7 +3,7 @@ import { useState } from "react";
3
3
  import { FlowView } from "./FlowDiagram.js";
4
4
  import { Pill } from "./Pill.js";
5
5
  import { Bone, BusyLabel, busy, useLoading } from "./skeleton.js";
6
- import { COLS, dotLayer, placeOf, SLOT_H, SLOT_W, slotsFor, UNPLACED, useMoves, } from "./stateMachineDots.js";
6
+ import { boxContentSize, dotArea, dotLayer, placeOf, slotsFor, UNPLACED, useMoves, } from "./stateMachineDots.js";
7
7
  import { useFlowLayout } from "./useFlowLayout.js";
8
8
  /** Each kind's box tone, and the tag that says it in words. */
9
9
  const KIND_TONE = {
@@ -20,20 +20,21 @@ const KIND_TAG = {
20
20
  terminal: { text: "end", tone: "neutral" },
21
21
  failed: { text: "failed", tone: "danger" },
22
22
  };
23
- /** A box's tags: what kind of state it is, who owns it, and how many items it holds. */
23
+ /**
24
+ * A box's tags: what kind of state it is, who owns it, and how many items it holds. The row is
25
+ * always there: a box with no items keeps an invisible count tag in it, so an empty box and a full
26
+ * one are the same height.
27
+ */
24
28
  function boxTags(tag, owner, count) {
25
- if (!tag && !owner && count === 0)
26
- return null;
27
- return (_jsxs("span", { className: "flex flex-wrap items-center justify-center gap-1", children: [tag && (_jsx(Pill, { size: "sm", tone: tag.tone, children: tag.text })), owner && _jsx(Pill, { size: "sm", children: owner }), count > 0 && (_jsx(Pill, { size: "sm", tone: "accent", dot: true, children: count === 1 ? "1 item" : `${count} items` }))] }));
29
+ return (_jsxs("span", { className: "flex flex-wrap items-center justify-center gap-1", children: [tag && (_jsx(Pill, { size: "sm", tone: tag.tone, children: tag.text })), owner && _jsx(Pill, { size: "sm", children: owner }), count > 0 ? (_jsx(Pill, { size: "sm", tone: "accent", dot: true, children: count === 1 ? "1 item" : `${count} items` })) : (_jsx("span", { "aria-hidden": "true", className: "flex invisible", children: _jsx(Pill, { size: "sm", tone: "accent", dot: true, children: "0 items" }) }))] }));
28
30
  }
29
- /** What a box holds under its label: its tags and the room its dots take. */
31
+ /**
32
+ * What a box holds under its label: its tags, and the dot area it always reserves (the full grid,
33
+ * even empty), so a box keeps its size whatever its item count.
34
+ */
30
35
  function boxContent(state, count, slots) {
31
36
  const tags = boxTags(state ? KIND_TAG[state.kind ?? "normal"] : null, state?.owner, count);
32
- if (tags === null)
33
- return undefined;
34
- const cols = Math.min(COLS, slots);
35
- const rows = Math.ceil(slots / COLS);
36
- return (_jsxs(_Fragment, { children: [tags, slots > 0 && (_jsx("span", { "aria-hidden": "true", className: "mx-auto mt-1 block", style: { width: cols * SLOT_W, height: rows * SLOT_H } }))] }));
37
+ return (_jsxs(_Fragment, { children: [tags, _jsx("span", { "aria-hidden": "true", className: "mx-auto mt-1 block", style: dotArea(slots) })] }));
37
38
  }
38
39
  /** The items each box holds: its state's, and the unplaced box's for an unknown state. */
39
40
  function itemsByBox(items, known) {
@@ -53,6 +54,7 @@ function boxesFor(states, inBox, open) {
53
54
  label: s.label,
54
55
  tone: KIND_TONE[s.kind ?? "normal"],
55
56
  content: boxContent(s, inBox.get(s.id)?.length ?? 0, slots(s.id)),
57
+ contentSize: boxContentSize(slots(s.id)),
56
58
  }));
57
59
  const unplaced = inBox.get(UNPLACED)?.length ?? 0;
58
60
  if (unplaced === 0)
@@ -64,6 +66,7 @@ function boxesFor(states, inBox, open) {
64
66
  label: "Not in any state",
65
67
  tone: "warn",
66
68
  content: boxContent(null, unplaced, slots(UNPLACED)),
69
+ contentSize: boxContentSize(slots(UNPLACED)),
67
70
  },
68
71
  ];
69
72
  }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Button's tokens: the class tables `@slashsuite/ui-react` draws a Button from, and the sizes the
3
+ * native renderer measures against. The tables are the web's (Tailwind utilities, remapped by every
4
+ * theme); `parity.ts` reads the box sizes from them, so a change here moves both renderers.
5
+ */
6
+ /** A Button's look: `primary` the one main action, `outline` and `ghost` the others, `link` text in running text, `dashed` the add-another row. */
7
+ export type ButtonVariant = "primary" | "outline" | "ghost" | "link" | "dashed";
8
+ /** A Button's height and text, on the library's one size scale. */
9
+ export type ButtonSize = "sm" | "md" | "lg";
10
+ /** A Button's tones: `neutral` (the accent fill, the default), `positive` and `danger`. */
11
+ export type ButtonTone = "neutral" | "positive" | "danger";
12
+ /** A colour and its hover, as two class strings. */
13
+ export type ButtonLook = {
14
+ color: string;
15
+ hover: string;
16
+ };
17
+ export declare const BUTTON_SHAPE = "inline-flex items-center justify-center rounded-lg border font-medium transition";
18
+ export declare const BUTTON_BOX: Record<ButtonSize, string>;
19
+ export declare const BUTTON_BOX_MD: Record<ButtonSize, string>;
20
+ /** The gap of the link variant, which has no box. */
21
+ export declare const BUTTON_LINK_GAP = "gap-1.5";
22
+ /** The dashed variant fills its container. */
23
+ export declare const BUTTON_DASHED_BOX = "w-full border-dashed";
24
+ export declare const BUTTON_DISABLED_PLAIN = "disabled:pointer-events-none disabled:opacity-50";
25
+ export declare const BUTTON_TONE: Record<ButtonTone, Record<Exclude<ButtonVariant, "dashed">, ButtonLook>>;
26
+ export declare const BUTTON_DASHED: ButtonLook;
27
+ export declare const BUTTON_TOGGLE_OFF: ButtonLook;
28
+ export declare const BUTTON_COUNT = "inline-flex min-h-4 min-w-4 items-center justify-center rounded-full border border-current px-1 text-[0.625rem]/[1.4] font-semibold tabular-nums";
29
+ export declare const BUTTON_BLOCKED = "cursor-not-allowed border-slate-200 bg-slate-100 text-slate-400";
30
+ export declare const BUTTON_BLOCKED_BY_VARIANT: Partial<Record<ButtonVariant, string>>;
31
+ export declare const BUTTON_BUSY = "cursor-progress opacity-85";
32
+ /** The look of an idle Button: the dashed look, a toggle's, or the tone's for the variant. */
33
+ export declare function buttonLook(variant: ButtonVariant, tone: ButtonTone, pressed?: boolean): ButtonLook;
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Button's tokens: the class tables `@slashsuite/ui-react` draws a Button from, and the sizes the
3
+ * native renderer measures against. The tables are the web's (Tailwind utilities, remapped by every
4
+ * theme); `parity.ts` reads the box sizes from them, so a change here moves both renderers.
5
+ */
6
+ export const BUTTON_SHAPE = "inline-flex items-center justify-center rounded-lg border font-medium transition";
7
+ // Size sets the padding; the text is the renderer's control text, from the size and the type step.
8
+ // The link variant has no box, so it takes the text size only.
9
+ export const BUTTON_BOX = {
10
+ sm: "gap-1.5 px-2.5 py-1",
11
+ md: "gap-2 px-4 py-2",
12
+ lg: "gap-2 px-5 py-2.5",
13
+ };
14
+ // `BUTTON_BOX` from the `md` breakpoint up, for a responsive size, every class written out in full.
15
+ export const BUTTON_BOX_MD = {
16
+ sm: "md:gap-1.5 md:px-2.5 md:py-1",
17
+ md: "md:gap-2 md:px-4 md:py-2",
18
+ lg: "md:gap-2 md:px-5 md:py-2.5",
19
+ };
20
+ /** The gap of the link variant, which has no box. */
21
+ export const BUTTON_LINK_GAP = "gap-1.5";
22
+ /** The dashed variant fills its container. */
23
+ export const BUTTON_DASHED_BOX = "w-full border-dashed";
24
+ // A plain `disabled` washes out and ignores the pointer. A busy button is disabled too, but keeps
25
+ // pointer events (the cursor says why) and does not take this; a blocked one is `aria-disabled`.
26
+ export const BUTTON_DISABLED_PLAIN = "disabled:pointer-events-none disabled:opacity-50";
27
+ const LINK = "underline-offset-2";
28
+ export const BUTTON_TONE = {
29
+ neutral: {
30
+ primary: {
31
+ color: "border-violet-600 bg-violet-600 text-violet-50",
32
+ hover: "hover:bg-violet-700",
33
+ },
34
+ outline: { color: "border-violet-600 text-violet-600", hover: "hover:bg-violet-50" },
35
+ ghost: { color: "border-transparent text-slate-600", hover: "hover:bg-slate-100" },
36
+ link: {
37
+ color: `border-transparent text-violet-600 ${LINK}`,
38
+ hover: "hover:text-violet-700 hover:underline",
39
+ },
40
+ },
41
+ positive: {
42
+ primary: {
43
+ color: "border-emerald-600 bg-emerald-600 text-emerald-50",
44
+ hover: "hover:bg-emerald-700",
45
+ },
46
+ outline: { color: "border-emerald-200 text-emerald-700", hover: "hover:bg-emerald-50" },
47
+ ghost: { color: "border-transparent text-emerald-700", hover: "hover:bg-emerald-50" },
48
+ link: { color: `border-transparent text-emerald-700 ${LINK}`, hover: "hover:underline" },
49
+ },
50
+ danger: {
51
+ primary: { color: "border-red-600 bg-red-600 text-red-50", hover: "hover:bg-red-700" },
52
+ outline: { color: "border-red-200 text-red-700", hover: "hover:bg-red-50" },
53
+ ghost: { color: "border-transparent text-red-700", hover: "hover:bg-red-50" },
54
+ link: { color: `border-transparent text-red-700 ${LINK}`, hover: "hover:underline" },
55
+ },
56
+ };
57
+ // The add row: Card dashed's outline and muted text, lit with the accent on hover. One look, so
58
+ // `tone` does not apply to it.
59
+ export const BUTTON_DASHED = {
60
+ color: "border-slate-300 text-slate-500",
61
+ hover: "hover:border-violet-400 hover:text-violet-700",
62
+ };
63
+ // An outline or ghost Button with `pressed` set is a toggle, such as a filter chip: off is neutral
64
+ // (the surface, a hairline, muted text, lit with the accent on hover), on is the tone's primary
65
+ // fill, so the selected one stands out in every theme.
66
+ export const BUTTON_TOGGLE_OFF = {
67
+ color: "border-slate-200 bg-white text-slate-600",
68
+ hover: "hover:border-violet-400",
69
+ };
70
+ // The count chip: a pill in the button's own text colour (a hairline of `currentColor`), so it reads
71
+ // on every variant and tone and needs no palette entry. The size is a Badge's: rem text and a
72
+ // min-height, so the chip grows with the reader's text size.
73
+ export const BUTTON_COUNT = "inline-flex min-h-4 min-w-4 items-center justify-center rounded-full border border-current px-1 text-[0.625rem]/[1.4] font-semibold tabular-nums";
74
+ // Blocked replaces the variant's colour and hover rather than overriding them, so no `!` is needed.
75
+ export const BUTTON_BLOCKED = "cursor-not-allowed border-slate-200 bg-slate-100 text-slate-400";
76
+ export const BUTTON_BLOCKED_BY_VARIANT = {
77
+ link: "cursor-not-allowed border-transparent text-slate-400",
78
+ dashed: "cursor-not-allowed border-slate-200 text-slate-400",
79
+ };
80
+ export const BUTTON_BUSY = "cursor-progress opacity-85";
81
+ /** The look of an idle Button: the dashed look, a toggle's, or the tone's for the variant. */
82
+ export function buttonLook(variant, tone, pressed) {
83
+ if (variant === "dashed")
84
+ return BUTTON_DASHED;
85
+ if (pressed !== undefined && (variant === "outline" || variant === "ghost")) {
86
+ return pressed ? BUTTON_TONE[tone].primary : BUTTON_TOGGLE_OFF;
87
+ }
88
+ return BUTTON_TONE[tone][variant];
89
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * A control's text: its type size by `size` at each type step, and its line height by `size`. A
3
+ * Button, a field and a pill take their text from here on every renderer, so a control's height
4
+ * (line height, padding and hairline) is the same on the web and on a phone.
5
+ */
6
+ import type { ButtonSize } from "./button.js";
7
+ /** The type step an app may set once: `compact` is one step down, for an app's chrome. */
8
+ export type ControlTypeStep = "default" | "compact";
9
+ /** A control's type size at each step: `md` is 16px at the default step, and `compact` is one step down. */
10
+ export declare const CONTROL_TEXT: Record<ControlTypeStep, Record<ButtonSize, string>>;
11
+ /**
12
+ * A control's line height by `size`, whatever its type step: 16, 20 and 24px, so with its padding
13
+ * every control is 26, 38 and 46px tall at both steps.
14
+ */
15
+ export declare const CONTROL_LEADING: Record<ButtonSize, string>;
@@ -0,0 +1,14 @@
1
+ /** A control's type size at each step: `md` is 16px at the default step, and `compact` is one step down. */
2
+ export const CONTROL_TEXT = {
3
+ default: { sm: "text-sm", md: "text-base", lg: "text-lg" },
4
+ compact: { sm: "text-xs", md: "text-sm", lg: "text-base" },
5
+ };
6
+ /**
7
+ * A control's line height by `size`, whatever its type step: 16, 20 and 24px, so with its padding
8
+ * every control is 26, 38 and 46px tall at both steps.
9
+ */
10
+ export const CONTROL_LEADING = {
11
+ sm: "leading-4",
12
+ md: "leading-5",
13
+ lg: "leading-6",
14
+ };
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Button's story fixtures: the stories both renderers draw from the same data, so a web story and
3
+ * its native shot share one story id (`actions-button--variants`). Each is a row of Buttons; the
4
+ * renderer lays the row out by `layout` and draws each item with its own Button.
5
+ */
6
+ import type { ButtonSize, ButtonTone, ButtonVariant } from "../button.js";
7
+ import type { StoryFixture } from "./types.js";
8
+ /** One Button in a fixture: its label and the props that change its look or state. */
9
+ export type ButtonFixtureItem = {
10
+ label: string;
11
+ variant?: ButtonVariant;
12
+ size?: ButtonSize;
13
+ tone?: ButtonTone;
14
+ pressed?: boolean;
15
+ disabledReason?: string;
16
+ busy?: boolean | string;
17
+ };
18
+ export declare const buttonFixtures: {
19
+ Variants: StoryFixture<ButtonFixtureItem>;
20
+ Small: StoryFixture<ButtonFixtureItem>;
21
+ Danger: StoryFixture<ButtonFixtureItem>;
22
+ Positive: StoryFixture<ButtonFixtureItem>;
23
+ Pressed: StoryFixture<ButtonFixtureItem>;
24
+ Blocked: StoryFixture<ButtonFixtureItem>;
25
+ Busy: StoryFixture<ButtonFixtureItem>;
26
+ };
@@ -0,0 +1,52 @@
1
+ const TITLE = "Actions/Button";
2
+ const fixture = (story, layout, items) => ({ title: TITLE, story, layout, items });
3
+ export const buttonFixtures = {
4
+ Variants: fixture("Variants", "wrap", [
5
+ { label: "Save" },
6
+ { label: "Cancel", variant: "outline" },
7
+ { label: "Skip", variant: "ghost" },
8
+ { label: "Edit", variant: "link" },
9
+ ]),
10
+ Small: fixture("Small", "wrap-center", [
11
+ { label: "Save", size: "sm" },
12
+ { label: "Cancel", size: "sm", variant: "outline" },
13
+ { label: "Skip", size: "sm", variant: "ghost" },
14
+ { label: "Edit", size: "sm", variant: "link" },
15
+ { label: "Remove", size: "sm", tone: "danger", variant: "outline" },
16
+ ]),
17
+ Danger: fixture("Danger", "wrap-center", [
18
+ { label: "Delete", tone: "danger" },
19
+ { label: "Clear", tone: "danger", variant: "outline" },
20
+ { label: "Remove", tone: "danger", variant: "ghost" },
21
+ { label: "Remove", tone: "danger", variant: "link" },
22
+ { label: "Delete", tone: "danger", size: "sm" },
23
+ { label: "Blocked", tone: "danger", disabledReason: "Nothing to delete" },
24
+ { label: "Delete", tone: "danger", busy: "Deleting…" },
25
+ ]),
26
+ Positive: fixture("Positive", "wrap-center", [
27
+ { label: "Accept", tone: "positive" },
28
+ { label: "Accept", tone: "positive", variant: "outline" },
29
+ { label: "Accept", tone: "positive", variant: "ghost" },
30
+ { label: "Accept", tone: "positive", variant: "link" },
31
+ { label: "Accept", tone: "positive", size: "sm" },
32
+ { label: "Blocked", tone: "positive", disabledReason: "Nothing to accept" },
33
+ { label: "Accept", tone: "positive", busy: "Accepting…" },
34
+ ]),
35
+ Pressed: fixture("Pressed", "wrap-center", [
36
+ { label: "Flag", variant: "outline", pressed: false },
37
+ { label: "Flag", variant: "outline", pressed: true },
38
+ { label: "Flag", variant: "ghost", pressed: true },
39
+ { label: "Accepted", variant: "outline", tone: "positive", pressed: true },
40
+ { label: "Rejected", variant: "outline", tone: "danger", pressed: true },
41
+ ]),
42
+ Blocked: fixture("Blocked", "wrap", [
43
+ { label: "Save", disabledReason: "Pick a shop first" },
44
+ { label: "Cancel", variant: "outline", disabledReason: "Pick a shop first" },
45
+ { label: "Skip", variant: "ghost", disabledReason: "Pick a shop first" },
46
+ ]),
47
+ Busy: fixture("Busy", "wrap", [
48
+ { label: "Save", busy: "Saving…" },
49
+ { label: "Cancel", variant: "outline", busy: "Cancelling…" },
50
+ { label: "Skip", variant: "ghost", busy: true },
51
+ ]),
52
+ };
@@ -0,0 +1,13 @@
1
+ /**
2
+ * A story fixture: a story as data, which every renderer draws. `title` and `story` give the story
3
+ * id both renderers use (`storyId`), and `layout` how the items sit: `wrap` a wrapping row with the
4
+ * standard gap, `wrap-center` the same row with its items centred on the cross axis.
5
+ */
6
+ export type StoryFixture<Item> = {
7
+ title: string;
8
+ story: string;
9
+ layout: "wrap" | "wrap-center";
10
+ items: Item[];
11
+ };
12
+ /** Storybook's id for a story: `Actions/Button` and `Variants` give `actions-button--variants`. */
13
+ export declare function storyId(title: string, story: string): string;
@@ -0,0 +1,10 @@
1
+ /** Storybook's slug of a title or a story name: camelCase split, lower-cased, hyphenated. */
2
+ const slug = (text) => text
3
+ .replace(/([a-z\d])([A-Z])/g, "$1-$2")
4
+ .toLowerCase()
5
+ .replace(/[^a-z\d]+/g, "-")
6
+ .replace(/^-|-$/g, "");
7
+ /** Storybook's id for a story: `Actions/Button` and `Variants` give `actions-button--variants`. */
8
+ export function storyId(title, story) {
9
+ return `${slug(title)}--${slug(story)}`;
10
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The keyboard focus ring every interactive control shares, on every renderer: a 2px accent
3
+ * outline 2px out. `FOCUS_RING_INSET` draws it inside, for a control that fills a box which clips
4
+ * anything outside it (a table's sortable title, a scroller).
5
+ */
6
+ export declare const FOCUS_RING = "focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-violet-600";
7
+ export declare const FOCUS_RING_INSET = "focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-violet-600";
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The keyboard focus ring every interactive control shares, on every renderer: a 2px accent
3
+ * outline 2px out. `FOCUS_RING_INSET` draws it inside, for a control that fills a box which clips
4
+ * anything outside it (a table's sortable title, a scroller).
5
+ */
6
+ export const FOCUS_RING = "focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-violet-600";
7
+ export const FOCUS_RING_INSET = "focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-violet-600";
@@ -0,0 +1,12 @@
1
+ /**
2
+ * `@slashsuite/core`: what every UISlash renderer shares. The token tables and prop types of the
3
+ * components that have moved here, their story fixtures, the parity manifest built from the
4
+ * tables, and the native theme generator. Pure TypeScript, no runtime dependencies.
5
+ */
6
+ export * from "./button.js";
7
+ export { buttonFixtures, type ButtonFixtureItem } from "./fixtures/button.js";
8
+ export { storyId, type StoryFixture } from "./fixtures/types.js";
9
+ export { parityJson, parityManifest, radiusPx, spacingPx, type BoxMetrics, type ParityManifest, } from "./parity.js";
10
+ export { missingFromNative, nativeTheme, nativeThemeJson, STATE_OF_VARIANT, type NativeCompound, type NativeState, type NativeStyle, type NativeTheme, } from "./themeNative.js";
11
+ export { CONTROL_LEADING, CONTROL_TEXT, type ControlTypeStep } from "./control.js";
12
+ export { FOCUS_RING, FOCUS_RING_INSET } from "./focus.js";
@@ -0,0 +1,12 @@
1
+ /**
2
+ * `@slashsuite/core`: what every UISlash renderer shares. The token tables and prop types of the
3
+ * components that have moved here, their story fixtures, the parity manifest built from the
4
+ * tables, and the native theme generator. Pure TypeScript, no runtime dependencies.
5
+ */
6
+ export * from "./button.js";
7
+ export { buttonFixtures } from "./fixtures/button.js";
8
+ export { storyId } from "./fixtures/types.js";
9
+ export { parityJson, parityManifest, radiusPx, spacingPx, } from "./parity.js";
10
+ export { missingFromNative, nativeTheme, nativeThemeJson, STATE_OF_VARIANT, } from "./themeNative.js";
11
+ export { CONTROL_LEADING, CONTROL_TEXT } from "./control.js";
12
+ export { FOCUS_RING, FOCUS_RING_INSET } from "./focus.js";
@@ -0,0 +1,22 @@
1
+ /** The px of the first `<prefix>-<n>` spacing class in `classes`, or 0 when there is none. */
2
+ export declare function spacingPx(classes: string, prefix: string): number;
3
+ /** The px of the radius class in `classes`, or 0 when there is none. */
4
+ export declare function radiusPx(classes: string): number;
5
+ /** One size of a component's box, in logical px. */
6
+ export type BoxMetrics = {
7
+ height: number;
8
+ paddingX: number;
9
+ paddingY: number;
10
+ gap: number;
11
+ radius: number;
12
+ borderWidth: number;
13
+ };
14
+ /** The manifest: component, then size, then its box. */
15
+ export type ParityManifest = {
16
+ version: 1;
17
+ components: Record<string, Record<string, BoxMetrics>>;
18
+ };
19
+ /** The manifest from the tables as they are now. */
20
+ export declare function parityManifest(): ParityManifest;
21
+ /** The manifest as the file holds it: two-space JSON with a trailing newline. */
22
+ export declare const parityJson: () => string;
@@ -0,0 +1,53 @@
1
+ /**
2
+ * The parity manifest: the box every renderer must draw for each component and size, in logical px,
3
+ * read from the token tables (never written by hand). `scripts/parity.ts` writes it to
4
+ * `parity.json`; its test fails when the file is stale, so a token change shows up as a diff of
5
+ * the manifest that both renderers are measured against.
6
+ */
7
+ import { BUTTON_BOX, BUTTON_SHAPE } from "./button.js";
8
+ import { CONTROL_LEADING } from "./control.js";
9
+ /** Tailwind's spacing step: `p-1` is 0.25rem, 4px at the default root size. */
10
+ const SPACING_PX = 4;
11
+ /** Tailwind v4's radius scale, in px. */
12
+ const RADIUS_PX = {
13
+ "rounded-sm": 4,
14
+ "rounded-md": 6,
15
+ "rounded-lg": 8,
16
+ "rounded-xl": 12,
17
+ "rounded-full": 9999,
18
+ };
19
+ /** The px of the first `<prefix>-<n>` spacing class in `classes`, or 0 when there is none. */
20
+ export function spacingPx(classes, prefix) {
21
+ const step = new RegExp(`(?:^|\\s)${prefix}-(\\d+(?:\\.\\d+)?)(?=\\s|$)`).exec(classes)?.[1];
22
+ return step === undefined ? 0 : Number(step) * SPACING_PX;
23
+ }
24
+ /** The px of the radius class in `classes`, or 0 when there is none. */
25
+ export function radiusPx(classes) {
26
+ const radius = classes.split(/\s+/).find((name) => name in RADIUS_PX);
27
+ return radius === undefined ? 0 : (RADIUS_PX[radius] ?? 0);
28
+ }
29
+ function buttonBox(size) {
30
+ const box = BUTTON_BOX[size];
31
+ const borderWidth = /(?:^|\s)border(?=\s|$)/.test(BUTTON_SHAPE) ? 1 : 0;
32
+ const paddingY = spacingPx(box, "py");
33
+ return {
34
+ height: spacingPx(CONTROL_LEADING[size], "leading") + 2 * paddingY + 2 * borderWidth,
35
+ paddingX: spacingPx(box, "px"),
36
+ paddingY,
37
+ gap: spacingPx(box, "gap"),
38
+ radius: radiusPx(BUTTON_SHAPE),
39
+ borderWidth,
40
+ };
41
+ }
42
+ const SIZES = ["sm", "md", "lg"];
43
+ /** The manifest from the tables as they are now. */
44
+ export function parityManifest() {
45
+ return {
46
+ version: 1,
47
+ components: {
48
+ Button: Object.fromEntries(SIZES.map((size) => [size, buttonBox(size)])),
49
+ },
50
+ };
51
+ }
52
+ /** The manifest as the file holds it: two-space JSON with a trailing newline. */
53
+ export const parityJson = () => `${JSON.stringify(parityManifest(), null, 2)}\n`;