@dloizides/ui-layout 1.9.1 → 1.10.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/CHANGELOG.md +197 -165
- package/README.md +8 -0
- package/dist/index.js +82 -37
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +82 -37
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -100,10 +100,7 @@ var SEGMENT_PAD_V = 7;
|
|
|
100
100
|
var SEGMENT_FONT = 14;
|
|
101
101
|
var SEGMENT_WEIGHT = "600";
|
|
102
102
|
var BORDER_WIDTH = 1;
|
|
103
|
-
var
|
|
104
|
-
var SHADOW_OPACITY = 0.1;
|
|
105
|
-
var SHADOW_RADIUS = 3;
|
|
106
|
-
var SHADOW_OFFSET = { width: 0, height: 1 };
|
|
103
|
+
var SEGMENT_BOX_SHADOW = "0px 1px 3px rgba(20, 30, 50, 0.1)";
|
|
107
104
|
var SHADOW_ELEVATION = 2;
|
|
108
105
|
var TRANSPARENT = "transparent";
|
|
109
106
|
var styles4 = reactNative.StyleSheet.create({
|
|
@@ -122,10 +119,7 @@ var styles4 = reactNative.StyleSheet.create({
|
|
|
122
119
|
borderRadius: SEGMENT_RADIUS
|
|
123
120
|
},
|
|
124
121
|
segmentSelected: {
|
|
125
|
-
|
|
126
|
-
shadowOpacity: SHADOW_OPACITY,
|
|
127
|
-
shadowRadius: SHADOW_RADIUS,
|
|
128
|
-
shadowOffset: SHADOW_OFFSET,
|
|
122
|
+
boxShadow: SEGMENT_BOX_SHADOW,
|
|
129
123
|
elevation: SHADOW_ELEVATION
|
|
130
124
|
},
|
|
131
125
|
label: {
|
|
@@ -343,6 +337,14 @@ function buildPortalPopoverStyle(rect, minWidth = 0) {
|
|
|
343
337
|
function buildAnchorStackStyle(isMenuOpen) {
|
|
344
338
|
return isMenuOpen ? { zIndex: ANCHOR_OPEN_Z_INDEX, elevation: MENU_ELEVATION } : null;
|
|
345
339
|
}
|
|
340
|
+
function isAnchorOutOfView(rect, viewportHeight, viewportWidth) {
|
|
341
|
+
const hasLayout = rect.width > 0 && rect.bottom !== rect.top;
|
|
342
|
+
const hasViewport = viewportHeight > 0 && viewportWidth > 0;
|
|
343
|
+
if (!hasLayout || !hasViewport) return false;
|
|
344
|
+
const isAboveOrBelow = rect.bottom <= 0 || rect.top >= viewportHeight;
|
|
345
|
+
const isLeftOrRight = rect.left + rect.width <= 0 || rect.left >= viewportWidth;
|
|
346
|
+
return isAboveOrBelow || isLeftOrRight;
|
|
347
|
+
}
|
|
346
348
|
var OPTION_BORDER_RADIUS = 4;
|
|
347
349
|
var BODY_FONT_SIZE = 14;
|
|
348
350
|
var SELECTED_FONT_WEIGHT = "600";
|
|
@@ -387,6 +389,57 @@ var OptionRow = ({
|
|
|
387
389
|
}
|
|
388
390
|
);
|
|
389
391
|
};
|
|
392
|
+
var IS_WEB = reactNative.Platform.OS === "web";
|
|
393
|
+
function toDomNode(containerRef) {
|
|
394
|
+
const node = containerRef.current;
|
|
395
|
+
if (node === null || typeof node.getBoundingClientRect !== "function") return null;
|
|
396
|
+
return node;
|
|
397
|
+
}
|
|
398
|
+
function readAnchorRect(containerRef) {
|
|
399
|
+
if (!IS_WEB) return null;
|
|
400
|
+
const node = toDomNode(containerRef);
|
|
401
|
+
if (node === null) return null;
|
|
402
|
+
const r = node.getBoundingClientRect();
|
|
403
|
+
return { top: r.top, left: r.left, width: r.width, bottom: r.bottom };
|
|
404
|
+
}
|
|
405
|
+
function observeLayout(node, onChange) {
|
|
406
|
+
if (typeof ResizeObserver !== "function") return null;
|
|
407
|
+
const observer = new ResizeObserver(onChange);
|
|
408
|
+
if (node !== null) observer.observe(node);
|
|
409
|
+
observer.observe(document.body);
|
|
410
|
+
return observer;
|
|
411
|
+
}
|
|
412
|
+
function useAnchorTracking(containerRef, onOutOfView) {
|
|
413
|
+
const [rect, setRect] = React8.useState(() => readAnchorRect(containerRef));
|
|
414
|
+
React8.useLayoutEffect(() => {
|
|
415
|
+
if (!IS_WEB) return void 0;
|
|
416
|
+
let frame = null;
|
|
417
|
+
let isDisposed = false;
|
|
418
|
+
const apply = () => {
|
|
419
|
+
frame = null;
|
|
420
|
+
if (isDisposed) return;
|
|
421
|
+
const next = readAnchorRect(containerRef);
|
|
422
|
+
setRect(next);
|
|
423
|
+
if (next !== null && isAnchorOutOfView(next, window.innerHeight, window.innerWidth)) onOutOfView();
|
|
424
|
+
};
|
|
425
|
+
const schedule = () => {
|
|
426
|
+
if (frame !== null) return;
|
|
427
|
+
frame = window.requestAnimationFrame(apply);
|
|
428
|
+
};
|
|
429
|
+
apply();
|
|
430
|
+
document.addEventListener("scroll", schedule, true);
|
|
431
|
+
window.addEventListener("resize", schedule);
|
|
432
|
+
const observer = observeLayout(toDomNode(containerRef), schedule);
|
|
433
|
+
return () => {
|
|
434
|
+
isDisposed = true;
|
|
435
|
+
if (frame !== null) window.cancelAnimationFrame(frame);
|
|
436
|
+
document.removeEventListener("scroll", schedule, true);
|
|
437
|
+
window.removeEventListener("resize", schedule);
|
|
438
|
+
if (observer !== null) observer.disconnect();
|
|
439
|
+
};
|
|
440
|
+
}, [containerRef, onOutOfView]);
|
|
441
|
+
return rect;
|
|
442
|
+
}
|
|
390
443
|
function refContains(ref, target) {
|
|
391
444
|
if (ref === void 0) return false;
|
|
392
445
|
const node = ref.current;
|
|
@@ -451,7 +504,7 @@ function useMenuKeyboard(params) {
|
|
|
451
504
|
};
|
|
452
505
|
}, [containerRef, menuRef, enabled, onClose, params]);
|
|
453
506
|
}
|
|
454
|
-
var
|
|
507
|
+
var IS_WEB2 = reactNative.Platform.OS === "web";
|
|
455
508
|
var BORDER_RADIUS2 = 8;
|
|
456
509
|
var BORDER_WIDTH3 = 1;
|
|
457
510
|
var MENU_PADDING2 = 4;
|
|
@@ -472,30 +525,6 @@ var styles7 = reactNative.StyleSheet.create({
|
|
|
472
525
|
elevation: MENU_ELEVATION
|
|
473
526
|
}
|
|
474
527
|
});
|
|
475
|
-
function readAnchorRect(containerRef) {
|
|
476
|
-
if (!IS_WEB) return null;
|
|
477
|
-
const node = containerRef.current;
|
|
478
|
-
if (node === null || typeof node.getBoundingClientRect !== "function") return null;
|
|
479
|
-
const r = node.getBoundingClientRect();
|
|
480
|
-
return { top: r.top, left: r.left, width: r.width, bottom: r.bottom };
|
|
481
|
-
}
|
|
482
|
-
function useAnchorRect(containerRef) {
|
|
483
|
-
const [rect, setRect] = React8.useState(() => readAnchorRect(containerRef));
|
|
484
|
-
React8.useLayoutEffect(() => {
|
|
485
|
-
if (!IS_WEB) return void 0;
|
|
486
|
-
const measure = () => {
|
|
487
|
-
setRect(readAnchorRect(containerRef));
|
|
488
|
-
};
|
|
489
|
-
measure();
|
|
490
|
-
window.addEventListener("scroll", measure, true);
|
|
491
|
-
window.addEventListener("resize", measure);
|
|
492
|
-
return () => {
|
|
493
|
-
window.removeEventListener("scroll", measure, true);
|
|
494
|
-
window.removeEventListener("resize", measure);
|
|
495
|
-
};
|
|
496
|
-
}, [containerRef]);
|
|
497
|
-
return rect;
|
|
498
|
-
}
|
|
499
528
|
var InlineMenu = ({
|
|
500
529
|
testID,
|
|
501
530
|
accessibilityLabel,
|
|
@@ -510,7 +539,7 @@ var InlineMenu = ({
|
|
|
510
539
|
const { theme } = uiFeedback.useUi();
|
|
511
540
|
const { colors } = theme;
|
|
512
541
|
const menuRef = React8.useRef(null);
|
|
513
|
-
const rect =
|
|
542
|
+
const rect = useAnchorTracking(containerRef, onClose);
|
|
514
543
|
const selectedIndex = React8.useMemo(
|
|
515
544
|
() => Math.max(0, options.findIndex((opt) => opt.value === value)),
|
|
516
545
|
[options, value]
|
|
@@ -540,7 +569,7 @@ var InlineMenu = ({
|
|
|
540
569
|
});
|
|
541
570
|
const popoverStyle = React8.useMemo(() => {
|
|
542
571
|
const themed = { borderColor: colors.border, backgroundColor: colors.surface };
|
|
543
|
-
if (
|
|
572
|
+
if (IS_WEB2)
|
|
544
573
|
return [
|
|
545
574
|
buildPortalPopoverStyle(rect ?? { left: 0, width: 0, bottom: 0 }, menuMinWidth),
|
|
546
575
|
themed
|
|
@@ -568,7 +597,7 @@ var InlineMenu = ({
|
|
|
568
597
|
)) })
|
|
569
598
|
}
|
|
570
599
|
);
|
|
571
|
-
if (
|
|
600
|
+
if (IS_WEB2) return reactDom.createPortal(menu, document.body);
|
|
572
601
|
return menu;
|
|
573
602
|
};
|
|
574
603
|
var MENU_BREAKPOINT = 768;
|
|
@@ -582,6 +611,7 @@ function useResolvedDropdownVariant(explicit) {
|
|
|
582
611
|
const { width } = reactNative.useWindowDimensions();
|
|
583
612
|
return resolveDropdownVariant(explicit, width, reactNative.Platform.OS);
|
|
584
613
|
}
|
|
614
|
+
var IS_WEB3 = reactNative.Platform.OS === "web";
|
|
585
615
|
var BORDER_RADIUS3 = 8;
|
|
586
616
|
var BORDER_WIDTH4 = 1;
|
|
587
617
|
var BODY_FONT_SIZE2 = 14;
|
|
@@ -590,8 +620,21 @@ var MODAL_MIN_WIDTH = 200;
|
|
|
590
620
|
var MODAL_MAX_HEIGHT = 300;
|
|
591
621
|
var CONTAINER_PADDING_H = 12;
|
|
592
622
|
var CONTAINER_PADDING_V = 10;
|
|
623
|
+
var SR_ONLY_SIZE = 1;
|
|
624
|
+
var SR_ONLY_OFFSET = -1;
|
|
625
|
+
function buildHintProps(hint, hintId) {
|
|
626
|
+
return IS_WEB3 ? { "aria-describedby": hintId } : { accessibilityHint: hint };
|
|
627
|
+
}
|
|
593
628
|
var styles8 = reactNative.StyleSheet.create({
|
|
594
629
|
anchor: { position: "relative" },
|
|
630
|
+
srOnly: {
|
|
631
|
+
position: "absolute",
|
|
632
|
+
width: SR_ONLY_SIZE,
|
|
633
|
+
height: SR_ONLY_SIZE,
|
|
634
|
+
margin: SR_ONLY_OFFSET,
|
|
635
|
+
padding: 0,
|
|
636
|
+
overflow: "hidden"
|
|
637
|
+
},
|
|
595
638
|
container: {
|
|
596
639
|
borderWidth: BORDER_WIDTH4,
|
|
597
640
|
borderRadius: BORDER_RADIUS3,
|
|
@@ -629,6 +672,7 @@ var ModalDropdown = ({
|
|
|
629
672
|
const resolvedVariant = useResolvedDropdownVariant(variant);
|
|
630
673
|
const isMenu = resolvedVariant === "menu" /* Menu */;
|
|
631
674
|
const [isOpen, setIsOpen] = React8.useState(false);
|
|
675
|
+
const hintId = `${testID}-hint`;
|
|
632
676
|
const anchorRef = React8.useRef(null);
|
|
633
677
|
const dialogRef = React8.useRef(null);
|
|
634
678
|
useFocusTrap(dialogRef, isOpen && !isMenu);
|
|
@@ -683,7 +727,7 @@ var ModalDropdown = ({
|
|
|
683
727
|
reactNative.TouchableOpacity,
|
|
684
728
|
{
|
|
685
729
|
accessible: true,
|
|
686
|
-
accessibilityHint,
|
|
730
|
+
...buildHintProps(accessibilityHint, hintId),
|
|
687
731
|
accessibilityLabel,
|
|
688
732
|
accessibilityRole: "button",
|
|
689
733
|
accessibilityState: { expanded: isOpen },
|
|
@@ -694,6 +738,7 @@ var ModalDropdown = ({
|
|
|
694
738
|
children: renderTrigger !== void 0 ? renderTrigger({ label: selectedLabel, isOpen }) : /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles8.selectedText, { color: colors.text }], children: selectedLabel })
|
|
695
739
|
}
|
|
696
740
|
),
|
|
741
|
+
IS_WEB3 ? /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { nativeID: hintId, style: styles8.srOnly, testID: `${testID}-hint`, children: accessibilityHint }) : null,
|
|
697
742
|
isMenu && isOpen ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
698
743
|
InlineMenu,
|
|
699
744
|
{
|