rift-ds 1.24.0 → 1.25.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.
Files changed (99) hide show
  1. package/README.md +4 -4
  2. package/chat/ChatWidget.d.ts +5 -1
  3. package/chat/ChatWidget.js +12 -1
  4. package/components/Attachment/Attachment.css +8 -0
  5. package/components/Attachment/AttachmentViewer.js +26 -5
  6. package/components/Attachment/fileTypes.d.ts +4 -0
  7. package/components/CurrencyInput/CurrencyInput.css +12 -0
  8. package/components/CurrencyInput/CurrencyInput.d.ts +51 -0
  9. package/components/CurrencyInput/CurrencyInput.js +158 -0
  10. package/components/DataTable/columnTypes.js +4 -16
  11. package/components/DatePicker/DatePicker.d.ts +2 -0
  12. package/components/DatePicker/DatePicker.js +44 -131
  13. package/components/DatePicker/MonthGrid.d.ts +56 -0
  14. package/components/DatePicker/MonthGrid.js +65 -0
  15. package/components/DatePicker/calendar.d.ts +42 -0
  16. package/components/DatePicker/calendar.js +108 -0
  17. package/components/DateRangePicker/DateRangePicker.css +92 -0
  18. package/components/DateRangePicker/DateRangePicker.d.ts +86 -0
  19. package/components/DateRangePicker/DateRangePicker.js +294 -0
  20. package/components/Deadline/Deadline.css +82 -0
  21. package/components/Deadline/Deadline.d.ts +44 -0
  22. package/components/Deadline/Deadline.js +94 -0
  23. package/components/Deadline/deadlineStatus.d.ts +15 -0
  24. package/components/Deadline/deadlineStatus.js +13 -0
  25. package/components/DescriptionList/DescriptionList.css +184 -0
  26. package/components/DescriptionList/DescriptionList.d.ts +64 -0
  27. package/components/DescriptionList/DescriptionList.js +100 -0
  28. package/components/DescriptionList/DescriptionListCopy.d.ts +18 -0
  29. package/components/DescriptionList/DescriptionListCopy.js +45 -0
  30. package/components/DocumentViewer/DocumentViewer.css +188 -0
  31. package/components/DocumentViewer/DocumentViewer.d.ts +59 -0
  32. package/components/DocumentViewer/DocumentViewer.js +185 -0
  33. package/components/ErrorSummary/ErrorSummary.css +94 -0
  34. package/components/ErrorSummary/ErrorSummary.d.ts +34 -0
  35. package/components/ErrorSummary/ErrorSummary.js +70 -0
  36. package/components/ErrorSummary/fieldErrors.d.ts +36 -0
  37. package/components/ErrorSummary/fieldErrors.js +19 -0
  38. package/components/Field/Field.css +12 -0
  39. package/components/Field/Field.d.ts +10 -2
  40. package/components/Field/Field.js +12 -5
  41. package/components/Heading/Heading.css +129 -0
  42. package/components/Heading/Heading.d.ts +31 -0
  43. package/components/Heading/Heading.js +39 -0
  44. package/components/Input/Input.css +120 -0
  45. package/components/Input/Input.d.ts +20 -1
  46. package/components/Input/Input.js +70 -5
  47. package/components/Link/Link.css +84 -0
  48. package/components/Link/Link.d.ts +43 -0
  49. package/components/Link/Link.js +74 -0
  50. package/components/List/List.css +173 -0
  51. package/components/List/List.d.ts +44 -0
  52. package/components/List/List.js +60 -0
  53. package/components/MaskedInput/MaskedInput.css +16 -0
  54. package/components/MaskedInput/MaskedInput.d.ts +57 -0
  55. package/components/MaskedInput/MaskedInput.js +142 -0
  56. package/components/MaskedInput/mask.d.ts +58 -0
  57. package/components/MaskedInput/mask.js +106 -0
  58. package/components/ShaderScene/ShaderScene.css +19 -0
  59. package/components/ShaderScene/ShaderScene.d.ts +82 -0
  60. package/components/ShaderScene/ShaderScene.js +144 -0
  61. package/components/ShaderScene/assemble.d.ts +5 -0
  62. package/components/ShaderScene/assemble.js +74 -0
  63. package/components/ShaderScene/common.glsl.d.ts +6 -0
  64. package/components/ShaderScene/common.glsl.js +49 -0
  65. package/components/ShaderScene/passes.d.ts +2 -0
  66. package/components/ShaderScene/passes.js +93 -0
  67. package/components/ShaderScene/renderer.d.ts +35 -0
  68. package/components/ShaderScene/renderer.js +125 -0
  69. package/components/ShaderScene/scenes.d.ts +20 -0
  70. package/components/ShaderScene/scenes.js +184 -0
  71. package/components/ShaderScene/types.d.ts +70 -0
  72. package/components/ShaderScene/types.js +8 -0
  73. package/components/SignaturePad/SignaturePad.css +141 -0
  74. package/components/SignaturePad/SignaturePad.d.ts +68 -0
  75. package/components/SignaturePad/SignaturePad.js +287 -0
  76. package/components/SignaturePad/signature.d.ts +32 -0
  77. package/components/SignaturePad/signature.js +46 -0
  78. package/components/Text/Text.css +129 -0
  79. package/components/Text/Text.d.ts +36 -0
  80. package/components/Text/Text.js +36 -0
  81. package/components/Widget/Widget.css +111 -0
  82. package/components/Widget/Widget.d.ts +15 -1
  83. package/components/Widget/Widget.js +63 -11
  84. package/components/Widget/WidgetDisclosure.d.ts +30 -0
  85. package/components/Widget/WidgetDisclosure.js +52 -0
  86. package/components/registry.json +111 -2
  87. package/components/registry.json.d.ts +111 -2
  88. package/components/registry.json.js +2 -2
  89. package/format/index.d.ts +15 -0
  90. package/format/index.js +17 -0
  91. package/format/money.d.ts +89 -0
  92. package/format/money.js +187 -0
  93. package/format/relative.d.ts +49 -0
  94. package/format/relative.js +50 -0
  95. package/index.d.ts +13 -0
  96. package/index.js +46 -0
  97. package/package.json +9 -2
  98. package/tokens/motion.d.ts +4 -0
  99. package/tokens/motion.js +4 -0
@@ -0,0 +1,185 @@
1
+ "use client";
2
+ import { jsx, jsxs, Fragment } from "react/jsx-runtime";
3
+ import { useState, useEffect } from "react";
4
+ import { CircularButton } from "../CircularButton/CircularButton.js";
5
+ import { Button } from "../Button/Button.js";
6
+ import { Spinner } from "../Spinner/Spinner.js";
7
+ import { useLocale } from "../../behaviors/LocaleProvider.js";
8
+ import { getFileKind } from "../Attachment/fileTypes.js";
9
+ import "../../fonts/material-symbols.css";
10
+ import "../../behaviors/visually-hidden.css";
11
+ import "./DocumentViewer.css";
12
+ const ZOOMS = [0.5, 0.75, 1, 1.5, 2, 3];
13
+ function resolveKind(kind, name, mime) {
14
+ if (kind !== "auto") return kind;
15
+ const file = getFileKind({ name, type: mime });
16
+ if (file === "pdf" || file === "image") return file;
17
+ if (file === "text" || file === "code" || file === "pasted") return "text";
18
+ return null;
19
+ }
20
+ function DocumentViewer({
21
+ src,
22
+ title,
23
+ kind = "auto",
24
+ fileName,
25
+ mimeType,
26
+ height = "default",
27
+ bare = false,
28
+ download = true,
29
+ onDownload,
30
+ openInNewTab = true,
31
+ toolbar,
32
+ fallback,
33
+ downloadLabel = "Download",
34
+ openLabel = "Open in new tab",
35
+ zoomInLabel = "Zoom in",
36
+ zoomOutLabel = "Zoom out",
37
+ resetZoomLabel,
38
+ loadingLabel = "Loading document",
39
+ fallbackLabel = "This file can’t be shown here.",
40
+ locale: localeProp,
41
+ className = "",
42
+ ref,
43
+ ...rest
44
+ }) {
45
+ const locale = useLocale(localeProp);
46
+ const name = fileName ?? decodeURIComponent(src.split(/[?#]/)[0].split("/").pop() ?? "");
47
+ const resolved = resolveKind(kind, name, mimeType);
48
+ const [zoom, setZoom] = useState(ZOOMS.indexOf(1));
49
+ const [text, setText] = useState(null);
50
+ useEffect(() => {
51
+ if (resolved !== "text") return;
52
+ let cancelled = false;
53
+ fetch(src).then((response) => response.ok ? response.text() : Promise.reject(new Error(String(response.status)))).then((body2) => !cancelled && setText({ src, body: body2, failed: false })).catch(() => !cancelled && setText({ src, body: null, failed: true }));
54
+ return () => {
55
+ cancelled = true;
56
+ };
57
+ }, [resolved, src]);
58
+ const downloadName = typeof download === "string" ? download : name || void 0;
59
+ const downloadButton = download ? onDownload ? /* @__PURE__ */ jsx(CircularButton, { icon: "download", variant: "tertiary", size: "compact", ariaLabel: downloadLabel, onClick: onDownload }) : /* @__PURE__ */ jsx(
60
+ CircularButton,
61
+ {
62
+ icon: "download",
63
+ variant: "tertiary",
64
+ size: "compact",
65
+ ariaLabel: downloadLabel,
66
+ href: src,
67
+ ...{ download: downloadName }
68
+ }
69
+ ) : null;
70
+ const fallbackNode = fallback ?? /* @__PURE__ */ jsxs("div", { className: "ds-document-viewer__fallback", children: [
71
+ /* @__PURE__ */ jsx("span", { className: "ds-document-viewer__fallback-icon material-symbols-rounded", "aria-hidden": "true", children: "description" }),
72
+ /* @__PURE__ */ jsx("p", { className: "ds-document-viewer__fallback-text", children: fallbackLabel }),
73
+ download && (onDownload ? /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "compact", iconLeft: "download", label: downloadLabel, onClick: onDownload }) : /* @__PURE__ */ jsx(
74
+ Button,
75
+ {
76
+ variant: "secondary",
77
+ size: "compact",
78
+ iconLeft: "download",
79
+ label: downloadLabel,
80
+ href: src,
81
+ ...{ download: downloadName }
82
+ }
83
+ ))
84
+ ] });
85
+ const percent = new Intl.NumberFormat(locale, { style: "percent" }).format(ZOOMS[zoom]);
86
+ const resetLabel = resetZoomLabel ? resetZoomLabel(percent) : `Fit to width, now ${percent}`;
87
+ let body;
88
+ if (resolved === "pdf") {
89
+ body = /* @__PURE__ */ jsx("object", { className: "ds-document-viewer__frame", data: src, type: "application/pdf", "aria-label": title, children: fallbackNode });
90
+ } else if (resolved === "image") {
91
+ body = /* @__PURE__ */ jsx("div", { className: "ds-document-viewer__scroll", role: "region", "aria-label": title, tabIndex: 0, children: /* @__PURE__ */ jsx(
92
+ "img",
93
+ {
94
+ className: "ds-document-viewer__image",
95
+ src,
96
+ alt: title,
97
+ style: { inlineSize: `${ZOOMS[zoom] * 100}%` }
98
+ }
99
+ ) });
100
+ } else if (resolved === "text") {
101
+ const current = text?.src === src ? text : null;
102
+ body = current?.failed ? fallbackNode : current?.body != null ? /* @__PURE__ */ jsx("div", { className: "ds-document-viewer__scroll", role: "region", "aria-label": title, tabIndex: 0, children: /* @__PURE__ */ jsx("pre", { className: "ds-document-viewer__text", children: current.body }) }) : /* @__PURE__ */ jsxs("div", { className: "ds-document-viewer__loading", role: "status", children: [
103
+ /* @__PURE__ */ jsx(Spinner, { size: "md" }),
104
+ /* @__PURE__ */ jsx("span", { className: "ds-visually-hidden", children: loadingLabel })
105
+ ] });
106
+ } else {
107
+ body = fallbackNode;
108
+ }
109
+ return (
110
+ // The frame itself stays unnamed, so it is a plain container rather than
111
+ // a second landmark beside the scrolling region the title names.
112
+ /* @__PURE__ */ jsxs(
113
+ "section",
114
+ {
115
+ ...rest,
116
+ ref,
117
+ className: [
118
+ "ds-document-viewer",
119
+ `ds-document-viewer--height-${bare ? "fill" : height}`,
120
+ bare && "ds-document-viewer--bare",
121
+ className
122
+ ].filter(Boolean).join(" "),
123
+ children: [
124
+ !bare && /* @__PURE__ */ jsxs("header", { className: "ds-document-viewer__toolbar", children: [
125
+ /* @__PURE__ */ jsx("span", { className: "ds-document-viewer__title", children: title }),
126
+ /* @__PURE__ */ jsxs("div", { className: "ds-document-viewer__actions", children: [
127
+ resolved === "image" && /* @__PURE__ */ jsxs(Fragment, { children: [
128
+ /* @__PURE__ */ jsx(
129
+ CircularButton,
130
+ {
131
+ icon: "zoom_out",
132
+ variant: "tertiary",
133
+ size: "compact",
134
+ ariaLabel: zoomOutLabel,
135
+ disabled: zoom === 0,
136
+ onClick: () => setZoom((z) => Math.max(0, z - 1))
137
+ }
138
+ ),
139
+ /* @__PURE__ */ jsx(
140
+ "button",
141
+ {
142
+ type: "button",
143
+ className: "ds-document-viewer__zoom",
144
+ "aria-label": resetLabel,
145
+ onClick: () => setZoom(ZOOMS.indexOf(1)),
146
+ children: percent
147
+ }
148
+ ),
149
+ /* @__PURE__ */ jsx(
150
+ CircularButton,
151
+ {
152
+ icon: "zoom_in",
153
+ variant: "tertiary",
154
+ size: "compact",
155
+ ariaLabel: zoomInLabel,
156
+ disabled: zoom === ZOOMS.length - 1,
157
+ onClick: () => setZoom((z) => Math.min(ZOOMS.length - 1, z + 1))
158
+ }
159
+ )
160
+ ] }),
161
+ toolbar,
162
+ openInNewTab && /* @__PURE__ */ jsx(
163
+ CircularButton,
164
+ {
165
+ icon: "open_in_new",
166
+ variant: "tertiary",
167
+ size: "compact",
168
+ ariaLabel: openLabel,
169
+ href: src,
170
+ target: "_blank",
171
+ rel: "noopener noreferrer"
172
+ }
173
+ ),
174
+ downloadButton
175
+ ] })
176
+ ] }),
177
+ /* @__PURE__ */ jsx("div", { className: "ds-document-viewer__body", children: body })
178
+ ]
179
+ }
180
+ )
181
+ );
182
+ }
183
+ export {
184
+ DocumentViewer
185
+ };
@@ -0,0 +1,94 @@
1
+ /* ============================================
2
+ ERROR SUMMARY
3
+ The Alert's error surface (status fill, status
4
+ border, its radius and inset), holding a
5
+ heading and a list of links, one per error.
6
+ ============================================ */
7
+
8
+ /* Base */
9
+ .ds-error-summary {
10
+ display: flex;
11
+ align-items: flex-start;
12
+ gap: var(--gap-200);
13
+ box-sizing: border-box;
14
+ width: 100%;
15
+ padding: var(--padding-400);
16
+ border: var(--border-025) solid var(--color-status-error-border);
17
+ border-radius: var(--radius-200);
18
+ background-color: var(--color-status-error-bg);
19
+ color: var(--color-status-error-text);
20
+ }
21
+
22
+ .ds-error-summary:focus {
23
+ outline: none;
24
+ }
25
+
26
+ .ds-error-summary:focus-visible {
27
+ outline: var(--border-050) solid var(--color-action-primary-bg);
28
+ outline-offset: var(--border-050);
29
+ }
30
+
31
+ .ds-error-summary__icon {
32
+ flex-shrink: 0;
33
+ --icon-size: var(--icon-size-600);
34
+ line-height: 1;
35
+ color: var(--color-status-error-border);
36
+ }
37
+
38
+ .ds-error-summary__content {
39
+ display: flex;
40
+ flex: 1;
41
+ flex-direction: column;
42
+ gap: var(--gap-100);
43
+ min-width: 0;
44
+ }
45
+
46
+ .ds-error-summary__title {
47
+ margin: 0;
48
+ font-family: var(--font-paragraph-emphasis-family);
49
+ font-size: var(--font-paragraph-emphasis-size);
50
+ font-weight: var(--font-paragraph-emphasis-weight);
51
+ line-height: var(--font-paragraph-emphasis-line-height);
52
+ letter-spacing: var(--font-paragraph-emphasis-letter-spacing);
53
+ }
54
+
55
+ .ds-error-summary__description {
56
+ margin: 0;
57
+ font-family: var(--font-paragraph-family);
58
+ font-size: var(--font-paragraph-size);
59
+ font-weight: var(--font-paragraph-weight);
60
+ line-height: var(--font-paragraph-line-height);
61
+ letter-spacing: var(--font-paragraph-letter-spacing);
62
+ }
63
+
64
+ /* List */
65
+ .ds-error-summary__list {
66
+ display: flex;
67
+ flex-direction: column;
68
+ gap: var(--gap-100);
69
+ margin: 0;
70
+ padding: 0;
71
+ list-style: none;
72
+ }
73
+
74
+ .ds-error-summary__link {
75
+ border-radius: var(--radius-050);
76
+ font-family: var(--font-paragraph-family);
77
+ font-size: var(--font-paragraph-size);
78
+ font-weight: var(--font-paragraph-weight);
79
+ line-height: var(--font-paragraph-line-height);
80
+ letter-spacing: var(--font-paragraph-letter-spacing);
81
+ color: inherit;
82
+ text-decoration-line: underline;
83
+ text-decoration-thickness: from-font;
84
+ text-underline-offset: 0.2em;
85
+ }
86
+
87
+ .ds-error-summary__link:hover {
88
+ text-decoration-thickness: var(--border-050);
89
+ }
90
+
91
+ .ds-error-summary__link:focus-visible {
92
+ outline: var(--border-050) solid var(--color-action-primary-bg);
93
+ outline-offset: var(--border-050);
94
+ }
@@ -0,0 +1,34 @@
1
+ import { default as React } from 'react';
2
+ import { ErrorSummaryError } from './fieldErrors';
3
+ /** Props owned by ErrorSummary itself; everything else falls through to the root `<section>`. */
4
+ type ErrorSummaryOwnProps = {
5
+ /** The errors, in the form's order: each the id of the control it belongs to and what is wrong. The summary renders nothing while the list is empty. */
6
+ errors: ErrorSummaryError<React.ReactNode>[];
7
+ /** The heading, in place of the one `titleLabel` writes. Note: this replaces the native `title` attribute, which ErrorSummary does not expose. */
8
+ title?: React.ReactNode;
9
+ /** The heading for a given number of errors: the count as a number (for a plural rule) and as written in the locale (for display). Defaults to "There is a problem" for one and "There are <count> problems" for more. */
10
+ titleLabel?: (count: number, formatted: string) => string;
11
+ /** A line under the heading, before the list. */
12
+ description?: React.ReactNode;
13
+ /** Move focus to the summary when the list goes from empty to holding errors (on a submit), so a screen reader reads it and a keyboard user starts from it. Defaults to true. */
14
+ focusOnMount?: boolean;
15
+ /** The heading's level, so the summary takes its place in the page's outline. Defaults to 2. */
16
+ headingLevel?: 2 | 3 | 4;
17
+ /** Called with a control's id after its link moves focus to it. */
18
+ onErrorClick?: (id: string) => void;
19
+ /** The BCP 47 locale the count is written in. Defaults to the nearest LocaleProvider's, else `en-US`. */
20
+ locale?: string;
21
+ /** Additional CSS classes. */
22
+ className?: string;
23
+ };
24
+ export interface ErrorSummaryProps extends ErrorSummaryOwnProps, Omit<React.ComponentPropsWithRef<'section'>, keyof ErrorSummaryOwnProps | 'children'> {
25
+ }
26
+ /**
27
+ * Every error on a form in one place, at the top of it: a heading that says
28
+ * how many, and a link per error that moves focus to the control and scrolls
29
+ * it into view. Takes the focus when errors first appear, so the reader
30
+ * starts from what needs fixing.
31
+ */
32
+ export declare function ErrorSummary({ errors, title, titleLabel, description, focusOnMount, headingLevel, onErrorClick, locale: localeProp, className, ref, ...rest }: ErrorSummaryProps): React.JSX.Element | null;
33
+ export { fieldErrorsFrom } from './fieldErrors';
34
+ export type { ErrorSummaryError, FieldErrors, FieldErrorsFromOptions } from './fieldErrors';
@@ -0,0 +1,70 @@
1
+ "use client";
2
+ import { jsxs, jsx } from "react/jsx-runtime";
3
+ import { useId, useRef, useEffect } from "react";
4
+ import { useLocale } from "../../behaviors/LocaleProvider.js";
5
+ import { formatNumber } from "../../behaviors/locale.js";
6
+ import "../../fonts/material-symbols.css";
7
+ import "./ErrorSummary.css";
8
+ const DEFAULT_TITLE_LABEL = (count, formatted) => count === 1 ? "There is a problem" : `There are ${formatted} problems`;
9
+ function ErrorSummary({
10
+ errors,
11
+ title,
12
+ titleLabel = DEFAULT_TITLE_LABEL,
13
+ description,
14
+ focusOnMount = true,
15
+ headingLevel = 2,
16
+ onErrorClick,
17
+ locale: localeProp,
18
+ className = "",
19
+ ref,
20
+ ...rest
21
+ }) {
22
+ const locale = useLocale(localeProp);
23
+ const headingId = useId();
24
+ const rootRef = useRef(null);
25
+ const hadErrors = useRef(false);
26
+ const count = errors.length;
27
+ useEffect(() => {
28
+ const has = count > 0;
29
+ if (has && !hadErrors.current && focusOnMount) rootRef.current?.focus();
30
+ hadErrors.current = has;
31
+ }, [count, focusOnMount]);
32
+ if (count === 0) return null;
33
+ const setRef = (node) => {
34
+ rootRef.current = node;
35
+ if (typeof ref === "function") ref(node);
36
+ else if (ref) ref.current = node;
37
+ };
38
+ const goTo = (event, id) => {
39
+ const target = document.getElementById(id);
40
+ if (!target) return;
41
+ event.preventDefault();
42
+ const frame = target.closest(".ds-field") ?? target;
43
+ frame.scrollIntoView({ block: "center" });
44
+ target.focus({ preventScroll: true });
45
+ onErrorClick?.(id);
46
+ };
47
+ const Heading = `h${headingLevel}`;
48
+ const heading = title ?? titleLabel(count, formatNumber(count, locale));
49
+ return /* @__PURE__ */ jsxs(
50
+ "section",
51
+ {
52
+ ...rest,
53
+ ref: setRef,
54
+ tabIndex: -1,
55
+ "aria-labelledby": headingId,
56
+ className: ["ds-error-summary", className].filter(Boolean).join(" "),
57
+ children: [
58
+ /* @__PURE__ */ jsx("span", { className: "ds-error-summary__icon material-symbols-rounded", "aria-hidden": "true", children: "error" }),
59
+ /* @__PURE__ */ jsxs("div", { className: "ds-error-summary__content", children: [
60
+ /* @__PURE__ */ jsx(Heading, { className: "ds-error-summary__title", id: headingId, children: heading }),
61
+ description != null && description !== false && /* @__PURE__ */ jsx("p", { className: "ds-error-summary__description", children: description }),
62
+ /* @__PURE__ */ jsx("ul", { className: "ds-error-summary__list", children: errors.map((error, index) => /* @__PURE__ */ jsx("li", { className: "ds-error-summary__item", children: /* @__PURE__ */ jsx("a", { className: "ds-error-summary__link", href: `#${error.id}`, onClick: (event) => goTo(event, error.id), children: error.message }) }, `${error.id}-${index}`)) })
63
+ ] })
64
+ ]
65
+ }
66
+ );
67
+ }
68
+ export {
69
+ ErrorSummary
70
+ };
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Server field errors into the shapes ErrorSummary and Field take. No React,
3
+ * so a route handler or a form action can call it too.
4
+ */
5
+ /** One error ErrorSummary lists: the id of the control it belongs to, and what is wrong. */
6
+ export type ErrorSummaryError<Message = string> = {
7
+ /** The id of the control the error belongs to; the summary's link focuses it. */
8
+ id: string;
9
+ /** What is wrong, in words that say how to fix it. */
10
+ message: Message;
11
+ };
12
+ /** Options for {@link fieldErrorsFrom}. */
13
+ export type FieldErrorsFromOptions = {
14
+ /** The control id for a field name, when the two differ (`email` named, `signup-email` its id). Defaults to the name itself. */
15
+ idFor?: (name: string) => string;
16
+ /** The order the summary lists fields in, usually the form's own order. Fields not named come after, in the record's order. */
17
+ order?: readonly string[];
18
+ };
19
+ /** What {@link fieldErrorsFrom} returns: the summary's list, and one message per field for its `errorText`. */
20
+ export type FieldErrors = {
21
+ /** Every message, one entry each, for ErrorSummary's `errors`. */
22
+ errors: ErrorSummaryError[];
23
+ /** One message per field name (several joined by a space), for each Field's or Input's `errorText`. */
24
+ errorText: Record<string, string>;
25
+ };
26
+ /**
27
+ * Turn the common server shape, `{ fieldName: message | message[] }`, into
28
+ * ErrorSummary's `errors` and a per-field `errorText` map. Empty messages
29
+ * and empty lists are dropped, so a record with nothing wrong gives empty
30
+ * results.
31
+ *
32
+ * ```ts
33
+ * const { errors, errorText } = fieldErrorsFrom(response.fieldErrors, { order: ['name', 'email'] });
34
+ * ```
35
+ */
36
+ export declare function fieldErrorsFrom(record: Readonly<Record<string, string | readonly string[] | null | undefined>> | null | undefined, options?: FieldErrorsFromOptions): FieldErrors;
@@ -0,0 +1,19 @@
1
+ function fieldErrorsFrom(record, options = {}) {
2
+ const { idFor = (name) => name, order = [] } = options;
3
+ const names = Object.keys(record ?? {});
4
+ const ranked = [...order.filter((name) => names.includes(name)), ...names.filter((name) => !order.includes(name))];
5
+ const errors = [];
6
+ const errorText = {};
7
+ for (const name of ranked) {
8
+ const raw = record?.[name];
9
+ const messages = (Array.isArray(raw) ? raw : [raw]).filter((m) => typeof m === "string" && m.trim() !== "");
10
+ if (messages.length === 0) continue;
11
+ const id = idFor(name);
12
+ for (const message of messages) errors.push({ id, message });
13
+ errorText[name] = messages.join(" ");
14
+ }
15
+ return { errors, errorText };
16
+ }
17
+ export {
18
+ fieldErrorsFrom
19
+ };
@@ -62,6 +62,18 @@
62
62
  color: var(--color-status-error-border);
63
63
  }
64
64
 
65
+ /* The newer form: the error is a message of its own under the control,
66
+ and the helper text keeps its colour beside it. */
67
+ .ds-field__error {
68
+ margin: 0;
69
+ font-family: var(--font-paragraph-sm-family);
70
+ font-size: var(--font-paragraph-sm-size);
71
+ font-weight: var(--font-paragraph-sm-weight);
72
+ line-height: var(--font-paragraph-sm-line-height);
73
+ letter-spacing: var(--font-paragraph-sm-letter-spacing);
74
+ color: var(--color-status-error-text);
75
+ }
76
+
65
77
  /* ============================================
66
78
  DISABLED STATE
67
79
  ============================================ */
@@ -5,15 +5,23 @@ type FieldOwnProps = {
5
5
  label?: string;
6
6
  /** The form control this field labels */
7
7
  children?: React.ReactNode;
8
- /** Helper or error message rendered below the control */
8
+ /** Helper text rendered below the control. With `errorText` it stays as it is while an error shows; with the older `error` flag it is recoloured as the error message. */
9
9
  helperText?: string;
10
+ /**
11
+ * The error message, shown under the control in the error colour while the
12
+ * helper text keeps its place, and announced politely when it changes.
13
+ * Setting it marks the field invalid, so `error` is not needed alongside
14
+ * it. The older form, `error` with the message in `helperText`, still
15
+ * works.
16
+ */
17
+ errorText?: React.ReactNode;
10
18
  /**
11
19
  * Optional content rendered opposite the helper text — a character counter,
12
20
  * a unit, a "0/280". Present only when supplied; without it the helper sits
13
21
  * directly in the field's column and no extra wrapper is introduced.
14
22
  */
15
23
  aside?: React.ReactNode;
16
- /** Error state — recolours the helper text and marks the control invalid */
24
+ /** Error state: marks the control invalid and, in the older form without `errorText`, recolours the helper text as the error message. */
17
25
  error?: boolean;
18
26
  /** Marks the field required and renders the required marker */
19
27
  required?: boolean;
@@ -8,6 +8,7 @@ const Field = React.forwardRef(
8
8
  label,
9
9
  children,
10
10
  helperText,
11
+ errorText,
11
12
  aside,
12
13
  error = false,
13
14
  required = false,
@@ -21,12 +22,17 @@ const Field = React.forwardRef(
21
22
  const baseClass = "ds-field";
22
23
  const generatedId = useId();
23
24
  const controlId = id || generatedId;
24
- const describedBy = helperText ? `${controlId}-helper` : void 0;
25
+ const hasErrorText = errorText != null && errorText !== false && errorText !== "";
26
+ const helperId = helperText ? `${controlId}-helper` : void 0;
27
+ const errorId = hasErrorText ? `${controlId}-error` : void 0;
28
+ const describedBy = [errorId, helperId].filter(Boolean).join(" ") || void 0;
29
+ const invalid = error || hasErrorText;
25
30
  const labelId = label ? `${controlId}-label` : void 0;
26
31
  const classes = [
27
32
  baseClass,
28
33
  size === "compact" ? `${baseClass}--compact` : "",
29
- error ? `${baseClass}--error` : "",
34
+ error && !hasErrorText ? `${baseClass}--error` : "",
35
+ hasErrorText ? `${baseClass}--invalid` : "",
30
36
  disabled ? `${baseClass}--disabled` : "",
31
37
  className
32
38
  ].filter(Boolean).join(" ");
@@ -34,7 +40,7 @@ const Field = React.forwardRef(
34
40
  controlId,
35
41
  labelId,
36
42
  describedBy,
37
- invalid: error,
43
+ invalid,
38
44
  required,
39
45
  disabled
40
46
  };
@@ -57,10 +63,11 @@ const Field = React.forwardRef(
57
63
  ] })
58
64
  ] })),
59
65
  children,
66
+ hasErrorText && /* @__PURE__ */ jsx("p", { className: `${baseClass}__error`, id: errorId, "aria-live": "polite", children: errorText }),
60
67
  aside ? /* @__PURE__ */ jsxs("div", { className: `${baseClass}__footer`, children: [
61
- helperText ? /* @__PURE__ */ jsx("p", { className: `${baseClass}__helper`, id: describedBy, children: helperText }) : /* @__PURE__ */ jsx("span", {}),
68
+ helperText ? /* @__PURE__ */ jsx("p", { className: `${baseClass}__helper`, id: helperId, children: helperText }) : /* @__PURE__ */ jsx("span", {}),
62
69
  aside
63
- ] }) : helperText && /* @__PURE__ */ jsx("p", { className: `${baseClass}__helper`, id: describedBy, children: helperText })
70
+ ] }) : helperText && /* @__PURE__ */ jsx("p", { className: `${baseClass}__helper`, id: helperId, children: helperText })
64
71
  ] }) });
65
72
  }
66
73
  );
@@ -0,0 +1,129 @@
1
+ /* ============================================
2
+ HEADING
3
+ One element per outline level, one class per
4
+ type tier. Each tier reads its five tokens
5
+ from tokens-typography.css; the display tiers
6
+ take the display text role and the heading
7
+ tiers the heading role, so a theme that tones
8
+ either tier tones every Heading with it.
9
+ ============================================ */
10
+
11
+ /* Base */
12
+ .ds-heading {
13
+ margin: 0;
14
+ color: var(--color-text-heading);
15
+ overflow-wrap: break-word;
16
+ }
17
+
18
+ /* Tiers: display */
19
+ .ds-heading--mega-1 {
20
+ font-family: var(--font-mega-1-family);
21
+ font-size: var(--font-mega-1-size);
22
+ font-weight: var(--font-mega-1-weight);
23
+ line-height: var(--font-mega-1-line-height);
24
+ letter-spacing: var(--font-mega-1-letter-spacing);
25
+ color: var(--color-text-display);
26
+ }
27
+
28
+ .ds-heading--mega-2 {
29
+ font-family: var(--font-mega-2-family);
30
+ font-size: var(--font-mega-2-size);
31
+ font-weight: var(--font-mega-2-weight);
32
+ line-height: var(--font-mega-2-line-height);
33
+ letter-spacing: var(--font-mega-2-letter-spacing);
34
+ color: var(--color-text-display);
35
+ }
36
+
37
+ .ds-heading--display-1 {
38
+ font-family: var(--font-display-1-family);
39
+ font-size: var(--font-display-1-size);
40
+ font-weight: var(--font-display-1-weight);
41
+ line-height: var(--font-display-1-line-height);
42
+ letter-spacing: var(--font-display-1-letter-spacing);
43
+ color: var(--color-text-display);
44
+ }
45
+
46
+ .ds-heading--display-2 {
47
+ font-family: var(--font-display-2-family);
48
+ font-size: var(--font-display-2-size);
49
+ font-weight: var(--font-display-2-weight);
50
+ line-height: var(--font-display-2-line-height);
51
+ letter-spacing: var(--font-display-2-letter-spacing);
52
+ color: var(--color-text-display);
53
+ }
54
+
55
+ .ds-heading--sub-display {
56
+ font-family: var(--font-sub-display-family);
57
+ font-size: var(--font-sub-display-size);
58
+ font-weight: var(--font-sub-display-weight);
59
+ line-height: var(--font-sub-display-line-height);
60
+ letter-spacing: var(--font-sub-display-letter-spacing);
61
+ color: var(--color-text-display);
62
+ }
63
+
64
+ /* Tiers: heading */
65
+ .ds-heading--heading-1 {
66
+ font-family: var(--font-heading-1-family);
67
+ font-size: var(--font-heading-1-size);
68
+ font-weight: var(--font-heading-1-weight);
69
+ line-height: var(--font-heading-1-line-height);
70
+ letter-spacing: var(--font-heading-1-letter-spacing);
71
+ color: var(--color-text-heading);
72
+ }
73
+
74
+ .ds-heading--heading-2 {
75
+ font-family: var(--font-heading-2-family);
76
+ font-size: var(--font-heading-2-size);
77
+ font-weight: var(--font-heading-2-weight);
78
+ line-height: var(--font-heading-2-line-height);
79
+ letter-spacing: var(--font-heading-2-letter-spacing);
80
+ color: var(--color-text-heading);
81
+ }
82
+
83
+ .ds-heading--heading-3 {
84
+ font-family: var(--font-heading-3-family);
85
+ font-size: var(--font-heading-3-size);
86
+ font-weight: var(--font-heading-3-weight);
87
+ line-height: var(--font-heading-3-line-height);
88
+ letter-spacing: var(--font-heading-3-letter-spacing);
89
+ color: var(--color-text-heading);
90
+ }
91
+
92
+ /* Tiers: title in the body face */
93
+ .ds-heading--title-body {
94
+ font-family: var(--font-title-body-family);
95
+ font-size: var(--font-title-body-size);
96
+ font-weight: var(--font-title-body-weight);
97
+ line-height: var(--font-title-body-line-height);
98
+ letter-spacing: var(--font-title-body-letter-spacing);
99
+ color: var(--color-text-heading);
100
+ }
101
+
102
+ /* Tone */
103
+ .ds-heading.ds-heading--tone-neutral {
104
+ color: var(--color-text-secondary);
105
+ }
106
+
107
+ /* Wrapping */
108
+ .ds-heading--truncate {
109
+ overflow: hidden;
110
+ white-space: nowrap;
111
+ text-overflow: ellipsis;
112
+ }
113
+
114
+ .ds-heading--balance {
115
+ text-wrap: balance;
116
+ }
117
+
118
+ /* Alignment */
119
+ .ds-heading--align-start {
120
+ text-align: start;
121
+ }
122
+
123
+ .ds-heading--align-center {
124
+ text-align: center;
125
+ }
126
+
127
+ .ds-heading--align-end {
128
+ text-align: end;
129
+ }