@atom63/inform 0.2.0-beta.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/LICENSE +27 -0
- package/README.md +25 -0
- package/dist/chunk-KT6PQL7E.js +554 -0
- package/dist/chunk-KT6PQL7E.js.map +1 -0
- package/dist/chunk-OGT26DRQ.js +222 -0
- package/dist/chunk-OGT26DRQ.js.map +1 -0
- package/dist/flyout-stack-BvsgCm0f.d.ts +26 -0
- package/dist/index.d.ts +52 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/persistence-DkSUn_qI.d.ts +18 -0
- package/dist/react/index.d.ts +42 -0
- package/dist/react/index.js +128 -0
- package/dist/react/index.js.map +1 -0
- package/dist/surfaces/index.d.ts +160 -0
- package/dist/surfaces/index.js +3 -0
- package/dist/surfaces/index.js.map +1 -0
- package/dist/types-7x7Ygbcz.d.ts +75 -0
- package/package.json +92 -0
- package/src/styles.css +17 -0
- package/src/surfaces/inform-banner.css +28 -0
- package/src/surfaces/inform-corner-flyout.css +73 -0
- package/src/surfaces/inform-dialog.css +24 -0
- package/src/surfaces/inform-parts.css +176 -0
- package/src/surfaces/inform-spotlight.css +55 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 You Zhang (ATOM63)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
The MIT license above covers the code and documentation in this repository. It does not grant
|
|
26
|
+
any right to use the ATOM63 name, the ATOM63 logo or other ATOM63 brand marks, including the
|
|
27
|
+
artwork in packages/brand. All rights to them are reserved.
|
package/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# @atom63/inform
|
|
2
|
+
|
|
3
|
+
The Atom63 inform pattern: one message model, one arbiter, four surfaces.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
pnpm add @atom63/inform @atom63/ui-react
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```css
|
|
10
|
+
@import '@atom63/styles';
|
|
11
|
+
@import '@atom63/ui-react/recipes.css';
|
|
12
|
+
@import '@atom63/inform/styles.css';
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
The surfaces ship their own stylesheet (`.a63-Inform*` classes on `--a63-*` tokens) and need no
|
|
16
|
+
Tailwind.
|
|
17
|
+
|
|
18
|
+
- `@atom63/inform` — message types, `defineInformRegistry`, the arbiter, and the dismissal stores. No React.
|
|
19
|
+
- `@atom63/inform/react` — `InformProvider`, `InformOutlet`, `useInform`, `useInformContext`.
|
|
20
|
+
- `@atom63/inform/surfaces` — `InformBanner`, `InformDialog`, `InformCornerFlyout`, `InformSpotlight`,
|
|
21
|
+
`InformFlyoutStack` and the icon, media and dismiss slots. Controlled components, usable without
|
|
22
|
+
the runtime.
|
|
23
|
+
|
|
24
|
+
See the design system's [Inform pattern page](https://system.atom63.io/patterns/pattern-inform) for
|
|
25
|
+
the message model, the arbiter and when to use each surface.
|
|
@@ -0,0 +1,554 @@
|
|
|
1
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
|
+
import { Button, Dialog, DialogPopup, DialogHeader, DialogTitle, DialogDescription, DialogFooter } from '@atom63/ui-react';
|
|
3
|
+
import { Children, useState, useRef, useCallback, useLayoutEffect, useEffect, useId } from 'react';
|
|
4
|
+
import { createPortal } from 'react-dom';
|
|
5
|
+
|
|
6
|
+
// src/surfaces/control-slot.ts
|
|
7
|
+
var SLOT_SIZE_CLASS = "a63-Inform-slot";
|
|
8
|
+
|
|
9
|
+
// src/lib/cn.ts
|
|
10
|
+
function cn(...inputs) {
|
|
11
|
+
return inputs.filter(Boolean).join(" ");
|
|
12
|
+
}
|
|
13
|
+
function InformDismissButton({
|
|
14
|
+
className,
|
|
15
|
+
label = "Dismiss",
|
|
16
|
+
onDismiss
|
|
17
|
+
}) {
|
|
18
|
+
return /* @__PURE__ */ jsx(
|
|
19
|
+
"button",
|
|
20
|
+
{
|
|
21
|
+
"aria-label": label,
|
|
22
|
+
className: cn(SLOT_SIZE_CLASS, "a63-InformDismissButton", className),
|
|
23
|
+
onClick: onDismiss,
|
|
24
|
+
type: "button",
|
|
25
|
+
children: /* @__PURE__ */ jsx(
|
|
26
|
+
"svg",
|
|
27
|
+
{
|
|
28
|
+
"aria-hidden": true,
|
|
29
|
+
fill: "none",
|
|
30
|
+
height: "14",
|
|
31
|
+
stroke: "currentColor",
|
|
32
|
+
strokeLinecap: "round",
|
|
33
|
+
strokeWidth: "1.5",
|
|
34
|
+
viewBox: "0 0 16 16",
|
|
35
|
+
width: "14",
|
|
36
|
+
children: /* @__PURE__ */ jsx("path", { d: "M4 4l8 8M12 4l-8 8" })
|
|
37
|
+
}
|
|
38
|
+
)
|
|
39
|
+
}
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
function InformIconSlot({ children, className }) {
|
|
43
|
+
return /* @__PURE__ */ jsx("span", { className: cn(SLOT_SIZE_CLASS, "a63-InformIconSlot", className), "data-slot": "inform-icon", children });
|
|
44
|
+
}
|
|
45
|
+
function InformActions({ actions, className }) {
|
|
46
|
+
if (actions.length === 0) return null;
|
|
47
|
+
return /* @__PURE__ */ jsx("div", { className: cn("a63-InformActions", className), children: actions.map((action) => /* @__PURE__ */ jsx(
|
|
48
|
+
Button,
|
|
49
|
+
{
|
|
50
|
+
onClick: action.onSelect,
|
|
51
|
+
size: "sm",
|
|
52
|
+
type: "button",
|
|
53
|
+
variant: action.variant === "primary" ? "primary" : "outline",
|
|
54
|
+
children: action.label
|
|
55
|
+
},
|
|
56
|
+
action.id
|
|
57
|
+
)) });
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// src/surfaces/severity.ts
|
|
61
|
+
var SEVERITY_BORDER_CLASS = {
|
|
62
|
+
info: "a63-Inform-border-info",
|
|
63
|
+
success: "a63-Inform-border-success",
|
|
64
|
+
warning: "a63-Inform-border-warning",
|
|
65
|
+
danger: "a63-Inform-border-danger"
|
|
66
|
+
};
|
|
67
|
+
var SEVERITY_TEXT_CLASS = {
|
|
68
|
+
info: "a63-Inform-text-info",
|
|
69
|
+
success: "a63-Inform-text-success",
|
|
70
|
+
warning: "a63-Inform-text-warning",
|
|
71
|
+
danger: "a63-Inform-text-danger"
|
|
72
|
+
};
|
|
73
|
+
var PATHS = {
|
|
74
|
+
info: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
75
|
+
/* @__PURE__ */ jsx("circle", { cx: "12", cy: "12", r: "9" }),
|
|
76
|
+
/* @__PURE__ */ jsx("path", { d: "M12 11v5M12 7.5h.01", strokeLinecap: "round" })
|
|
77
|
+
] }),
|
|
78
|
+
success: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
79
|
+
/* @__PURE__ */ jsx("circle", { cx: "12", cy: "12", r: "9" }),
|
|
80
|
+
/* @__PURE__ */ jsx("path", { d: "m8.5 12.2 2.4 2.4 4.6-4.9", strokeLinecap: "round", strokeLinejoin: "round" })
|
|
81
|
+
] }),
|
|
82
|
+
warning: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
83
|
+
/* @__PURE__ */ jsx("path", { d: "M12 4.5 21 19.5H3L12 4.5Z", strokeLinecap: "round", strokeLinejoin: "round" }),
|
|
84
|
+
/* @__PURE__ */ jsx("path", { d: "M12 10v4M12 17h.01", strokeLinecap: "round" })
|
|
85
|
+
] }),
|
|
86
|
+
danger: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
87
|
+
/* @__PURE__ */ jsx("circle", { cx: "12", cy: "12", r: "9" }),
|
|
88
|
+
/* @__PURE__ */ jsx("path", { d: "m9.2 9.2 5.6 5.6M14.8 9.2l-5.6 5.6", strokeLinecap: "round" })
|
|
89
|
+
] })
|
|
90
|
+
};
|
|
91
|
+
function InformSeverityIcon({ severity }) {
|
|
92
|
+
return /* @__PURE__ */ jsx("svg", { "aria-hidden": true, fill: "none", stroke: "currentColor", strokeWidth: "1.5", viewBox: "0 0 24 24", children: PATHS[severity] });
|
|
93
|
+
}
|
|
94
|
+
function resolveInformIcon(icon, severity) {
|
|
95
|
+
if (icon === void 0) return /* @__PURE__ */ jsx(InformSeverityIcon, { severity });
|
|
96
|
+
return icon;
|
|
97
|
+
}
|
|
98
|
+
function InformBanner({
|
|
99
|
+
actions,
|
|
100
|
+
body,
|
|
101
|
+
icon,
|
|
102
|
+
className,
|
|
103
|
+
dismissLabel,
|
|
104
|
+
dismissable = false,
|
|
105
|
+
onDismiss,
|
|
106
|
+
severity = "info",
|
|
107
|
+
title
|
|
108
|
+
}) {
|
|
109
|
+
const resolvedIcon = resolveInformIcon(icon, severity);
|
|
110
|
+
return /* @__PURE__ */ jsxs(
|
|
111
|
+
"div",
|
|
112
|
+
{
|
|
113
|
+
"aria-live": "polite",
|
|
114
|
+
className: cn("a63-InformBanner", SEVERITY_BORDER_CLASS[severity], className),
|
|
115
|
+
"data-severity": severity,
|
|
116
|
+
role: "status",
|
|
117
|
+
children: [
|
|
118
|
+
resolvedIcon === null ? null : /* @__PURE__ */ jsx(InformIconSlot, { children: resolvedIcon }),
|
|
119
|
+
/* @__PURE__ */ jsxs("div", { className: "a63-Inform-content", children: [
|
|
120
|
+
title === void 0 ? null : /* @__PURE__ */ jsx("p", { className: cn("a63-Inform-title", SEVERITY_TEXT_CLASS[severity]), children: title }),
|
|
121
|
+
/* @__PURE__ */ jsx("p", { className: "a63-Inform-body", children: body }),
|
|
122
|
+
actions === void 0 ? null : /* @__PURE__ */ jsx(InformActions, { actions })
|
|
123
|
+
] }),
|
|
124
|
+
dismissable ? /* @__PURE__ */ jsx(InformDismissButton, { label: dismissLabel, onDismiss }) : null
|
|
125
|
+
]
|
|
126
|
+
}
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
var PEEK_PX = 14;
|
|
130
|
+
var SCALE_STEP = 0.05;
|
|
131
|
+
var EXPANDED_GAP_PX = 8;
|
|
132
|
+
function isTopAnchored(placement) {
|
|
133
|
+
return placement.startsWith("top");
|
|
134
|
+
}
|
|
135
|
+
function InformFlyoutStack({
|
|
136
|
+
children,
|
|
137
|
+
className,
|
|
138
|
+
offset = "1rem",
|
|
139
|
+
placement = "bottom-right"
|
|
140
|
+
}) {
|
|
141
|
+
const items = Children.toArray(children);
|
|
142
|
+
const count = items.length;
|
|
143
|
+
const top = isTopAnchored(placement);
|
|
144
|
+
const [expanded, setExpanded] = useState(false);
|
|
145
|
+
const [heights, setHeights] = useState([]);
|
|
146
|
+
const itemRefs = useRef([]);
|
|
147
|
+
const measure = useCallback(() => {
|
|
148
|
+
const next = itemRefs.current.slice(0, count).map((element) => element?.offsetHeight ?? 0);
|
|
149
|
+
setHeights(
|
|
150
|
+
(previous) => previous.length === next.length && previous.every((value, index) => value === next[index]) ? previous : next
|
|
151
|
+
);
|
|
152
|
+
}, [count]);
|
|
153
|
+
useLayoutEffect(() => {
|
|
154
|
+
measure();
|
|
155
|
+
if (typeof ResizeObserver === "undefined") return;
|
|
156
|
+
const observer = new ResizeObserver(measure);
|
|
157
|
+
for (const element of itemRefs.current.slice(0, count)) {
|
|
158
|
+
if (element != null) observer.observe(element);
|
|
159
|
+
}
|
|
160
|
+
return () => {
|
|
161
|
+
observer.disconnect();
|
|
162
|
+
};
|
|
163
|
+
}, [measure, count, expanded]);
|
|
164
|
+
const heightOf = (index) => heights[index] ?? 0;
|
|
165
|
+
const offsetFor = (index) => {
|
|
166
|
+
if (!expanded) return index * PEEK_PX;
|
|
167
|
+
let total = 0;
|
|
168
|
+
for (let i = 0; i < index; i += 1) total += heightOf(i) + EXPANDED_GAP_PX;
|
|
169
|
+
return total;
|
|
170
|
+
};
|
|
171
|
+
const totalHeight = items.reduce((sum, _item, index) => sum + heightOf(index), 0);
|
|
172
|
+
const containerHeight = expanded ? totalHeight + (count - 1) * EXPANDED_GAP_PX : heightOf(0) + (count - 1) * PEEK_PX;
|
|
173
|
+
const itemStyle = (index) => ({
|
|
174
|
+
position: "absolute",
|
|
175
|
+
insetInline: 0,
|
|
176
|
+
[top ? "top" : "bottom"]: 0,
|
|
177
|
+
// Cards in front must paint over the ones behind them.
|
|
178
|
+
zIndex: count - index,
|
|
179
|
+
transform: `translateY(${(top ? 1 : -1) * offsetFor(index)}px) scale(${expanded ? 1 : 1 - index * SCALE_STEP})`,
|
|
180
|
+
transformOrigin: top ? "top center" : "bottom center"
|
|
181
|
+
});
|
|
182
|
+
return /* @__PURE__ */ jsx(
|
|
183
|
+
"div",
|
|
184
|
+
{
|
|
185
|
+
className: cn("a63-InformFlyoutStack", className),
|
|
186
|
+
"data-expanded": expanded ? "" : void 0,
|
|
187
|
+
"data-placement": placement,
|
|
188
|
+
"data-slot": "inform-flyout-stack",
|
|
189
|
+
"data-testid": "inform-flyout-stack",
|
|
190
|
+
onBlur: (event) => {
|
|
191
|
+
if (!event.currentTarget.contains(event.relatedTarget)) setExpanded(false);
|
|
192
|
+
},
|
|
193
|
+
onFocus: () => {
|
|
194
|
+
setExpanded(true);
|
|
195
|
+
},
|
|
196
|
+
onMouseEnter: () => {
|
|
197
|
+
setExpanded(true);
|
|
198
|
+
},
|
|
199
|
+
onMouseLeave: () => {
|
|
200
|
+
setExpanded(false);
|
|
201
|
+
},
|
|
202
|
+
style: {
|
|
203
|
+
[top ? "top" : "bottom"]: offset,
|
|
204
|
+
height: containerHeight === 0 ? void 0 : containerHeight
|
|
205
|
+
},
|
|
206
|
+
children: items.map((item, index) => /* @__PURE__ */ jsx(
|
|
207
|
+
"div",
|
|
208
|
+
{
|
|
209
|
+
className: "a63-InformFlyoutStack-item",
|
|
210
|
+
"data-slot": "inform-flyout-item",
|
|
211
|
+
ref: (element) => {
|
|
212
|
+
itemRefs.current[index] = element;
|
|
213
|
+
},
|
|
214
|
+
style: itemStyle(index),
|
|
215
|
+
children: item
|
|
216
|
+
},
|
|
217
|
+
index
|
|
218
|
+
))
|
|
219
|
+
}
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
function InformThumbnail({ children, className }) {
|
|
223
|
+
return /* @__PURE__ */ jsx("span", { className: cn("a63-InformThumbnail", className), "data-slot": "inform-thumbnail", children });
|
|
224
|
+
}
|
|
225
|
+
function InformMedia({ children, className }) {
|
|
226
|
+
return /* @__PURE__ */ jsx("div", { className: cn("a63-InformMedia", className), "data-slot": "inform-media", children });
|
|
227
|
+
}
|
|
228
|
+
var LEAVE_DURATION_MS = 150;
|
|
229
|
+
function InformCornerFlyout({
|
|
230
|
+
actions,
|
|
231
|
+
body,
|
|
232
|
+
className,
|
|
233
|
+
dismissLabel,
|
|
234
|
+
dismissable = true,
|
|
235
|
+
icon,
|
|
236
|
+
media,
|
|
237
|
+
onDismiss,
|
|
238
|
+
open,
|
|
239
|
+
severity = "info",
|
|
240
|
+
title
|
|
241
|
+
}) {
|
|
242
|
+
const resolvedIcon = resolveInformIcon(icon, severity);
|
|
243
|
+
const [entered, setEntered] = useState(false);
|
|
244
|
+
const [leaving, setLeaving] = useState(false);
|
|
245
|
+
const leaveTimer = useRef(null);
|
|
246
|
+
useEffect(
|
|
247
|
+
() => () => {
|
|
248
|
+
if (leaveTimer.current !== null) clearTimeout(leaveTimer.current);
|
|
249
|
+
},
|
|
250
|
+
[]
|
|
251
|
+
);
|
|
252
|
+
const requestDismiss = () => {
|
|
253
|
+
if (leaving) return;
|
|
254
|
+
const reduced = typeof window !== "undefined" && window.matchMedia?.("(prefers-reduced-motion: reduce)").matches === true;
|
|
255
|
+
if (reduced) {
|
|
256
|
+
onDismiss?.();
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
setLeaving(true);
|
|
260
|
+
leaveTimer.current = setTimeout(() => {
|
|
261
|
+
onDismiss?.();
|
|
262
|
+
}, LEAVE_DURATION_MS);
|
|
263
|
+
};
|
|
264
|
+
useEffect(() => {
|
|
265
|
+
if (!open) {
|
|
266
|
+
setEntered(false);
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
const frame = requestAnimationFrame(() => {
|
|
270
|
+
setEntered(true);
|
|
271
|
+
});
|
|
272
|
+
return () => {
|
|
273
|
+
cancelAnimationFrame(frame);
|
|
274
|
+
};
|
|
275
|
+
}, [open]);
|
|
276
|
+
if (!open) return null;
|
|
277
|
+
return /* @__PURE__ */ jsx(
|
|
278
|
+
"div",
|
|
279
|
+
{
|
|
280
|
+
"aria-live": "polite",
|
|
281
|
+
className: cn("a63-InformCornerFlyout", className),
|
|
282
|
+
"data-leaving": leaving ? "" : void 0,
|
|
283
|
+
"data-severity": severity,
|
|
284
|
+
"data-state": entered ? "entered" : "entering",
|
|
285
|
+
role: "status",
|
|
286
|
+
children: /* @__PURE__ */ jsxs("div", { className: "a63-Inform-row", children: [
|
|
287
|
+
media !== void 0 ? /* @__PURE__ */ jsx(InformThumbnail, { children: media }) : resolvedIcon === null ? null : /* @__PURE__ */ jsx(InformIconSlot, { children: resolvedIcon }),
|
|
288
|
+
/* @__PURE__ */ jsxs("div", { className: "a63-Inform-content", children: [
|
|
289
|
+
title === void 0 ? null : /* @__PURE__ */ jsx("p", { className: cn("a63-Inform-title", SEVERITY_TEXT_CLASS[severity]), children: title }),
|
|
290
|
+
/* @__PURE__ */ jsx("p", { className: "a63-Inform-body", children: body }),
|
|
291
|
+
actions === void 0 ? null : /* @__PURE__ */ jsx(InformActions, { actions })
|
|
292
|
+
] }),
|
|
293
|
+
dismissable ? /* @__PURE__ */ jsx(InformDismissButton, { label: dismissLabel, onDismiss: requestDismiss }) : null
|
|
294
|
+
] })
|
|
295
|
+
}
|
|
296
|
+
);
|
|
297
|
+
}
|
|
298
|
+
function InformDialog({
|
|
299
|
+
actions,
|
|
300
|
+
body,
|
|
301
|
+
className,
|
|
302
|
+
dismissable = true,
|
|
303
|
+
icon,
|
|
304
|
+
media,
|
|
305
|
+
onDismiss,
|
|
306
|
+
open,
|
|
307
|
+
severity = "info",
|
|
308
|
+
title
|
|
309
|
+
}) {
|
|
310
|
+
const resolvedIcon = resolveInformIcon(icon, severity);
|
|
311
|
+
return /* @__PURE__ */ jsx(
|
|
312
|
+
Dialog,
|
|
313
|
+
{
|
|
314
|
+
onOpenChange: (next) => {
|
|
315
|
+
if (!next) onDismiss?.();
|
|
316
|
+
},
|
|
317
|
+
open,
|
|
318
|
+
children: /* @__PURE__ */ jsxs(
|
|
319
|
+
DialogPopup,
|
|
320
|
+
{
|
|
321
|
+
className: cn("a63-InformDialog", className),
|
|
322
|
+
"data-severity": severity,
|
|
323
|
+
showCloseButton: dismissable,
|
|
324
|
+
children: [
|
|
325
|
+
/* @__PURE__ */ jsxs(DialogHeader, { children: [
|
|
326
|
+
media === void 0 ? null : /* @__PURE__ */ jsx(InformMedia, { children: media }),
|
|
327
|
+
/* @__PURE__ */ jsxs("div", { className: "a63-InformDialog-row", children: [
|
|
328
|
+
resolvedIcon === null ? null : /* @__PURE__ */ jsx(InformIconSlot, { children: resolvedIcon }),
|
|
329
|
+
/* @__PURE__ */ jsxs("div", { className: "a63-InformDialog-text", children: [
|
|
330
|
+
title === void 0 ? null : /* @__PURE__ */ jsx(DialogTitle, { className: SEVERITY_TEXT_CLASS[severity], children: title }),
|
|
331
|
+
/* @__PURE__ */ jsx(DialogDescription, { children: body })
|
|
332
|
+
] })
|
|
333
|
+
] })
|
|
334
|
+
] }),
|
|
335
|
+
actions === void 0 ? null : /* @__PURE__ */ jsx(DialogFooter, { children: /* @__PURE__ */ jsx(InformActions, { actions }) })
|
|
336
|
+
]
|
|
337
|
+
}
|
|
338
|
+
)
|
|
339
|
+
}
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
function readRect(anchor) {
|
|
343
|
+
if (typeof document === "undefined") return null;
|
|
344
|
+
const element = document.querySelector(anchor);
|
|
345
|
+
if (element === null) return null;
|
|
346
|
+
const rect = element.getBoundingClientRect();
|
|
347
|
+
if (rect.width === 0 || rect.height === 0) return null;
|
|
348
|
+
return { top: rect.top, left: rect.left, width: rect.width, height: rect.height };
|
|
349
|
+
}
|
|
350
|
+
function useAnchorRect(anchor, active) {
|
|
351
|
+
const [rect, setRect] = useState(null);
|
|
352
|
+
useEffect(() => {
|
|
353
|
+
if (!active) {
|
|
354
|
+
setRect(null);
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
const update = () => {
|
|
358
|
+
setRect(readRect(anchor));
|
|
359
|
+
};
|
|
360
|
+
update();
|
|
361
|
+
const element = typeof document === "undefined" ? null : document.querySelector(anchor);
|
|
362
|
+
const observer = element === null || typeof ResizeObserver === "undefined" ? null : new ResizeObserver(update);
|
|
363
|
+
if (element !== null) observer?.observe(element);
|
|
364
|
+
window.addEventListener("resize", update);
|
|
365
|
+
window.addEventListener("scroll", update, true);
|
|
366
|
+
return () => {
|
|
367
|
+
observer?.disconnect();
|
|
368
|
+
window.removeEventListener("resize", update);
|
|
369
|
+
window.removeEventListener("scroll", update, true);
|
|
370
|
+
};
|
|
371
|
+
}, [anchor, active]);
|
|
372
|
+
return rect;
|
|
373
|
+
}
|
|
374
|
+
function readViewport() {
|
|
375
|
+
if (typeof window === "undefined") return { width: 0, height: 0 };
|
|
376
|
+
return { width: window.innerWidth, height: window.innerHeight };
|
|
377
|
+
}
|
|
378
|
+
function useViewportSize(active) {
|
|
379
|
+
const [size, setSize] = useState(readViewport);
|
|
380
|
+
useEffect(() => {
|
|
381
|
+
if (!active) return;
|
|
382
|
+
const update = () => {
|
|
383
|
+
setSize(readViewport());
|
|
384
|
+
};
|
|
385
|
+
update();
|
|
386
|
+
window.addEventListener("resize", update);
|
|
387
|
+
return () => {
|
|
388
|
+
window.removeEventListener("resize", update);
|
|
389
|
+
};
|
|
390
|
+
}, [active]);
|
|
391
|
+
return size;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
// src/surfaces/place-bubble.ts
|
|
395
|
+
var BUBBLE_GAP = 12;
|
|
396
|
+
var BUBBLE_MARGIN = 8;
|
|
397
|
+
function clamp(value, min, max) {
|
|
398
|
+
if (max < min) return min;
|
|
399
|
+
return Math.min(Math.max(value, min), max);
|
|
400
|
+
}
|
|
401
|
+
function placeBubble({ anchor, bubble, viewport }) {
|
|
402
|
+
const anchorBottom = anchor.top + anchor.height;
|
|
403
|
+
const needed = bubble.height + BUBBLE_GAP + BUBBLE_MARGIN;
|
|
404
|
+
const roomBelow = viewport.height - anchorBottom;
|
|
405
|
+
const roomAbove = anchor.top;
|
|
406
|
+
const side = roomBelow >= needed || roomBelow >= roomAbove ? "bottom" : "top";
|
|
407
|
+
const preferredTop = side === "bottom" ? anchorBottom + BUBBLE_GAP : anchor.top - bubble.height - BUBBLE_GAP;
|
|
408
|
+
return {
|
|
409
|
+
side,
|
|
410
|
+
top: clamp(preferredTop, BUBBLE_MARGIN, viewport.height - bubble.height - BUBBLE_MARGIN),
|
|
411
|
+
left: clamp(anchor.left, BUBBLE_MARGIN, viewport.width - bubble.width - BUBBLE_MARGIN)
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
var FOCUSABLE = 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
|
|
415
|
+
var UNMEASURED = { width: 0, height: 0 };
|
|
416
|
+
function inertBackground(except) {
|
|
417
|
+
if (typeof document === "undefined") return () => void 0;
|
|
418
|
+
const marked = [];
|
|
419
|
+
for (const child of document.body.children) {
|
|
420
|
+
if (!(child instanceof HTMLElement)) continue;
|
|
421
|
+
if (except !== null && child.contains(except)) continue;
|
|
422
|
+
if (child.hasAttribute("inert")) continue;
|
|
423
|
+
child.setAttribute("inert", "");
|
|
424
|
+
marked.push(child);
|
|
425
|
+
}
|
|
426
|
+
return () => {
|
|
427
|
+
for (const element of marked) element.removeAttribute("inert");
|
|
428
|
+
};
|
|
429
|
+
}
|
|
430
|
+
function InformSpotlight({
|
|
431
|
+
actions,
|
|
432
|
+
anchor,
|
|
433
|
+
body,
|
|
434
|
+
className,
|
|
435
|
+
icon,
|
|
436
|
+
onDismiss,
|
|
437
|
+
open,
|
|
438
|
+
severity = "info",
|
|
439
|
+
title
|
|
440
|
+
}) {
|
|
441
|
+
const resolvedIcon = resolveInformIcon(icon, severity);
|
|
442
|
+
const rect = useAnchorRect(anchor, open);
|
|
443
|
+
const viewport = useViewportSize(open);
|
|
444
|
+
const [bubbleSize, setBubbleSize] = useState(null);
|
|
445
|
+
const bubbleRef = useRef(null);
|
|
446
|
+
const titleId = useId();
|
|
447
|
+
const bodyId = useId();
|
|
448
|
+
const rootRef = useRef(null);
|
|
449
|
+
const restoreRef = useRef(null);
|
|
450
|
+
const visible = open && rect !== null;
|
|
451
|
+
useLayoutEffect(() => {
|
|
452
|
+
if (!visible) {
|
|
453
|
+
setBubbleSize(null);
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
const element = bubbleRef.current;
|
|
457
|
+
if (element === null) return;
|
|
458
|
+
const measure = () => {
|
|
459
|
+
const measured = element.getBoundingClientRect();
|
|
460
|
+
setBubbleSize(
|
|
461
|
+
(previous) => previous !== null && previous.width === measured.width && previous.height === measured.height ? previous : { width: measured.width, height: measured.height }
|
|
462
|
+
);
|
|
463
|
+
};
|
|
464
|
+
measure();
|
|
465
|
+
if (typeof ResizeObserver === "undefined") return;
|
|
466
|
+
const observer = new ResizeObserver(measure);
|
|
467
|
+
observer.observe(element);
|
|
468
|
+
return () => {
|
|
469
|
+
observer.disconnect();
|
|
470
|
+
};
|
|
471
|
+
}, [visible, rect]);
|
|
472
|
+
useEffect(() => {
|
|
473
|
+
if (!visible) return;
|
|
474
|
+
restoreRef.current = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
475
|
+
const previousOverflow = document.body.style.overflow;
|
|
476
|
+
document.body.style.overflow = "hidden";
|
|
477
|
+
const restoreBackground = inertBackground(rootRef.current);
|
|
478
|
+
bubbleRef.current?.focus();
|
|
479
|
+
const onKeyDown = (event) => {
|
|
480
|
+
if (event.key === "Escape") {
|
|
481
|
+
event.preventDefault();
|
|
482
|
+
onDismiss?.();
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
if (event.key !== "Tab") return;
|
|
486
|
+
const bubble = bubbleRef.current;
|
|
487
|
+
if (bubble === null) return;
|
|
488
|
+
const focusable = [...bubble.querySelectorAll(FOCUSABLE)];
|
|
489
|
+
const first = focusable[0] ?? bubble;
|
|
490
|
+
const last = focusable.at(-1) ?? bubble;
|
|
491
|
+
if (event.shiftKey && document.activeElement === first) {
|
|
492
|
+
event.preventDefault();
|
|
493
|
+
last.focus();
|
|
494
|
+
} else if (!event.shiftKey && document.activeElement === last) {
|
|
495
|
+
event.preventDefault();
|
|
496
|
+
first.focus();
|
|
497
|
+
}
|
|
498
|
+
};
|
|
499
|
+
document.addEventListener("keydown", onKeyDown);
|
|
500
|
+
return () => {
|
|
501
|
+
document.removeEventListener("keydown", onKeyDown);
|
|
502
|
+
document.body.style.overflow = previousOverflow;
|
|
503
|
+
restoreBackground();
|
|
504
|
+
restoreRef.current?.focus();
|
|
505
|
+
};
|
|
506
|
+
}, [onDismiss, visible]);
|
|
507
|
+
if (!visible || rect === null) return null;
|
|
508
|
+
const placement = placeBubble({
|
|
509
|
+
anchor: rect,
|
|
510
|
+
bubble: bubbleSize ?? UNMEASURED,
|
|
511
|
+
viewport
|
|
512
|
+
});
|
|
513
|
+
return createPortal(
|
|
514
|
+
/* @__PURE__ */ jsxs("div", { className: "a63-InformSpotlight", ref: rootRef, children: [
|
|
515
|
+
/* @__PURE__ */ jsx(
|
|
516
|
+
"div",
|
|
517
|
+
{
|
|
518
|
+
"aria-hidden": true,
|
|
519
|
+
className: "a63-InformSpotlight-cutout",
|
|
520
|
+
"data-testid": "inform-spotlight-cutout",
|
|
521
|
+
style: { top: rect.top, left: rect.left, width: rect.width, height: rect.height }
|
|
522
|
+
}
|
|
523
|
+
),
|
|
524
|
+
/* @__PURE__ */ jsx(
|
|
525
|
+
"div",
|
|
526
|
+
{
|
|
527
|
+
"aria-describedby": title === void 0 ? void 0 : bodyId,
|
|
528
|
+
"aria-labelledby": title === void 0 ? bodyId : titleId,
|
|
529
|
+
"aria-modal": "true",
|
|
530
|
+
className: cn("a63-InformSpotlight-bubble", className),
|
|
531
|
+
"data-severity": severity,
|
|
532
|
+
"data-side": placement.side,
|
|
533
|
+
ref: bubbleRef,
|
|
534
|
+
role: "dialog",
|
|
535
|
+
style: { top: placement.top, left: placement.left },
|
|
536
|
+
tabIndex: -1,
|
|
537
|
+
children: /* @__PURE__ */ jsxs("div", { className: "a63-Inform-row", children: [
|
|
538
|
+
resolvedIcon === null ? null : /* @__PURE__ */ jsx(InformIconSlot, { children: resolvedIcon }),
|
|
539
|
+
/* @__PURE__ */ jsxs("div", { className: "a63-Inform-content", children: [
|
|
540
|
+
title === void 0 ? null : /* @__PURE__ */ jsx("p", { className: cn("a63-Inform-title", SEVERITY_TEXT_CLASS[severity]), id: titleId, children: title }),
|
|
541
|
+
/* @__PURE__ */ jsx("p", { className: "a63-Inform-body", id: bodyId, children: body }),
|
|
542
|
+
actions === void 0 ? null : /* @__PURE__ */ jsx(InformActions, { actions })
|
|
543
|
+
] })
|
|
544
|
+
] })
|
|
545
|
+
}
|
|
546
|
+
)
|
|
547
|
+
] }),
|
|
548
|
+
document.body
|
|
549
|
+
);
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
export { InformActions, InformBanner, InformCornerFlyout, InformDialog, InformDismissButton, InformFlyoutStack, InformIconSlot, InformMedia, InformSpotlight, InformThumbnail, SEVERITY_BORDER_CLASS, SEVERITY_TEXT_CLASS, SLOT_SIZE_CLASS, useAnchorRect };
|
|
553
|
+
//# sourceMappingURL=chunk-KT6PQL7E.js.map
|
|
554
|
+
//# sourceMappingURL=chunk-KT6PQL7E.js.map
|