@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.mjs
CHANGED
|
@@ -94,10 +94,7 @@ var SEGMENT_PAD_V = 7;
|
|
|
94
94
|
var SEGMENT_FONT = 14;
|
|
95
95
|
var SEGMENT_WEIGHT = "600";
|
|
96
96
|
var BORDER_WIDTH = 1;
|
|
97
|
-
var
|
|
98
|
-
var SHADOW_OPACITY = 0.1;
|
|
99
|
-
var SHADOW_RADIUS = 3;
|
|
100
|
-
var SHADOW_OFFSET = { width: 0, height: 1 };
|
|
97
|
+
var SEGMENT_BOX_SHADOW = "0px 1px 3px rgba(20, 30, 50, 0.1)";
|
|
101
98
|
var SHADOW_ELEVATION = 2;
|
|
102
99
|
var TRANSPARENT = "transparent";
|
|
103
100
|
var styles4 = StyleSheet.create({
|
|
@@ -116,10 +113,7 @@ var styles4 = StyleSheet.create({
|
|
|
116
113
|
borderRadius: SEGMENT_RADIUS
|
|
117
114
|
},
|
|
118
115
|
segmentSelected: {
|
|
119
|
-
|
|
120
|
-
shadowOpacity: SHADOW_OPACITY,
|
|
121
|
-
shadowRadius: SHADOW_RADIUS,
|
|
122
|
-
shadowOffset: SHADOW_OFFSET,
|
|
116
|
+
boxShadow: SEGMENT_BOX_SHADOW,
|
|
123
117
|
elevation: SHADOW_ELEVATION
|
|
124
118
|
},
|
|
125
119
|
label: {
|
|
@@ -337,6 +331,14 @@ function buildPortalPopoverStyle(rect, minWidth = 0) {
|
|
|
337
331
|
function buildAnchorStackStyle(isMenuOpen) {
|
|
338
332
|
return isMenuOpen ? { zIndex: ANCHOR_OPEN_Z_INDEX, elevation: MENU_ELEVATION } : null;
|
|
339
333
|
}
|
|
334
|
+
function isAnchorOutOfView(rect, viewportHeight, viewportWidth) {
|
|
335
|
+
const hasLayout = rect.width > 0 && rect.bottom !== rect.top;
|
|
336
|
+
const hasViewport = viewportHeight > 0 && viewportWidth > 0;
|
|
337
|
+
if (!hasLayout || !hasViewport) return false;
|
|
338
|
+
const isAboveOrBelow = rect.bottom <= 0 || rect.top >= viewportHeight;
|
|
339
|
+
const isLeftOrRight = rect.left + rect.width <= 0 || rect.left >= viewportWidth;
|
|
340
|
+
return isAboveOrBelow || isLeftOrRight;
|
|
341
|
+
}
|
|
340
342
|
var OPTION_BORDER_RADIUS = 4;
|
|
341
343
|
var BODY_FONT_SIZE = 14;
|
|
342
344
|
var SELECTED_FONT_WEIGHT = "600";
|
|
@@ -381,6 +383,57 @@ var OptionRow = ({
|
|
|
381
383
|
}
|
|
382
384
|
);
|
|
383
385
|
};
|
|
386
|
+
var IS_WEB = Platform.OS === "web";
|
|
387
|
+
function toDomNode(containerRef) {
|
|
388
|
+
const node = containerRef.current;
|
|
389
|
+
if (node === null || typeof node.getBoundingClientRect !== "function") return null;
|
|
390
|
+
return node;
|
|
391
|
+
}
|
|
392
|
+
function readAnchorRect(containerRef) {
|
|
393
|
+
if (!IS_WEB) return null;
|
|
394
|
+
const node = toDomNode(containerRef);
|
|
395
|
+
if (node === null) return null;
|
|
396
|
+
const r = node.getBoundingClientRect();
|
|
397
|
+
return { top: r.top, left: r.left, width: r.width, bottom: r.bottom };
|
|
398
|
+
}
|
|
399
|
+
function observeLayout(node, onChange) {
|
|
400
|
+
if (typeof ResizeObserver !== "function") return null;
|
|
401
|
+
const observer = new ResizeObserver(onChange);
|
|
402
|
+
if (node !== null) observer.observe(node);
|
|
403
|
+
observer.observe(document.body);
|
|
404
|
+
return observer;
|
|
405
|
+
}
|
|
406
|
+
function useAnchorTracking(containerRef, onOutOfView) {
|
|
407
|
+
const [rect, setRect] = useState(() => readAnchorRect(containerRef));
|
|
408
|
+
useLayoutEffect(() => {
|
|
409
|
+
if (!IS_WEB) return void 0;
|
|
410
|
+
let frame = null;
|
|
411
|
+
let isDisposed = false;
|
|
412
|
+
const apply = () => {
|
|
413
|
+
frame = null;
|
|
414
|
+
if (isDisposed) return;
|
|
415
|
+
const next = readAnchorRect(containerRef);
|
|
416
|
+
setRect(next);
|
|
417
|
+
if (next !== null && isAnchorOutOfView(next, window.innerHeight, window.innerWidth)) onOutOfView();
|
|
418
|
+
};
|
|
419
|
+
const schedule = () => {
|
|
420
|
+
if (frame !== null) return;
|
|
421
|
+
frame = window.requestAnimationFrame(apply);
|
|
422
|
+
};
|
|
423
|
+
apply();
|
|
424
|
+
document.addEventListener("scroll", schedule, true);
|
|
425
|
+
window.addEventListener("resize", schedule);
|
|
426
|
+
const observer = observeLayout(toDomNode(containerRef), schedule);
|
|
427
|
+
return () => {
|
|
428
|
+
isDisposed = true;
|
|
429
|
+
if (frame !== null) window.cancelAnimationFrame(frame);
|
|
430
|
+
document.removeEventListener("scroll", schedule, true);
|
|
431
|
+
window.removeEventListener("resize", schedule);
|
|
432
|
+
if (observer !== null) observer.disconnect();
|
|
433
|
+
};
|
|
434
|
+
}, [containerRef, onOutOfView]);
|
|
435
|
+
return rect;
|
|
436
|
+
}
|
|
384
437
|
function refContains(ref, target) {
|
|
385
438
|
if (ref === void 0) return false;
|
|
386
439
|
const node = ref.current;
|
|
@@ -445,7 +498,7 @@ function useMenuKeyboard(params) {
|
|
|
445
498
|
};
|
|
446
499
|
}, [containerRef, menuRef, enabled, onClose, params]);
|
|
447
500
|
}
|
|
448
|
-
var
|
|
501
|
+
var IS_WEB2 = Platform.OS === "web";
|
|
449
502
|
var BORDER_RADIUS2 = 8;
|
|
450
503
|
var BORDER_WIDTH3 = 1;
|
|
451
504
|
var MENU_PADDING2 = 4;
|
|
@@ -466,30 +519,6 @@ var styles7 = StyleSheet.create({
|
|
|
466
519
|
elevation: MENU_ELEVATION
|
|
467
520
|
}
|
|
468
521
|
});
|
|
469
|
-
function readAnchorRect(containerRef) {
|
|
470
|
-
if (!IS_WEB) return null;
|
|
471
|
-
const node = containerRef.current;
|
|
472
|
-
if (node === null || typeof node.getBoundingClientRect !== "function") return null;
|
|
473
|
-
const r = node.getBoundingClientRect();
|
|
474
|
-
return { top: r.top, left: r.left, width: r.width, bottom: r.bottom };
|
|
475
|
-
}
|
|
476
|
-
function useAnchorRect(containerRef) {
|
|
477
|
-
const [rect, setRect] = useState(() => readAnchorRect(containerRef));
|
|
478
|
-
useLayoutEffect(() => {
|
|
479
|
-
if (!IS_WEB) return void 0;
|
|
480
|
-
const measure = () => {
|
|
481
|
-
setRect(readAnchorRect(containerRef));
|
|
482
|
-
};
|
|
483
|
-
measure();
|
|
484
|
-
window.addEventListener("scroll", measure, true);
|
|
485
|
-
window.addEventListener("resize", measure);
|
|
486
|
-
return () => {
|
|
487
|
-
window.removeEventListener("scroll", measure, true);
|
|
488
|
-
window.removeEventListener("resize", measure);
|
|
489
|
-
};
|
|
490
|
-
}, [containerRef]);
|
|
491
|
-
return rect;
|
|
492
|
-
}
|
|
493
522
|
var InlineMenu = ({
|
|
494
523
|
testID,
|
|
495
524
|
accessibilityLabel,
|
|
@@ -504,7 +533,7 @@ var InlineMenu = ({
|
|
|
504
533
|
const { theme } = useUi();
|
|
505
534
|
const { colors } = theme;
|
|
506
535
|
const menuRef = useRef(null);
|
|
507
|
-
const rect =
|
|
536
|
+
const rect = useAnchorTracking(containerRef, onClose);
|
|
508
537
|
const selectedIndex = useMemo(
|
|
509
538
|
() => Math.max(0, options.findIndex((opt) => opt.value === value)),
|
|
510
539
|
[options, value]
|
|
@@ -534,7 +563,7 @@ var InlineMenu = ({
|
|
|
534
563
|
});
|
|
535
564
|
const popoverStyle = useMemo(() => {
|
|
536
565
|
const themed = { borderColor: colors.border, backgroundColor: colors.surface };
|
|
537
|
-
if (
|
|
566
|
+
if (IS_WEB2)
|
|
538
567
|
return [
|
|
539
568
|
buildPortalPopoverStyle(rect ?? { left: 0, width: 0, bottom: 0 }, menuMinWidth),
|
|
540
569
|
themed
|
|
@@ -562,7 +591,7 @@ var InlineMenu = ({
|
|
|
562
591
|
)) })
|
|
563
592
|
}
|
|
564
593
|
);
|
|
565
|
-
if (
|
|
594
|
+
if (IS_WEB2) return createPortal(menu, document.body);
|
|
566
595
|
return menu;
|
|
567
596
|
};
|
|
568
597
|
var MENU_BREAKPOINT = 768;
|
|
@@ -576,6 +605,7 @@ function useResolvedDropdownVariant(explicit) {
|
|
|
576
605
|
const { width } = useWindowDimensions();
|
|
577
606
|
return resolveDropdownVariant(explicit, width, Platform.OS);
|
|
578
607
|
}
|
|
608
|
+
var IS_WEB3 = Platform.OS === "web";
|
|
579
609
|
var BORDER_RADIUS3 = 8;
|
|
580
610
|
var BORDER_WIDTH4 = 1;
|
|
581
611
|
var BODY_FONT_SIZE2 = 14;
|
|
@@ -584,8 +614,21 @@ var MODAL_MIN_WIDTH = 200;
|
|
|
584
614
|
var MODAL_MAX_HEIGHT = 300;
|
|
585
615
|
var CONTAINER_PADDING_H = 12;
|
|
586
616
|
var CONTAINER_PADDING_V = 10;
|
|
617
|
+
var SR_ONLY_SIZE = 1;
|
|
618
|
+
var SR_ONLY_OFFSET = -1;
|
|
619
|
+
function buildHintProps(hint, hintId) {
|
|
620
|
+
return IS_WEB3 ? { "aria-describedby": hintId } : { accessibilityHint: hint };
|
|
621
|
+
}
|
|
587
622
|
var styles8 = StyleSheet.create({
|
|
588
623
|
anchor: { position: "relative" },
|
|
624
|
+
srOnly: {
|
|
625
|
+
position: "absolute",
|
|
626
|
+
width: SR_ONLY_SIZE,
|
|
627
|
+
height: SR_ONLY_SIZE,
|
|
628
|
+
margin: SR_ONLY_OFFSET,
|
|
629
|
+
padding: 0,
|
|
630
|
+
overflow: "hidden"
|
|
631
|
+
},
|
|
589
632
|
container: {
|
|
590
633
|
borderWidth: BORDER_WIDTH4,
|
|
591
634
|
borderRadius: BORDER_RADIUS3,
|
|
@@ -623,6 +666,7 @@ var ModalDropdown = ({
|
|
|
623
666
|
const resolvedVariant = useResolvedDropdownVariant(variant);
|
|
624
667
|
const isMenu = resolvedVariant === "menu" /* Menu */;
|
|
625
668
|
const [isOpen, setIsOpen] = useState(false);
|
|
669
|
+
const hintId = `${testID}-hint`;
|
|
626
670
|
const anchorRef = useRef(null);
|
|
627
671
|
const dialogRef = useRef(null);
|
|
628
672
|
useFocusTrap(dialogRef, isOpen && !isMenu);
|
|
@@ -677,7 +721,7 @@ var ModalDropdown = ({
|
|
|
677
721
|
TouchableOpacity,
|
|
678
722
|
{
|
|
679
723
|
accessible: true,
|
|
680
|
-
accessibilityHint,
|
|
724
|
+
...buildHintProps(accessibilityHint, hintId),
|
|
681
725
|
accessibilityLabel,
|
|
682
726
|
accessibilityRole: "button",
|
|
683
727
|
accessibilityState: { expanded: isOpen },
|
|
@@ -688,6 +732,7 @@ var ModalDropdown = ({
|
|
|
688
732
|
children: renderTrigger !== void 0 ? renderTrigger({ label: selectedLabel, isOpen }) : /* @__PURE__ */ jsx(Text, { style: [styles8.selectedText, { color: colors.text }], children: selectedLabel })
|
|
689
733
|
}
|
|
690
734
|
),
|
|
735
|
+
IS_WEB3 ? /* @__PURE__ */ jsx(Text, { nativeID: hintId, style: styles8.srOnly, testID: `${testID}-hint`, children: accessibilityHint }) : null,
|
|
691
736
|
isMenu && isOpen ? /* @__PURE__ */ jsx(
|
|
692
737
|
InlineMenu,
|
|
693
738
|
{
|