@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.d.ts CHANGED
@@ -281,5 +281,47 @@ declare const LAYOUT_TEST_IDS: {
281
281
  };
282
282
  /** Route the UpgradePrompt CTA navigates to by default (the apps' billing settings path). */
283
283
  declare const DEFAULT_BILLING_ROUTE = "/settings/billing";
284
+ /**
285
+ * Every translation key this package resolves through `t(...)` — the host app's i18n contract.
286
+ *
287
+ * WHY THIS EXISTS: the kit is deliberately fallback-free. The neutral default `t` returns the key
288
+ * itself, so a host that forgets a key does not silently show English — it shows the raw dotted
289
+ * name to users, or announces it to screen readers. Without a machine-readable manifest each
290
+ * portal had to hand-maintain its ui-layout key list, and hand-maintained lists rot: one app was
291
+ * found missing 26 kit keys (rendering raw names to users), another had `accordionToggleHint`
292
+ * undefined while `Accordion` was mounted, announcing the raw key to assistive tech.
293
+ *
294
+ * Bind a missing-key guard to this map (the same way apps already bind `TABLE_I18N` /
295
+ * `FILTERS_I18N` from `@dloizides/ui-tables`) and an upgrade can never drift unnoticed. Every
296
+ * `t(...)` call in this package references this map, so it cannot fall out of date.
297
+ */
298
+ declare const LAYOUT_I18N: {
299
+ /** Placeholder shown by `ModalDropdown` when no option matches the current value. */
300
+ readonly selectPlaceholder: "common.selectPlaceholder";
301
+ /** Accessible name + hint of the modal-variant dropdown's dismiss backdrop. */
302
+ readonly dismissDropdown: "common.dismissDropdown";
303
+ readonly dismissDropdownHint: "common.dismissDropdownHint";
304
+ /** Accessible hint on a single dropdown option row. */
305
+ readonly selectOptionHint: "common.selectOptionHint";
306
+ /** Default accessible hint on an `AccordionItem` header when the caller supplies none. */
307
+ readonly accordionToggleHint: "common.accordionToggleHint";
308
+ /** Default accessible hint on a `StatusBadge` when the caller supplies none. */
309
+ readonly statusBadgeHint: "common.statusBadgeHint";
310
+ /** `ModalShell`: accessible name of the dialog when its title is not a plain string. */
311
+ readonly dialog: "common.dialog";
312
+ /** `ModalShell`: accessible hint on the close button. */
313
+ readonly closeDialogHint: "common.closeDialogHint";
314
+ /** `ModalShell`: accessible name of the close button. */
315
+ readonly close: "quizTemplates.cancel";
316
+ /** `ModalShell`: heading fallback when no title is supplied. */
317
+ readonly closeHeading: "close";
318
+ readonly upgradePromptTitle: "settings.billing.upgradePrompt.title";
319
+ /** Body copy, parameterised: "…requires {{p1}}, you are on {{p2}}." */
320
+ readonly upgradePromptMessage: "settings.billing.upgradePrompt.message";
321
+ readonly upgradePromptCta: "settings.billing.upgradePrompt.cta";
322
+ readonly upgradePromptCtaHint: "settings.billing.upgradePrompt.ctaHint";
323
+ readonly upgradePromptDismiss: "settings.billing.upgradePrompt.dismiss";
324
+ readonly upgradePromptDismissHint: "settings.billing.upgradePrompt.dismissHint";
325
+ };
284
326
 
285
- export { Accordion, AccordionItem, type AccordionItemProps, type AccordionProps, type AccordionVariant, DEFAULT_BILLING_ROUTE, type DropdownOption, type DropdownTriggerState, DropdownVariant, Heading, type HeadingProps, LAYOUT_TEST_IDS, ModalDropdown, type ModalDropdownProps, ModalShell, type ModalShellProps, Section, type SectionProps, SegmentedControl, type SegmentedControlProps, type SegmentedOption, StatusBadge, type StatusBadgeProps, UpgradePrompt, type UpgradePromptProps, useFocusTrap };
327
+ export { Accordion, AccordionItem, type AccordionItemProps, type AccordionProps, type AccordionVariant, DEFAULT_BILLING_ROUTE, type DropdownOption, type DropdownTriggerState, DropdownVariant, Heading, type HeadingProps, LAYOUT_I18N, LAYOUT_TEST_IDS, ModalDropdown, type ModalDropdownProps, ModalShell, type ModalShellProps, Section, type SectionProps, SegmentedControl, type SegmentedControlProps, type SegmentedOption, StatusBadge, type StatusBadgeProps, UpgradePrompt, type UpgradePromptProps, useFocusTrap };
package/dist/index.js CHANGED
@@ -40,6 +40,34 @@ var LAYOUT_TEST_IDS = {
40
40
  accordion: "accordion"
41
41
  };
42
42
  var DEFAULT_BILLING_ROUTE = "/settings/billing";
43
+ var LAYOUT_I18N = {
44
+ /** Placeholder shown by `ModalDropdown` when no option matches the current value. */
45
+ selectPlaceholder: "common.selectPlaceholder",
46
+ /** Accessible name + hint of the modal-variant dropdown's dismiss backdrop. */
47
+ dismissDropdown: "common.dismissDropdown",
48
+ dismissDropdownHint: "common.dismissDropdownHint",
49
+ /** Accessible hint on a single dropdown option row. */
50
+ selectOptionHint: "common.selectOptionHint",
51
+ /** Default accessible hint on an `AccordionItem` header when the caller supplies none. */
52
+ accordionToggleHint: "common.accordionToggleHint",
53
+ /** Default accessible hint on a `StatusBadge` when the caller supplies none. */
54
+ statusBadgeHint: "common.statusBadgeHint",
55
+ /** `ModalShell`: accessible name of the dialog when its title is not a plain string. */
56
+ dialog: "common.dialog",
57
+ /** `ModalShell`: accessible hint on the close button. */
58
+ closeDialogHint: "common.closeDialogHint",
59
+ /** `ModalShell`: accessible name of the close button. */
60
+ close: "quizTemplates.cancel",
61
+ /** `ModalShell`: heading fallback when no title is supplied. */
62
+ closeHeading: "close",
63
+ upgradePromptTitle: "settings.billing.upgradePrompt.title",
64
+ /** Body copy, parameterised: "…requires {{p1}}, you are on {{p2}}." */
65
+ upgradePromptMessage: "settings.billing.upgradePrompt.message",
66
+ upgradePromptCta: "settings.billing.upgradePrompt.cta",
67
+ upgradePromptCtaHint: "settings.billing.upgradePrompt.ctaHint",
68
+ upgradePromptDismiss: "settings.billing.upgradePrompt.dismiss",
69
+ upgradePromptDismissHint: "settings.billing.upgradePrompt.dismissHint"
70
+ };
43
71
  var styles2 = reactNative.StyleSheet.create({
44
72
  heading: {
45
73
  fontWeight: "700",
@@ -84,7 +112,7 @@ var StatusBadge = ({
84
112
  return /* @__PURE__ */ jsxRuntime.jsx(
85
113
  reactNative.View,
86
114
  {
87
- accessibilityHint: accessibilityHint ?? t("common.statusBadgeHint"),
115
+ accessibilityHint: accessibilityHint ?? t(LAYOUT_I18N.statusBadgeHint),
88
116
  accessibilityLabel: accessibilityLabel ?? label,
89
117
  style: [styles3.badge, dynamicBadge],
90
118
  testID,
@@ -216,30 +244,30 @@ var UpgradePrompt = ({
216
244
  style: [styles5.container, { borderColor: primary, backgroundColor: colors.surface }],
217
245
  testID: LAYOUT_TEST_IDS.upgradePrompt,
218
246
  children: [
219
- /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles5.title, { color: colors.text }], children: t("settings.billing.upgradePrompt.title") }),
220
- /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles5.message, { color: colors.textSecondary }], children: t("settings.billing.upgradePrompt.message", requiredTier, currentTier) }),
247
+ /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles5.title, { color: colors.text }], children: t(LAYOUT_I18N.upgradePromptTitle) }),
248
+ /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles5.message, { color: colors.textSecondary }], children: t(LAYOUT_I18N.upgradePromptMessage, requiredTier, currentTier) }),
221
249
  /* @__PURE__ */ jsxRuntime.jsx(
222
250
  reactNative.TouchableOpacity,
223
251
  {
224
- accessibilityHint: t("settings.billing.upgradePrompt.ctaHint"),
225
- accessibilityLabel: t("settings.billing.upgradePrompt.cta"),
252
+ accessibilityHint: t(LAYOUT_I18N.upgradePromptCtaHint),
253
+ accessibilityLabel: t(LAYOUT_I18N.upgradePromptCta),
226
254
  accessibilityRole: "button",
227
255
  style: [styles5.cta, { backgroundColor: primary }],
228
256
  testID: LAYOUT_TEST_IDS.upgradePromptCta,
229
257
  onPress: handleUpgradePress,
230
- children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles5.ctaText, { color: colors.surface }], children: t("settings.billing.upgradePrompt.cta") })
258
+ children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles5.ctaText, { color: colors.surface }], children: t(LAYOUT_I18N.upgradePromptCta) })
231
259
  }
232
260
  ),
233
261
  onDismiss ? /* @__PURE__ */ jsxRuntime.jsx(
234
262
  reactNative.TouchableOpacity,
235
263
  {
236
- accessibilityHint: t("settings.billing.upgradePrompt.dismissHint"),
237
- accessibilityLabel: t("settings.billing.upgradePrompt.dismiss"),
264
+ accessibilityHint: t(LAYOUT_I18N.upgradePromptDismissHint),
265
+ accessibilityLabel: t(LAYOUT_I18N.upgradePromptDismiss),
238
266
  accessibilityRole: "button",
239
267
  style: styles5.dismiss,
240
268
  testID: LAYOUT_TEST_IDS.upgradePromptDismiss,
241
269
  onPress: onDismiss,
242
- children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles5.dismissText, { color: colors.textSecondary }], children: t("settings.billing.upgradePrompt.dismiss") })
270
+ children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles5.dismissText, { color: colors.textSecondary }], children: t(LAYOUT_I18N.upgradePromptDismiss) })
243
271
  }
244
272
  ) : null
245
273
  ]
@@ -337,13 +365,14 @@ function buildPortalPopoverStyle(rect, minWidth = 0) {
337
365
  function buildAnchorStackStyle(isMenuOpen) {
338
366
  return isMenuOpen ? { zIndex: ANCHOR_OPEN_Z_INDEX, elevation: MENU_ELEVATION } : null;
339
367
  }
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;
368
+ var MIN_VISIBLE_PX = 8;
369
+ function isAnchorHidden(rect, clip, minVisiblePx) {
370
+ const hasLayout = rect.width > 0 && rect.bottom > rect.top;
371
+ const hasClip = clip.bottom > clip.top && clip.right > clip.left;
372
+ if (!hasLayout || !hasClip) return false;
373
+ const visibleHeight = Math.min(rect.bottom, clip.bottom) - Math.max(rect.top, clip.top);
374
+ const visibleWidth = Math.min(rect.left + rect.width, clip.right) - Math.max(rect.left, clip.left);
375
+ return visibleHeight < minVisiblePx || visibleWidth < minVisiblePx;
347
376
  }
348
377
  var OPTION_BORDER_RADIUS = 4;
349
378
  var BODY_FONT_SIZE = 14;
@@ -378,7 +407,7 @@ var OptionRow = ({
378
407
  reactNative.TouchableOpacity,
379
408
  {
380
409
  accessible: true,
381
- accessibilityHint: t("common.selectOptionHint"),
410
+ accessibilityHint: t(LAYOUT_I18N.selectOptionHint),
382
411
  accessibilityLabel: label,
383
412
  accessibilityRole: "button",
384
413
  "aria-selected": isSelected,
@@ -402,6 +431,33 @@ function readAnchorRect(containerRef) {
402
431
  const r = node.getBoundingClientRect();
403
432
  return { top: r.top, left: r.left, width: r.width, bottom: r.bottom };
404
433
  }
434
+ function clipsAxis(overflow) {
435
+ return overflow !== "" && overflow !== "visible";
436
+ }
437
+ function clipToAncestor(bounds, el) {
438
+ const style = window.getComputedStyle(el);
439
+ const clipsY = clipsAxis(style.overflowY) || clipsAxis(style.overflow);
440
+ const clipsX = clipsAxis(style.overflowX) || clipsAxis(style.overflow);
441
+ if (!clipsY && !clipsX) return;
442
+ const r = el.getBoundingClientRect();
443
+ if (clipsY) {
444
+ bounds.top = Math.max(bounds.top, r.top);
445
+ bounds.bottom = Math.min(bounds.bottom, r.bottom);
446
+ }
447
+ if (clipsX) {
448
+ bounds.left = Math.max(bounds.left, r.left);
449
+ bounds.right = Math.min(bounds.right, r.right);
450
+ }
451
+ }
452
+ function readClipBounds(node) {
453
+ const bounds = { top: 0, left: 0, bottom: window.innerHeight, right: window.innerWidth };
454
+ let el = node?.parentElement ?? null;
455
+ while (el !== null && el !== document.body && el !== document.documentElement) {
456
+ clipToAncestor(bounds, el);
457
+ el = el.parentElement;
458
+ }
459
+ return bounds;
460
+ }
405
461
  function observeLayout(node, onChange) {
406
462
  if (typeof ResizeObserver !== "function") return null;
407
463
  const observer = new ResizeObserver(onChange);
@@ -415,12 +471,15 @@ function useAnchorTracking(containerRef, onOutOfView) {
415
471
  if (!IS_WEB) return void 0;
416
472
  let frame = null;
417
473
  let isDisposed = false;
474
+ let hasMeasured = false;
418
475
  const apply = () => {
419
476
  frame = null;
420
477
  if (isDisposed) return;
421
478
  const next = readAnchorRect(containerRef);
422
479
  setRect(next);
423
- if (next !== null && isAnchorOutOfView(next, window.innerHeight, window.innerWidth)) onOutOfView();
480
+ const isHidden = next !== null && isAnchorHidden(next, readClipBounds(toDomNode(containerRef)), MIN_VISIBLE_PX);
481
+ if (hasMeasured && isHidden) onOutOfView();
482
+ hasMeasured = true;
424
483
  };
425
484
  const schedule = () => {
426
485
  if (frame !== null) return;
@@ -678,7 +737,7 @@ var ModalDropdown = ({
678
737
  useFocusTrap(dialogRef, isOpen && !isMenu);
679
738
  const selectedLabel = React8.useMemo(() => {
680
739
  const found = options.find((opt) => opt.value === value);
681
- return found?.label ?? t("common.selectPlaceholder");
740
+ return found?.label ?? t(LAYOUT_I18N.selectPlaceholder);
682
741
  }, [options, value, t]);
683
742
  const handleToggle = React8.useCallback(() => {
684
743
  setIsOpen((prev) => !prev);
@@ -758,8 +817,8 @@ var ModalDropdown = ({
758
817
  reactNative.TouchableOpacity,
759
818
  {
760
819
  accessible: true,
761
- accessibilityHint: t("common.dismissDropdownHint"),
762
- accessibilityLabel: t("common.dismissDropdown"),
820
+ accessibilityHint: t(LAYOUT_I18N.dismissDropdownHint),
821
+ accessibilityLabel: t(LAYOUT_I18N.dismissDropdown),
763
822
  accessibilityRole: "button",
764
823
  activeOpacity: 1,
765
824
  style: reactNative.StyleSheet.absoluteFill,
@@ -810,8 +869,8 @@ var ModalShell = ({
810
869
  () => [styles9.container, { backgroundColor: theme.colors.background }, contentStyle],
811
870
  [theme.colors.background, contentStyle]
812
871
  );
813
- const closeA11yLabel = t("quizTemplates.cancel");
814
- const accessibleTitle = typeof title === "string" ? title : t("common.dialog");
872
+ const closeA11yLabel = t(LAYOUT_I18N.close);
873
+ const accessibleTitle = typeof title === "string" ? title : t(LAYOUT_I18N.dialog);
815
874
  return /* @__PURE__ */ jsxRuntime.jsx(
816
875
  reactNative.Modal,
817
876
  {
@@ -828,11 +887,11 @@ var ModalShell = ({
828
887
  style: containerStyle,
829
888
  children: [
830
889
  /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles9.headerRow, children: [
831
- /* @__PURE__ */ jsxRuntime.jsx(Heading, { children: title ?? t("close") }),
890
+ /* @__PURE__ */ jsxRuntime.jsx(Heading, { children: title ?? t(LAYOUT_I18N.closeHeading) }),
832
891
  showClose ? /* @__PURE__ */ jsxRuntime.jsx(
833
892
  reactNative.TouchableOpacity,
834
893
  {
835
- accessibilityHint: t("common.closeDialogHint"),
894
+ accessibilityHint: t(LAYOUT_I18N.closeDialogHint),
836
895
  accessibilityLabel: closeA11yLabel,
837
896
  accessibilityRole: "button",
838
897
  style: styles9.closeButton,
@@ -1066,7 +1125,7 @@ var AccordionItem = ({
1066
1125
  /* @__PURE__ */ jsxRuntime.jsxs(
1067
1126
  reactNative.Pressable,
1068
1127
  {
1069
- accessibilityHint: accessibilityHint ?? t("common.accordionToggleHint"),
1128
+ accessibilityHint: accessibilityHint ?? t(LAYOUT_I18N.accordionToggleHint),
1070
1129
  accessibilityLabel: resolvedLabel,
1071
1130
  accessibilityRole: "button",
1072
1131
  accessibilityState: { expanded, disabled },
@@ -1130,6 +1189,7 @@ exports.AccordionItem = AccordionItem;
1130
1189
  exports.DEFAULT_BILLING_ROUTE = DEFAULT_BILLING_ROUTE;
1131
1190
  exports.DropdownVariant = DropdownVariant;
1132
1191
  exports.Heading = Heading;
1192
+ exports.LAYOUT_I18N = LAYOUT_I18N;
1133
1193
  exports.LAYOUT_TEST_IDS = LAYOUT_TEST_IDS;
1134
1194
  exports.ModalDropdown = ModalDropdown;
1135
1195
  exports.ModalShell = ModalShell;