@dloizides/ui-layout 1.22.1 → 1.24.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 CHANGED
@@ -1,5 +1,62 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.24.0
4
+
5
+ **The inline dropdown popover now stays inside the viewport — a floored menu can no longer spill off the right edge.**
6
+
7
+ `buildPortalPopoverStyle` positioned the fixed popover at `left: rect.left` with no horizontal
8
+ clamp. That was fine while the menu matched its trigger's width, but a COMPACT trigger with a
9
+ `menuMinWidth` floor (e.g. the `@dloizides/ui-nav` "More ▾" overflow menu, whose trigger sits near
10
+ the right of the bar) opens a menu WIDER than its trigger — which then extended past the right edge
11
+ of the viewport and clipped its lower/right content ("some items get hidden").
12
+
13
+ - **`buildPortalPopoverStyle(rect, minWidth, viewportWidth?)`** takes an optional `viewportWidth`.
14
+ When given, the popover's `left` is clamped so its right edge clears `MENU_VIEWPORT_MARGIN` (8px) —
15
+ sliding it left, right-aligning it to the trigger in the limit — while never crossing the left
16
+ margin. `viewportWidth = 0` (the default, and the native/pure path) keeps the exact prior
17
+ trigger-anchored behaviour, so every existing caller is unchanged.
18
+ - **`InlineMenu`** passes `window.innerWidth` on web (re-read whenever the tracked trigger rect
19
+ re-measures on scroll/resize); native is untouched.
20
+ - New export `MENU_VIEWPORT_MARGIN`.
21
+
22
+ ## 1.23.0
23
+
24
+ **Modals, the dropdown popover and the accordion body now ANIMATE on web — adopts `@dloizides/ui-motion`.**
25
+
26
+ On react-native-web, RN's `Modal animationType` and `LayoutAnimation` are effectively no-ops, so
27
+ `Modal`, `ModalShell`, the `ModalDropdown` popover and the `Accordion` body all SNAPPED open/closed
28
+ on the web build (all 7 portals). This wires those surfaces to `@dloizides/ui-motion`, which drives
29
+ enter/exit with RN `Animated` (works on web AND native) and collapses every animation to instant
30
+ under the OS "reduce motion" preference. **No public APIs changed** — every prop, testID and a11y
31
+ attribute is identical; this is a purely visual upgrade.
32
+
33
+ - **`Modal`** — the backdrop now **fades** (opacity) and the panel **fades + scales in** (0.96→1) on
34
+ open, reversing on close, via `useEnterExit`. The RN `Modal` host is kept **mounted through the
35
+ exit** (driven by `useEnterExit`'s `mounted` flag, not `visible`) so the close animation can play
36
+ instead of the host unmounting instantly — the trick that made `animationType` a no-op on web. The
37
+ scrim moved to its own animated layer behind the tap-catcher; close-on-backdrop, Escape, focus
38
+ trap, scroll-lock and every testID are unchanged.
39
+ - **`ModalShell`** — the full-screen sheet **fades + scales in** on open (replacing the native-only
40
+ `animationType="slide"`), mounted through the exit the same way.
41
+ - **`ModalDropdown`** — the popover (the inline anchored menu on web-desktop, the centered modal on
42
+ mobile/native) **fades + scales in** from the anchor on open (`transformOrigin: top`), with a snappy
43
+ ~120ms curve so the close reads as near-instant. `useAnchorTracking`, the web portal, keyboard nav
44
+ and outside-click detection are untouched (the fade/scale rides an INNER wrapper so the popover's
45
+ own DOM node — which the outside-click/portal logic depends on — is unchanged).
46
+ - **`Accordion`** — the item body now renders inside ui-motion's **`<Collapse>`** (measured, animated
47
+ height) instead of RN `LayoutAnimation`, so the body animates on web too. The chevron rotation is
48
+ unchanged. Behaviour note: `<Collapse>` keeps the body **mounted at all times** (clipped to height 0
49
+ when closed) so `aria-controls` always resolves and screen readers reach the content — the open
50
+ state is conveyed by the header's `aria-expanded` (the value handed to `<Collapse open>`). The
51
+ internal `accordionAnimation.ts` (`LayoutAnimation` helper) was removed.
52
+ - **New dependency `@dloizides/ui-motion` (`^1.0.1`)** — the shared RN/RN-web motion kit
53
+ (`useEnterExit`, `Collapse`, reduced-motion-aware).
54
+
55
+ Additive and back-compatible for consumers. Covered by the existing `Modal`, `ModalShell`,
56
+ `ModalDropdown` (web + native) and `Accordion` suites; the accordion tests now assert open state via
57
+ `aria-expanded`/the `Collapse` container rather than body-text presence (the body is always mounted).
58
+ The Jest env is pinned to reduced-motion so enter/exit resolve synchronously in tests.
59
+
3
60
  ## 1.22.0
4
61
 
5
62
  **Two shared modal primitives: a themed centered `Modal` dialog and a `ConfirmDialog` popup.**
package/dist/index.js CHANGED
@@ -5,6 +5,7 @@ var reactNative = require('react-native');
5
5
  var uiFeedback = require('@dloizides/ui-feedback');
6
6
  var jsxRuntime = require('react/jsx-runtime');
7
7
  var a11y = require('@dloizides/a11y');
8
+ var uiMotion = require('@dloizides/ui-motion');
8
9
  var reactDom = require('react-dom');
9
10
  var uiIcons = require('@dloizides/ui-icons');
10
11
  var uiButtons = require('@dloizides/ui-buttons');
@@ -327,14 +328,21 @@ var BORDER_RADIUS = 8;
327
328
  var BORDER_WIDTH2 = 1;
328
329
  var MENU_PADDING = 4;
329
330
  var MENU_BOX_SHADOW = "0px 2px 8px rgba(0, 0, 0, 0.15)";
330
- function buildPortalPopoverStyle(rect, minWidth = 0) {
331
+ var MENU_VIEWPORT_MARGIN = 8;
332
+ function buildPortalPopoverStyle(rect, minWidth = 0, viewportWidth = 0) {
333
+ const width = Math.max(rect.width, minWidth);
334
+ let left = rect.left;
335
+ if (viewportWidth > 0) {
336
+ const maxLeft = viewportWidth - width - MENU_VIEWPORT_MARGIN;
337
+ left = Math.max(MENU_VIEWPORT_MARGIN, Math.min(rect.left, maxLeft));
338
+ }
331
339
  return {
332
340
  // RN's ViewStyle union omits 'fixed', but react-native-web honours it at runtime.
333
341
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- web-only position value
334
342
  position: "fixed",
335
343
  top: rect.bottom + MENU_TOP_GAP,
336
- left: rect.left,
337
- width: Math.max(rect.width, minWidth),
344
+ left,
345
+ width,
338
346
  zIndex: MENU_Z_INDEX,
339
347
  borderWidth: BORDER_WIDTH2,
340
348
  borderRadius: BORDER_RADIUS,
@@ -564,7 +572,11 @@ var styles6 = reactNative.StyleSheet.create({
564
572
  maxHeight: MENU_MAX_HEIGHT,
565
573
  boxShadow: MENU_BOX_SHADOW,
566
574
  elevation: MENU_ELEVATION
567
- }
575
+ },
576
+ // The enter/exit fade+scale lives on an INNER wrapper so the outer popover keeps its raw DOM
577
+ // node (the `menuRef` outside-click / keyboard logic and the web portal target depend on it).
578
+ // `transformOrigin: 'top'` makes the scale grow downward FROM the anchor rather than the centre.
579
+ animated: { transformOrigin: "top" }
568
580
  });
569
581
  var InlineMenu = ({
570
582
  testID,
@@ -574,6 +586,7 @@ var InlineMenu = ({
574
586
  containerRef,
575
587
  optionTestID,
576
588
  menuMinWidth = 0,
589
+ animatedStyle,
577
590
  onSelect,
578
591
  onClose
579
592
  }) => {
@@ -610,11 +623,13 @@ var InlineMenu = ({
610
623
  });
611
624
  const popoverStyle = React10.useMemo(() => {
612
625
  const themed = { borderColor: colors.border, backgroundColor: colors.surface };
613
- if (IS_WEB2)
626
+ if (IS_WEB2) {
627
+ const viewportWidth = typeof window !== "undefined" ? window.innerWidth : 0;
614
628
  return [
615
- buildPortalPopoverStyle(rect ?? { left: 0, width: 0, bottom: 0 }, menuMinWidth),
629
+ buildPortalPopoverStyle(rect ?? { left: 0, width: 0, bottom: 0 }, menuMinWidth, viewportWidth),
616
630
  themed
617
631
  ];
632
+ }
618
633
  return [styles6.popover, { minWidth: menuMinWidth }, themed];
619
634
  }, [colors.border, colors.surface, menuMinWidth, rect]);
620
635
  const menu = /* @__PURE__ */ jsxRuntime.jsx(
@@ -625,7 +640,7 @@ var InlineMenu = ({
625
640
  "aria-label": accessibilityLabel,
626
641
  style: popoverStyle,
627
642
  testID: `${testID}-menu`,
628
- children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.ScrollView, { keyboardShouldPersistTaps: "handled", children: options.map((option, index) => /* @__PURE__ */ jsxRuntime.jsx(
643
+ children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Animated.View, { style: [styles6.animated, animatedStyle], children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.ScrollView, { keyboardShouldPersistTaps: "handled", children: options.map((option, index) => /* @__PURE__ */ jsxRuntime.jsx(
629
644
  OptionRow,
630
645
  {
631
646
  isHighlighted: index === highlightedIndex,
@@ -635,7 +650,7 @@ var InlineMenu = ({
635
650
  onSelect: () => onSelect(option.value)
636
651
  },
637
652
  String(option.value)
638
- )) })
653
+ )) }) })
639
654
  }
640
655
  );
641
656
  if (IS_WEB2) return reactDom.createPortal(menu, document.body);
@@ -668,6 +683,8 @@ var HAMBURGER_GLYPH = "\u2630";
668
683
  var HAMBURGER_FONT_SIZE = 18;
669
684
  var CARET_OPEN_ROTATION = "180deg";
670
685
  var CARET_CLOSED_ROTATION = "0deg";
686
+ var POPOVER_ENTER_SCALE = 0.96;
687
+ var POPOVER_MOTION_MS = 120;
671
688
  var styles7 = reactNative.StyleSheet.create({
672
689
  anchor: { position: "relative" },
673
690
  container: {
@@ -747,6 +764,16 @@ var ModalDropdown = ({
747
764
  const anchorRef = React10.useRef(null);
748
765
  const dialogRef = React10.useRef(null);
749
766
  useFocusTrap(dialogRef, isOpen && !isMenu);
767
+ const menuAnim = uiMotion.useEnterExit({
768
+ visible: isMenu && isOpen,
769
+ fromScale: POPOVER_ENTER_SCALE,
770
+ duration: POPOVER_MOTION_MS
771
+ });
772
+ const modalAnim = uiMotion.useEnterExit({
773
+ visible: !isMenu && isOpen,
774
+ fromScale: POPOVER_ENTER_SCALE,
775
+ duration: POPOVER_MOTION_MS
776
+ });
750
777
  const selectedLabel = React10.useMemo(() => {
751
778
  const found = options.find((opt) => opt.value === value);
752
779
  return found?.label ?? t(LAYOUT_I18N.selectPlaceholder);
@@ -821,10 +848,11 @@ var ModalDropdown = ({
821
848
  ] }) : /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles7.selectedText, { color: colors.text }], children: selectedLabel }),
822
849
  hintNode
823
850
  ] }),
824
- isMenu && isOpen ? /* @__PURE__ */ jsxRuntime.jsx(
851
+ isMenu && menuAnim.mounted ? /* @__PURE__ */ jsxRuntime.jsx(
825
852
  InlineMenu,
826
853
  {
827
854
  accessibilityLabel,
855
+ animatedStyle: menuAnim.style,
828
856
  containerRef: anchorRef,
829
857
  menuMinWidth,
830
858
  optionTestID: optionTestIDFor,
@@ -835,7 +863,7 @@ var ModalDropdown = ({
835
863
  onSelect: handleSelect
836
864
  }
837
865
  ) : null,
838
- !isMenu ? /* @__PURE__ */ jsxRuntime.jsx(reactNative.Modal, { transparent: true, animationType: "fade", visible: isOpen, onRequestClose: handleClose, children: /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles7.modalOverlay, children: [
866
+ !isMenu ? /* @__PURE__ */ jsxRuntime.jsx(reactNative.Modal, { transparent: true, visible: modalAnim.mounted, onRequestClose: handleClose, children: /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles7.modalOverlay, children: [
839
867
  /* @__PURE__ */ jsxRuntime.jsx(
840
868
  reactNative.TouchableOpacity,
841
869
  {
@@ -850,13 +878,13 @@ var ModalDropdown = ({
850
878
  }
851
879
  ),
852
880
  /* @__PURE__ */ jsxRuntime.jsx(
853
- reactNative.View,
881
+ reactNative.Animated.View,
854
882
  {
855
883
  ref: dialogRef,
856
884
  accessibilityViewIsModal: true,
857
885
  "aria-label": accessibilityLabel,
858
886
  role: "dialog",
859
- style: modalContentStyle,
887
+ style: [modalContentStyle, modalAnim.style],
860
888
  children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.FlatList, { data: [...options], keyExtractor, renderItem: renderModalOption })
861
889
  }
862
890
  )
@@ -1122,7 +1150,9 @@ var UpgradePrompt = ({
1122
1150
  );
1123
1151
  };
1124
1152
  var CLOSE_ICON_SIZE = 18;
1153
+ var PANEL_ENTER_SCALE = 0.96;
1125
1154
  var styles10 = reactNative.StyleSheet.create({
1155
+ animatedFill: { flex: 1 },
1126
1156
  container: {
1127
1157
  flex: 1,
1128
1158
  padding: 16
@@ -1146,6 +1176,7 @@ var ModalShell = ({
1146
1176
  showClose = true
1147
1177
  }) => {
1148
1178
  const { theme, t } = uiFeedback.useUi();
1179
+ const { style: sheetStyle, mounted } = uiMotion.useEnterExit({ visible, fromScale: PANEL_ENTER_SCALE });
1149
1180
  const containerStyle = React10__default.default.useMemo(
1150
1181
  () => [styles10.container, { backgroundColor: theme.colors.background }, contentStyle],
1151
1182
  [theme.colors.background, contentStyle]
@@ -1155,11 +1186,11 @@ var ModalShell = ({
1155
1186
  return /* @__PURE__ */ jsxRuntime.jsx(
1156
1187
  reactNative.Modal,
1157
1188
  {
1158
- animationType: "slide",
1189
+ transparent: true,
1159
1190
  testID: LAYOUT_TEST_IDS.modalShell,
1160
- visible,
1191
+ visible: mounted,
1161
1192
  onRequestClose: onCancel,
1162
- children: /* @__PURE__ */ jsxRuntime.jsxs(
1193
+ children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Animated.View, { style: [styles10.animatedFill, sheetStyle], children: /* @__PURE__ */ jsxRuntime.jsxs(
1163
1194
  reactNative.ScrollView,
1164
1195
  {
1165
1196
  accessibilityViewIsModal: true,
@@ -1185,7 +1216,7 @@ var ModalShell = ({
1185
1216
  children
1186
1217
  ]
1187
1218
  }
1188
- )
1219
+ ) })
1189
1220
  }
1190
1221
  );
1191
1222
  };
@@ -1219,15 +1250,20 @@ var HEADER_GAP = 12;
1219
1250
  var FOOTER_MARGIN = 16;
1220
1251
  var HEADER_MARGIN = 12;
1221
1252
  var DIALOG_MAX_HEIGHT = "90%";
1253
+ var PANEL_ENTER_SCALE2 = 0.96;
1222
1254
  var SIZE_MAX_WIDTH = { sm: 360, md: 480, lg: 640 };
1223
1255
  var styles11 = reactNative.StyleSheet.create({
1224
1256
  overlay: {
1225
1257
  flex: 1,
1226
1258
  justifyContent: "center",
1227
1259
  alignItems: "center",
1228
- padding: OVERLAY_PADDING,
1229
- backgroundColor: uiFeedback.MODAL_OVERLAY_COLOR
1260
+ padding: OVERLAY_PADDING
1230
1261
  },
1262
+ // The scrim is its OWN animated layer (behind the tap-catcher and the panel) so its opacity
1263
+ // can fade independently of the panel's fade+scale. `animationType` is a native-only no-op on
1264
+ // react-native-web, which is why the fade is driven by `Animated` instead. `pointerEvents` lives
1265
+ // in style (not the deprecated prop) so taps fall through to the sibling tap-catcher below.
1266
+ scrim: { backgroundColor: uiFeedback.MODAL_OVERLAY_COLOR, pointerEvents: "none" },
1231
1267
  dialog: {
1232
1268
  width: "100%",
1233
1269
  borderRadius: DIALOG_RADIUS,
@@ -1258,6 +1294,9 @@ var Modal3 = ({
1258
1294
  }) => {
1259
1295
  const { theme, t } = uiFeedback.useUi();
1260
1296
  const dialogRef = React10.useRef(null);
1297
+ const backdrop = uiMotion.useEnterExit({ visible });
1298
+ const panel = uiMotion.useEnterExit({ visible, fromScale: PANEL_ENTER_SCALE2 });
1299
+ const mounted = panel.mounted || backdrop.mounted;
1261
1300
  useFocusTrap(dialogRef, visible);
1262
1301
  useEscapeKey(visible, onClose);
1263
1302
  useScrollLock(visible);
@@ -1268,7 +1307,13 @@ var Modal3 = ({
1268
1307
  [theme.colors.surface, size]
1269
1308
  );
1270
1309
  const hasHeader = title !== void 0 || showClose;
1271
- return /* @__PURE__ */ jsxRuntime.jsx(reactNative.Modal, { transparent: true, animationType: "fade", visible, onRequestClose: onClose, children: /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles11.overlay, children: [
1310
+ return /* @__PURE__ */ jsxRuntime.jsx(reactNative.Modal, { transparent: true, visible: mounted, onRequestClose: onClose, children: /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles11.overlay, children: [
1311
+ /* @__PURE__ */ jsxRuntime.jsx(
1312
+ reactNative.Animated.View,
1313
+ {
1314
+ style: [reactNative.StyleSheet.absoluteFill, styles11.scrim, { opacity: backdrop.style.opacity }]
1315
+ }
1316
+ ),
1272
1317
  /* @__PURE__ */ jsxRuntime.jsx(
1273
1318
  reactNative.TouchableOpacity,
1274
1319
  {
@@ -1283,13 +1328,13 @@ var Modal3 = ({
1283
1328
  }
1284
1329
  ),
1285
1330
  /* @__PURE__ */ jsxRuntime.jsxs(
1286
- reactNative.View,
1331
+ reactNative.Animated.View,
1287
1332
  {
1288
1333
  ref: dialogRef,
1289
1334
  accessibilityViewIsModal: true,
1290
1335
  "aria-label": accessibleName,
1291
1336
  role: "dialog",
1292
- style: dialogStyle,
1337
+ style: [dialogStyle, panel.style],
1293
1338
  testID,
1294
1339
  children: [
1295
1340
  hasHeader ? /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles11.headerRow, children: [
@@ -1386,26 +1431,6 @@ function useAccordionContext() {
1386
1431
  }
1387
1432
  return value;
1388
1433
  }
1389
- var androidEnabled = false;
1390
- function enableAndroidLayoutAnimationOnce() {
1391
- if (androidEnabled) return;
1392
- androidEnabled = true;
1393
- const isAndroid = reactNative.Platform.OS === "android";
1394
- const setter = reactNative.UIManager.setLayoutAnimationEnabledExperimental;
1395
- if (isAndroid && typeof setter === "function") {
1396
- setter(true);
1397
- }
1398
- }
1399
- function animateNextLayout() {
1400
- if (rnWebHooks.prefersReducedMotion()) return;
1401
- enableAndroidLayoutAnimationOnce();
1402
- const configure = reactNative.LayoutAnimation.configureNext;
1403
- if (typeof configure !== "function") return;
1404
- try {
1405
- configure(reactNative.LayoutAnimation.Presets.easeInEaseOut);
1406
- } catch {
1407
- }
1408
- }
1409
1434
  var BOXED_GAP = 12;
1410
1435
  var styles13 = reactNative.StyleSheet.create({
1411
1436
  container: { alignSelf: "stretch" },
@@ -1446,7 +1471,6 @@ var Accordion = ({
1446
1471
  );
1447
1472
  const toggle = React10.useCallback(
1448
1473
  (id) => {
1449
- animateNextLayout();
1450
1474
  const next = new Set(openSet);
1451
1475
  const willOpen = !next.has(id);
1452
1476
  if (!allowMultiple) next.clear();
@@ -1633,7 +1657,7 @@ var AccordionItem = ({
1633
1657
  ]
1634
1658
  }
1635
1659
  ),
1636
- expanded ? /* @__PURE__ */ jsxRuntime.jsx(
1660
+ /* @__PURE__ */ jsxRuntime.jsx(uiMotion.Collapse, { open: expanded, testID: `${headerTestID}-collapse`, children: /* @__PURE__ */ jsxRuntime.jsx(
1637
1661
  reactNative.View,
1638
1662
  {
1639
1663
  accessibilityLabel: resolvedLabel,
@@ -1643,7 +1667,7 @@ var AccordionItem = ({
1643
1667
  testID: bodyTestID,
1644
1668
  children
1645
1669
  }
1646
- ) : null
1670
+ ) })
1647
1671
  ] });
1648
1672
  };
1649
1673