@xsolla/xui-b2c-popover 0.209.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/web/index.mjs ADDED
@@ -0,0 +1,808 @@
1
+ // src/Popover.tsx
2
+ import { forwardRef, useCallback as useCallback2, useEffect as useEffect4, useRef as useRef2, useState as useState4 } from "react";
3
+
4
+ // ../../foundation/primitives-web/src/Box.tsx
5
+ import React2 from "react";
6
+ import styled from "styled-components";
7
+
8
+ // ../../foundation/primitives-web/src/filterDOMProps.ts
9
+ import React from "react";
10
+
11
+ // ../../../node_modules/@emotion/memoize/dist/memoize.esm.js
12
+ function memoize(fn) {
13
+ var cache = {};
14
+ return function(arg) {
15
+ if (cache[arg] === void 0) cache[arg] = fn(arg);
16
+ return cache[arg];
17
+ };
18
+ }
19
+ var memoize_esm_default = memoize;
20
+
21
+ // ../../../node_modules/@emotion/is-prop-valid/dist/is-prop-valid.esm.js
22
+ var reactPropsRegex = /^((children|dangerouslySetInnerHTML|key|ref|autoFocus|defaultValue|defaultChecked|innerHTML|suppressContentEditableWarning|suppressHydrationWarning|valueLink|accept|acceptCharset|accessKey|action|allow|allowUserMedia|allowPaymentRequest|allowFullScreen|allowTransparency|alt|async|autoComplete|autoPlay|capture|cellPadding|cellSpacing|challenge|charSet|checked|cite|classID|className|cols|colSpan|content|contentEditable|contextMenu|controls|controlsList|coords|crossOrigin|data|dateTime|decoding|default|defer|dir|disabled|disablePictureInPicture|download|draggable|encType|form|formAction|formEncType|formMethod|formNoValidate|formTarget|frameBorder|headers|height|hidden|high|href|hrefLang|htmlFor|httpEquiv|id|inputMode|integrity|is|keyParams|keyType|kind|label|lang|list|loading|loop|low|marginHeight|marginWidth|max|maxLength|media|mediaGroup|method|min|minLength|multiple|muted|name|nonce|noValidate|open|optimum|pattern|placeholder|playsInline|poster|preload|profile|radioGroup|readOnly|referrerPolicy|rel|required|reversed|role|rows|rowSpan|sandbox|scope|scoped|scrolling|seamless|selected|shape|size|sizes|slot|span|spellCheck|src|srcDoc|srcLang|srcSet|start|step|style|summary|tabIndex|target|title|type|useMap|value|width|wmode|wrap|about|datatype|inlist|prefix|property|resource|typeof|vocab|autoCapitalize|autoCorrect|autoSave|color|inert|itemProp|itemScope|itemType|itemID|itemRef|on|results|security|unselectable|accentHeight|accumulate|additive|alignmentBaseline|allowReorder|alphabetic|amplitude|arabicForm|ascent|attributeName|attributeType|autoReverse|azimuth|baseFrequency|baselineShift|baseProfile|bbox|begin|bias|by|calcMode|capHeight|clip|clipPathUnits|clipPath|clipRule|colorInterpolation|colorInterpolationFilters|colorProfile|colorRendering|contentScriptType|contentStyleType|cursor|cx|cy|d|decelerate|descent|diffuseConstant|direction|display|divisor|dominantBaseline|dur|dx|dy|edgeMode|elevation|enableBackground|end|exponent|externalResourcesRequired|fill|fillOpacity|fillRule|filter|filterRes|filterUnits|floodColor|floodOpacity|focusable|fontFamily|fontSize|fontSizeAdjust|fontStretch|fontStyle|fontVariant|fontWeight|format|from|fr|fx|fy|g1|g2|glyphName|glyphOrientationHorizontal|glyphOrientationVertical|glyphRef|gradientTransform|gradientUnits|hanging|horizAdvX|horizOriginX|ideographic|imageRendering|in|in2|intercept|k|k1|k2|k3|k4|kernelMatrix|kernelUnitLength|kerning|keyPoints|keySplines|keyTimes|lengthAdjust|letterSpacing|lightingColor|limitingConeAngle|local|markerEnd|markerMid|markerStart|markerHeight|markerUnits|markerWidth|mask|maskContentUnits|maskUnits|mathematical|mode|numOctaves|offset|opacity|operator|order|orient|orientation|origin|overflow|overlinePosition|overlineThickness|panose1|paintOrder|pathLength|patternContentUnits|patternTransform|patternUnits|pointerEvents|points|pointsAtX|pointsAtY|pointsAtZ|preserveAlpha|preserveAspectRatio|primitiveUnits|r|radius|refX|refY|renderingIntent|repeatCount|repeatDur|requiredExtensions|requiredFeatures|restart|result|rotate|rx|ry|scale|seed|shapeRendering|slope|spacing|specularConstant|specularExponent|speed|spreadMethod|startOffset|stdDeviation|stemh|stemv|stitchTiles|stopColor|stopOpacity|strikethroughPosition|strikethroughThickness|string|stroke|strokeDasharray|strokeDashoffset|strokeLinecap|strokeLinejoin|strokeMiterlimit|strokeOpacity|strokeWidth|surfaceScale|systemLanguage|tableValues|targetX|targetY|textAnchor|textDecoration|textRendering|textLength|to|transform|u1|u2|underlinePosition|underlineThickness|unicode|unicodeBidi|unicodeRange|unitsPerEm|vAlphabetic|vHanging|vIdeographic|vMathematical|values|vectorEffect|version|vertAdvY|vertOriginX|vertOriginY|viewBox|viewTarget|visibility|widths|wordSpacing|writingMode|x|xHeight|x1|x2|xChannelSelector|xlinkActuate|xlinkArcrole|xlinkHref|xlinkRole|xlinkShow|xlinkTitle|xlinkType|xmlBase|xmlns|xmlnsXlink|xmlLang|xmlSpace|y|y1|y2|yChannelSelector|z|zoomAndPan|for|class|autofocus)|(([Dd][Aa][Tt][Aa]|[Aa][Rr][Ii][Aa]|x)-.*))$/;
23
+ var index = memoize_esm_default(
24
+ function(prop) {
25
+ return reactPropsRegex.test(prop) || prop.charCodeAt(0) === 111 && prop.charCodeAt(1) === 110 && prop.charCodeAt(2) < 91;
26
+ }
27
+ /* Z+1 */
28
+ );
29
+ var is_prop_valid_esm_default = index;
30
+
31
+ // ../../foundation/primitives-web/src/filterDOMProps.ts
32
+ var ADDITIONAL_BLOCKED_PROPS = /* @__PURE__ */ new Set([
33
+ // RN-only event handlers (pass isPropValid's on* pattern)
34
+ "onPress",
35
+ "onChangeText",
36
+ "onLayout",
37
+ "onMoveShouldSetResponder",
38
+ "onResponderGrant",
39
+ "onResponderMove",
40
+ "onResponderRelease",
41
+ "onResponderTerminate",
42
+ // SVG attributes that pass isPropValid
43
+ "strokeWidth",
44
+ // CSS properties that pass isPropValid but are used as component props
45
+ "overflow",
46
+ "opacity",
47
+ "cursor",
48
+ "fontSize",
49
+ "fontWeight",
50
+ "fontFamily",
51
+ "textDecoration",
52
+ // Cross-platform layout prop that Text consumes as CSS, never as an
53
+ // attribute. Pinned explicitly because it is now spread into the styled
54
+ // component rather than destructured away before it can reach the DOM.
55
+ "numberOfLines"
56
+ ]);
57
+ function shouldForwardProp(key) {
58
+ if (ADDITIONAL_BLOCKED_PROPS.has(key)) return false;
59
+ return is_prop_valid_esm_default(key);
60
+ }
61
+ function createFilteredElement(defaultTag) {
62
+ const Component = React.forwardRef(
63
+ ({ children, elementType, ...props }, ref) => {
64
+ const Tag = elementType || defaultTag;
65
+ const htmlProps = {};
66
+ for (const key of Object.keys(props)) {
67
+ if (shouldForwardProp(key)) {
68
+ htmlProps[key] = props[key];
69
+ }
70
+ }
71
+ return React.createElement(
72
+ Tag,
73
+ { ref, ...htmlProps },
74
+ children
75
+ );
76
+ }
77
+ );
78
+ Component.displayName = `Filtered(${defaultTag})`;
79
+ return Component;
80
+ }
81
+
82
+ // ../../foundation/primitives-web/src/Box.tsx
83
+ import { jsx } from "react/jsx-runtime";
84
+ var FilteredDiv = createFilteredElement("div");
85
+ var StyledBox = styled(FilteredDiv)`
86
+ display: flex;
87
+ box-sizing: border-box;
88
+ background-color: ${(props) => props.backgroundColor || "transparent"};
89
+ border-color: ${(props) => props.borderColor || "transparent"};
90
+ border-width: ${(props) => typeof props.borderWidth === "number" ? `${props.borderWidth}px` : props.borderWidth || 0};
91
+
92
+ ${(props) => props.borderBottomWidth !== void 0 && `
93
+ border-bottom-width: ${typeof props.borderBottomWidth === "number" ? `${props.borderBottomWidth}px` : props.borderBottomWidth};
94
+ border-bottom-color: ${props.borderBottomColor || props.borderColor || "transparent"};
95
+ border-bottom-style: solid;
96
+ `}
97
+ ${(props) => props.borderTopWidth !== void 0 && `
98
+ border-top-width: ${typeof props.borderTopWidth === "number" ? `${props.borderTopWidth}px` : props.borderTopWidth};
99
+ border-top-color: ${props.borderTopColor || props.borderColor || "transparent"};
100
+ border-top-style: solid;
101
+ `}
102
+ ${(props) => props.borderLeftWidth !== void 0 && `
103
+ border-left-width: ${typeof props.borderLeftWidth === "number" ? `${props.borderLeftWidth}px` : props.borderLeftWidth};
104
+ border-left-color: ${props.borderLeftColor || props.borderColor || "transparent"};
105
+ border-left-style: solid;
106
+ `}
107
+ ${(props) => props.borderRightWidth !== void 0 && `
108
+ border-right-width: ${typeof props.borderRightWidth === "number" ? `${props.borderRightWidth}px` : props.borderRightWidth};
109
+ border-right-color: ${props.borderRightColor || props.borderColor || "transparent"};
110
+ border-right-style: solid;
111
+ `}
112
+
113
+ border-style: ${(props) => props.borderStyle || (props.borderWidth || props.borderBottomWidth || props.borderTopWidth || props.borderLeftWidth || props.borderRightWidth ? "solid" : "none")};
114
+ border-radius: ${(props) => typeof props.borderRadius === "number" ? `${props.borderRadius}px` : props.borderRadius || 0};
115
+ height: ${(props) => typeof props.height === "number" ? `${props.height}px` : props.height || "auto"};
116
+ width: ${(props) => typeof props.width === "number" ? `${props.width}px` : props.width || "auto"};
117
+ min-width: ${(props) => typeof props.minWidth === "number" ? `${props.minWidth}px` : props.minWidth || "auto"};
118
+ min-height: ${(props) => typeof props.minHeight === "number" ? `${props.minHeight}px` : props.minHeight || "auto"};
119
+ max-width: ${(props) => typeof props.maxWidth === "number" ? `${props.maxWidth}px` : props.maxWidth || "none"};
120
+ max-height: ${(props) => typeof props.maxHeight === "number" ? `${props.maxHeight}px` : props.maxHeight || "none"};
121
+
122
+ padding: ${(props) => typeof props.padding === "number" ? `${props.padding}px` : props.padding || 0};
123
+ ${(props) => props.paddingHorizontal && `
124
+ padding-left: ${typeof props.paddingHorizontal === "number" ? `${props.paddingHorizontal}px` : props.paddingHorizontal};
125
+ padding-right: ${typeof props.paddingHorizontal === "number" ? `${props.paddingHorizontal}px` : props.paddingHorizontal};
126
+ `}
127
+ ${(props) => props.paddingVertical && `
128
+ padding-top: ${typeof props.paddingVertical === "number" ? `${props.paddingVertical}px` : props.paddingVertical};
129
+ padding-bottom: ${typeof props.paddingVertical === "number" ? `${props.paddingVertical}px` : props.paddingVertical};
130
+ `}
131
+ ${(props) => props.paddingTop !== void 0 && `padding-top: ${typeof props.paddingTop === "number" ? `${props.paddingTop}px` : props.paddingTop};`}
132
+ ${(props) => props.paddingBottom !== void 0 && `padding-bottom: ${typeof props.paddingBottom === "number" ? `${props.paddingBottom}px` : props.paddingBottom};`}
133
+ ${(props) => props.paddingLeft !== void 0 && `padding-left: ${typeof props.paddingLeft === "number" ? `${props.paddingLeft}px` : props.paddingLeft};`}
134
+ ${(props) => props.paddingRight !== void 0 && `padding-right: ${typeof props.paddingRight === "number" ? `${props.paddingRight}px` : props.paddingRight};`}
135
+
136
+ margin: ${(props) => typeof props.margin === "number" ? `${props.margin}px` : props.margin || 0};
137
+ ${(props) => props.marginTop !== void 0 && `margin-top: ${typeof props.marginTop === "number" ? `${props.marginTop}px` : props.marginTop};`}
138
+ ${(props) => props.marginBottom !== void 0 && `margin-bottom: ${typeof props.marginBottom === "number" ? `${props.marginBottom}px` : props.marginBottom};`}
139
+ ${(props) => props.marginLeft !== void 0 && `margin-left: ${typeof props.marginLeft === "number" ? `${props.marginLeft}px` : props.marginLeft};`}
140
+ ${(props) => props.marginRight !== void 0 && `margin-right: ${typeof props.marginRight === "number" ? `${props.marginRight}px` : props.marginRight};`}
141
+
142
+ flex-direction: ${(props) => props.flexDirection || "column"};
143
+ flex-wrap: ${(props) => props.flexWrap || "nowrap"};
144
+ align-items: ${(props) => props.alignItems || "stretch"};
145
+ justify-content: ${(props) => props.justifyContent || "flex-start"};
146
+ cursor: ${(props) => props.cursor ? props.cursor : props.onClick || props.onPress ? "pointer" : "inherit"};
147
+ position: ${(props) => props.position || "static"};
148
+ top: ${(props) => typeof props.top === "number" ? `${props.top}px` : props.top};
149
+ bottom: ${(props) => typeof props.bottom === "number" ? `${props.bottom}px` : props.bottom};
150
+ left: ${(props) => typeof props.left === "number" ? `${props.left}px` : props.left};
151
+ right: ${(props) => typeof props.right === "number" ? `${props.right}px` : props.right};
152
+ flex: ${(props) => props.flex};
153
+ flex-shrink: ${(props) => props.flexShrink ?? 1};
154
+ gap: ${(props) => typeof props.gap === "number" ? `${props.gap}px` : props.gap || 0};
155
+ align-self: ${(props) => props.alignSelf || "auto"};
156
+ /* Only emit overflow-x/y when explicitly set. Defaulting them to
157
+ visible after overflow would override the shorthand and break
158
+ clipping (e.g. OtherCard bottom-right promo image). */
159
+ overflow: ${(props) => props.overflow || "visible"};
160
+ ${(props) => props.overflowX != null ? `overflow-x: ${props.overflowX};` : ""}
161
+ ${(props) => props.overflowY != null ? `overflow-y: ${props.overflowY};` : ""}
162
+ z-index: ${(props) => props.zIndex};
163
+ opacity: ${(props) => props.opacity != null ? props.opacity : props.disabled ? 0.5 : 1};
164
+ pointer-events: ${(props) => props.disabled ? "none" : "auto"};
165
+
166
+ &:hover {
167
+ ${(props) => props.hoverStyle?.backgroundColor && `background-color: ${props.hoverStyle.backgroundColor};`}
168
+ ${(props) => props.hoverStyle?.borderColor && `border-color: ${props.hoverStyle.borderColor};`}
169
+ }
170
+
171
+ &:active {
172
+ ${(props) => props.pressStyle?.backgroundColor && `background-color: ${props.pressStyle.backgroundColor};`}
173
+ }
174
+ `;
175
+ var Box = React2.forwardRef(
176
+ ({
177
+ children,
178
+ onPress,
179
+ onKeyDown,
180
+ onKeyUp,
181
+ role,
182
+ "aria-label": ariaLabel,
183
+ "aria-labelledby": ariaLabelledBy,
184
+ "aria-current": ariaCurrent,
185
+ "aria-disabled": ariaDisabled,
186
+ "aria-live": ariaLive,
187
+ "aria-busy": ariaBusy,
188
+ "aria-describedby": ariaDescribedBy,
189
+ "aria-expanded": ariaExpanded,
190
+ "aria-haspopup": ariaHasPopup,
191
+ "aria-pressed": ariaPressed,
192
+ "aria-controls": ariaControls,
193
+ tabIndex,
194
+ as,
195
+ src,
196
+ alt,
197
+ onError,
198
+ onLoad,
199
+ type,
200
+ disabled,
201
+ id,
202
+ testID,
203
+ "data-testid": dataTestId,
204
+ ...props
205
+ }, ref) => {
206
+ if (as === "img" && src) {
207
+ return /* @__PURE__ */ jsx(
208
+ "img",
209
+ {
210
+ src,
211
+ alt: alt || "",
212
+ onError,
213
+ onLoad,
214
+ "data-testid": dataTestId || testID,
215
+ style: {
216
+ display: "block",
217
+ objectFit: "cover",
218
+ width: typeof props.width === "number" ? `${props.width}px` : props.width,
219
+ height: typeof props.height === "number" ? `${props.height}px` : props.height,
220
+ borderRadius: typeof props.borderRadius === "number" ? `${props.borderRadius}px` : props.borderRadius,
221
+ position: props.position,
222
+ top: typeof props.top === "number" ? `${props.top}px` : props.top,
223
+ left: typeof props.left === "number" ? `${props.left}px` : props.left,
224
+ right: typeof props.right === "number" ? `${props.right}px` : props.right,
225
+ bottom: typeof props.bottom === "number" ? `${props.bottom}px` : props.bottom,
226
+ ...props.style
227
+ }
228
+ }
229
+ );
230
+ }
231
+ return /* @__PURE__ */ jsx(
232
+ StyledBox,
233
+ {
234
+ ref,
235
+ elementType: as,
236
+ id,
237
+ type: as === "button" ? type || "button" : void 0,
238
+ disabled: as === "button" ? disabled : void 0,
239
+ onClick: onPress,
240
+ onKeyDown,
241
+ onKeyUp,
242
+ role,
243
+ "aria-label": ariaLabel,
244
+ "aria-labelledby": ariaLabelledBy,
245
+ "aria-current": ariaCurrent,
246
+ "aria-disabled": ariaDisabled,
247
+ "aria-busy": ariaBusy,
248
+ "aria-describedby": ariaDescribedBy,
249
+ "aria-expanded": ariaExpanded,
250
+ "aria-haspopup": ariaHasPopup,
251
+ "aria-pressed": ariaPressed,
252
+ "aria-controls": ariaControls,
253
+ "aria-live": ariaLive,
254
+ tabIndex: tabIndex !== void 0 ? tabIndex : void 0,
255
+ "data-testid": dataTestId || testID,
256
+ ...props,
257
+ children
258
+ }
259
+ );
260
+ }
261
+ );
262
+ Box.displayName = "Box";
263
+
264
+ // src/Popover.tsx
265
+ import { radiusScale, useResolvedTheme } from "@xsolla/xui-core";
266
+
267
+ // src/PopoverRoot.web.tsx
268
+ import { memo, useEffect, useState } from "react";
269
+ import ReactDOM from "react-dom";
270
+ import {
271
+ useOverlayLayer,
272
+ OverlayLayerProvider,
273
+ MODAL_LAYER_STEP
274
+ } from "@xsolla/xui-core";
275
+ import { jsx as jsx2, jsxs } from "react/jsx-runtime";
276
+ var OUTER_PADDING = 20;
277
+ var PopoverRoot = memo(
278
+ ({
279
+ children,
280
+ open,
281
+ onExited,
282
+ onBackdropClick,
283
+ scrimColor,
284
+ fullScreen,
285
+ position,
286
+ animationDuration,
287
+ testID
288
+ }) => {
289
+ const [visible, setVisible] = useState(false);
290
+ const popoverLayer = useOverlayLayer() + MODAL_LAYER_STEP;
291
+ useEffect(() => {
292
+ if (!open) return;
293
+ const frame = requestAnimationFrame(() => setVisible(true));
294
+ return () => cancelAnimationFrame(frame);
295
+ }, [open]);
296
+ useEffect(() => {
297
+ if (open) return;
298
+ setVisible(false);
299
+ const timer = setTimeout(onExited, animationDuration);
300
+ return () => clearTimeout(timer);
301
+ }, [open, animationDuration, onExited]);
302
+ const locksScroll = fullScreen || Boolean(scrimColor);
303
+ useEffect(() => {
304
+ if (!locksScroll || typeof document === "undefined") return;
305
+ const original = document.body.style.overflow;
306
+ document.body.style.overflow = "hidden";
307
+ return () => {
308
+ document.body.style.overflow = original;
309
+ };
310
+ }, [locksScroll]);
311
+ if (typeof document === "undefined") return null;
312
+ const positioned = !fullScreen && position !== void 0;
313
+ return ReactDOM.createPortal(
314
+ /* @__PURE__ */ jsxs(
315
+ "div",
316
+ {
317
+ "data-testid": testID,
318
+ style: {
319
+ position: "fixed",
320
+ inset: 0,
321
+ zIndex: popoverLayer,
322
+ padding: fullScreen || positioned ? 0 : OUTER_PADDING,
323
+ display: "flex",
324
+ alignItems: fullScreen ? "stretch" : "center",
325
+ justifyContent: "center",
326
+ // Without a scrim the page behind stays interactive, so the
327
+ // full-viewport wrapper must not swallow presses meant for it.
328
+ // The panel itself re-enables pointer events below.
329
+ pointerEvents: scrimColor ? void 0 : "none"
330
+ },
331
+ children: [
332
+ scrimColor && /* @__PURE__ */ jsx2(
333
+ "div",
334
+ {
335
+ style: {
336
+ position: "absolute",
337
+ inset: 0,
338
+ background: scrimColor,
339
+ opacity: visible ? 1 : 0,
340
+ cursor: onBackdropClick ? "pointer" : "default",
341
+ transition: `opacity ${animationDuration}ms ease`
342
+ },
343
+ onClick: onBackdropClick,
344
+ "aria-hidden": "true"
345
+ }
346
+ ),
347
+ /* @__PURE__ */ jsx2(
348
+ "div",
349
+ {
350
+ style: {
351
+ position: positioned ? "absolute" : "relative",
352
+ left: positioned ? position.x : void 0,
353
+ top: positioned ? position.y : void 0,
354
+ zIndex: 1,
355
+ pointerEvents: "auto",
356
+ display: "flex",
357
+ maxHeight: "100%",
358
+ width: fullScreen ? "100%" : void 0,
359
+ opacity: visible ? 1 : 0,
360
+ transform: visible ? "scale(1)" : "scale(0.95)",
361
+ transition: `opacity ${animationDuration}ms ease, transform ${animationDuration}ms ease`
362
+ },
363
+ children: /* @__PURE__ */ jsx2(OverlayLayerProvider, { value: popoverLayer, children })
364
+ }
365
+ )
366
+ ]
367
+ }
368
+ ),
369
+ document.body
370
+ );
371
+ }
372
+ );
373
+ PopoverRoot.displayName = "PopoverRoot";
374
+
375
+ // src/PopoverTitleBar.tsx
376
+ import { memo as memo2 } from "react";
377
+ import { IconButton } from "@xsolla/xui-button";
378
+ import { Drag, Pin, Remove, Unpin } from "@xsolla/xui-icons-base";
379
+ import { Typography } from "@xsolla/xui-typography";
380
+ import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
381
+ var PopoverTitleBar = memo2(
382
+ ({
383
+ title,
384
+ draggable,
385
+ dragHandleProps,
386
+ pinned,
387
+ onPinnedChange,
388
+ onClose,
389
+ testID
390
+ }) => /* @__PURE__ */ jsxs2(
391
+ "div",
392
+ {
393
+ "data-testid": testID,
394
+ style: {
395
+ flexShrink: 0,
396
+ width: "100%",
397
+ display: "flex",
398
+ flexDirection: "row",
399
+ alignItems: "center",
400
+ gap: 8,
401
+ cursor: draggable ? "grab" : void 0
402
+ },
403
+ ...draggable ? dragHandleProps : {},
404
+ children: [
405
+ draggable && /* @__PURE__ */ jsx3(
406
+ "span",
407
+ {
408
+ "data-xui-popover-drag-handle": "",
409
+ role: "button",
410
+ tabIndex: 0,
411
+ "aria-label": "Move popover",
412
+ style: { display: "inline-flex", flexShrink: 0 },
413
+ children: /* @__PURE__ */ jsx3(Drag, {})
414
+ }
415
+ ),
416
+ /* @__PURE__ */ jsx3("div", { style: { flex: 1, minWidth: 0, overflow: "hidden" }, children: title && /* @__PURE__ */ jsx3(Typography, { variant: "bodyLgAccent", noWrap: true, children: title }) }),
417
+ onPinnedChange && /* @__PURE__ */ jsx3(
418
+ IconButton,
419
+ {
420
+ variant: "secondary",
421
+ tone: "mono",
422
+ size: "xs",
423
+ icon: pinned ? /* @__PURE__ */ jsx3(Unpin, {}) : /* @__PURE__ */ jsx3(Pin, {}),
424
+ onPress: () => onPinnedChange(!pinned),
425
+ "aria-label": pinned ? "Unpin popover" : "Pin popover",
426
+ "aria-pressed": pinned
427
+ }
428
+ ),
429
+ onClose && /* @__PURE__ */ jsx3(
430
+ IconButton,
431
+ {
432
+ variant: "secondary",
433
+ tone: "mono",
434
+ size: "xs",
435
+ icon: /* @__PURE__ */ jsx3(Remove, {}),
436
+ onPress: onClose,
437
+ "aria-label": "Close popover"
438
+ }
439
+ )
440
+ ]
441
+ }
442
+ )
443
+ );
444
+ PopoverTitleBar.displayName = "PopoverTitleBar";
445
+
446
+ // src/usePopoverDrag.ts
447
+ import {
448
+ useCallback,
449
+ useEffect as useEffect2,
450
+ useRef,
451
+ useState as useState2
452
+ } from "react";
453
+ var KEYBOARD_STEP = 16;
454
+ var EDGE_MARGIN = 8;
455
+ var isInteractive = (target) => target instanceof Element && target.closest("button, a, input") !== null;
456
+ var clampToViewport = (position, panel) => {
457
+ if (!panel || typeof window === "undefined") return position;
458
+ const { width, height } = panel.getBoundingClientRect();
459
+ const maxX = Math.max(EDGE_MARGIN, window.innerWidth - width - EDGE_MARGIN);
460
+ const maxY = Math.max(EDGE_MARGIN, window.innerHeight - height - EDGE_MARGIN);
461
+ return {
462
+ x: Math.min(Math.max(position.x, EDGE_MARGIN), maxX),
463
+ y: Math.min(Math.max(position.y, EDGE_MARGIN), maxY)
464
+ };
465
+ };
466
+ var usePopoverDrag = ({
467
+ enabled,
468
+ initialPosition,
469
+ onPositionChange
470
+ }) => {
471
+ const panelRef = useRef(null);
472
+ const [position, setPosition] = useState2(
473
+ initialPosition
474
+ );
475
+ const [isDragging, setIsDragging] = useState2(false);
476
+ const grabOffset = useRef({ x: 0, y: 0 });
477
+ useEffect2(() => {
478
+ if (!enabled) setPosition(void 0);
479
+ }, [enabled]);
480
+ const commit = useCallback(
481
+ (next) => {
482
+ const clamped = clampToViewport(next, panelRef.current);
483
+ setPosition(clamped);
484
+ onPositionChange?.(clamped);
485
+ },
486
+ [onPositionChange]
487
+ );
488
+ const onPointerDown = useCallback(
489
+ (event) => {
490
+ if (!enabled || event.button !== 0) return;
491
+ if (isInteractive(event.target)) return;
492
+ const panel = panelRef.current;
493
+ if (!panel) return;
494
+ event.preventDefault();
495
+ const rect = panel.getBoundingClientRect();
496
+ grabOffset.current = {
497
+ x: event.clientX - rect.left,
498
+ y: event.clientY - rect.top
499
+ };
500
+ setIsDragging(true);
501
+ },
502
+ [enabled]
503
+ );
504
+ const onKeyDown = useCallback(
505
+ (event) => {
506
+ if (!enabled) return;
507
+ if (!(event.target instanceof Element) || !event.target.closest("[data-xui-popover-drag-handle]")) {
508
+ return;
509
+ }
510
+ const deltas = {
511
+ ArrowUp: { x: 0, y: -KEYBOARD_STEP },
512
+ ArrowDown: { x: 0, y: KEYBOARD_STEP },
513
+ ArrowLeft: { x: -KEYBOARD_STEP, y: 0 },
514
+ ArrowRight: { x: KEYBOARD_STEP, y: 0 }
515
+ };
516
+ const delta = deltas[event.key];
517
+ if (!delta) return;
518
+ event.preventDefault();
519
+ const rect = panelRef.current?.getBoundingClientRect();
520
+ const base = position ?? { x: rect?.left ?? 0, y: rect?.top ?? 0 };
521
+ commit({ x: base.x + delta.x, y: base.y + delta.y });
522
+ },
523
+ [commit, enabled, position]
524
+ );
525
+ useEffect2(() => {
526
+ if (!isDragging || typeof document === "undefined") return;
527
+ const handleMove = (event) => {
528
+ commit({
529
+ x: event.clientX - grabOffset.current.x,
530
+ y: event.clientY - grabOffset.current.y
531
+ });
532
+ };
533
+ const stop = () => setIsDragging(false);
534
+ document.addEventListener("pointermove", handleMove);
535
+ document.addEventListener("pointerup", stop);
536
+ document.addEventListener("pointercancel", stop);
537
+ return () => {
538
+ document.removeEventListener("pointermove", handleMove);
539
+ document.removeEventListener("pointerup", stop);
540
+ document.removeEventListener("pointercancel", stop);
541
+ };
542
+ }, [commit, isDragging]);
543
+ return {
544
+ position: enabled ? position : void 0,
545
+ panelRef,
546
+ dragHandleProps: { onPointerDown, onKeyDown },
547
+ isDragging
548
+ };
549
+ };
550
+
551
+ // src/useDeviceType.ts
552
+ import { useEffect as useEffect3, useState as useState3 } from "react";
553
+ var POPOVER_BREAKPOINTS = {
554
+ /** Widths at or below this are `mobile` (Figma: "Mobile: 320-768px"). */
555
+ mobileMax: 768,
556
+ /** Widths at or below this, but above `mobileMax`, are `tablet` (Figma: "Tablet: 769-1023px"). */
557
+ tabletMax: 1023
558
+ };
559
+ var resolveDevice = (width) => {
560
+ if (width <= POPOVER_BREAKPOINTS.mobileMax) return "mobile";
561
+ if (width <= POPOVER_BREAKPOINTS.tabletMax) return "tablet";
562
+ return "desktop";
563
+ };
564
+ var useDeviceType = (override) => {
565
+ const [device, setDevice] = useState3(
566
+ () => typeof window === "undefined" ? "desktop" : resolveDevice(window.innerWidth)
567
+ );
568
+ useEffect3(() => {
569
+ if (override || typeof window === "undefined") return;
570
+ const update = () => setDevice(resolveDevice(window.innerWidth));
571
+ update();
572
+ window.addEventListener("resize", update);
573
+ return () => window.removeEventListener("resize", update);
574
+ }, [override]);
575
+ return override ?? device;
576
+ };
577
+
578
+ // src/Popover.tsx
579
+ import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
580
+ var FOCUSABLE_SELECTORS = 'button:not([disabled]), [href], input:not([disabled]):not([type="hidden"]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
581
+ var DEFAULT_WIDTH = 400;
582
+ var PANEL_PADDING = 16;
583
+ var SECTION_GAP = 24;
584
+ var PANEL_RADIUS = radiusScale["200"];
585
+ var BACKDROP_BLUR = "blur(24px)";
586
+ var ANIMATION_DURATION = 200;
587
+ var isElementVisible = (el) => {
588
+ if (el.offsetParent === null && getComputedStyle(el).position !== "fixed")
589
+ return false;
590
+ const style = getComputedStyle(el);
591
+ return style.visibility !== "hidden" && style.display !== "none";
592
+ };
593
+ var getFocusableElements = (container) => Array.from(
594
+ container.querySelectorAll(FOCUSABLE_SELECTORS)
595
+ ).filter(isElementVisible);
596
+ var Popover = forwardRef(
597
+ ({
598
+ open = false,
599
+ onClose,
600
+ device: deviceProp,
601
+ width = DEFAULT_WIDTH,
602
+ draggable = false,
603
+ initialPosition,
604
+ onPositionChange,
605
+ title,
606
+ pinned,
607
+ onPinnedChange,
608
+ showCloseButton = true,
609
+ titleBar,
610
+ header,
611
+ children,
612
+ footer,
613
+ closeOnOverlayClick = true,
614
+ closeOnEscape = true,
615
+ scrim = true,
616
+ backgroundColor,
617
+ blur = true,
618
+ styled: styledProps,
619
+ initialFocusRef,
620
+ "aria-label": ariaLabel,
621
+ testID,
622
+ themeMode,
623
+ themeProductContext = "b2c"
624
+ }, ref) => {
625
+ const { theme } = useResolvedTheme({ themeMode, themeProductContext });
626
+ const device = useDeviceType(deviceProp);
627
+ const fullScreen = device === "mobile";
628
+ const canDrag = draggable && !fullScreen;
629
+ const dismissOnScrim = closeOnOverlayClick && !pinned && !fullScreen;
630
+ const [mounted, setMounted] = useState4(open);
631
+ const dialogRef = useRef2(null);
632
+ const previousActiveElement = useRef2(null);
633
+ const { position, panelRef, dragHandleProps } = usePopoverDrag({
634
+ enabled: canDrag,
635
+ initialPosition,
636
+ onPositionChange
637
+ });
638
+ useEffect4(() => {
639
+ if (open) setMounted(true);
640
+ }, [open]);
641
+ useEffect4(() => {
642
+ if (!open || typeof document === "undefined") return;
643
+ previousActiveElement.current = document.activeElement;
644
+ const focusTarget = initialFocusRef?.current || dialogRef.current && getFocusableElements(dialogRef.current)[0];
645
+ if (focusTarget) focusTarget.focus();
646
+ else dialogRef.current?.focus();
647
+ }, [open, initialFocusRef]);
648
+ useEffect4(() => {
649
+ if (!open || !closeOnEscape || !onClose) return;
650
+ if (typeof document === "undefined") return;
651
+ const handleKeyDown2 = (event) => {
652
+ if (event.key === "Escape") onClose();
653
+ };
654
+ document.addEventListener("keydown", handleKeyDown2);
655
+ return () => document.removeEventListener("keydown", handleKeyDown2);
656
+ }, [open, closeOnEscape, onClose]);
657
+ const handleKeyDown = useCallback2((event) => {
658
+ if (event.key !== "Tab" || !dialogRef.current) return;
659
+ if (typeof document === "undefined") return;
660
+ const focusableElements = getFocusableElements(dialogRef.current);
661
+ const firstElement = focusableElements[0];
662
+ const lastElement = focusableElements[focusableElements.length - 1];
663
+ if (!firstElement) {
664
+ event.preventDefault();
665
+ return;
666
+ }
667
+ if (event.shiftKey && document.activeElement === firstElement) {
668
+ event.preventDefault();
669
+ lastElement.focus();
670
+ } else if (!event.shiftKey && document.activeElement === lastElement) {
671
+ event.preventDefault();
672
+ firstElement.focus();
673
+ }
674
+ }, []);
675
+ const setPanelNode = useCallback2(
676
+ (node) => {
677
+ dialogRef.current = node;
678
+ panelRef.current = node;
679
+ if (typeof ref === "function") ref(node);
680
+ else if (ref) ref.current = node;
681
+ },
682
+ [panelRef, ref]
683
+ );
684
+ const handleExited = useCallback2(() => {
685
+ setMounted(false);
686
+ previousActiveElement.current?.focus();
687
+ }, []);
688
+ if (!mounted) return null;
689
+ const closeControl = showCloseButton ? onClose : void 0;
690
+ const hasDefaultTitleBar = !titleBar && (title || closeControl || canDrag);
691
+ const accessibleName = ariaLabel ?? (typeof title === "string" ? title : void 0);
692
+ return /* @__PURE__ */ jsx4(
693
+ PopoverRoot,
694
+ {
695
+ open,
696
+ onExited: handleExited,
697
+ onBackdropClick: dismissOnScrim ? onClose : void 0,
698
+ scrimColor: scrim && !fullScreen ? theme.colors.layer?.scrim ?? "rgba(0, 0, 0, 0.75)" : void 0,
699
+ fullScreen,
700
+ position,
701
+ animationDuration: ANIMATION_DURATION,
702
+ children: /* @__PURE__ */ jsxs3(
703
+ Box,
704
+ {
705
+ testID,
706
+ ref: setPanelNode,
707
+ role: "dialog",
708
+ "aria-modal": fullScreen || scrim ? "true" : void 0,
709
+ "aria-label": accessibleName,
710
+ "data-popover-device": device,
711
+ "data-popover-pinned": pinned ? "true" : void 0,
712
+ tabIndex: -1,
713
+ onKeyDown: handleKeyDown,
714
+ style: {
715
+ boxSizing: "border-box",
716
+ display: "flex",
717
+ flexDirection: "column",
718
+ alignItems: "center",
719
+ gap: SECTION_GAP,
720
+ width: fullScreen ? "100%" : width,
721
+ maxWidth: "100%",
722
+ height: fullScreen ? "100%" : void 0,
723
+ maxHeight: "100%",
724
+ outline: "none",
725
+ color: theme.colors.content.primary,
726
+ backgroundColor: backgroundColor ?? theme.colors.background.primary,
727
+ paddingLeft: PANEL_PADDING,
728
+ paddingRight: PANEL_PADDING,
729
+ // The Figma mobile frame carries only a bottom inset — its top bars
730
+ // are full-bleed, and its children supply their own side padding.
731
+ // A slot component cannot assume the caller re-pads for one
732
+ // breakpoint, so the sides stay inset and only the top is dropped.
733
+ paddingTop: fullScreen ? 0 : PANEL_PADDING,
734
+ paddingBottom: PANEL_PADDING,
735
+ borderRadius: fullScreen ? 0 : PANEL_RADIUS,
736
+ border: fullScreen ? void 0 : `1px solid ${theme.colors.border.secondary}`,
737
+ boxShadow: fullScreen ? void 0 : theme.shadow.popover,
738
+ backdropFilter: !fullScreen && blur ? BACKDROP_BLUR : void 0,
739
+ ...styledProps
740
+ },
741
+ children: [
742
+ titleBar ?? (hasDefaultTitleBar ? /* @__PURE__ */ jsx4(
743
+ PopoverTitleBar,
744
+ {
745
+ title,
746
+ draggable: canDrag,
747
+ dragHandleProps,
748
+ pinned,
749
+ onPinnedChange,
750
+ onClose: closeControl,
751
+ testID: testID ? `${testID}-title-bar` : void 0
752
+ }
753
+ ) : null),
754
+ header && /* @__PURE__ */ jsx4("div", { style: { flexShrink: 0, width: "100%" }, children: header }),
755
+ /* @__PURE__ */ jsx4(
756
+ "div",
757
+ {
758
+ style: {
759
+ flex: 1,
760
+ minHeight: 0,
761
+ width: "100%",
762
+ overflowY: "auto",
763
+ overscrollBehavior: "contain"
764
+ },
765
+ children
766
+ }
767
+ ),
768
+ footer && /* @__PURE__ */ jsx4("div", { style: { flexShrink: 0, width: "100%" }, children: footer })
769
+ ]
770
+ }
771
+ )
772
+ }
773
+ );
774
+ }
775
+ );
776
+ Popover.displayName = "Popover";
777
+
778
+ // src/usePopover.ts
779
+ import { useCallback as useCallback3, useState as useState5 } from "react";
780
+ function usePopover(options) {
781
+ const [isOpen, setIsOpen] = useState5(false);
782
+ const open = useCallback3(() => {
783
+ setIsOpen(true);
784
+ options?.onOpen?.();
785
+ }, [options]);
786
+ const close = useCallback3(() => {
787
+ setIsOpen(false);
788
+ options?.onClose?.();
789
+ }, [options]);
790
+ const toggle = useCallback3(() => {
791
+ setIsOpen((previous) => {
792
+ if (previous) options?.onClose?.();
793
+ else options?.onOpen?.();
794
+ return !previous;
795
+ });
796
+ }, [options]);
797
+ return { isOpen, open, close, toggle };
798
+ }
799
+ export {
800
+ POPOVER_BREAKPOINTS,
801
+ Popover,
802
+ PopoverTitleBar,
803
+ resolveDevice,
804
+ useDeviceType,
805
+ usePopover,
806
+ usePopoverDrag
807
+ };
808
+ //# sourceMappingURL=index.mjs.map