@stackone/malachite 2.98.0 → 2.99.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/COMPONENTS.md +24 -22
- package/dist/components/CardStrip.js +231 -235
- package/dist/components/CardStrip.js.map +1 -1
- package/dist/components/ChoiceGroup.js +127 -0
- package/dist/components/ChoiceGroup.js.map +1 -0
- package/dist/components/CornerBadge.js +37 -0
- package/dist/components/CornerBadge.js.map +1 -0
- package/dist/components/ResourceCard.js +56 -0
- package/dist/components/ResourceCard.js.map +1 -0
- package/dist/components/SegmentedControl.js +42 -58
- package/dist/components/SegmentedControl.js.map +1 -1
- package/dist/components/StepList.js +55 -49
- package/dist/components/StepList.js.map +1 -1
- package/dist/components/rovingKeys.js +20 -0
- package/dist/components/rovingKeys.js.map +1 -0
- package/dist/index.d.ts +103 -4
- package/dist/index.js +372 -368
- package/dist/index.js.map +1 -1
- package/dist/tailwind.css.js +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { useRef as
|
|
3
|
-
import { FOCUS_RING as
|
|
1
|
+
import { jsx as m, jsxs as S } from "react/jsx-runtime";
|
|
2
|
+
import { useRef as $ } from "react";
|
|
3
|
+
import { FOCUS_RING as w } from "./focusRing.js";
|
|
4
|
+
import { rovingTabStop as I, nextRovingIndex as D } from "./rovingKeys.js";
|
|
4
5
|
const N = {
|
|
5
6
|
small: {
|
|
6
7
|
text: "text-[length:var(--malachite-font-size-small,13px)]",
|
|
@@ -17,83 +18,66 @@ const N = {
|
|
|
17
18
|
track: "h-[var(--malachite-control-height-large,42px)]",
|
|
18
19
|
item: "h-full px-4"
|
|
19
20
|
}
|
|
20
|
-
},
|
|
21
|
-
options:
|
|
22
|
-
value:
|
|
23
|
-
onChange:
|
|
24
|
-
size:
|
|
21
|
+
}, j = "inline-flex items-center justify-center gap-1.5 rounded-[var(--malachite-radius-10,10px)] border-0 font-medium tracking-[0.13px] whitespace-nowrap transition-colors duration-150 ease-in-out", K = ({
|
|
22
|
+
options: l,
|
|
23
|
+
value: s,
|
|
24
|
+
onChange: u,
|
|
25
|
+
size: g = "medium",
|
|
25
26
|
fullWidth: x = !1,
|
|
26
|
-
disabled:
|
|
27
|
-
"aria-label":
|
|
28
|
-
"aria-labelledby":
|
|
29
|
-
className:
|
|
27
|
+
disabled: r = !1,
|
|
28
|
+
"aria-label": b,
|
|
29
|
+
"aria-labelledby": v,
|
|
30
|
+
className: p = ""
|
|
30
31
|
}) => {
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
var n;
|
|
34
|
-
if (c || !D.has(e.key))
|
|
35
|
-
return;
|
|
36
|
-
const t = s.reduce((l, f, S) => (f.disabled || l.push({ option: f, index: S }), l), []);
|
|
37
|
-
if (t.length === 0)
|
|
38
|
-
return;
|
|
39
|
-
e.preventDefault();
|
|
40
|
-
const r = t.findIndex(({ option: l }) => l.value === o);
|
|
41
|
-
let a;
|
|
42
|
-
if (e.key === "Home")
|
|
43
|
-
a = 0;
|
|
44
|
-
else if (e.key === "End")
|
|
45
|
-
a = t.length - 1;
|
|
46
|
-
else {
|
|
47
|
-
const l = e.key === "ArrowLeft" || e.key === "ArrowUp" ? -1 : 1;
|
|
48
|
-
a = ((r === -1 ? 0 : r) + l + t.length) % t.length;
|
|
49
|
-
}
|
|
50
|
-
const i = t[a];
|
|
51
|
-
i.option.value !== o && d(i.option.value), (n = g.current[i.index]) == null || n.focus();
|
|
52
|
-
},
|
|
53
|
-
[c, d, s, o]
|
|
54
|
-
);
|
|
55
|
-
return /* @__PURE__ */ u(
|
|
32
|
+
const o = $([]), d = N[g], k = l.findIndex((e) => e.value === s), h = l.map((e) => !e.disabled), f = I(k, h);
|
|
33
|
+
return /* @__PURE__ */ m(
|
|
56
34
|
"div",
|
|
57
35
|
{
|
|
58
36
|
role: "radiogroup",
|
|
59
|
-
"aria-label":
|
|
60
|
-
"aria-labelledby":
|
|
61
|
-
"aria-disabled":
|
|
62
|
-
onKeyDown:
|
|
37
|
+
"aria-label": b,
|
|
38
|
+
"aria-labelledby": v,
|
|
39
|
+
"aria-disabled": r || void 0,
|
|
40
|
+
onKeyDown: (e) => {
|
|
41
|
+
var a;
|
|
42
|
+
if (r)
|
|
43
|
+
return;
|
|
44
|
+
const n = o.current.findIndex((c) => c === e.target), t = D(e, n >= 0 ? n : f, h);
|
|
45
|
+
t !== void 0 && (e.preventDefault(), l[t].value !== s && u(l[t].value), (a = o.current[t]) == null || a.focus());
|
|
46
|
+
},
|
|
63
47
|
className: `${// One display utility, not two: `flex` and `inline-flex` are both plain
|
|
64
48
|
// `display` utilities, so emitting both would resolve by stylesheet order
|
|
65
49
|
// (same hazard as the background above).
|
|
66
|
-
x ? "flex w-full" : "inline-flex"} ${
|
|
67
|
-
children:
|
|
68
|
-
const
|
|
69
|
-
let
|
|
70
|
-
return
|
|
50
|
+
x ? "flex w-full" : "inline-flex"} ${d.track} items-center gap-1 p-0.5 rounded-xl bg-[var(--malachite-segmented-control-track-background)] ${r ? "opacity-50" : ""} ${p}`,
|
|
51
|
+
children: l.map((e, n) => {
|
|
52
|
+
const t = e.value === s, a = r || e.disabled, c = e.badge !== void 0 && e.badge !== null && e.badge !== !1;
|
|
53
|
+
let i;
|
|
54
|
+
return t ? i = "bg-[var(--malachite-segmented-control-selected-background)] text-[var(--malachite-segmented-control-selected-foreground)]" : a ? i = "bg-transparent text-[var(--malachite-segmented-control-item-foreground)]" : i = "bg-transparent text-[var(--malachite-segmented-control-item-foreground)] hover:text-[var(--malachite-segmented-control-item-hover-foreground)] cursor-pointer", /* @__PURE__ */ S(
|
|
71
55
|
"button",
|
|
72
56
|
{
|
|
73
|
-
ref: (
|
|
74
|
-
|
|
57
|
+
ref: (y) => {
|
|
58
|
+
o.current[n] = y;
|
|
75
59
|
},
|
|
76
60
|
type: "button",
|
|
77
61
|
role: "radio",
|
|
78
|
-
"aria-checked":
|
|
62
|
+
"aria-checked": t,
|
|
79
63
|
disabled: a,
|
|
80
|
-
tabIndex:
|
|
64
|
+
tabIndex: n === f ? 0 : -1,
|
|
81
65
|
onClick: () => {
|
|
82
|
-
!a && !
|
|
66
|
+
!a && !t && u(e.value);
|
|
83
67
|
},
|
|
84
|
-
className: `${
|
|
68
|
+
className: `${w} ${j} ${d.text} ${d.item} ${i} ${x ? "flex-1" : ""} ${e.disabled && !r ? "opacity-50 cursor-not-allowed" : ""}`,
|
|
85
69
|
style: {
|
|
86
70
|
// Inline rather than a `shadow-[...]` class: Tailwind's shadow
|
|
87
71
|
// utilities compose `--tw-shadow-*` custom properties that rely on
|
|
88
72
|
// document-level @property registration and silently don't paint
|
|
89
73
|
// inside a shadow root (same caveat as `ring-*`).
|
|
90
|
-
boxShadow:
|
|
74
|
+
boxShadow: t ? "var(--malachite-segmented-control-selected-shadow, 0px 1px 5px 0px rgba(0, 0, 0, 0.1))" : void 0
|
|
91
75
|
},
|
|
92
76
|
children: [
|
|
93
|
-
e.icon ? /* @__PURE__ */
|
|
77
|
+
e.icon ? /* @__PURE__ */ m("span", { className: "inline-flex items-center justify-center w-4 h-4 shrink-0", children: e.icon }) : null,
|
|
94
78
|
e.label,
|
|
95
|
-
|
|
96
|
-
|
|
79
|
+
c ? " " : null,
|
|
80
|
+
c ? /* @__PURE__ */ m("span", { className: "inline-flex items-center shrink-0", children: e.badge }) : null
|
|
97
81
|
]
|
|
98
82
|
},
|
|
99
83
|
e.value
|
|
@@ -103,7 +87,7 @@ const N = {
|
|
|
103
87
|
);
|
|
104
88
|
};
|
|
105
89
|
export {
|
|
106
|
-
|
|
107
|
-
|
|
90
|
+
K as SegmentedControl,
|
|
91
|
+
K as default
|
|
108
92
|
};
|
|
109
93
|
//# sourceMappingURL=SegmentedControl.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SegmentedControl.js","sources":["../../src/components/SegmentedControl.tsx"],"sourcesContent":["import React, { useCallback, useRef } from 'react';\nimport { FOCUS_RING } from './focusRing';\n\ntype SegmentedControlSize = 'small' | 'medium' | 'large';\n\ninterface SegmentedControlOption<T extends string = string> {\n value: T;\n label: string;\n icon?: React.ReactNode;\n /**\n * Small mark after the label, e.g. a compact `Tag` naming a saving. It renders inside\n * the segment's `<button>`, so it must not be interactive — no `onClick` or `onRemove`.\n */\n badge?: React.ReactNode;\n disabled?: boolean;\n}\n\ninterface SegmentedControlProps<T extends string = string> {\n options: SegmentedControlOption<T>[];\n /** The selected option's value. A value not present in `options` renders nothing selected. */\n value: T;\n onChange: (value: T) => void;\n size?: SegmentedControlSize;\n /** Stretch the track to its container and split it into equal segments. */\n fullWidth?: boolean;\n /** Disables every segment. Individual segments can also be disabled via `options`. */\n disabled?: boolean;\n 'aria-label'?: string;\n 'aria-labelledby'?: string;\n className?: string;\n}\n\n// The ladder governs a control's outer box. The height therefore sits on the track and\n// the items fill whatever the 4px inset leaves — putting it on the item instead makes a\n// `medium` segmented control 40px tall beside a 32px Dropdown.\nconst SIZE_CLASSES: Record<SegmentedControlSize, { text: string; track: string; item: string }> = {\n small: {\n text: 'text-[length:var(--malachite-font-size-small,13px)]',\n track: 'h-[var(--malachite-control-height-small,28px)]',\n item: 'h-full px-2.5',\n },\n medium: {\n text: 'text-[length:var(--malachite-font-size-small,13px)]',\n track: 'h-[var(--malachite-control-height-medium,32px)]',\n item: 'h-full px-2.5',\n },\n large: {\n text: 'text-[length:var(--malachite-font-size-15,15px)]',\n track: 'h-[var(--malachite-control-height-large,42px)]',\n item: 'h-full px-4',\n },\n};\n\n/** Arrow keys move AND select, per the WAI-ARIA radiogroup pattern. */\nconst NAV_KEYS = new Set(['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown', 'Home', 'End']);\n\n// Deliberately no `bg-*` here: each state branch below supplies exactly one\n// background-color utility. Both `bg-transparent` and `bg-[var(--…)]` are plain\n// single-class utilities in the same `@layer utilities`, so an element carrying both\n// resolves by stylesheet order — and the arbitrary value loses, silently rendering the\n// selected thumb transparent.\nconst ITEM_BASE =\n 'inline-flex items-center justify-center gap-1.5 rounded-[var(--malachite-radius-10,10px)] border-0 font-medium tracking-[0.13px] whitespace-nowrap transition-colors duration-150 ease-in-out';\n\n/**\n * A rounded track of mutually-exclusive options — the segmented \"one of these\" control.\n *\n * Owns the track background, the selected-thumb chrome and the radiogroup semantics in\n * one place, so consumers never hand-roll a track around `PillButton` (whose `default`\n * variant tokens are tuned for standalone filter pills, not for a sunken track).\n *\n * Selection is conveyed non-visually via `role=\"radio\"` + `aria-checked`, and by a\n * foreground-colour change as well as the thumb, so it does not rest on background\n * colour alone.\n */\nconst SegmentedControl = <T extends string = string>({\n options,\n value,\n onChange,\n size = 'medium',\n fullWidth = false,\n disabled = false,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n className = '',\n}: SegmentedControlProps<T>) => {\n const itemRefs = useRef<(HTMLButtonElement | null)[]>([]);\n const sizeBlock = SIZE_CLASSES[size];\n\n const selectedIndex = options.findIndex((option) => option.value === value);\n // Roving tabindex: the group is a single tab stop. When the selected option is\n // missing or disabled, the first enabled option takes the stop so the control is\n // still reachable by keyboard.\n const selectedIsEnabled = selectedIndex >= 0 && !options[selectedIndex].disabled;\n const tabStopIndex = selectedIsEnabled\n ? selectedIndex\n : options.findIndex((option) => !option.disabled);\n\n const handleKeyDown = useCallback(\n (event: React.KeyboardEvent) => {\n if (disabled || !NAV_KEYS.has(event.key)) {\n return;\n }\n\n const enabled = options.reduce<\n Array<{ option: SegmentedControlOption<T>; index: number }>\n >((acc, option, index) => {\n if (!option.disabled) {\n acc.push({ option, index });\n }\n return acc;\n }, []);\n if (enabled.length === 0) {\n return;\n }\n\n // Only once we know we'll act — otherwise Home/End etc. should still scroll.\n event.preventDefault();\n\n const currentPosition = enabled.findIndex(({ option }) => option.value === value);\n let nextPosition: number;\n if (event.key === 'Home') {\n nextPosition = 0;\n } else if (event.key === 'End') {\n nextPosition = enabled.length - 1;\n } else {\n const delta = event.key === 'ArrowLeft' || event.key === 'ArrowUp' ? -1 : 1;\n const from = currentPosition === -1 ? 0 : currentPosition;\n nextPosition = (from + delta + enabled.length) % enabled.length;\n }\n\n const next = enabled[nextPosition];\n if (next.option.value !== value) {\n onChange(next.option.value);\n }\n itemRefs.current[next.index]?.focus();\n },\n [disabled, onChange, options, value],\n );\n\n return (\n <div\n role=\"radiogroup\"\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n aria-disabled={disabled || undefined}\n onKeyDown={handleKeyDown}\n className={`${\n // One display utility, not two: `flex` and `inline-flex` are both plain\n // `display` utilities, so emitting both would resolve by stylesheet order\n // (same hazard as the background above).\n fullWidth ? 'flex w-full' : 'inline-flex'\n } ${sizeBlock.track} items-center gap-1 p-0.5 rounded-xl bg-[var(--malachite-segmented-control-track-background)] ${\n disabled ? 'opacity-50' : ''\n } ${className}`}\n >\n {options.map((option, index) => {\n const isSelected = option.value === value;\n const isDisabled = disabled || option.disabled;\n const hasBadge =\n option.badge !== undefined && option.badge !== null && option.badge !== false;\n\n let colorClasses: string;\n if (isSelected) {\n colorClasses =\n 'bg-[var(--malachite-segmented-control-selected-background)] text-[var(--malachite-segmented-control-selected-foreground)]';\n } else if (isDisabled) {\n colorClasses =\n 'bg-transparent text-[var(--malachite-segmented-control-item-foreground)]';\n } else {\n colorClasses =\n 'bg-transparent text-[var(--malachite-segmented-control-item-foreground)] hover:text-[var(--malachite-segmented-control-item-hover-foreground)] cursor-pointer';\n }\n\n return (\n <button\n key={option.value}\n ref={(element) => {\n itemRefs.current[index] = element;\n }}\n type=\"button\"\n role=\"radio\"\n aria-checked={isSelected}\n disabled={isDisabled}\n tabIndex={index === tabStopIndex ? 0 : -1}\n onClick={() => {\n // Radios don't toggle off on re-click.\n if (!isDisabled && !isSelected) {\n onChange(option.value);\n }\n }}\n className={`${FOCUS_RING} ${ITEM_BASE} ${sizeBlock.text} ${sizeBlock.item} ${colorClasses} ${\n fullWidth ? 'flex-1' : ''\n } ${option.disabled && !disabled ? 'opacity-50 cursor-not-allowed' : ''}`}\n style={{\n // Inline rather than a `shadow-[...]` class: Tailwind's shadow\n // utilities compose `--tw-shadow-*` custom properties that rely on\n // document-level @property registration and silently don't paint\n // inside a shadow root (same caveat as `ring-*`).\n boxShadow: isSelected\n ? 'var(--malachite-segmented-control-selected-shadow, 0px 1px 5px 0px rgba(0, 0, 0, 0.1))'\n : undefined,\n }}\n >\n {option.icon ? (\n <span className=\"inline-flex items-center justify-center w-4 h-4 shrink-0\">\n {option.icon}\n </span>\n ) : null}\n {option.label}\n {/* The space keeps the name \"Annual Save\" rather than \"AnnualSave\";\n the flex gap already spaces the two visually. */}\n {hasBadge ? ' ' : null}\n {hasBadge ? (\n <span className=\"inline-flex items-center shrink-0\">\n {option.badge}\n </span>\n ) : null}\n </button>\n );\n })}\n </div>\n );\n};\n\nexport default SegmentedControl;\nexport { SegmentedControl };\nexport type { SegmentedControlProps, SegmentedControlOption, SegmentedControlSize };\n"],"names":["SIZE_CLASSES","NAV_KEYS","ITEM_BASE","SegmentedControl","options","value","onChange","size","fullWidth","disabled","ariaLabel","ariaLabelledBy","className","itemRefs","useRef","sizeBlock","selectedIndex","option","tabStopIndex","handleKeyDown","useCallback","event","enabled","acc","index","currentPosition","nextPosition","delta","next","_a","jsx","isSelected","isDisabled","hasBadge","colorClasses","jsxs","element","FOCUS_RING"],"mappings":";;;AAmCA,MAAMA,IAA4F;AAAA,EAC9F,OAAO;AAAA,IACH,MAAM;AAAA,IACN,OAAO;AAAA,IACP,MAAM;AAAA,EAAA;AAAA,EAEV,QAAQ;AAAA,IACJ,MAAM;AAAA,IACN,OAAO;AAAA,IACP,MAAM;AAAA,EAAA;AAAA,EAEV,OAAO;AAAA,IACH,MAAM;AAAA,IACN,OAAO;AAAA,IACP,MAAM;AAAA,EAAA;AAEd,GAGMC,IAAW,oBAAI,IAAI,CAAC,aAAa,cAAc,WAAW,aAAa,QAAQ,KAAK,CAAC,GAOrFC,IACF,iMAaEC,IAAmB,CAA4B;AAAA,EACjD,SAA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GT,UAAA;AAAA,cAAAd,EAAO,OACJ,gBAAAa,EAAC,QAAA,EAAK,WAAU,4DACX,UAAAb,EAAO,MACZ,IACA;AAAA,cACHA,EAAO;AAAA,cAGPgB,IAAW,MAAM;AAAA,cACjBA,IACG,gBAAAH,EAAC,QAAA,EAAK,WAAU,qCACX,UAAAb,EAAO,OACZ,IACA;AAAA,YAAA;AAAA,UAAA;AAAA,UAzCCA,EAAO;AAAA,QAAA;AAAA,MA4CxB,CAAC;AAAA,IAAA;AAAA,EAAA;AAGb;"}
|
|
1
|
+
{"version":3,"file":"SegmentedControl.js","sources":["../../src/components/SegmentedControl.tsx"],"sourcesContent":["import React, { useRef } from 'react';\nimport { FOCUS_RING } from './focusRing';\nimport { nextRovingIndex, rovingTabStop } from './rovingKeys';\n\ntype SegmentedControlSize = 'small' | 'medium' | 'large';\n\ninterface SegmentedControlOption<T extends string = string> {\n value: T;\n label: string;\n icon?: React.ReactNode;\n /**\n * Small mark after the label, e.g. a compact `Tag` naming a saving. It renders inside\n * the segment's `<button>`, so it must not be interactive — no `onClick` or `onRemove`.\n */\n badge?: React.ReactNode;\n disabled?: boolean;\n}\n\ninterface SegmentedControlProps<T extends string = string> {\n options: SegmentedControlOption<T>[];\n /** The selected option's value. A value not present in `options` renders nothing selected. */\n value: T;\n onChange: (value: T) => void;\n size?: SegmentedControlSize;\n /** Stretch the track to its container and split it into equal segments. */\n fullWidth?: boolean;\n /** Disables every segment. Individual segments can also be disabled via `options`. */\n disabled?: boolean;\n 'aria-label'?: string;\n 'aria-labelledby'?: string;\n className?: string;\n}\n\n// The ladder governs a control's outer box. The height therefore sits on the track and\n// the items fill whatever the 4px inset leaves — putting it on the item instead makes a\n// `medium` segmented control 40px tall beside a 32px Dropdown.\nconst SIZE_CLASSES: Record<SegmentedControlSize, { text: string; track: string; item: string }> = {\n small: {\n text: 'text-[length:var(--malachite-font-size-small,13px)]',\n track: 'h-[var(--malachite-control-height-small,28px)]',\n item: 'h-full px-2.5',\n },\n medium: {\n text: 'text-[length:var(--malachite-font-size-small,13px)]',\n track: 'h-[var(--malachite-control-height-medium,32px)]',\n item: 'h-full px-2.5',\n },\n large: {\n text: 'text-[length:var(--malachite-font-size-15,15px)]',\n track: 'h-[var(--malachite-control-height-large,42px)]',\n item: 'h-full px-4',\n },\n};\n\n// Deliberately no `bg-*` here: each state branch below supplies exactly one\n// background-color utility. Both `bg-transparent` and `bg-[var(--…)]` are plain\n// single-class utilities in the same `@layer utilities`, so an element carrying both\n// resolves by stylesheet order — and the arbitrary value loses, silently rendering the\n// selected thumb transparent.\nconst ITEM_BASE =\n 'inline-flex items-center justify-center gap-1.5 rounded-[var(--malachite-radius-10,10px)] border-0 font-medium tracking-[0.13px] whitespace-nowrap transition-colors duration-150 ease-in-out';\n\n/**\n * A rounded track of mutually-exclusive options — the segmented \"one of these\" control.\n *\n * Owns the track background, the selected-thumb chrome and the radiogroup semantics in\n * one place, so consumers never hand-roll a track around `PillButton` (whose `default`\n * variant tokens are tuned for standalone filter pills, not for a sunken track).\n *\n * Selection is conveyed non-visually via `role=\"radio\"` + `aria-checked`, and by a\n * foreground-colour change as well as the thumb, so it does not rest on background\n * colour alone.\n */\nconst SegmentedControl = <T extends string = string>({\n options,\n value,\n onChange,\n size = 'medium',\n fullWidth = false,\n disabled = false,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n className = '',\n}: SegmentedControlProps<T>) => {\n const itemRefs = useRef<(HTMLButtonElement | null)[]>([]);\n const sizeBlock = SIZE_CLASSES[size];\n\n const selectedIndex = options.findIndex((option) => option.value === value);\n const enabled = options.map((option) => !option.disabled);\n // Roving tabindex: the group is a single tab stop. When the selected option is\n // missing or disabled, the first enabled option takes the stop so the control is\n // still reachable by keyboard.\n const tabStopIndex = rovingTabStop(selectedIndex, enabled);\n\n // Arrow keys move AND select, per the WAI-ARIA radiogroup pattern, from the focused option.\n const handleKeyDown = (event: React.KeyboardEvent) => {\n if (disabled) {\n return;\n }\n const focused = itemRefs.current.findIndex((item) => item === event.target);\n const next = nextRovingIndex(event, focused >= 0 ? focused : tabStopIndex, enabled);\n if (next === undefined) {\n return;\n }\n\n // Only once we know we'll act — otherwise Home/End etc. should still scroll.\n event.preventDefault();\n if (options[next].value !== value) {\n onChange(options[next].value);\n }\n itemRefs.current[next]?.focus();\n };\n\n return (\n <div\n role=\"radiogroup\"\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n aria-disabled={disabled || undefined}\n onKeyDown={handleKeyDown}\n className={`${\n // One display utility, not two: `flex` and `inline-flex` are both plain\n // `display` utilities, so emitting both would resolve by stylesheet order\n // (same hazard as the background above).\n fullWidth ? 'flex w-full' : 'inline-flex'\n } ${sizeBlock.track} items-center gap-1 p-0.5 rounded-xl bg-[var(--malachite-segmented-control-track-background)] ${\n disabled ? 'opacity-50' : ''\n } ${className}`}\n >\n {options.map((option, index) => {\n const isSelected = option.value === value;\n const isDisabled = disabled || option.disabled;\n const hasBadge =\n option.badge !== undefined && option.badge !== null && option.badge !== false;\n\n let colorClasses: string;\n if (isSelected) {\n colorClasses =\n 'bg-[var(--malachite-segmented-control-selected-background)] text-[var(--malachite-segmented-control-selected-foreground)]';\n } else if (isDisabled) {\n colorClasses =\n 'bg-transparent text-[var(--malachite-segmented-control-item-foreground)]';\n } else {\n colorClasses =\n 'bg-transparent text-[var(--malachite-segmented-control-item-foreground)] hover:text-[var(--malachite-segmented-control-item-hover-foreground)] cursor-pointer';\n }\n\n return (\n <button\n key={option.value}\n ref={(element) => {\n itemRefs.current[index] = element;\n }}\n type=\"button\"\n role=\"radio\"\n aria-checked={isSelected}\n disabled={isDisabled}\n tabIndex={index === tabStopIndex ? 0 : -1}\n onClick={() => {\n // Radios don't toggle off on re-click.\n if (!isDisabled && !isSelected) {\n onChange(option.value);\n }\n }}\n className={`${FOCUS_RING} ${ITEM_BASE} ${sizeBlock.text} ${sizeBlock.item} ${colorClasses} ${\n fullWidth ? 'flex-1' : ''\n } ${option.disabled && !disabled ? 'opacity-50 cursor-not-allowed' : ''}`}\n style={{\n // Inline rather than a `shadow-[...]` class: Tailwind's shadow\n // utilities compose `--tw-shadow-*` custom properties that rely on\n // document-level @property registration and silently don't paint\n // inside a shadow root (same caveat as `ring-*`).\n boxShadow: isSelected\n ? 'var(--malachite-segmented-control-selected-shadow, 0px 1px 5px 0px rgba(0, 0, 0, 0.1))'\n : undefined,\n }}\n >\n {option.icon ? (\n <span className=\"inline-flex items-center justify-center w-4 h-4 shrink-0\">\n {option.icon}\n </span>\n ) : null}\n {option.label}\n {/* The space keeps the name \"Annual Save\" rather than \"AnnualSave\";\n the flex gap already spaces the two visually. */}\n {hasBadge ? ' ' : null}\n {hasBadge ? (\n <span className=\"inline-flex items-center shrink-0\">\n {option.badge}\n </span>\n ) : null}\n </button>\n );\n })}\n </div>\n );\n};\n\nexport default SegmentedControl;\nexport { SegmentedControl };\nexport type { SegmentedControlProps, SegmentedControlOption, SegmentedControlSize };\n"],"names":["SIZE_CLASSES","ITEM_BASE","SegmentedControl","options","value","onChange","size","fullWidth","disabled","ariaLabel","ariaLabelledBy","className","itemRefs","useRef","sizeBlock","selectedIndex","option","enabled","tabStopIndex","rovingTabStop","jsx","event","focused","item","next","nextRovingIndex","_a","index","isSelected","isDisabled","hasBadge","colorClasses","jsxs","element","FOCUS_RING"],"mappings":";;;;AAoCA,MAAMA,IAA4F;AAAA,EAC9F,OAAO;AAAA,IACH,MAAM;AAAA,IACN,OAAO;AAAA,IACP,MAAM;AAAA,EAAA;AAAA,EAEV,QAAQ;AAAA,IACJ,MAAM;AAAA,IACN,OAAO;AAAA,IACP,MAAM;AAAA,EAAA;AAAA,EAEV,OAAO;AAAA,IACH,MAAM;AAAA,IACN,OAAO;AAAA,IACP,MAAM;AAAA,EAAA;AAEd,GAOMC,IACF,iMAaEC,IAAmB,CAA4B;AAAA,EACjD,SAAAC;AAAA,EACA,OAAAC;AAAA,EACA,UAAAC;AAAA,EACA,MAAAC,IAAO;AAAA,EACP,WAAAC,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AA,UAAC;AAAA,UAAA;AAAA,YAEG,KAAK,CAACC,MAAY;AACd,cAAArB,EAAS,QAAQe,CAAK,IAAIM;AAAA,YAC9B;AAAA,YACA,MAAK;AAAA,YACL,MAAK;AAAA,YACL,gBAAcL;AAAA,YACd,UAAUC;AAAA,YACV,UAAUF,MAAUT,IAAe,IAAI;AAAA,YACvC,SAAS,MAAM;AAEX,cAAI,CAACW,KAAc,CAACD,KAChBvB,EAASW,EAAO,KAAK;AAAA,YAE7B;AAAA,YACA,WAAW,GAAGkB,CAAU,IAAIjC,CAAS,IAAIa,EAAU,IAAI,IAAIA,EAAU,IAAI,IAAIiB,CAAY,IACrFxB,IAAY,WAAW,EAC3B,IAAIS,EAAO,YAAY,CAACR,IAAW,kCAAkC,EAAE;AAAA,YACvE,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA,cAKH,WAAWoB,IACL,2FACA;AAAA,YAAA;AAAA,YAGT,UAAA;AAAA,cAAAZ,EAAO,OACJ,gBAAAI,EAAC,QAAA,EAAK,WAAU,4DACX,UAAAJ,EAAO,MACZ,IACA;AAAA,cACHA,EAAO;AAAA,cAGPc,IAAW,MAAM;AAAA,cACjBA,IACG,gBAAAV,EAAC,QAAA,EAAK,WAAU,qCACX,UAAAJ,EAAO,OACZ,IACA;AAAA,YAAA;AAAA,UAAA;AAAA,UAzCCA,EAAO;AAAA,QAAA;AAAA,MA4CxB,CAAC;AAAA,IAAA;AAAA,EAAA;AAGb;"}
|
|
@@ -1,101 +1,107 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { isRenderableNode as
|
|
5
|
-
const i = 24,
|
|
1
|
+
import { jsx as t, jsxs as o } from "react/jsx-runtime";
|
|
2
|
+
import N from "./CustomIcons/CheckmarkIcon.js";
|
|
3
|
+
import c from "./Typography/Text.js";
|
|
4
|
+
import { isRenderableNode as s } from "./renderableNode.js";
|
|
5
|
+
const i = 24, g = 1, E = {
|
|
6
6
|
medium: { padding: { x: 28, y: 16 }, title: "medium", description: "small" },
|
|
7
7
|
small: { padding: { x: 20, y: 12 }, title: "small", description: "xsmall" }
|
|
8
|
-
},
|
|
8
|
+
}, $ = {
|
|
9
9
|
complete: "Completed",
|
|
10
10
|
open: void 0,
|
|
11
11
|
locked: "Locked"
|
|
12
|
-
},
|
|
13
|
-
insetInlineStart:
|
|
14
|
-
top:
|
|
15
|
-
height: `calc(100% - ${i - (r ?
|
|
16
|
-
}),
|
|
12
|
+
}, z = (a, r) => ({
|
|
13
|
+
insetInlineStart: a.x + i / 2 - 1,
|
|
14
|
+
top: a.y + i,
|
|
15
|
+
height: `calc(100% - ${i - (r ? g : 0)}px)`
|
|
16
|
+
}), d = "var(--malachite-card-border, rgb(232, 232, 232))", A = "var(--malachite-accent-background, rgb(0, 175, 102))", I = `repeating-linear-gradient(to bottom, ${d} 0px, ${d} 4px, transparent 4px, transparent 8px)`, R = {
|
|
17
17
|
complete: "bg-[var(--malachite-accent-background,rgb(0,175,102))] text-white",
|
|
18
18
|
open: "border-[1.5px] border-solid border-[var(--malachite-accent-background,rgb(0,175,102))] bg-[var(--malachite-card-background,rgb(255,255,255))] text-[var(--malachite-accent-foreground,rgb(2,122,66))]",
|
|
19
19
|
locked: "border-[1.5px] border-solid border-[var(--malachite-text-dimmed,rgb(153,153,153))] bg-[var(--malachite-card-background,rgb(255,255,255))] text-[var(--malachite-text-dimmed,rgb(153,153,153))]"
|
|
20
|
-
},
|
|
21
|
-
steps:
|
|
20
|
+
}, w = (a, r) => a.key ?? `#${r}`, j = ({
|
|
21
|
+
steps: a,
|
|
22
22
|
size: r = "medium",
|
|
23
|
-
dividers:
|
|
24
|
-
|
|
25
|
-
"aria-
|
|
26
|
-
|
|
23
|
+
dividers: m = !1,
|
|
24
|
+
completeLabel: p,
|
|
25
|
+
"aria-label": u,
|
|
26
|
+
"aria-labelledby": f,
|
|
27
|
+
className: k = ""
|
|
27
28
|
}) => {
|
|
28
|
-
const
|
|
29
|
+
const l = E[r], y = a.findIndex((e) => e.status === "open"), b = (e) => !!p && e.status === "complete" && !s(e.action), v = /* @__PURE__ */ o("span", { "aria-hidden": "true", className: "flex items-center gap-[6px]", children: [
|
|
30
|
+
/* @__PURE__ */ t("span", { className: "size-[8px] shrink-0 rounded-full bg-[var(--malachite-text-success,rgb(2,122,66))]" }),
|
|
31
|
+
/* @__PURE__ */ t(c, { size: "small", fontWeight: "semi-bold", color: "success", children: p })
|
|
32
|
+
] }), S = a.some(
|
|
33
|
+
(e) => s(e.action) || b(e)
|
|
34
|
+
);
|
|
29
35
|
return (
|
|
30
36
|
// `role="list"`: Safari drops the list role from a list styled `list-none`.
|
|
31
|
-
/* @__PURE__ */
|
|
37
|
+
/* @__PURE__ */ t(
|
|
32
38
|
"ol",
|
|
33
39
|
{
|
|
34
40
|
role: "list",
|
|
35
|
-
"aria-label":
|
|
36
|
-
"aria-labelledby":
|
|
37
|
-
className: `isolate m-0 list-none p-0 ${
|
|
38
|
-
children:
|
|
39
|
-
const
|
|
40
|
-
return /* @__PURE__ */
|
|
41
|
+
"aria-label": u,
|
|
42
|
+
"aria-labelledby": f,
|
|
43
|
+
className: `isolate m-0 list-none p-0 ${k}`,
|
|
44
|
+
children: a.map((e, n) => {
|
|
45
|
+
const x = e.status === "locked", h = $[e.status];
|
|
46
|
+
return /* @__PURE__ */ o(
|
|
41
47
|
"li",
|
|
42
48
|
{
|
|
43
|
-
"aria-current":
|
|
49
|
+
"aria-current": n === y ? "step" : void 0,
|
|
44
50
|
style: {
|
|
45
|
-
padding: `${
|
|
46
|
-
borderBottom:
|
|
51
|
+
padding: `${l.padding.y}px ${l.padding.x}px`,
|
|
52
|
+
borderBottom: m ? `${g}px solid ${d}` : void 0
|
|
47
53
|
},
|
|
48
54
|
className: "relative flex items-start gap-[12px]",
|
|
49
55
|
children: [
|
|
50
|
-
|
|
56
|
+
n < a.length - 1 && /* @__PURE__ */ t(
|
|
51
57
|
"span",
|
|
52
58
|
{
|
|
53
59
|
"aria-hidden": "true",
|
|
54
60
|
className: "absolute z-[1] w-[2px]",
|
|
55
61
|
style: {
|
|
56
|
-
...
|
|
57
|
-
background: e.status === "complete" ?
|
|
62
|
+
...z(l.padding, m),
|
|
63
|
+
background: e.status === "complete" ? A : I
|
|
58
64
|
}
|
|
59
65
|
}
|
|
60
66
|
),
|
|
61
|
-
/* @__PURE__ */
|
|
67
|
+
/* @__PURE__ */ t(
|
|
62
68
|
"span",
|
|
63
69
|
{
|
|
64
70
|
"aria-hidden": "true",
|
|
65
|
-
className: `relative z-[2] box-border flex shrink-0 items-center justify-center rounded-full text-[length:var(--malachite-font-size-xsmall,11px)] [font-weight:600] ${
|
|
71
|
+
className: `relative z-[2] box-border flex shrink-0 items-center justify-center rounded-full text-[length:var(--malachite-font-size-xsmall,11px)] [font-weight:600] ${R[e.status]}`,
|
|
66
72
|
style: { width: i, height: i },
|
|
67
|
-
children: e.status === "complete" ? /* @__PURE__ */
|
|
73
|
+
children: e.status === "complete" ? /* @__PURE__ */ t(N, { size: 12 }) : n + 1
|
|
68
74
|
}
|
|
69
75
|
),
|
|
70
|
-
/* @__PURE__ */
|
|
71
|
-
/* @__PURE__ */
|
|
72
|
-
|
|
76
|
+
/* @__PURE__ */ o("span", { className: "flex min-w-0 flex-1 flex-col gap-[2px] pt-[2px]", children: [
|
|
77
|
+
/* @__PURE__ */ o(
|
|
78
|
+
c,
|
|
73
79
|
{
|
|
74
|
-
size:
|
|
80
|
+
size: l.title,
|
|
75
81
|
fontWeight: "semi-bold",
|
|
76
|
-
color:
|
|
82
|
+
color: x ? "dimmed" : "primary",
|
|
77
83
|
children: [
|
|
78
84
|
e.title,
|
|
79
|
-
|
|
85
|
+
h && /* @__PURE__ */ o("span", { className: "sr-only", children: [
|
|
80
86
|
", ",
|
|
81
|
-
|
|
87
|
+
h
|
|
82
88
|
] })
|
|
83
89
|
]
|
|
84
90
|
}
|
|
85
91
|
),
|
|
86
|
-
|
|
87
|
-
|
|
92
|
+
s(e.description) && /* @__PURE__ */ t(
|
|
93
|
+
c,
|
|
88
94
|
{
|
|
89
|
-
size:
|
|
90
|
-
color:
|
|
95
|
+
size: l.description,
|
|
96
|
+
color: x ? "dimmed" : "secondary",
|
|
91
97
|
children: e.description
|
|
92
98
|
}
|
|
93
99
|
)
|
|
94
100
|
] }),
|
|
95
|
-
|
|
101
|
+
S && /* @__PURE__ */ t("span", { className: "ml-[16px] flex min-w-[120px] items-center justify-end", children: b(e) ? v : e.action })
|
|
96
102
|
]
|
|
97
103
|
},
|
|
98
|
-
|
|
104
|
+
w(e, n)
|
|
99
105
|
);
|
|
100
106
|
})
|
|
101
107
|
}
|
|
@@ -103,7 +109,7 @@ const i = 24, x = 1, v = {
|
|
|
103
109
|
);
|
|
104
110
|
};
|
|
105
111
|
export {
|
|
106
|
-
|
|
107
|
-
|
|
112
|
+
j as StepList,
|
|
113
|
+
j as default
|
|
108
114
|
};
|
|
109
115
|
//# sourceMappingURL=StepList.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StepList.js","sources":["../../src/components/StepList.tsx"],"sourcesContent":["import type React from 'react';\nimport CheckmarkIcon from './CustomIcons/CheckmarkIcon';\nimport Text from './Typography/Text';\nimport { isRenderableNode } from './renderableNode';\n\nexport type StepListStatus = 'complete' | 'open' | 'locked';\n\nexport type StepListSize = 'medium' | 'small';\n\nexport interface StepListItem {\n /** Keys the row; falls back to its position, so pass one when steps come and go. */\n key?: string;\n title: React.ReactNode;\n description?: React.ReactNode;\n /**\n * `complete` fills the marker with a tick, `open` rings it in the accent, and `locked`\n * dims the marker and the text. The first `open` step is the current one.\n */\n status: StepListStatus;\n /**\n * Right of the text, e.g. the step's button. The state is already announced after the\n * title, so a label that repeats it, such as \"Completed\", wants `aria-hidden`.\n */\n action?: React.ReactNode;\n}\n\nexport interface StepListProps {\n steps: StepListItem[];\n /** `small` is the compact list for a sidebar: tighter rows and smaller text. */\n size?: StepListSize;\n /** Rules a line under each row, for a list that fills its container edge to edge. */\n dividers?: boolean;\n 'aria-label'?: string;\n 'aria-labelledby'?: string;\n /** On the list. Each connector runs to the next row's marker, so add no gap between rows. */\n className?: string;\n}\n\nconst MARKER_SIZE = 24;\nconst DIVIDER_WIDTH = 1;\n\nconst SIZES: Record<\n StepListSize,\n {\n padding: { x: number; y: number };\n title: 'medium' | 'small';\n description: 'small' | 'xsmall';\n }\n> = {\n medium: { padding: { x: 28, y: 16 }, title: 'medium', description: 'small' },\n small: { padding: { x: 20, y: 12 }, title: 'small', description: 'xsmall' },\n};\n\n// Read out after the title: the marker is hidden, and the dimmed text alone says nothing.\nconst STATUS_LABELS: Record<StepListStatus, string | undefined> = {\n complete: 'Completed',\n open: undefined,\n locked: 'Locked',\n};\n\n// From a marker's foot, through the next row's top padding and any rule, to its marker.\nconst connectorStyle = (\n padding: { x: number; y: number },\n divider: boolean,\n): React.CSSProperties => ({\n insetInlineStart: padding.x + MARKER_SIZE / 2 - 1,\n top: padding.y + MARKER_SIZE,\n height: `calc(100% - ${MARKER_SIZE - (divider ? DIVIDER_WIDTH : 0)}px)`,\n});\n\nconst BORDER = 'var(--malachite-card-border, rgb(232, 232, 232))';\nconst ACCENT = 'var(--malachite-accent-background, rgb(0, 175, 102))';\n\nconst DASHED = `repeating-linear-gradient(to bottom, ${BORDER} 0px, ${BORDER} 4px, transparent 4px, transparent 8px)`;\n\n// White on the accent fill in both themes, as Checkbox draws its tick.\nconst MARKER_CLASSES: Record<StepListStatus, string> = {\n complete: 'bg-[var(--malachite-accent-background,rgb(0,175,102))] text-white',\n open: 'border-[1.5px] border-solid border-[var(--malachite-accent-background,rgb(0,175,102))] bg-[var(--malachite-card-background,rgb(255,255,255))] text-[var(--malachite-accent-foreground,rgb(2,122,66))]',\n locked: 'border-[1.5px] border-solid border-[var(--malachite-text-dimmed,rgb(153,153,153))] bg-[var(--malachite-card-background,rgb(255,255,255))] text-[var(--malachite-text-dimmed,rgb(153,153,153))]',\n};\n\n// The position, not the title: two steps may share one. `#` keeps it off consumers' keys.\nconst keyOf = (step: StepListItem, index: number): string => step.key ?? `#${index}`;\n\n/**\n * A numbered, vertical list of setup steps: a marker per step joined by a line that turns\n * solid once a step is done, the step's title and description, and an optional action.\n */\nconst StepList: React.FC<StepListProps> = ({\n steps,\n size = 'medium',\n dividers = false,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n className = '',\n}) => {\n const sizing = SIZES[size];\n const current = steps.findIndex((step) => step.status === 'open');\n // Every row keeps the column once any step has an action, so the text wraps alike.\n const hasActions = steps.some((step) => isRenderableNode(step.action));\n\n return (\n // `role=\"list\"`: Safari drops the list role from a list styled `list-none`.\n <ol\n role=\"list\"\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n className={`isolate m-0 list-none p-0 ${className}`}\n >\n {steps.map((step, index) => {\n const locked = step.status === 'locked';\n const statusLabel = STATUS_LABELS[step.status];\n return (\n <li\n key={keyOf(step, index)}\n aria-current={index === current ? 'step' : undefined}\n style={{\n padding: `${sizing.padding.y}px ${sizing.padding.x}px`,\n borderBottom: dividers\n ? `${DIVIDER_WIDTH}px solid ${BORDER}`\n : undefined,\n }}\n className=\"relative flex items-start gap-[12px]\"\n >\n {index < steps.length - 1 && (\n <span\n aria-hidden=\"true\"\n className=\"absolute z-[1] w-[2px]\"\n style={{\n ...connectorStyle(sizing.padding, dividers),\n background: step.status === 'complete' ? ACCENT : DASHED,\n }}\n />\n )}\n <span\n aria-hidden=\"true\"\n className={`relative z-[2] box-border flex shrink-0 items-center justify-center rounded-full text-[length:var(--malachite-font-size-xsmall,11px)] [font-weight:600] ${MARKER_CLASSES[step.status]}`}\n style={{ width: MARKER_SIZE, height: MARKER_SIZE }}\n >\n {step.status === 'complete' ? <CheckmarkIcon size={12} /> : index + 1}\n </span>\n <span className=\"flex min-w-0 flex-1 flex-col gap-[2px] pt-[2px]\">\n <Text\n size={sizing.title}\n fontWeight=\"semi-bold\"\n color={locked ? 'dimmed' : 'primary'}\n >\n {step.title}\n {statusLabel && <span className=\"sr-only\">, {statusLabel}</span>}\n </Text>\n {isRenderableNode(step.description) && (\n <Text\n size={sizing.description}\n color={locked ? 'dimmed' : 'secondary'}\n >\n {step.description}\n </Text>\n )}\n </span>\n {hasActions && (\n <span className=\"ml-[16px] flex min-w-[120px] items-center justify-end\">\n {step.action}\n </span>\n )}\n </li>\n );\n })}\n </ol>\n );\n};\n\nexport default StepList;\nexport { StepList };\n"],"names":["MARKER_SIZE","DIVIDER_WIDTH","SIZES","STATUS_LABELS","connectorStyle","padding","divider","BORDER","ACCENT","DASHED","MARKER_CLASSES","keyOf","step","index","StepList","steps","size","dividers","ariaLabel","ariaLabelledBy","className","sizing","current","hasActions","isRenderableNode","jsx","locked","statusLabel","jsxs","CheckmarkIcon","Text"],"mappings":";;;;AAsCA,MAAMA,IAAc,IACdC,IAAgB,GAEhBC,IAOF;AAAA,EACA,QAAQ,EAAE,SAAS,EAAE,GAAG,IAAI,GAAG,GAAA,GAAM,OAAO,UAAU,aAAa,QAAA;AAAA,EACnE,OAAO,EAAE,SAAS,EAAE,GAAG,IAAI,GAAG,MAAM,OAAO,SAAS,aAAa,SAAA;AACrE,GAGMC,IAA4D;AAAA,EAC9D,UAAU;AAAA,EACV,MAAM;AAAA,EACN,QAAQ;AACZ,GAGMC,IAAiB,CACnBC,GACAC,OACuB;AAAA,EACvB,kBAAkBD,EAAQ,IAAIL,IAAc,IAAI;AAAA,EAChD,KAAKK,EAAQ,IAAIL;AAAA,EACjB,QAAQ,eAAeA,KAAeM,IAAUL,IAAgB,EAAE;AACtE,IAEMM,IAAS,oDACTC,IAAS,wDAETC,IAAS,wCAAwCF,CAAM,SAASA,CAAM,2CAGtEG,IAAiD;AAAA,EACnD,UAAU;AAAA,EACV,MAAM;AAAA,EACN,QAAQ;AACZ,GAGMC,IAAQ,CAACC,GAAoBC,MAA0BD,EAAK,OAAO,IAAIC,CAAK,IAM5EC,IAAoC,CAAC;AAAA,EACvC,OAAAC;AAAA,EACA,MAAAC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OZ,GAAa,QAAQA,EAAA;AAAA,oBAEpC,UAAAY,EAAK,WAAW,aAAa,gBAAAa,EAACI,KAAc,MAAM,IAAI,IAAKhB,IAAQ;AAAA,kBAAA;AAAA,gBAAA;AAAA,gBAExE,gBAAAe,EAAC,QAAA,EAAK,WAAU,mDACZ,UAAA;AAAA,kBAAA,gBAAAA;AAAA,oBAACE;AAAA,oBAAA;AAAA,sBACG,MAAMT,EAAO;AAAA,sBACb,YAAW;AAAA,sBACX,OAAOK,IAAS,WAAW;AAAA,sBAE1B,UAAA;AAAA,wBAAAd,EAAK;AAAA,wBACLe,KAAe,gBAAAC,EAAC,QAAA,EAAK,WAAU,WAAU,UAAA;AAAA,0BAAA;AAAA,0BAAGD;AAAA,wBAAA,EAAA,CAAY;AAAA,sBAAA;AAAA,oBAAA;AAAA,kBAAA;AAAA,kBAE5DH,EAAiBZ,EAAK,WAAW,KAC9B,gBAAAa;AAAA,oBAACK;AAAA,oBAAA;AAAA,sBACG,MAAMT,EAAO;AAAA,sBACb,OAAOK,IAAS,WAAW;AAAA,sBAE1B,UAAAd,EAAK;AAAA,oBAAA;AAAA,kBAAA;AAAA,gBACV,GAER;AAAA,gBACCW,KACG,gBAAAE,EAAC,QAAA,EAAK,WAAU,yDACX,YAAK,OAAA,CACV;AAAA,cAAA;AAAA,YAAA;AAAA,YAhDCd,EAAMC,GAAMC,CAAK;AAAA,UAAA;AAAA,QAoDlC,CAAC;AAAA,MAAA;AAAA,IAAA;AAAA;AAGb;"}
|
|
1
|
+
{"version":3,"file":"StepList.js","sources":["../../src/components/StepList.tsx"],"sourcesContent":["import type React from 'react';\nimport CheckmarkIcon from './CustomIcons/CheckmarkIcon';\nimport Text from './Typography/Text';\nimport { isRenderableNode } from './renderableNode';\n\nexport type StepListStatus = 'complete' | 'open' | 'locked';\n\nexport type StepListSize = 'medium' | 'small';\n\nexport interface StepListItem {\n /** Keys the row; falls back to its position, so pass one when steps come and go. */\n key?: string;\n title: React.ReactNode;\n description?: React.ReactNode;\n /**\n * `complete` fills the marker with a tick, `open` rings it in the accent, and `locked`\n * dims the marker and the text. The first `open` step is the current one.\n */\n status: StepListStatus;\n /** Right of the text, e.g. the step's button. See `completeLabel` for a complete step. */\n action?: React.ReactNode;\n}\n\nexport interface StepListProps {\n steps: StepListItem[];\n /** `small` is the compact list for a sidebar: tighter rows and smaller text. */\n size?: StepListSize;\n /** Rules a line under each row, for a list that fills its container edge to edge. */\n dividers?: boolean;\n /**\n * Shown, with a dot, in the action column of a complete step that has no `action`, e.g.\n * \"Completed\". Hidden from assistive tech, which already hears the state after the title.\n */\n completeLabel?: string;\n 'aria-label'?: string;\n 'aria-labelledby'?: string;\n /** On the list. Each connector runs to the next row's marker, so add no gap between rows. */\n className?: string;\n}\n\nconst MARKER_SIZE = 24;\nconst DIVIDER_WIDTH = 1;\n\nconst SIZES: Record<\n StepListSize,\n {\n padding: { x: number; y: number };\n title: 'medium' | 'small';\n description: 'small' | 'xsmall';\n }\n> = {\n medium: { padding: { x: 28, y: 16 }, title: 'medium', description: 'small' },\n small: { padding: { x: 20, y: 12 }, title: 'small', description: 'xsmall' },\n};\n\n// Read out after the title: the marker is hidden, and the dimmed text alone says nothing.\nconst STATUS_LABELS: Record<StepListStatus, string | undefined> = {\n complete: 'Completed',\n open: undefined,\n locked: 'Locked',\n};\n\n// From a marker's foot, through the next row's top padding and any rule, to its marker.\nconst connectorStyle = (\n padding: { x: number; y: number },\n divider: boolean,\n): React.CSSProperties => ({\n insetInlineStart: padding.x + MARKER_SIZE / 2 - 1,\n top: padding.y + MARKER_SIZE,\n height: `calc(100% - ${MARKER_SIZE - (divider ? DIVIDER_WIDTH : 0)}px)`,\n});\n\nconst BORDER = 'var(--malachite-card-border, rgb(232, 232, 232))';\nconst ACCENT = 'var(--malachite-accent-background, rgb(0, 175, 102))';\n\nconst DASHED = `repeating-linear-gradient(to bottom, ${BORDER} 0px, ${BORDER} 4px, transparent 4px, transparent 8px)`;\n\n// White on the accent fill in both themes, as Checkbox draws its tick.\nconst MARKER_CLASSES: Record<StepListStatus, string> = {\n complete: 'bg-[var(--malachite-accent-background,rgb(0,175,102))] text-white',\n open: 'border-[1.5px] border-solid border-[var(--malachite-accent-background,rgb(0,175,102))] bg-[var(--malachite-card-background,rgb(255,255,255))] text-[var(--malachite-accent-foreground,rgb(2,122,66))]',\n locked: 'border-[1.5px] border-solid border-[var(--malachite-text-dimmed,rgb(153,153,153))] bg-[var(--malachite-card-background,rgb(255,255,255))] text-[var(--malachite-text-dimmed,rgb(153,153,153))]',\n};\n\n// The position, not the title: two steps may share one. `#` keeps it off consumers' keys.\nconst keyOf = (step: StepListItem, index: number): string => step.key ?? `#${index}`;\n\n/**\n * A numbered, vertical list of setup steps: a marker per step joined by a line that turns\n * solid once a step is done, the step's title and description, and an optional action.\n */\nconst StepList: React.FC<StepListProps> = ({\n steps,\n size = 'medium',\n dividers = false,\n completeLabel,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n className = '',\n}) => {\n const sizing = SIZES[size];\n const current = steps.findIndex((step) => step.status === 'open');\n const showsCompleteLabel = (step: StepListItem) =>\n Boolean(completeLabel) && step.status === 'complete' && !isRenderableNode(step.action);\n const completeMark = (\n <span aria-hidden=\"true\" className=\"flex items-center gap-[6px]\">\n {/* Success, as its text: the label reports a status, not a choice. */}\n <span className=\"size-[8px] shrink-0 rounded-full bg-[var(--malachite-text-success,rgb(2,122,66))]\" />\n <Text size=\"small\" fontWeight=\"semi-bold\" color=\"success\">\n {completeLabel}\n </Text>\n </span>\n );\n // Every row keeps the column once any step has an action or a complete label, so the text\n // wraps alike.\n const hasActions = steps.some(\n (step) => isRenderableNode(step.action) || showsCompleteLabel(step),\n );\n\n return (\n // `role=\"list\"`: Safari drops the list role from a list styled `list-none`.\n <ol\n role=\"list\"\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n className={`isolate m-0 list-none p-0 ${className}`}\n >\n {steps.map((step, index) => {\n const locked = step.status === 'locked';\n const statusLabel = STATUS_LABELS[step.status];\n return (\n <li\n key={keyOf(step, index)}\n aria-current={index === current ? 'step' : undefined}\n style={{\n padding: `${sizing.padding.y}px ${sizing.padding.x}px`,\n borderBottom: dividers\n ? `${DIVIDER_WIDTH}px solid ${BORDER}`\n : undefined,\n }}\n className=\"relative flex items-start gap-[12px]\"\n >\n {index < steps.length - 1 && (\n <span\n aria-hidden=\"true\"\n className=\"absolute z-[1] w-[2px]\"\n style={{\n ...connectorStyle(sizing.padding, dividers),\n background: step.status === 'complete' ? ACCENT : DASHED,\n }}\n />\n )}\n <span\n aria-hidden=\"true\"\n className={`relative z-[2] box-border flex shrink-0 items-center justify-center rounded-full text-[length:var(--malachite-font-size-xsmall,11px)] [font-weight:600] ${MARKER_CLASSES[step.status]}`}\n style={{ width: MARKER_SIZE, height: MARKER_SIZE }}\n >\n {step.status === 'complete' ? <CheckmarkIcon size={12} /> : index + 1}\n </span>\n <span className=\"flex min-w-0 flex-1 flex-col gap-[2px] pt-[2px]\">\n <Text\n size={sizing.title}\n fontWeight=\"semi-bold\"\n color={locked ? 'dimmed' : 'primary'}\n >\n {step.title}\n {statusLabel && <span className=\"sr-only\">, {statusLabel}</span>}\n </Text>\n {isRenderableNode(step.description) && (\n <Text\n size={sizing.description}\n color={locked ? 'dimmed' : 'secondary'}\n >\n {step.description}\n </Text>\n )}\n </span>\n {hasActions && (\n <span className=\"ml-[16px] flex min-w-[120px] items-center justify-end\">\n {showsCompleteLabel(step) ? completeMark : step.action}\n </span>\n )}\n </li>\n );\n })}\n </ol>\n );\n};\n\nexport default StepList;\nexport { StepList };\n"],"names":["MARKER_SIZE","DIVIDER_WIDTH","SIZES","STATUS_LABELS","connectorStyle","padding","divider","BORDER","ACCENT","DASHED","MARKER_CLASSES","keyOf","step","index","StepList","steps","size","dividers","completeLabel","ariaLabel","ariaLabelledBy","className","sizing","current","showsCompleteLabel","isRenderableNode","completeMark","jsxs","jsx","Text","hasActions","locked","statusLabel","CheckmarkIcon"],"mappings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IAAQ;AAAA,kBAAA;AAAA,gBAAA;AAAA,gBAExE,gBAAAc,EAAC,QAAA,EAAK,WAAU,mDACZ,UAAA;AAAA,kBAAA,gBAAAA;AAAA,oBAACE;AAAA,oBAAA;AAAA,sBACG,MAAMP,EAAO;AAAA,sBACb,YAAW;AAAA,sBACX,OAAOS,IAAS,WAAW;AAAA,sBAE1B,UAAA;AAAA,wBAAAnB,EAAK;AAAA,wBACLoB,KAAe,gBAAAL,EAAC,QAAA,EAAK,WAAU,WAAU,UAAA;AAAA,0BAAA;AAAA,0BAAGK;AAAA,wBAAA,EAAA,CAAY;AAAA,sBAAA;AAAA,oBAAA;AAAA,kBAAA;AAAA,kBAE5DP,EAAiBb,EAAK,WAAW,KAC9B,gBAAAgB;AAAA,oBAACC;AAAA,oBAAA;AAAA,sBACG,MAAMP,EAAO;AAAA,sBACb,OAAOS,IAAS,WAAW;AAAA,sBAE1B,UAAAnB,EAAK;AAAA,oBAAA;AAAA,kBAAA;AAAA,gBACV,GAER;AAAA,gBACCkB,KACG,gBAAAF,EAAC,QAAA,EAAK,WAAU,yDACX,YAAmBhB,CAAI,IAAIc,IAAed,EAAK,OAAA,CACpD;AAAA,cAAA;AAAA,YAAA;AAAA,YAhDCD,EAAMC,GAAMC,CAAK;AAAA,UAAA;AAAA,QAoDlC,CAAC;AAAA,MAAA;AAAA,IAAA;AAAA;AAGb;"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const s = { ArrowDown: 1, ArrowRight: 1, ArrowUp: -1, ArrowLeft: -1 }, g = (o) => !(o.altKey || o.ctrlKey || o.metaKey) && (o.key in s || o.key === "Home" || o.key === "End"), k = (o, r, n) => {
|
|
2
|
+
if (!g(o))
|
|
3
|
+
return;
|
|
4
|
+
const f = (i) => i < 0 ? void 0 : i;
|
|
5
|
+
if (o.key === "Home")
|
|
6
|
+
return f(n.indexOf(!0));
|
|
7
|
+
if (o.key === "End")
|
|
8
|
+
return f(n.lastIndexOf(!0));
|
|
9
|
+
const t = n.length, y = s[o.key], u = r >= 0 ? r : y > 0 ? -1 : t;
|
|
10
|
+
return Array.from(
|
|
11
|
+
{ length: t },
|
|
12
|
+
(i, c) => ((u + y * (c + 1)) % t + t) % t
|
|
13
|
+
).find((i) => n[i]);
|
|
14
|
+
}, d = (o, r) => o >= 0 && r[o] ? o : r.indexOf(!0);
|
|
15
|
+
export {
|
|
16
|
+
g as isRovingKey,
|
|
17
|
+
k as nextRovingIndex,
|
|
18
|
+
d as rovingTabStop
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=rovingKeys.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rovingKeys.js","sources":["../../src/components/rovingKeys.ts"],"sourcesContent":["const STEPS: Record<string, number> = { ArrowDown: 1, ArrowRight: 1, ArrowUp: -1, ArrowLeft: -1 };\n\ntype RovingKeyEvent = Pick<KeyboardEvent, 'key' | 'altKey' | 'ctrlKey' | 'metaKey'>;\n\n/** An arrow, Home or End key with no modifier held: one a roving group acts on. */\nexport const isRovingKey = (event: RovingKeyEvent): boolean =>\n !(event.altKey || event.ctrlKey || event.metaKey) &&\n (event.key in STEPS || event.key === 'Home' || event.key === 'End');\n\n/**\n * The option an arrow, Home or End key moves a roving tab stop to among `enabled`, wrapping and\n * skipping disabled options; undefined for any other key or with a modifier held, so browser and\n * OS shortcuts (Alt+ArrowLeft, Cmd+ArrowLeft) still reach the page.\n */\nexport const nextRovingIndex = (\n event: RovingKeyEvent,\n current: number,\n enabled: readonly boolean[],\n): number | undefined => {\n if (!isRovingKey(event)) {\n return undefined;\n }\n const found = (index: number) => (index < 0 ? undefined : index);\n if (event.key === 'Home') {\n return found(enabled.indexOf(true));\n }\n if (event.key === 'End') {\n return found(enabled.lastIndexOf(true));\n }\n const count = enabled.length;\n const step = STEPS[event.key];\n // From outside the list, forward lands on the first option and backward on the last.\n const from = current >= 0 ? current : step > 0 ? -1 : count;\n return Array.from(\n { length: count },\n (_, offset) => (((from + step * (offset + 1)) % count) + count) % count,\n ).find((index) => enabled[index]);\n};\n\n/** The one tab stop of a roving group: the chosen option, or else the first that can take focus. */\nexport const rovingTabStop = (chosen: number, enabled: readonly boolean[]): number =>\n chosen >= 0 && enabled[chosen] ? chosen : enabled.indexOf(true);\n"],"names":["STEPS","isRovingKey","event","nextRovingIndex","current","enabled","found","index","count","step","from","_","offset","rovingTabStop","chosen"],"mappings":"AAAA,MAAMA,IAAgC,EAAE,WAAW,GAAG,YAAY,GAAG,SAAS,IAAI,WAAW,GAAA,GAKhFC,IAAc,CAACC,MACxB,EAAEA,EAAM,UAAUA,EAAM,WAAWA,EAAM,aACxCA,EAAM,OAAOF,KAASE,EAAM,QAAQ,UAAUA,EAAM,QAAQ,QAOpDC,IAAkB,CAC3BD,GACAE,GACAC,MACqB;AACrB,MAAI,CAACJ,EAAYC,CAAK;AAClB;AAEJ,QAAMI,IAAQ,CAACC,MAAmBA,IAAQ,IAAI,SAAYA;AAC1D,MAAIL,EAAM,QAAQ;AACd,WAAOI,EAAMD,EAAQ,QAAQ,EAAI,CAAC;AAEtC,MAAIH,EAAM,QAAQ;AACd,WAAOI,EAAMD,EAAQ,YAAY,EAAI,CAAC;AAE1C,QAAMG,IAAQH,EAAQ,QAChBI,IAAOT,EAAME,EAAM,GAAG,GAEtBQ,IAAON,KAAW,IAAIA,IAAUK,IAAO,IAAI,KAAKD;AACtD,SAAO,MAAM;AAAA,IACT,EAAE,QAAQA,EAAA;AAAA,IACV,CAACG,GAAGC,QAAcF,IAAOD,KAAQG,IAAS,MAAMJ,IAASA,KAASA;AAAA,EAAA,EACpE,KAAK,CAACD,MAAUF,EAAQE,CAAK,CAAC;AACpC,GAGaM,IAAgB,CAACC,GAAgBT,MAC1CS,KAAU,KAAKT,EAAQS,CAAM,IAAIA,IAAST,EAAQ,QAAQ,EAAI;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1063,6 +1063,73 @@ export declare const CheckmarkIcon: React.FC<IconProps_26>;
|
|
|
1063
1063
|
|
|
1064
1064
|
export declare const ChevronsUpDownIcon: React.FC<IconProps_27>;
|
|
1065
1065
|
|
|
1066
|
+
/**
|
|
1067
|
+
* A grid of tiles to choose one option from: the chosen tile takes the accent border, tint and a
|
|
1068
|
+
* corner tick. `mode` sets the semantics; see `ChoiceGroupProps['mode']`. The tick overhangs the
|
|
1069
|
+
* tile's top-right corner by a third of its size, so leave that room above and after the group.
|
|
1070
|
+
*/
|
|
1071
|
+
export declare function ChoiceGroup<T extends string = string>({ options, value, onChange, mode, size, columns, custom, disabled, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, className, }: ChoiceGroupProps<T>): default_2.ReactElement;
|
|
1072
|
+
|
|
1073
|
+
declare interface ChoiceGroupBaseProps<T extends string = string> {
|
|
1074
|
+
options: ChoiceGroupOption<T>[];
|
|
1075
|
+
/** The chosen option; one not in `options`, or none, leaves every tile unchosen. */
|
|
1076
|
+
value: T | undefined;
|
|
1077
|
+
onChange: (value: T) => void;
|
|
1078
|
+
/** `small` centres a label in a compact tile; `medium` leads with `icon`. */
|
|
1079
|
+
size?: ChoiceGroupSize;
|
|
1080
|
+
/** Columns across the grid, counting the `custom` cell. */
|
|
1081
|
+
columns?: ChoiceGroupColumns;
|
|
1082
|
+
disabled?: boolean;
|
|
1083
|
+
'aria-label'?: string;
|
|
1084
|
+
'aria-labelledby'?: string;
|
|
1085
|
+
className?: string;
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
export declare type ChoiceGroupColumns = 1 | 2 | 3 | 4 | 5 | 6;
|
|
1089
|
+
|
|
1090
|
+
export declare interface ChoiceGroupCustom {
|
|
1091
|
+
/**
|
|
1092
|
+
* A control that holds a choice of its own, such as a custom date picker. It fills the cell, and
|
|
1093
|
+
* the tick covers its top-right corner while chosen, so keep that corner clear.
|
|
1094
|
+
*/
|
|
1095
|
+
control: default_2.ReactNode;
|
|
1096
|
+
/** Names the cell, a group announced as focus enters it: "<label>, chosen" while chosen. */
|
|
1097
|
+
label: string;
|
|
1098
|
+
/** Ticks the control's cell, as a chosen tile is ticked. */
|
|
1099
|
+
chosen: boolean;
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
export declare type ChoiceGroupMode = 'radio' | 'toggle';
|
|
1103
|
+
|
|
1104
|
+
export declare interface ChoiceGroupOption<T extends string = string> {
|
|
1105
|
+
value: T;
|
|
1106
|
+
label: string;
|
|
1107
|
+
/** Before the label in a `medium` tile, such as a client's logo. Decorative. */
|
|
1108
|
+
icon?: default_2.ReactNode;
|
|
1109
|
+
/** A neutral corner mark while the option is not chosen, such as a star on a recommended one. */
|
|
1110
|
+
mark?: default_2.ReactNode;
|
|
1111
|
+
/** Names the option when its label alone says too little, e.g. "1 year, recommended". */
|
|
1112
|
+
'aria-label'?: string;
|
|
1113
|
+
disabled?: boolean;
|
|
1114
|
+
}
|
|
1115
|
+
|
|
1116
|
+
/**
|
|
1117
|
+
* `radio` is one choice among many: a single tab stop, moved with the arrow keys, Home and End,
|
|
1118
|
+
* and a press on the chosen tile changes nothing. `toggle` is a row of pressed buttons, each its
|
|
1119
|
+
* own tab stop, that reports every press, the chosen tile's too. Only a toggle group takes
|
|
1120
|
+
* `custom`, a last cell for a choice the tiles can't hold, such as a custom date: a radiogroup
|
|
1121
|
+
* may hold nothing but radios.
|
|
1122
|
+
*/
|
|
1123
|
+
export declare type ChoiceGroupProps<T extends string = string> = ChoiceGroupBaseProps<T> & ({
|
|
1124
|
+
mode?: 'radio';
|
|
1125
|
+
custom?: never;
|
|
1126
|
+
} | {
|
|
1127
|
+
mode: 'toggle';
|
|
1128
|
+
custom?: ChoiceGroupCustom;
|
|
1129
|
+
});
|
|
1130
|
+
|
|
1131
|
+
export declare type ChoiceGroupSize = 'small' | 'medium';
|
|
1132
|
+
|
|
1066
1133
|
/**
|
|
1067
1134
|
* Text clamped to `lines`, revealing the full text on hover / keyboard focus when
|
|
1068
1135
|
* `expandOnHover`. Pure CSS. The expanded state caps at 1000px, so this is for short blurbs.
|
|
@@ -4578,6 +4645,36 @@ export declare type RequiredIndicator = 'optional-suffix' | 'asterisk' | 'none';
|
|
|
4578
4645
|
*/
|
|
4579
4646
|
export declare function resetTheme(): void;
|
|
4580
4647
|
|
|
4648
|
+
/** A card pointing at a resource elsewhere, such as an SDK's documentation. */
|
|
4649
|
+
export declare const ResourceCard: default_2.FC<ResourceCardProps> & {
|
|
4650
|
+
Header: typeof ResourceHeader;
|
|
4651
|
+
};
|
|
4652
|
+
|
|
4653
|
+
export declare interface ResourceCardProps extends ResourceHeaderProps {
|
|
4654
|
+
href: string;
|
|
4655
|
+
/** The link's text; opens `href` in a new tab. */
|
|
4656
|
+
linkLabel?: string;
|
|
4657
|
+
titleAs?: ResourceCardTitleElement;
|
|
4658
|
+
className?: string;
|
|
4659
|
+
}
|
|
4660
|
+
|
|
4661
|
+
export declare type ResourceCardTitleElement = 'h3' | 'h4';
|
|
4662
|
+
|
|
4663
|
+
/**
|
|
4664
|
+
* A resource's icon tile, title and a two-line description, all phrasing content: the header of
|
|
4665
|
+
* a section that opens on a resource, such as an Accordion's, inside its button.
|
|
4666
|
+
*/
|
|
4667
|
+
declare const ResourceHeader: default_2.FC<ResourceHeaderProps>;
|
|
4668
|
+
|
|
4669
|
+
/** Phrasing content only, title included, so it can sit inside a button such as an Accordion's. */
|
|
4670
|
+
export declare interface ResourceHeaderProps {
|
|
4671
|
+
/** In a muted tile before the title. Decorative: the title names the resource. */
|
|
4672
|
+
icon: default_2.ReactNode;
|
|
4673
|
+
title: string;
|
|
4674
|
+
/** Clamped to two lines. */
|
|
4675
|
+
description?: string;
|
|
4676
|
+
}
|
|
4677
|
+
|
|
4581
4678
|
/**
|
|
4582
4679
|
* What sits at the far end of a field's label row. Data rather than a node, so nothing
|
|
4583
4680
|
* arbitrary reaches the row; discriminated so a further kind is additive. Plain text is
|
|
@@ -5262,10 +5359,7 @@ export declare interface StepListItem {
|
|
|
5262
5359
|
* dims the marker and the text. The first `open` step is the current one.
|
|
5263
5360
|
*/
|
|
5264
5361
|
status: StepListStatus;
|
|
5265
|
-
/**
|
|
5266
|
-
* Right of the text, e.g. the step's button. The state is already announced after the
|
|
5267
|
-
* title, so a label that repeats it, such as "Completed", wants `aria-hidden`.
|
|
5268
|
-
*/
|
|
5362
|
+
/** Right of the text, e.g. the step's button. See `completeLabel` for a complete step. */
|
|
5269
5363
|
action?: default_2.ReactNode;
|
|
5270
5364
|
}
|
|
5271
5365
|
|
|
@@ -5275,6 +5369,11 @@ export declare interface StepListProps {
|
|
|
5275
5369
|
size?: StepListSize;
|
|
5276
5370
|
/** Rules a line under each row, for a list that fills its container edge to edge. */
|
|
5277
5371
|
dividers?: boolean;
|
|
5372
|
+
/**
|
|
5373
|
+
* Shown, with a dot, in the action column of a complete step that has no `action`, e.g.
|
|
5374
|
+
* "Completed". Hidden from assistive tech, which already hears the state after the title.
|
|
5375
|
+
*/
|
|
5376
|
+
completeLabel?: string;
|
|
5278
5377
|
'aria-label'?: string;
|
|
5279
5378
|
'aria-labelledby'?: string;
|
|
5280
5379
|
/** On the list. Each connector runs to the next row's marker, so add no gap between rows. */
|