@dloizides/ui-layout 1.9.1 → 1.11.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/dist/index.mjs CHANGED
@@ -34,6 +34,34 @@ var LAYOUT_TEST_IDS = {
34
34
  accordion: "accordion"
35
35
  };
36
36
  var DEFAULT_BILLING_ROUTE = "/settings/billing";
37
+ var LAYOUT_I18N = {
38
+ /** Placeholder shown by `ModalDropdown` when no option matches the current value. */
39
+ selectPlaceholder: "common.selectPlaceholder",
40
+ /** Accessible name + hint of the modal-variant dropdown's dismiss backdrop. */
41
+ dismissDropdown: "common.dismissDropdown",
42
+ dismissDropdownHint: "common.dismissDropdownHint",
43
+ /** Accessible hint on a single dropdown option row. */
44
+ selectOptionHint: "common.selectOptionHint",
45
+ /** Default accessible hint on an `AccordionItem` header when the caller supplies none. */
46
+ accordionToggleHint: "common.accordionToggleHint",
47
+ /** Default accessible hint on a `StatusBadge` when the caller supplies none. */
48
+ statusBadgeHint: "common.statusBadgeHint",
49
+ /** `ModalShell`: accessible name of the dialog when its title is not a plain string. */
50
+ dialog: "common.dialog",
51
+ /** `ModalShell`: accessible hint on the close button. */
52
+ closeDialogHint: "common.closeDialogHint",
53
+ /** `ModalShell`: accessible name of the close button. */
54
+ close: "quizTemplates.cancel",
55
+ /** `ModalShell`: heading fallback when no title is supplied. */
56
+ closeHeading: "close",
57
+ upgradePromptTitle: "settings.billing.upgradePrompt.title",
58
+ /** Body copy, parameterised: "…requires {{p1}}, you are on {{p2}}." */
59
+ upgradePromptMessage: "settings.billing.upgradePrompt.message",
60
+ upgradePromptCta: "settings.billing.upgradePrompt.cta",
61
+ upgradePromptCtaHint: "settings.billing.upgradePrompt.ctaHint",
62
+ upgradePromptDismiss: "settings.billing.upgradePrompt.dismiss",
63
+ upgradePromptDismissHint: "settings.billing.upgradePrompt.dismissHint"
64
+ };
37
65
  var styles2 = StyleSheet.create({
38
66
  heading: {
39
67
  fontWeight: "700",
@@ -78,7 +106,7 @@ var StatusBadge = ({
78
106
  return /* @__PURE__ */ jsx(
79
107
  View,
80
108
  {
81
- accessibilityHint: accessibilityHint ?? t("common.statusBadgeHint"),
109
+ accessibilityHint: accessibilityHint ?? t(LAYOUT_I18N.statusBadgeHint),
82
110
  accessibilityLabel: accessibilityLabel ?? label,
83
111
  style: [styles3.badge, dynamicBadge],
84
112
  testID,
@@ -94,10 +122,7 @@ var SEGMENT_PAD_V = 7;
94
122
  var SEGMENT_FONT = 14;
95
123
  var SEGMENT_WEIGHT = "600";
96
124
  var BORDER_WIDTH = 1;
97
- var SHADOW_COLOR = "#141e32";
98
- var SHADOW_OPACITY = 0.1;
99
- var SHADOW_RADIUS = 3;
100
- var SHADOW_OFFSET = { width: 0, height: 1 };
125
+ var SEGMENT_BOX_SHADOW = "0px 1px 3px rgba(20, 30, 50, 0.1)";
101
126
  var SHADOW_ELEVATION = 2;
102
127
  var TRANSPARENT = "transparent";
103
128
  var styles4 = StyleSheet.create({
@@ -116,10 +141,7 @@ var styles4 = StyleSheet.create({
116
141
  borderRadius: SEGMENT_RADIUS
117
142
  },
118
143
  segmentSelected: {
119
- shadowColor: SHADOW_COLOR,
120
- shadowOpacity: SHADOW_OPACITY,
121
- shadowRadius: SHADOW_RADIUS,
122
- shadowOffset: SHADOW_OFFSET,
144
+ boxShadow: SEGMENT_BOX_SHADOW,
123
145
  elevation: SHADOW_ELEVATION
124
146
  },
125
147
  label: {
@@ -216,30 +238,30 @@ var UpgradePrompt = ({
216
238
  style: [styles5.container, { borderColor: primary, backgroundColor: colors.surface }],
217
239
  testID: LAYOUT_TEST_IDS.upgradePrompt,
218
240
  children: [
219
- /* @__PURE__ */ jsx(Text, { style: [styles5.title, { color: colors.text }], children: t("settings.billing.upgradePrompt.title") }),
220
- /* @__PURE__ */ jsx(Text, { style: [styles5.message, { color: colors.textSecondary }], children: t("settings.billing.upgradePrompt.message", requiredTier, currentTier) }),
241
+ /* @__PURE__ */ jsx(Text, { style: [styles5.title, { color: colors.text }], children: t(LAYOUT_I18N.upgradePromptTitle) }),
242
+ /* @__PURE__ */ jsx(Text, { style: [styles5.message, { color: colors.textSecondary }], children: t(LAYOUT_I18N.upgradePromptMessage, requiredTier, currentTier) }),
221
243
  /* @__PURE__ */ jsx(
222
244
  TouchableOpacity,
223
245
  {
224
- accessibilityHint: t("settings.billing.upgradePrompt.ctaHint"),
225
- accessibilityLabel: t("settings.billing.upgradePrompt.cta"),
246
+ accessibilityHint: t(LAYOUT_I18N.upgradePromptCtaHint),
247
+ accessibilityLabel: t(LAYOUT_I18N.upgradePromptCta),
226
248
  accessibilityRole: "button",
227
249
  style: [styles5.cta, { backgroundColor: primary }],
228
250
  testID: LAYOUT_TEST_IDS.upgradePromptCta,
229
251
  onPress: handleUpgradePress,
230
- children: /* @__PURE__ */ jsx(Text, { style: [styles5.ctaText, { color: colors.surface }], children: t("settings.billing.upgradePrompt.cta") })
252
+ children: /* @__PURE__ */ jsx(Text, { style: [styles5.ctaText, { color: colors.surface }], children: t(LAYOUT_I18N.upgradePromptCta) })
231
253
  }
232
254
  ),
233
255
  onDismiss ? /* @__PURE__ */ jsx(
234
256
  TouchableOpacity,
235
257
  {
236
- accessibilityHint: t("settings.billing.upgradePrompt.dismissHint"),
237
- accessibilityLabel: t("settings.billing.upgradePrompt.dismiss"),
258
+ accessibilityHint: t(LAYOUT_I18N.upgradePromptDismissHint),
259
+ accessibilityLabel: t(LAYOUT_I18N.upgradePromptDismiss),
238
260
  accessibilityRole: "button",
239
261
  style: styles5.dismiss,
240
262
  testID: LAYOUT_TEST_IDS.upgradePromptDismiss,
241
263
  onPress: onDismiss,
242
- children: /* @__PURE__ */ jsx(Text, { style: [styles5.dismissText, { color: colors.textSecondary }], children: t("settings.billing.upgradePrompt.dismiss") })
264
+ children: /* @__PURE__ */ jsx(Text, { style: [styles5.dismissText, { color: colors.textSecondary }], children: t(LAYOUT_I18N.upgradePromptDismiss) })
243
265
  }
244
266
  ) : null
245
267
  ]
@@ -337,6 +359,15 @@ function buildPortalPopoverStyle(rect, minWidth = 0) {
337
359
  function buildAnchorStackStyle(isMenuOpen) {
338
360
  return isMenuOpen ? { zIndex: ANCHOR_OPEN_Z_INDEX, elevation: MENU_ELEVATION } : null;
339
361
  }
362
+ var MIN_VISIBLE_PX = 8;
363
+ function isAnchorHidden(rect, clip, minVisiblePx) {
364
+ const hasLayout = rect.width > 0 && rect.bottom > rect.top;
365
+ const hasClip = clip.bottom > clip.top && clip.right > clip.left;
366
+ if (!hasLayout || !hasClip) return false;
367
+ const visibleHeight = Math.min(rect.bottom, clip.bottom) - Math.max(rect.top, clip.top);
368
+ const visibleWidth = Math.min(rect.left + rect.width, clip.right) - Math.max(rect.left, clip.left);
369
+ return visibleHeight < minVisiblePx || visibleWidth < minVisiblePx;
370
+ }
340
371
  var OPTION_BORDER_RADIUS = 4;
341
372
  var BODY_FONT_SIZE = 14;
342
373
  var SELECTED_FONT_WEIGHT = "600";
@@ -370,7 +401,7 @@ var OptionRow = ({
370
401
  TouchableOpacity,
371
402
  {
372
403
  accessible: true,
373
- accessibilityHint: t("common.selectOptionHint"),
404
+ accessibilityHint: t(LAYOUT_I18N.selectOptionHint),
374
405
  accessibilityLabel: label,
375
406
  accessibilityRole: "button",
376
407
  "aria-selected": isSelected,
@@ -381,6 +412,87 @@ var OptionRow = ({
381
412
  }
382
413
  );
383
414
  };
415
+ var IS_WEB = Platform.OS === "web";
416
+ function toDomNode(containerRef) {
417
+ const node = containerRef.current;
418
+ if (node === null || typeof node.getBoundingClientRect !== "function") return null;
419
+ return node;
420
+ }
421
+ function readAnchorRect(containerRef) {
422
+ if (!IS_WEB) return null;
423
+ const node = toDomNode(containerRef);
424
+ if (node === null) return null;
425
+ const r = node.getBoundingClientRect();
426
+ return { top: r.top, left: r.left, width: r.width, bottom: r.bottom };
427
+ }
428
+ function clipsAxis(overflow) {
429
+ return overflow !== "" && overflow !== "visible";
430
+ }
431
+ function clipToAncestor(bounds, el) {
432
+ const style = window.getComputedStyle(el);
433
+ const clipsY = clipsAxis(style.overflowY) || clipsAxis(style.overflow);
434
+ const clipsX = clipsAxis(style.overflowX) || clipsAxis(style.overflow);
435
+ if (!clipsY && !clipsX) return;
436
+ const r = el.getBoundingClientRect();
437
+ if (clipsY) {
438
+ bounds.top = Math.max(bounds.top, r.top);
439
+ bounds.bottom = Math.min(bounds.bottom, r.bottom);
440
+ }
441
+ if (clipsX) {
442
+ bounds.left = Math.max(bounds.left, r.left);
443
+ bounds.right = Math.min(bounds.right, r.right);
444
+ }
445
+ }
446
+ function readClipBounds(node) {
447
+ const bounds = { top: 0, left: 0, bottom: window.innerHeight, right: window.innerWidth };
448
+ let el = node?.parentElement ?? null;
449
+ while (el !== null && el !== document.body && el !== document.documentElement) {
450
+ clipToAncestor(bounds, el);
451
+ el = el.parentElement;
452
+ }
453
+ return bounds;
454
+ }
455
+ function observeLayout(node, onChange) {
456
+ if (typeof ResizeObserver !== "function") return null;
457
+ const observer = new ResizeObserver(onChange);
458
+ if (node !== null) observer.observe(node);
459
+ observer.observe(document.body);
460
+ return observer;
461
+ }
462
+ function useAnchorTracking(containerRef, onOutOfView) {
463
+ const [rect, setRect] = useState(() => readAnchorRect(containerRef));
464
+ useLayoutEffect(() => {
465
+ if (!IS_WEB) return void 0;
466
+ let frame = null;
467
+ let isDisposed = false;
468
+ let hasMeasured = false;
469
+ const apply = () => {
470
+ frame = null;
471
+ if (isDisposed) return;
472
+ const next = readAnchorRect(containerRef);
473
+ setRect(next);
474
+ const isHidden = next !== null && isAnchorHidden(next, readClipBounds(toDomNode(containerRef)), MIN_VISIBLE_PX);
475
+ if (hasMeasured && isHidden) onOutOfView();
476
+ hasMeasured = true;
477
+ };
478
+ const schedule = () => {
479
+ if (frame !== null) return;
480
+ frame = window.requestAnimationFrame(apply);
481
+ };
482
+ apply();
483
+ document.addEventListener("scroll", schedule, true);
484
+ window.addEventListener("resize", schedule);
485
+ const observer = observeLayout(toDomNode(containerRef), schedule);
486
+ return () => {
487
+ isDisposed = true;
488
+ if (frame !== null) window.cancelAnimationFrame(frame);
489
+ document.removeEventListener("scroll", schedule, true);
490
+ window.removeEventListener("resize", schedule);
491
+ if (observer !== null) observer.disconnect();
492
+ };
493
+ }, [containerRef, onOutOfView]);
494
+ return rect;
495
+ }
384
496
  function refContains(ref, target) {
385
497
  if (ref === void 0) return false;
386
498
  const node = ref.current;
@@ -445,7 +557,7 @@ function useMenuKeyboard(params) {
445
557
  };
446
558
  }, [containerRef, menuRef, enabled, onClose, params]);
447
559
  }
448
- var IS_WEB = Platform.OS === "web";
560
+ var IS_WEB2 = Platform.OS === "web";
449
561
  var BORDER_RADIUS2 = 8;
450
562
  var BORDER_WIDTH3 = 1;
451
563
  var MENU_PADDING2 = 4;
@@ -466,30 +578,6 @@ var styles7 = StyleSheet.create({
466
578
  elevation: MENU_ELEVATION
467
579
  }
468
580
  });
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
581
  var InlineMenu = ({
494
582
  testID,
495
583
  accessibilityLabel,
@@ -504,7 +592,7 @@ var InlineMenu = ({
504
592
  const { theme } = useUi();
505
593
  const { colors } = theme;
506
594
  const menuRef = useRef(null);
507
- const rect = useAnchorRect(containerRef);
595
+ const rect = useAnchorTracking(containerRef, onClose);
508
596
  const selectedIndex = useMemo(
509
597
  () => Math.max(0, options.findIndex((opt) => opt.value === value)),
510
598
  [options, value]
@@ -534,7 +622,7 @@ var InlineMenu = ({
534
622
  });
535
623
  const popoverStyle = useMemo(() => {
536
624
  const themed = { borderColor: colors.border, backgroundColor: colors.surface };
537
- if (IS_WEB)
625
+ if (IS_WEB2)
538
626
  return [
539
627
  buildPortalPopoverStyle(rect ?? { left: 0, width: 0, bottom: 0 }, menuMinWidth),
540
628
  themed
@@ -562,7 +650,7 @@ var InlineMenu = ({
562
650
  )) })
563
651
  }
564
652
  );
565
- if (IS_WEB) return createPortal(menu, document.body);
653
+ if (IS_WEB2) return createPortal(menu, document.body);
566
654
  return menu;
567
655
  };
568
656
  var MENU_BREAKPOINT = 768;
@@ -576,6 +664,7 @@ function useResolvedDropdownVariant(explicit) {
576
664
  const { width } = useWindowDimensions();
577
665
  return resolveDropdownVariant(explicit, width, Platform.OS);
578
666
  }
667
+ var IS_WEB3 = Platform.OS === "web";
579
668
  var BORDER_RADIUS3 = 8;
580
669
  var BORDER_WIDTH4 = 1;
581
670
  var BODY_FONT_SIZE2 = 14;
@@ -584,8 +673,21 @@ var MODAL_MIN_WIDTH = 200;
584
673
  var MODAL_MAX_HEIGHT = 300;
585
674
  var CONTAINER_PADDING_H = 12;
586
675
  var CONTAINER_PADDING_V = 10;
676
+ var SR_ONLY_SIZE = 1;
677
+ var SR_ONLY_OFFSET = -1;
678
+ function buildHintProps(hint, hintId) {
679
+ return IS_WEB3 ? { "aria-describedby": hintId } : { accessibilityHint: hint };
680
+ }
587
681
  var styles8 = StyleSheet.create({
588
682
  anchor: { position: "relative" },
683
+ srOnly: {
684
+ position: "absolute",
685
+ width: SR_ONLY_SIZE,
686
+ height: SR_ONLY_SIZE,
687
+ margin: SR_ONLY_OFFSET,
688
+ padding: 0,
689
+ overflow: "hidden"
690
+ },
589
691
  container: {
590
692
  borderWidth: BORDER_WIDTH4,
591
693
  borderRadius: BORDER_RADIUS3,
@@ -623,12 +725,13 @@ var ModalDropdown = ({
623
725
  const resolvedVariant = useResolvedDropdownVariant(variant);
624
726
  const isMenu = resolvedVariant === "menu" /* Menu */;
625
727
  const [isOpen, setIsOpen] = useState(false);
728
+ const hintId = `${testID}-hint`;
626
729
  const anchorRef = useRef(null);
627
730
  const dialogRef = useRef(null);
628
731
  useFocusTrap(dialogRef, isOpen && !isMenu);
629
732
  const selectedLabel = useMemo(() => {
630
733
  const found = options.find((opt) => opt.value === value);
631
- return found?.label ?? t("common.selectPlaceholder");
734
+ return found?.label ?? t(LAYOUT_I18N.selectPlaceholder);
632
735
  }, [options, value, t]);
633
736
  const handleToggle = useCallback(() => {
634
737
  setIsOpen((prev) => !prev);
@@ -677,7 +780,7 @@ var ModalDropdown = ({
677
780
  TouchableOpacity,
678
781
  {
679
782
  accessible: true,
680
- accessibilityHint,
783
+ ...buildHintProps(accessibilityHint, hintId),
681
784
  accessibilityLabel,
682
785
  accessibilityRole: "button",
683
786
  accessibilityState: { expanded: isOpen },
@@ -688,6 +791,7 @@ var ModalDropdown = ({
688
791
  children: renderTrigger !== void 0 ? renderTrigger({ label: selectedLabel, isOpen }) : /* @__PURE__ */ jsx(Text, { style: [styles8.selectedText, { color: colors.text }], children: selectedLabel })
689
792
  }
690
793
  ),
794
+ IS_WEB3 ? /* @__PURE__ */ jsx(Text, { nativeID: hintId, style: styles8.srOnly, testID: `${testID}-hint`, children: accessibilityHint }) : null,
691
795
  isMenu && isOpen ? /* @__PURE__ */ jsx(
692
796
  InlineMenu,
693
797
  {
@@ -707,8 +811,8 @@ var ModalDropdown = ({
707
811
  TouchableOpacity,
708
812
  {
709
813
  accessible: true,
710
- accessibilityHint: t("common.dismissDropdownHint"),
711
- accessibilityLabel: t("common.dismissDropdown"),
814
+ accessibilityHint: t(LAYOUT_I18N.dismissDropdownHint),
815
+ accessibilityLabel: t(LAYOUT_I18N.dismissDropdown),
712
816
  accessibilityRole: "button",
713
817
  activeOpacity: 1,
714
818
  style: StyleSheet.absoluteFill,
@@ -759,8 +863,8 @@ var ModalShell = ({
759
863
  () => [styles9.container, { backgroundColor: theme.colors.background }, contentStyle],
760
864
  [theme.colors.background, contentStyle]
761
865
  );
762
- const closeA11yLabel = t("quizTemplates.cancel");
763
- const accessibleTitle = typeof title === "string" ? title : t("common.dialog");
866
+ const closeA11yLabel = t(LAYOUT_I18N.close);
867
+ const accessibleTitle = typeof title === "string" ? title : t(LAYOUT_I18N.dialog);
764
868
  return /* @__PURE__ */ jsx(
765
869
  Modal,
766
870
  {
@@ -777,11 +881,11 @@ var ModalShell = ({
777
881
  style: containerStyle,
778
882
  children: [
779
883
  /* @__PURE__ */ jsxs(View, { style: styles9.headerRow, children: [
780
- /* @__PURE__ */ jsx(Heading, { children: title ?? t("close") }),
884
+ /* @__PURE__ */ jsx(Heading, { children: title ?? t(LAYOUT_I18N.closeHeading) }),
781
885
  showClose ? /* @__PURE__ */ jsx(
782
886
  TouchableOpacity,
783
887
  {
784
- accessibilityHint: t("common.closeDialogHint"),
888
+ accessibilityHint: t(LAYOUT_I18N.closeDialogHint),
785
889
  accessibilityLabel: closeA11yLabel,
786
890
  accessibilityRole: "button",
787
891
  style: styles9.closeButton,
@@ -1015,7 +1119,7 @@ var AccordionItem = ({
1015
1119
  /* @__PURE__ */ jsxs(
1016
1120
  Pressable,
1017
1121
  {
1018
- accessibilityHint: accessibilityHint ?? t("common.accordionToggleHint"),
1122
+ accessibilityHint: accessibilityHint ?? t(LAYOUT_I18N.accordionToggleHint),
1019
1123
  accessibilityLabel: resolvedLabel,
1020
1124
  accessibilityRole: "button",
1021
1125
  accessibilityState: { expanded, disabled },
@@ -1074,6 +1178,6 @@ var AccordionItem = ({
1074
1178
  ] });
1075
1179
  };
1076
1180
 
1077
- export { Accordion, AccordionItem, DEFAULT_BILLING_ROUTE, DropdownVariant, Heading, LAYOUT_TEST_IDS, ModalDropdown, ModalShell, Section, SegmentedControl, StatusBadge, UpgradePrompt, useFocusTrap };
1181
+ export { Accordion, AccordionItem, DEFAULT_BILLING_ROUTE, DropdownVariant, Heading, LAYOUT_I18N, LAYOUT_TEST_IDS, ModalDropdown, ModalShell, Section, SegmentedControl, StatusBadge, UpgradePrompt, useFocusTrap };
1078
1182
  //# sourceMappingURL=index.mjs.map
1079
1183
  //# sourceMappingURL=index.mjs.map