rift-ds 1.24.0 → 1.26.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 (117) hide show
  1. package/README.md +5 -4
  2. package/chat/ChatThreads.d.ts +3 -1
  3. package/chat/ChatThreads.js +3 -1
  4. package/chat/ChatWidget.css +166 -15
  5. package/chat/ChatWidget.d.ts +6 -2
  6. package/chat/ChatWidget.js +17 -3
  7. package/components/ActionCard/ActionCard.d.ts +1 -1
  8. package/components/Attachment/Attachment.css +8 -0
  9. package/components/Attachment/AttachmentViewer.js +26 -5
  10. package/components/Attachment/fileTypes.d.ts +4 -0
  11. package/components/ContextMenu/ContextMenu.css +11 -0
  12. package/components/ContextMenu/ContextMenu.d.ts +1 -1
  13. package/components/ContextMenu/ContextMenu.js +3 -1
  14. package/components/CurrencyInput/CurrencyInput.css +12 -0
  15. package/components/CurrencyInput/CurrencyInput.d.ts +51 -0
  16. package/components/CurrencyInput/CurrencyInput.js +158 -0
  17. package/components/DataTable/columnTypes.js +4 -16
  18. package/components/DatePicker/DatePicker.d.ts +2 -0
  19. package/components/DatePicker/DatePicker.js +44 -131
  20. package/components/DatePicker/MonthGrid.d.ts +56 -0
  21. package/components/DatePicker/MonthGrid.js +65 -0
  22. package/components/DatePicker/calendar.d.ts +42 -0
  23. package/components/DatePicker/calendar.js +108 -0
  24. package/components/DateRangePicker/DateRangePicker.css +92 -0
  25. package/components/DateRangePicker/DateRangePicker.d.ts +86 -0
  26. package/components/DateRangePicker/DateRangePicker.js +294 -0
  27. package/components/Deadline/Deadline.css +82 -0
  28. package/components/Deadline/Deadline.d.ts +44 -0
  29. package/components/Deadline/Deadline.js +94 -0
  30. package/components/Deadline/deadlineStatus.d.ts +15 -0
  31. package/components/Deadline/deadlineStatus.js +13 -0
  32. package/components/DescriptionList/DescriptionList.css +184 -0
  33. package/components/DescriptionList/DescriptionList.d.ts +64 -0
  34. package/components/DescriptionList/DescriptionList.js +100 -0
  35. package/components/DescriptionList/DescriptionListCopy.d.ts +18 -0
  36. package/components/DescriptionList/DescriptionListCopy.js +45 -0
  37. package/components/DocumentViewer/DocumentViewer.css +188 -0
  38. package/components/DocumentViewer/DocumentViewer.d.ts +59 -0
  39. package/components/DocumentViewer/DocumentViewer.js +185 -0
  40. package/components/DropdownMenu/DropdownMenu.css +38 -0
  41. package/components/DropdownMenu/DropdownMenu.d.ts +4 -0
  42. package/components/DropdownMenu/DropdownMenu.js +11 -5
  43. package/components/DropdownMenu/ShortcutHint.d.ts +9 -0
  44. package/components/DropdownMenu/ShortcutHint.js +6 -0
  45. package/components/ErrorSummary/ErrorSummary.css +94 -0
  46. package/components/ErrorSummary/ErrorSummary.d.ts +34 -0
  47. package/components/ErrorSummary/ErrorSummary.js +70 -0
  48. package/components/ErrorSummary/fieldErrors.d.ts +36 -0
  49. package/components/ErrorSummary/fieldErrors.js +19 -0
  50. package/components/Field/Field.css +12 -0
  51. package/components/Field/Field.d.ts +10 -2
  52. package/components/Field/Field.js +12 -5
  53. package/components/Heading/Heading.css +129 -0
  54. package/components/Heading/Heading.d.ts +31 -0
  55. package/components/Heading/Heading.js +39 -0
  56. package/components/Input/Input.css +120 -0
  57. package/components/Input/Input.d.ts +20 -1
  58. package/components/Input/Input.js +70 -5
  59. package/components/InterruptCard/InterruptCard.d.ts +1 -1
  60. package/components/Link/Link.css +84 -0
  61. package/components/Link/Link.d.ts +43 -0
  62. package/components/Link/Link.js +74 -0
  63. package/components/List/List.css +173 -0
  64. package/components/List/List.d.ts +44 -0
  65. package/components/List/List.js +60 -0
  66. package/components/MaskedInput/MaskedInput.css +16 -0
  67. package/components/MaskedInput/MaskedInput.d.ts +57 -0
  68. package/components/MaskedInput/MaskedInput.js +142 -0
  69. package/components/MaskedInput/mask.d.ts +58 -0
  70. package/components/MaskedInput/mask.js +106 -0
  71. package/components/MessageCard/MessageCard.css +17 -6
  72. package/components/MessageCard/MessageCard.d.ts +1 -1
  73. package/components/ShaderScene/ShaderScene.css +19 -0
  74. package/components/ShaderScene/ShaderScene.d.ts +82 -0
  75. package/components/ShaderScene/ShaderScene.js +167 -0
  76. package/components/ShaderScene/assemble.d.ts +5 -0
  77. package/components/ShaderScene/assemble.js +76 -0
  78. package/components/ShaderScene/common.glsl.d.ts +6 -0
  79. package/components/ShaderScene/common.glsl.js +49 -0
  80. package/components/ShaderScene/passes.d.ts +2 -0
  81. package/components/ShaderScene/passes.js +93 -0
  82. package/components/ShaderScene/renderer.d.ts +39 -0
  83. package/components/ShaderScene/renderer.js +170 -0
  84. package/components/ShaderScene/scenes.d.ts +76 -0
  85. package/components/ShaderScene/scenes.js +752 -0
  86. package/components/ShaderScene/types.d.ts +83 -0
  87. package/components/ShaderScene/types.js +8 -0
  88. package/components/SignaturePad/SignaturePad.css +141 -0
  89. package/components/SignaturePad/SignaturePad.d.ts +68 -0
  90. package/components/SignaturePad/SignaturePad.js +287 -0
  91. package/components/SignaturePad/signature.d.ts +32 -0
  92. package/components/SignaturePad/signature.js +46 -0
  93. package/components/Text/Text.css +129 -0
  94. package/components/Text/Text.d.ts +36 -0
  95. package/components/Text/Text.js +36 -0
  96. package/components/ThreadPanel/ThreadPanel.css +29 -0
  97. package/components/ThreadPanel/ThreadPanel.d.ts +2 -0
  98. package/components/ThreadPanel/ThreadPanel.js +13 -2
  99. package/components/Widget/Widget.css +111 -0
  100. package/components/Widget/Widget.d.ts +15 -1
  101. package/components/Widget/Widget.js +63 -11
  102. package/components/Widget/WidgetDisclosure.d.ts +30 -0
  103. package/components/Widget/WidgetDisclosure.js +52 -0
  104. package/components/registry.json +111 -2
  105. package/components/registry.json.d.ts +111 -2
  106. package/components/registry.json.js +2 -2
  107. package/format/index.d.ts +15 -0
  108. package/format/index.js +17 -0
  109. package/format/money.d.ts +89 -0
  110. package/format/money.js +187 -0
  111. package/format/relative.d.ts +49 -0
  112. package/format/relative.js +50 -0
  113. package/index.d.ts +13 -0
  114. package/index.js +48 -1
  115. package/package.json +9 -2
  116. package/tokens/motion.d.ts +4 -0
  117. package/tokens/motion.js +4 -0
@@ -0,0 +1,44 @@
1
+ import { default as React } from 'react';
2
+ import { DateInput } from '../../format/relative';
3
+ import { DeadlineStatus, DeadlineThresholds } from './deadlineStatus';
4
+ /** Props owned by Deadline itself; everything else falls through to the root `<span>`. */
5
+ type DeadlineOwnProps = {
6
+ /** The moment it falls due: a Date, an ISO 8601 string or milliseconds since the epoch. */
7
+ date: DateInput;
8
+ /** The IANA zone the time is shown in, named after it ("4:00 PM PST"), such as `America/Los_Angeles`. Without it the time shows in the reader's own zone. */
9
+ timeZone?: string;
10
+ /** `relative` writes the distance ("in 2 days"), `absolute` the date and time, `both` the two together. Defaults to `relative`. */
11
+ display?: 'relative' | 'absolute' | 'both';
12
+ /** How close the deadline must be before it turns to the warning and then the error role. */
13
+ thresholds?: DeadlineThresholds;
14
+ /** The word before the distance: "Due", "Closes", "Expires". Defaults to "Due". */
15
+ prefixLabel?: string;
16
+ /** What a deadline that has passed says in place of the distance. Defaults to "Overdue". */
17
+ overdueLabel?: string;
18
+ /** `badge` draws the Badge family's tinted pill; `text` writes it inline in the status text colour, for a sentence or a table cell. */
19
+ variant?: 'badge' | 'text';
20
+ /** Component size */
21
+ size?: 'default' | 'compact';
22
+ /** Rewrite the distance as time passes, pausing while the page is hidden. Defaults to true; off when `now` is set. */
23
+ tick?: boolean;
24
+ /** The moment to measure from, in place of the clock: for a server render that must match, a test, or a screenshot. */
25
+ now?: DateInput;
26
+ /** Called when the deadline moves to a new status as time passes, so a host can react (sort, notify). */
27
+ onStatusChange?: (status: DeadlineStatus) => void;
28
+ /** The BCP 47 locale the distance and the date are written in. Defaults to the nearest LocaleProvider's, else `en-US`. */
29
+ locale?: string;
30
+ /** Additional CSS classes */
31
+ className?: string;
32
+ };
33
+ export interface DeadlineProps extends DeadlineOwnProps, Omit<React.ComponentPropsWithRef<'span'>, keyof DeadlineOwnProps | 'children'> {
34
+ }
35
+ /**
36
+ * A deadline against now: "Due in 2 days", turning to the warning role as it
37
+ * nears and the error role on its last day, then "Overdue". Submission
38
+ * cutoffs, invoice due dates, trial expiry, ticket service levels. The full
39
+ * date sits in a `<time>` element, and the distance rewrites itself every
40
+ * half minute while the page shows.
41
+ */
42
+ export declare function Deadline({ date, timeZone, display, thresholds, prefixLabel, overdueLabel, variant, size, tick, now: nowProp, onStatusChange, locale: localeProp, className, ref, ...rest }: DeadlineProps): React.JSX.Element | null;
43
+ export { deadlineStatus } from './deadlineStatus';
44
+ export type { DeadlineStatus, DeadlineThresholds } from './deadlineStatus';
@@ -0,0 +1,94 @@
1
+ "use client";
2
+ import { jsx } from "react/jsx-runtime";
3
+ import { useRef, useEffect, useState } from "react";
4
+ import { useLocale } from "../../behaviors/LocaleProvider.js";
5
+ import { MOTION_DEADLINE_TICK_MS } from "../../tokens/motion.js";
6
+ import { toDate, formatInTimeZone, formatRelative } from "../../format/relative.js";
7
+ import { deadlineStatus } from "./deadlineStatus.js";
8
+ import "./Deadline.css";
9
+ function useNow(fixed, tick) {
10
+ const [clock, setClock] = useState(() => /* @__PURE__ */ new Date());
11
+ useEffect(() => {
12
+ if (fixed || !tick) return;
13
+ let timer;
14
+ const start = () => {
15
+ window.clearInterval(timer);
16
+ setClock(/* @__PURE__ */ new Date());
17
+ timer = window.setInterval(() => setClock(/* @__PURE__ */ new Date()), MOTION_DEADLINE_TICK_MS);
18
+ };
19
+ const onVisibility = () => {
20
+ if (document.hidden) window.clearInterval(timer);
21
+ else start();
22
+ };
23
+ start();
24
+ document.addEventListener("visibilitychange", onVisibility);
25
+ return () => {
26
+ window.clearInterval(timer);
27
+ document.removeEventListener("visibilitychange", onVisibility);
28
+ };
29
+ }, [fixed, tick]);
30
+ return fixed ?? clock;
31
+ }
32
+ function Deadline({
33
+ date,
34
+ timeZone,
35
+ display = "relative",
36
+ thresholds,
37
+ prefixLabel = "Due",
38
+ overdueLabel = "Overdue",
39
+ variant = "badge",
40
+ size = "default",
41
+ tick = true,
42
+ now: nowProp,
43
+ onStatusChange,
44
+ locale: localeProp,
45
+ className = "",
46
+ ref,
47
+ ...rest
48
+ }) {
49
+ const locale = useLocale(localeProp);
50
+ const due = toDate(date);
51
+ const fixed = nowProp !== void 0 ? toDate(nowProp) : null;
52
+ const now = useNow(fixed, tick);
53
+ const status = due ? deadlineStatus(due, now, thresholds) : "neutral";
54
+ const reported = useRef(status);
55
+ useEffect(() => {
56
+ if (reported.current === status) return;
57
+ reported.current = status;
58
+ onStatusChange?.(status);
59
+ }, [status, onStatusChange]);
60
+ if (!due) return null;
61
+ const zone = timeZone ?? new Intl.DateTimeFormat(locale).resolvedOptions().timeZone;
62
+ const absolute = formatInTimeZone(due, {
63
+ locale,
64
+ timeZone: zone,
65
+ month: "short",
66
+ day: "numeric",
67
+ hour: "numeric",
68
+ minute: "2-digit",
69
+ ...timeZone ? { timeZoneName: "short" } : {}
70
+ });
71
+ const full = formatInTimeZone(due, {
72
+ locale,
73
+ timeZone: zone,
74
+ dateStyle: "full",
75
+ timeStyle: "long"
76
+ });
77
+ const relative = formatRelative(due, { now, locale });
78
+ const overdue = status === "overdue";
79
+ const lead = overdue ? overdueLabel : prefixLabel;
80
+ const text = display === "absolute" ? `${lead} ${absolute}` : display === "both" ? `${overdue ? lead : `${lead} ${relative}`} · ${absolute}` : overdue ? lead : `${lead} ${relative}`;
81
+ const classes = [
82
+ "ds-deadline",
83
+ `ds-deadline--${variant}`,
84
+ `ds-deadline--${size}`,
85
+ `ds-deadline--${overdue ? "error" : status}`,
86
+ overdue && "ds-deadline--overdue",
87
+ className
88
+ ].filter(Boolean).join(" ");
89
+ return /* @__PURE__ */ jsx("span", { ...rest, ref, className: classes, children: /* @__PURE__ */ jsx("time", { dateTime: due.toISOString(), title: full, suppressHydrationWarning: true, children: text }) });
90
+ }
91
+ export {
92
+ Deadline,
93
+ deadlineStatus
94
+ };
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Where a deadline stands against now, without React: Deadline reads it, and
3
+ * a host can call it to sort or filter by the same rule.
4
+ */
5
+ /** How close a deadline must be for each warning, in milliseconds. */
6
+ export type DeadlineThresholds = {
7
+ /** Under this long to go, the deadline turns to the warning role. Defaults to three days. */
8
+ warning?: number;
9
+ /** Under this long to go, the deadline turns to the error role. Defaults to one day. */
10
+ critical?: number;
11
+ };
12
+ /** Where a deadline stands against now. */
13
+ export type DeadlineStatus = 'neutral' | 'warning' | 'error' | 'overdue';
14
+ /** Where `due` stands against `now`, given the thresholds. */
15
+ export declare function deadlineStatus(due: Date, now: Date, thresholds?: DeadlineThresholds): DeadlineStatus;
@@ -0,0 +1,13 @@
1
+ const HOUR = 36e5;
2
+ const DAY = 24 * HOUR;
3
+ function deadlineStatus(due, now, thresholds = {}) {
4
+ const { warning = 3 * DAY, critical = DAY } = thresholds;
5
+ const left = due.getTime() - now.getTime();
6
+ if (left < 0) return "overdue";
7
+ if (left < critical) return "error";
8
+ if (left < warning) return "warning";
9
+ return "neutral";
10
+ }
11
+ export {
12
+ deadlineStatus
13
+ };
@@ -0,0 +1,184 @@
1
+ /* ============================================
2
+ DESCRIPTION LIST
3
+ Terms in the secondary text colour, values in
4
+ the primary, the facts recipe the chat cards
5
+ use made general. The frame is the size
6
+ container, so the inline layout stacks and the
7
+ grid drops columns by the room the list has,
8
+ never by the viewport.
9
+ ============================================ */
10
+
11
+ /* Frame */
12
+ .ds-description-list__frame {
13
+ container-type: inline-size;
14
+ min-width: 0;
15
+ }
16
+
17
+ /* Base */
18
+ .ds-description-list {
19
+ display: flex;
20
+ flex-direction: column;
21
+ gap: var(--gap-300);
22
+ margin: 0;
23
+ min-width: 0;
24
+ }
25
+
26
+ .ds-description-list__item {
27
+ display: flex;
28
+ flex-direction: column;
29
+ gap: var(--gap-050);
30
+ min-width: 0;
31
+ }
32
+
33
+ .ds-description-list__term {
34
+ color: var(--color-text-secondary);
35
+ overflow-wrap: break-word;
36
+ }
37
+
38
+ .ds-description-list__details {
39
+ display: flex;
40
+ align-items: center;
41
+ gap: var(--gap-200);
42
+ min-width: 0;
43
+ margin: 0;
44
+ color: var(--color-text-primary);
45
+ }
46
+
47
+ .ds-description-list__value {
48
+ flex: 1 1 auto;
49
+ min-width: 0;
50
+ overflow-wrap: anywhere;
51
+ }
52
+
53
+ /* Stacked and grid entries keep a copy button or action beside the value;
54
+ the inline layout's value column runs to the far edge, so its actions
55
+ line up down the list there. */
56
+ .ds-description-list--stacked .ds-description-list__value,
57
+ .ds-description-list--grid .ds-description-list__value {
58
+ flex: 0 1 auto;
59
+ }
60
+
61
+ .ds-description-list__value--empty {
62
+ color: var(--color-text-tertiary);
63
+ }
64
+
65
+ .ds-description-list__actions {
66
+ display: inline-flex;
67
+ flex-shrink: 0;
68
+ align-items: center;
69
+ gap: var(--gap-100);
70
+ }
71
+
72
+ /* The copy button sits on the value's line without making the row taller. */
73
+ .ds-description-list__copy {
74
+ margin-block: calc(-1 * var(--padding-100));
75
+ }
76
+
77
+ /* Sizes */
78
+ .ds-description-list--default .ds-description-list__term,
79
+ .ds-description-list--default .ds-description-list__details {
80
+ font-family: var(--font-paragraph-family);
81
+ font-size: var(--font-paragraph-size);
82
+ font-weight: var(--font-paragraph-weight);
83
+ line-height: var(--font-paragraph-line-height);
84
+ letter-spacing: var(--font-paragraph-letter-spacing);
85
+ }
86
+
87
+ .ds-description-list--compact {
88
+ gap: var(--gap-200);
89
+ }
90
+
91
+ .ds-description-list--compact .ds-description-list__term,
92
+ .ds-description-list--compact .ds-description-list__details {
93
+ font-family: var(--font-paragraph-sm-family);
94
+ font-size: var(--font-paragraph-sm-size);
95
+ font-weight: var(--font-paragraph-sm-weight);
96
+ line-height: var(--font-paragraph-sm-line-height);
97
+ letter-spacing: var(--font-paragraph-sm-letter-spacing);
98
+ }
99
+
100
+ /* Inline: term and value in two columns, the term a quarter, a third or a half */
101
+ .ds-description-list--inline .ds-description-list__item {
102
+ display: grid;
103
+ align-items: baseline;
104
+ column-gap: var(--gap-400);
105
+ }
106
+
107
+ .ds-description-list--inline.ds-description-list--term-narrow .ds-description-list__item {
108
+ grid-template-columns: minmax(0, 1fr) minmax(0, 3fr);
109
+ }
110
+
111
+ .ds-description-list--inline.ds-description-list--term-default .ds-description-list__item {
112
+ grid-template-columns: minmax(0, 1fr) minmax(0, 2fr);
113
+ }
114
+
115
+ .ds-description-list--inline.ds-description-list--term-wide .ds-description-list__item {
116
+ grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
117
+ }
118
+
119
+ /* Grid: stacked entries in columns */
120
+ .ds-description-list--grid {
121
+ display: grid;
122
+ grid-template-columns: repeat(var(--ds-description-list-columns, 2), minmax(0, 1fr));
123
+ gap: var(--gap-400) var(--gap-500);
124
+ }
125
+
126
+ /* Alignment: values against the far edge */
127
+ .ds-description-list--align-end .ds-description-list__value {
128
+ text-align: end;
129
+ }
130
+
131
+ .ds-description-list--align-end .ds-description-list__details {
132
+ justify-content: flex-end;
133
+ }
134
+
135
+ /* Dividers */
136
+ .ds-description-list--dividers {
137
+ gap: 0;
138
+ }
139
+
140
+ .ds-description-list--dividers .ds-description-list__item {
141
+ padding-block: var(--padding-300);
142
+ border-block-end: var(--border-025) solid var(--color-divider);
143
+ }
144
+
145
+ .ds-description-list--dividers .ds-description-list__item:last-child {
146
+ border-block-end: none;
147
+ }
148
+
149
+ .ds-description-list--grid.ds-description-list--dividers {
150
+ column-gap: var(--gap-500);
151
+ }
152
+
153
+ /* Narrow room: the inline layout stacks once two columns cannot hold a
154
+ short term and value side by side; the grid drops to fewer columns. */
155
+ @container (max-width: 360px) {
156
+ .ds-description-list--inline .ds-description-list__item,
157
+ .ds-description-list--inline.ds-description-list--term-narrow .ds-description-list__item,
158
+ .ds-description-list--inline.ds-description-list--term-default .ds-description-list__item,
159
+ .ds-description-list--inline.ds-description-list--term-wide .ds-description-list__item {
160
+ display: flex;
161
+ flex-direction: column;
162
+ gap: var(--gap-050);
163
+ }
164
+
165
+ .ds-description-list--inline.ds-description-list--align-end .ds-description-list__value {
166
+ text-align: start;
167
+ }
168
+
169
+ .ds-description-list--inline.ds-description-list--align-end .ds-description-list__details {
170
+ justify-content: flex-start;
171
+ }
172
+ }
173
+
174
+ @container (max-width: 480px) {
175
+ .ds-description-list--grid {
176
+ grid-template-columns: minmax(0, 1fr);
177
+ }
178
+ }
179
+
180
+ @container (min-width: 481px) and (max-width: 720px) {
181
+ .ds-description-list--grid {
182
+ grid-template-columns: repeat(min(var(--ds-description-list-columns, 2), 2), minmax(0, 1fr));
183
+ }
184
+ }
@@ -0,0 +1,64 @@
1
+ import { default as React } from 'react';
2
+ /** One term and its value, as `items` takes them. */
3
+ export type DescriptionListEntry = {
4
+ /** The term: what the value is ("Account number", "Due date"). */
5
+ term: React.ReactNode;
6
+ /** The value. Empty (null, undefined or an empty string) shows the list's `emptyValue`. */
7
+ details?: React.ReactNode;
8
+ /** A stable key for the entry; also its element id. */
9
+ id?: string;
10
+ /** A trailing control for this value: an Edit button, a link. */
11
+ action?: React.ReactNode;
12
+ /** Offer a copy button: `true` copies the value when it is text, a string copies that string (the unformatted account number behind a formatted one). */
13
+ copyable?: boolean | string;
14
+ };
15
+ /** Props owned by DescriptionList itself; everything else falls through to the `<dl>`. */
16
+ type DescriptionListOwnProps = {
17
+ /** The entries, in order. Or compose `DescriptionListItem` children instead. */
18
+ items?: DescriptionListEntry[];
19
+ /** `DescriptionListItem` children, for a list written out by hand. */
20
+ children?: React.ReactNode;
21
+ /** `stacked` puts each term above its value; `inline` sets term and value in two columns and stacks them when the list is narrow; `grid` lays stacked entries out in `columns`. */
22
+ layout?: 'stacked' | 'inline' | 'grid';
23
+ /** How many columns the `grid` layout uses at full width, 1 to 4. Fewer show as the list narrows. */
24
+ columns?: 1 | 2 | 3 | 4;
25
+ /** Draw a divider between entries. */
26
+ dividers?: boolean;
27
+ /** The type size: `default` the paragraph face, `compact` the small paragraph face for dense panels. */
28
+ size?: 'default' | 'compact';
29
+ /** How much of the row the term column takes in the `inline` layout: a quarter, a third or a half. */
30
+ termWidth?: 'narrow' | 'default' | 'wide';
31
+ /** Where values sit: `end` lines amounts up against the far edge. */
32
+ align?: 'start' | 'end';
33
+ /** What an empty value shows. Defaults to "Not set". */
34
+ emptyValue?: React.ReactNode;
35
+ /** The copy button's accessible name, given the entry's term when it is text and an empty string when it is not. Defaults to "Copy <term>", or "Copy". */
36
+ copyLabel?: (term: string) => string;
37
+ /** The copy button's accessible name for a moment after a copy. Defaults to "Copied". */
38
+ copiedLabel?: string;
39
+ /** Called after a value is put on the clipboard, so a host can confirm it or count it. Only reaches a list rendered from a client component. */
40
+ onValueCopy?: (value: string) => void;
41
+ /** Additional CSS classes. */
42
+ className?: string;
43
+ };
44
+ export interface DescriptionListProps extends DescriptionListOwnProps, Omit<React.ComponentPropsWithRef<'dl'>, keyof DescriptionListOwnProps> {
45
+ }
46
+ /**
47
+ * Terms and their values: a review screen before submit, a receipt, account
48
+ * details, a record inspector. Stacked, in two columns that stack when
49
+ * narrow, or in a grid; values can be copied or carry a trailing action, and
50
+ * an empty value says so in words. Server-renderable.
51
+ */
52
+ export declare function DescriptionList({ items, children, layout, columns, dividers, size, termWidth, align, emptyValue, copyLabel, copiedLabel, onValueCopy, className, style, ref, ...rest }: DescriptionListProps): React.JSX.Element;
53
+ /** Props owned by DescriptionListItem itself; everything else falls through to the entry's wrapper `<div>`. */
54
+ type DescriptionListItemOwnProps = Omit<DescriptionListEntry, 'id'> & {
55
+ /** The value, as children. `details` wins when both are set. */
56
+ children?: React.ReactNode;
57
+ /** Additional CSS classes. */
58
+ className?: string;
59
+ };
60
+ export interface DescriptionListItemProps extends DescriptionListItemOwnProps, Omit<React.ComponentPropsWithRef<'div'>, keyof DescriptionListItemOwnProps> {
61
+ }
62
+ /** One term and its value inside a DescriptionList, for a list written out by hand. Server-renderable. */
63
+ export declare function DescriptionListItem({ term, details, children, action, copyable, className, ref, ...rest }: DescriptionListItemProps): React.JSX.Element;
64
+ export {};
@@ -0,0 +1,100 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import React from "react";
3
+ import { DescriptionListCopy } from "./DescriptionListCopy.js";
4
+ import "../../behaviors/visually-hidden.css";
5
+ import "./DescriptionList.css";
6
+ const isEmpty = (value) => value == null || value === false || value === "";
7
+ const textOf = (value) => typeof value === "string" || typeof value === "number" ? String(value) : null;
8
+ function renderEntry({ term, details, id, action, copyable }, settings, className = "", rest = {}, ref) {
9
+ const empty = isEmpty(details);
10
+ const copyText = empty ? null : typeof copyable === "string" ? copyable : copyable ? textOf(details) : null;
11
+ const termText = textOf(term);
12
+ const classes = ["ds-description-list__item", className].filter(Boolean).join(" ");
13
+ return /* @__PURE__ */ jsxs("div", { ...rest, ref, id: id ?? rest.id, className: classes, children: [
14
+ /* @__PURE__ */ jsx("dt", { className: "ds-description-list__term", children: term }),
15
+ /* @__PURE__ */ jsxs("dd", { className: "ds-description-list__details", children: [
16
+ /* @__PURE__ */ jsx("span", { className: `ds-description-list__value${empty ? " ds-description-list__value--empty" : ""}`, children: empty ? settings.emptyValue : details }),
17
+ (copyText || action) && /* @__PURE__ */ jsxs("span", { className: "ds-description-list__actions", children: [
18
+ copyText && /* @__PURE__ */ jsx(
19
+ DescriptionListCopy,
20
+ {
21
+ value: copyText,
22
+ label: settings.copyLabel(termText ?? ""),
23
+ copiedLabel: settings.copiedLabel,
24
+ onCopied: settings.onValueCopy
25
+ }
26
+ ),
27
+ action
28
+ ] })
29
+ ] })
30
+ ] });
31
+ }
32
+ const DEFAULT_COPY_LABEL = (term) => term ? `Copy ${term}` : "Copy";
33
+ const SETTINGS_PROP = "__dsDescriptionListSettings";
34
+ function DescriptionList({
35
+ items,
36
+ children,
37
+ layout = "stacked",
38
+ columns = 2,
39
+ dividers = false,
40
+ size = "default",
41
+ termWidth = "default",
42
+ align = "start",
43
+ emptyValue = "Not set",
44
+ copyLabel = DEFAULT_COPY_LABEL,
45
+ copiedLabel = "Copied",
46
+ onValueCopy,
47
+ className = "",
48
+ style,
49
+ ref,
50
+ ...rest
51
+ }) {
52
+ const settings = { emptyValue, copyLabel, copiedLabel, onValueCopy };
53
+ const classes = [
54
+ "ds-description-list",
55
+ `ds-description-list--${layout}`,
56
+ `ds-description-list--${size}`,
57
+ layout === "inline" && `ds-description-list--term-${termWidth}`,
58
+ dividers && "ds-description-list--dividers",
59
+ align === "end" && "ds-description-list--align-end",
60
+ className
61
+ ].filter(Boolean).join(" ");
62
+ const resolvedStyle = layout === "grid" ? { ...style, "--ds-description-list-columns": columns } : style;
63
+ const composed = React.Children.map(
64
+ children,
65
+ (child) => React.isValidElement(child) && child.type === DescriptionListItem ? React.cloneElement(child, { [SETTINGS_PROP]: settings }) : child
66
+ );
67
+ return /* @__PURE__ */ jsx("div", { className: "ds-description-list__frame", children: /* @__PURE__ */ jsxs("dl", { ...rest, ref, className: classes, style: resolvedStyle, children: [
68
+ items?.map((entry, index) => /* @__PURE__ */ jsx(React.Fragment, { children: renderEntry(entry, settings) }, entry.id ?? index)),
69
+ composed
70
+ ] }) });
71
+ }
72
+ function DescriptionListItem({
73
+ term,
74
+ details,
75
+ children,
76
+ action,
77
+ copyable,
78
+ className = "",
79
+ ref,
80
+ ...rest
81
+ }) {
82
+ const { [SETTINGS_PROP]: passed, ...divRest } = rest;
83
+ const settings = {
84
+ emptyValue: passed?.emptyValue ?? "Not set",
85
+ copyLabel: passed?.copyLabel ?? DEFAULT_COPY_LABEL,
86
+ copiedLabel: passed?.copiedLabel ?? "Copied",
87
+ onValueCopy: passed?.onValueCopy
88
+ };
89
+ return renderEntry(
90
+ { term, details: details ?? children, action, copyable },
91
+ settings,
92
+ className,
93
+ divRest,
94
+ ref
95
+ );
96
+ }
97
+ export {
98
+ DescriptionList,
99
+ DescriptionListItem
100
+ };
@@ -0,0 +1,18 @@
1
+ /** Props owned by DescriptionListCopy. */
2
+ export interface DescriptionListCopyProps {
3
+ /** The text put on the clipboard. */
4
+ value: string;
5
+ /** The button's accessible name before a copy. */
6
+ label: string;
7
+ /** The button's accessible name for a moment after a copy. */
8
+ copiedLabel: string;
9
+ /** Called after the value is put on the clipboard. */
10
+ onCopied?: (value: string) => void;
11
+ }
12
+ /**
13
+ * The copy button beside a description list value. Internal: DescriptionList
14
+ * renders it for a `copyable` item, so the list itself stays
15
+ * server-renderable. A compact tertiary CircularButton whose glyph and name
16
+ * turn to "Copied" for a moment after a press.
17
+ */
18
+ export declare function DescriptionListCopy({ value, label, copiedLabel, onCopied }: DescriptionListCopyProps): import("react").JSX.Element;
@@ -0,0 +1,45 @@
1
+ "use client";
2
+ import { jsx } from "react/jsx-runtime";
3
+ import { useState, useRef, useEffect } from "react";
4
+ import { CircularButton } from "../CircularButton/CircularButton.js";
5
+ import { MOTION_FEEDBACK_RESET_MS } from "../../tokens/motion.js";
6
+ function writeClipboard(text) {
7
+ const fallback = () => {
8
+ const textarea = document.createElement("textarea");
9
+ textarea.value = text;
10
+ textarea.setAttribute("readonly", "");
11
+ textarea.className = "ds-visually-hidden";
12
+ document.body.appendChild(textarea);
13
+ textarea.select();
14
+ document.execCommand("copy");
15
+ document.body.removeChild(textarea);
16
+ };
17
+ if (navigator.clipboard?.writeText) navigator.clipboard.writeText(text).catch(fallback);
18
+ else fallback();
19
+ }
20
+ function DescriptionListCopy({ value, label, copiedLabel, onCopied }) {
21
+ const [copied, setCopied] = useState(false);
22
+ const timer = useRef(void 0);
23
+ useEffect(() => () => window.clearTimeout(timer.current), []);
24
+ const copy = () => {
25
+ writeClipboard(value);
26
+ onCopied?.(value);
27
+ setCopied(true);
28
+ window.clearTimeout(timer.current);
29
+ timer.current = window.setTimeout(() => setCopied(false), MOTION_FEEDBACK_RESET_MS);
30
+ };
31
+ return /* @__PURE__ */ jsx(
32
+ CircularButton,
33
+ {
34
+ className: "ds-description-list__copy",
35
+ icon: copied ? "check" : "content_copy",
36
+ variant: "tertiary",
37
+ size: "compact",
38
+ ariaLabel: copied ? copiedLabel : label,
39
+ onClick: copy
40
+ }
41
+ );
42
+ }
43
+ export {
44
+ DescriptionListCopy
45
+ };