@dloizides/ui-layout 1.10.0 → 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,
@@ -210,30 +238,30 @@ var UpgradePrompt = ({
210
238
  style: [styles5.container, { borderColor: primary, backgroundColor: colors.surface }],
211
239
  testID: LAYOUT_TEST_IDS.upgradePrompt,
212
240
  children: [
213
- /* @__PURE__ */ jsx(Text, { style: [styles5.title, { color: colors.text }], children: t("settings.billing.upgradePrompt.title") }),
214
- /* @__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) }),
215
243
  /* @__PURE__ */ jsx(
216
244
  TouchableOpacity,
217
245
  {
218
- accessibilityHint: t("settings.billing.upgradePrompt.ctaHint"),
219
- accessibilityLabel: t("settings.billing.upgradePrompt.cta"),
246
+ accessibilityHint: t(LAYOUT_I18N.upgradePromptCtaHint),
247
+ accessibilityLabel: t(LAYOUT_I18N.upgradePromptCta),
220
248
  accessibilityRole: "button",
221
249
  style: [styles5.cta, { backgroundColor: primary }],
222
250
  testID: LAYOUT_TEST_IDS.upgradePromptCta,
223
251
  onPress: handleUpgradePress,
224
- 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) })
225
253
  }
226
254
  ),
227
255
  onDismiss ? /* @__PURE__ */ jsx(
228
256
  TouchableOpacity,
229
257
  {
230
- accessibilityHint: t("settings.billing.upgradePrompt.dismissHint"),
231
- accessibilityLabel: t("settings.billing.upgradePrompt.dismiss"),
258
+ accessibilityHint: t(LAYOUT_I18N.upgradePromptDismissHint),
259
+ accessibilityLabel: t(LAYOUT_I18N.upgradePromptDismiss),
232
260
  accessibilityRole: "button",
233
261
  style: styles5.dismiss,
234
262
  testID: LAYOUT_TEST_IDS.upgradePromptDismiss,
235
263
  onPress: onDismiss,
236
- 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) })
237
265
  }
238
266
  ) : null
239
267
  ]
@@ -331,13 +359,14 @@ function buildPortalPopoverStyle(rect, minWidth = 0) {
331
359
  function buildAnchorStackStyle(isMenuOpen) {
332
360
  return isMenuOpen ? { zIndex: ANCHOR_OPEN_Z_INDEX, elevation: MENU_ELEVATION } : null;
333
361
  }
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;
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;
341
370
  }
342
371
  var OPTION_BORDER_RADIUS = 4;
343
372
  var BODY_FONT_SIZE = 14;
@@ -372,7 +401,7 @@ var OptionRow = ({
372
401
  TouchableOpacity,
373
402
  {
374
403
  accessible: true,
375
- accessibilityHint: t("common.selectOptionHint"),
404
+ accessibilityHint: t(LAYOUT_I18N.selectOptionHint),
376
405
  accessibilityLabel: label,
377
406
  accessibilityRole: "button",
378
407
  "aria-selected": isSelected,
@@ -396,6 +425,33 @@ function readAnchorRect(containerRef) {
396
425
  const r = node.getBoundingClientRect();
397
426
  return { top: r.top, left: r.left, width: r.width, bottom: r.bottom };
398
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
+ }
399
455
  function observeLayout(node, onChange) {
400
456
  if (typeof ResizeObserver !== "function") return null;
401
457
  const observer = new ResizeObserver(onChange);
@@ -409,12 +465,15 @@ function useAnchorTracking(containerRef, onOutOfView) {
409
465
  if (!IS_WEB) return void 0;
410
466
  let frame = null;
411
467
  let isDisposed = false;
468
+ let hasMeasured = false;
412
469
  const apply = () => {
413
470
  frame = null;
414
471
  if (isDisposed) return;
415
472
  const next = readAnchorRect(containerRef);
416
473
  setRect(next);
417
- if (next !== null && isAnchorOutOfView(next, window.innerHeight, window.innerWidth)) onOutOfView();
474
+ const isHidden = next !== null && isAnchorHidden(next, readClipBounds(toDomNode(containerRef)), MIN_VISIBLE_PX);
475
+ if (hasMeasured && isHidden) onOutOfView();
476
+ hasMeasured = true;
418
477
  };
419
478
  const schedule = () => {
420
479
  if (frame !== null) return;
@@ -672,7 +731,7 @@ var ModalDropdown = ({
672
731
  useFocusTrap(dialogRef, isOpen && !isMenu);
673
732
  const selectedLabel = useMemo(() => {
674
733
  const found = options.find((opt) => opt.value === value);
675
- return found?.label ?? t("common.selectPlaceholder");
734
+ return found?.label ?? t(LAYOUT_I18N.selectPlaceholder);
676
735
  }, [options, value, t]);
677
736
  const handleToggle = useCallback(() => {
678
737
  setIsOpen((prev) => !prev);
@@ -752,8 +811,8 @@ var ModalDropdown = ({
752
811
  TouchableOpacity,
753
812
  {
754
813
  accessible: true,
755
- accessibilityHint: t("common.dismissDropdownHint"),
756
- accessibilityLabel: t("common.dismissDropdown"),
814
+ accessibilityHint: t(LAYOUT_I18N.dismissDropdownHint),
815
+ accessibilityLabel: t(LAYOUT_I18N.dismissDropdown),
757
816
  accessibilityRole: "button",
758
817
  activeOpacity: 1,
759
818
  style: StyleSheet.absoluteFill,
@@ -804,8 +863,8 @@ var ModalShell = ({
804
863
  () => [styles9.container, { backgroundColor: theme.colors.background }, contentStyle],
805
864
  [theme.colors.background, contentStyle]
806
865
  );
807
- const closeA11yLabel = t("quizTemplates.cancel");
808
- 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);
809
868
  return /* @__PURE__ */ jsx(
810
869
  Modal,
811
870
  {
@@ -822,11 +881,11 @@ var ModalShell = ({
822
881
  style: containerStyle,
823
882
  children: [
824
883
  /* @__PURE__ */ jsxs(View, { style: styles9.headerRow, children: [
825
- /* @__PURE__ */ jsx(Heading, { children: title ?? t("close") }),
884
+ /* @__PURE__ */ jsx(Heading, { children: title ?? t(LAYOUT_I18N.closeHeading) }),
826
885
  showClose ? /* @__PURE__ */ jsx(
827
886
  TouchableOpacity,
828
887
  {
829
- accessibilityHint: t("common.closeDialogHint"),
888
+ accessibilityHint: t(LAYOUT_I18N.closeDialogHint),
830
889
  accessibilityLabel: closeA11yLabel,
831
890
  accessibilityRole: "button",
832
891
  style: styles9.closeButton,
@@ -1060,7 +1119,7 @@ var AccordionItem = ({
1060
1119
  /* @__PURE__ */ jsxs(
1061
1120
  Pressable,
1062
1121
  {
1063
- accessibilityHint: accessibilityHint ?? t("common.accordionToggleHint"),
1122
+ accessibilityHint: accessibilityHint ?? t(LAYOUT_I18N.accordionToggleHint),
1064
1123
  accessibilityLabel: resolvedLabel,
1065
1124
  accessibilityRole: "button",
1066
1125
  accessibilityState: { expanded, disabled },
@@ -1119,6 +1178,6 @@ var AccordionItem = ({
1119
1178
  ] });
1120
1179
  };
1121
1180
 
1122
- 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 };
1123
1182
  //# sourceMappingURL=index.mjs.map
1124
1183
  //# sourceMappingURL=index.mjs.map