@dloizides/ui-layout 1.22.0 → 1.23.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,43 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.23.0
4
+
5
+ **Modals, the dropdown popover and the accordion body now ANIMATE on web — adopts `@dloizides/ui-motion`.**
6
+
7
+ On react-native-web, RN's `Modal animationType` and `LayoutAnimation` are effectively no-ops, so
8
+ `Modal`, `ModalShell`, the `ModalDropdown` popover and the `Accordion` body all SNAPPED open/closed
9
+ on the web build (all 7 portals). This wires those surfaces to `@dloizides/ui-motion`, which drives
10
+ enter/exit with RN `Animated` (works on web AND native) and collapses every animation to instant
11
+ under the OS "reduce motion" preference. **No public APIs changed** — every prop, testID and a11y
12
+ attribute is identical; this is a purely visual upgrade.
13
+
14
+ - **`Modal`** — the backdrop now **fades** (opacity) and the panel **fades + scales in** (0.96→1) on
15
+ open, reversing on close, via `useEnterExit`. The RN `Modal` host is kept **mounted through the
16
+ exit** (driven by `useEnterExit`'s `mounted` flag, not `visible`) so the close animation can play
17
+ instead of the host unmounting instantly — the trick that made `animationType` a no-op on web. The
18
+ scrim moved to its own animated layer behind the tap-catcher; close-on-backdrop, Escape, focus
19
+ trap, scroll-lock and every testID are unchanged.
20
+ - **`ModalShell`** — the full-screen sheet **fades + scales in** on open (replacing the native-only
21
+ `animationType="slide"`), mounted through the exit the same way.
22
+ - **`ModalDropdown`** — the popover (the inline anchored menu on web-desktop, the centered modal on
23
+ mobile/native) **fades + scales in** from the anchor on open (`transformOrigin: top`), with a snappy
24
+ ~120ms curve so the close reads as near-instant. `useAnchorTracking`, the web portal, keyboard nav
25
+ and outside-click detection are untouched (the fade/scale rides an INNER wrapper so the popover's
26
+ own DOM node — which the outside-click/portal logic depends on — is unchanged).
27
+ - **`Accordion`** — the item body now renders inside ui-motion's **`<Collapse>`** (measured, animated
28
+ height) instead of RN `LayoutAnimation`, so the body animates on web too. The chevron rotation is
29
+ unchanged. Behaviour note: `<Collapse>` keeps the body **mounted at all times** (clipped to height 0
30
+ when closed) so `aria-controls` always resolves and screen readers reach the content — the open
31
+ state is conveyed by the header's `aria-expanded` (the value handed to `<Collapse open>`). The
32
+ internal `accordionAnimation.ts` (`LayoutAnimation` helper) was removed.
33
+ - **New dependency `@dloizides/ui-motion` (`^1.0.1`)** — the shared RN/RN-web motion kit
34
+ (`useEnterExit`, `Collapse`, reduced-motion-aware).
35
+
36
+ Additive and back-compatible for consumers. Covered by the existing `Modal`, `ModalShell`,
37
+ `ModalDropdown` (web + native) and `Accordion` suites; the accordion tests now assert open state via
38
+ `aria-expanded`/the `Collapse` container rather than body-text presence (the body is always mounted).
39
+ The Jest env is pinned to reduced-motion so enter/exit resolve synchronously in tests.
40
+
3
41
  ## 1.22.0
4
42
 
5
43
  **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');
@@ -564,7 +565,11 @@ var styles6 = reactNative.StyleSheet.create({
564
565
  maxHeight: MENU_MAX_HEIGHT,
565
566
  boxShadow: MENU_BOX_SHADOW,
566
567
  elevation: MENU_ELEVATION
567
- }
568
+ },
569
+ // The enter/exit fade+scale lives on an INNER wrapper so the outer popover keeps its raw DOM
570
+ // node (the `menuRef` outside-click / keyboard logic and the web portal target depend on it).
571
+ // `transformOrigin: 'top'` makes the scale grow downward FROM the anchor rather than the centre.
572
+ animated: { transformOrigin: "top" }
568
573
  });
569
574
  var InlineMenu = ({
570
575
  testID,
@@ -574,6 +579,7 @@ var InlineMenu = ({
574
579
  containerRef,
575
580
  optionTestID,
576
581
  menuMinWidth = 0,
582
+ animatedStyle,
577
583
  onSelect,
578
584
  onClose
579
585
  }) => {
@@ -625,7 +631,7 @@ var InlineMenu = ({
625
631
  "aria-label": accessibilityLabel,
626
632
  style: popoverStyle,
627
633
  testID: `${testID}-menu`,
628
- children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.ScrollView, { keyboardShouldPersistTaps: "handled", children: options.map((option, index) => /* @__PURE__ */ jsxRuntime.jsx(
634
+ 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
635
  OptionRow,
630
636
  {
631
637
  isHighlighted: index === highlightedIndex,
@@ -635,7 +641,7 @@ var InlineMenu = ({
635
641
  onSelect: () => onSelect(option.value)
636
642
  },
637
643
  String(option.value)
638
- )) })
644
+ )) }) })
639
645
  }
640
646
  );
641
647
  if (IS_WEB2) return reactDom.createPortal(menu, document.body);
@@ -668,13 +674,20 @@ var HAMBURGER_GLYPH = "\u2630";
668
674
  var HAMBURGER_FONT_SIZE = 18;
669
675
  var CARET_OPEN_ROTATION = "180deg";
670
676
  var CARET_CLOSED_ROTATION = "0deg";
677
+ var POPOVER_ENTER_SCALE = 0.96;
678
+ var POPOVER_MOTION_MS = 120;
671
679
  var styles7 = reactNative.StyleSheet.create({
672
680
  anchor: { position: "relative" },
673
681
  container: {
674
682
  borderWidth: BORDER_WIDTH4,
675
683
  borderRadius: BORDER_RADIUS3,
676
684
  paddingHorizontal: CONTAINER_PADDING_H,
677
- paddingVertical: CONTAINER_PADDING_V
685
+ paddingVertical: CONTAINER_PADDING_V,
686
+ // Match the shared control height used by @dloizides/ui-forms inputs (same MIN_TOUCH_TARGET_PX
687
+ // floor from @dloizides/a11y), so a select trigger and a text/typeahead field sitting side by
688
+ // side in a filter bar are exactly the same height. Centre the label within that floor.
689
+ minHeight: a11y.MIN_TOUCH_TARGET_PX,
690
+ justifyContent: "center"
678
691
  },
679
692
  // Caret variant: a row with the label leading and the caret pinned to the trailing edge, at a
680
693
  // phone-friendly minimum height. Only applied when `showCaret` is set, so field dropdowns are
@@ -742,6 +755,16 @@ var ModalDropdown = ({
742
755
  const anchorRef = React10.useRef(null);
743
756
  const dialogRef = React10.useRef(null);
744
757
  useFocusTrap(dialogRef, isOpen && !isMenu);
758
+ const menuAnim = uiMotion.useEnterExit({
759
+ visible: isMenu && isOpen,
760
+ fromScale: POPOVER_ENTER_SCALE,
761
+ duration: POPOVER_MOTION_MS
762
+ });
763
+ const modalAnim = uiMotion.useEnterExit({
764
+ visible: !isMenu && isOpen,
765
+ fromScale: POPOVER_ENTER_SCALE,
766
+ duration: POPOVER_MOTION_MS
767
+ });
745
768
  const selectedLabel = React10.useMemo(() => {
746
769
  const found = options.find((opt) => opt.value === value);
747
770
  return found?.label ?? t(LAYOUT_I18N.selectPlaceholder);
@@ -816,10 +839,11 @@ var ModalDropdown = ({
816
839
  ] }) : /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles7.selectedText, { color: colors.text }], children: selectedLabel }),
817
840
  hintNode
818
841
  ] }),
819
- isMenu && isOpen ? /* @__PURE__ */ jsxRuntime.jsx(
842
+ isMenu && menuAnim.mounted ? /* @__PURE__ */ jsxRuntime.jsx(
820
843
  InlineMenu,
821
844
  {
822
845
  accessibilityLabel,
846
+ animatedStyle: menuAnim.style,
823
847
  containerRef: anchorRef,
824
848
  menuMinWidth,
825
849
  optionTestID: optionTestIDFor,
@@ -830,7 +854,7 @@ var ModalDropdown = ({
830
854
  onSelect: handleSelect
831
855
  }
832
856
  ) : null,
833
- !isMenu ? /* @__PURE__ */ jsxRuntime.jsx(reactNative.Modal, { transparent: true, animationType: "fade", visible: isOpen, onRequestClose: handleClose, children: /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles7.modalOverlay, children: [
857
+ !isMenu ? /* @__PURE__ */ jsxRuntime.jsx(reactNative.Modal, { transparent: true, visible: modalAnim.mounted, onRequestClose: handleClose, children: /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles7.modalOverlay, children: [
834
858
  /* @__PURE__ */ jsxRuntime.jsx(
835
859
  reactNative.TouchableOpacity,
836
860
  {
@@ -845,13 +869,13 @@ var ModalDropdown = ({
845
869
  }
846
870
  ),
847
871
  /* @__PURE__ */ jsxRuntime.jsx(
848
- reactNative.View,
872
+ reactNative.Animated.View,
849
873
  {
850
874
  ref: dialogRef,
851
875
  accessibilityViewIsModal: true,
852
876
  "aria-label": accessibilityLabel,
853
877
  role: "dialog",
854
- style: modalContentStyle,
878
+ style: [modalContentStyle, modalAnim.style],
855
879
  children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.FlatList, { data: [...options], keyExtractor, renderItem: renderModalOption })
856
880
  }
857
881
  )
@@ -1117,7 +1141,9 @@ var UpgradePrompt = ({
1117
1141
  );
1118
1142
  };
1119
1143
  var CLOSE_ICON_SIZE = 18;
1144
+ var PANEL_ENTER_SCALE = 0.96;
1120
1145
  var styles10 = reactNative.StyleSheet.create({
1146
+ animatedFill: { flex: 1 },
1121
1147
  container: {
1122
1148
  flex: 1,
1123
1149
  padding: 16
@@ -1141,6 +1167,7 @@ var ModalShell = ({
1141
1167
  showClose = true
1142
1168
  }) => {
1143
1169
  const { theme, t } = uiFeedback.useUi();
1170
+ const { style: sheetStyle, mounted } = uiMotion.useEnterExit({ visible, fromScale: PANEL_ENTER_SCALE });
1144
1171
  const containerStyle = React10__default.default.useMemo(
1145
1172
  () => [styles10.container, { backgroundColor: theme.colors.background }, contentStyle],
1146
1173
  [theme.colors.background, contentStyle]
@@ -1150,11 +1177,11 @@ var ModalShell = ({
1150
1177
  return /* @__PURE__ */ jsxRuntime.jsx(
1151
1178
  reactNative.Modal,
1152
1179
  {
1153
- animationType: "slide",
1180
+ transparent: true,
1154
1181
  testID: LAYOUT_TEST_IDS.modalShell,
1155
- visible,
1182
+ visible: mounted,
1156
1183
  onRequestClose: onCancel,
1157
- children: /* @__PURE__ */ jsxRuntime.jsxs(
1184
+ children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Animated.View, { style: [styles10.animatedFill, sheetStyle], children: /* @__PURE__ */ jsxRuntime.jsxs(
1158
1185
  reactNative.ScrollView,
1159
1186
  {
1160
1187
  accessibilityViewIsModal: true,
@@ -1180,7 +1207,7 @@ var ModalShell = ({
1180
1207
  children
1181
1208
  ]
1182
1209
  }
1183
- )
1210
+ ) })
1184
1211
  }
1185
1212
  );
1186
1213
  };
@@ -1214,15 +1241,20 @@ var HEADER_GAP = 12;
1214
1241
  var FOOTER_MARGIN = 16;
1215
1242
  var HEADER_MARGIN = 12;
1216
1243
  var DIALOG_MAX_HEIGHT = "90%";
1244
+ var PANEL_ENTER_SCALE2 = 0.96;
1217
1245
  var SIZE_MAX_WIDTH = { sm: 360, md: 480, lg: 640 };
1218
1246
  var styles11 = reactNative.StyleSheet.create({
1219
1247
  overlay: {
1220
1248
  flex: 1,
1221
1249
  justifyContent: "center",
1222
1250
  alignItems: "center",
1223
- padding: OVERLAY_PADDING,
1224
- backgroundColor: uiFeedback.MODAL_OVERLAY_COLOR
1251
+ padding: OVERLAY_PADDING
1225
1252
  },
1253
+ // The scrim is its OWN animated layer (behind the tap-catcher and the panel) so its opacity
1254
+ // can fade independently of the panel's fade+scale. `animationType` is a native-only no-op on
1255
+ // react-native-web, which is why the fade is driven by `Animated` instead. `pointerEvents` lives
1256
+ // in style (not the deprecated prop) so taps fall through to the sibling tap-catcher below.
1257
+ scrim: { backgroundColor: uiFeedback.MODAL_OVERLAY_COLOR, pointerEvents: "none" },
1226
1258
  dialog: {
1227
1259
  width: "100%",
1228
1260
  borderRadius: DIALOG_RADIUS,
@@ -1253,6 +1285,9 @@ var Modal3 = ({
1253
1285
  }) => {
1254
1286
  const { theme, t } = uiFeedback.useUi();
1255
1287
  const dialogRef = React10.useRef(null);
1288
+ const backdrop = uiMotion.useEnterExit({ visible });
1289
+ const panel = uiMotion.useEnterExit({ visible, fromScale: PANEL_ENTER_SCALE2 });
1290
+ const mounted = panel.mounted || backdrop.mounted;
1256
1291
  useFocusTrap(dialogRef, visible);
1257
1292
  useEscapeKey(visible, onClose);
1258
1293
  useScrollLock(visible);
@@ -1263,7 +1298,13 @@ var Modal3 = ({
1263
1298
  [theme.colors.surface, size]
1264
1299
  );
1265
1300
  const hasHeader = title !== void 0 || showClose;
1266
- return /* @__PURE__ */ jsxRuntime.jsx(reactNative.Modal, { transparent: true, animationType: "fade", visible, onRequestClose: onClose, children: /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles11.overlay, children: [
1301
+ return /* @__PURE__ */ jsxRuntime.jsx(reactNative.Modal, { transparent: true, visible: mounted, onRequestClose: onClose, children: /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles11.overlay, children: [
1302
+ /* @__PURE__ */ jsxRuntime.jsx(
1303
+ reactNative.Animated.View,
1304
+ {
1305
+ style: [reactNative.StyleSheet.absoluteFill, styles11.scrim, { opacity: backdrop.style.opacity }]
1306
+ }
1307
+ ),
1267
1308
  /* @__PURE__ */ jsxRuntime.jsx(
1268
1309
  reactNative.TouchableOpacity,
1269
1310
  {
@@ -1278,13 +1319,13 @@ var Modal3 = ({
1278
1319
  }
1279
1320
  ),
1280
1321
  /* @__PURE__ */ jsxRuntime.jsxs(
1281
- reactNative.View,
1322
+ reactNative.Animated.View,
1282
1323
  {
1283
1324
  ref: dialogRef,
1284
1325
  accessibilityViewIsModal: true,
1285
1326
  "aria-label": accessibleName,
1286
1327
  role: "dialog",
1287
- style: dialogStyle,
1328
+ style: [dialogStyle, panel.style],
1288
1329
  testID,
1289
1330
  children: [
1290
1331
  hasHeader ? /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles11.headerRow, children: [
@@ -1381,26 +1422,6 @@ function useAccordionContext() {
1381
1422
  }
1382
1423
  return value;
1383
1424
  }
1384
- var androidEnabled = false;
1385
- function enableAndroidLayoutAnimationOnce() {
1386
- if (androidEnabled) return;
1387
- androidEnabled = true;
1388
- const isAndroid = reactNative.Platform.OS === "android";
1389
- const setter = reactNative.UIManager.setLayoutAnimationEnabledExperimental;
1390
- if (isAndroid && typeof setter === "function") {
1391
- setter(true);
1392
- }
1393
- }
1394
- function animateNextLayout() {
1395
- if (rnWebHooks.prefersReducedMotion()) return;
1396
- enableAndroidLayoutAnimationOnce();
1397
- const configure = reactNative.LayoutAnimation.configureNext;
1398
- if (typeof configure !== "function") return;
1399
- try {
1400
- configure(reactNative.LayoutAnimation.Presets.easeInEaseOut);
1401
- } catch {
1402
- }
1403
- }
1404
1425
  var BOXED_GAP = 12;
1405
1426
  var styles13 = reactNative.StyleSheet.create({
1406
1427
  container: { alignSelf: "stretch" },
@@ -1441,7 +1462,6 @@ var Accordion = ({
1441
1462
  );
1442
1463
  const toggle = React10.useCallback(
1443
1464
  (id) => {
1444
- animateNextLayout();
1445
1465
  const next = new Set(openSet);
1446
1466
  const willOpen = !next.has(id);
1447
1467
  if (!allowMultiple) next.clear();
@@ -1628,7 +1648,7 @@ var AccordionItem = ({
1628
1648
  ]
1629
1649
  }
1630
1650
  ),
1631
- expanded ? /* @__PURE__ */ jsxRuntime.jsx(
1651
+ /* @__PURE__ */ jsxRuntime.jsx(uiMotion.Collapse, { open: expanded, testID: `${headerTestID}-collapse`, children: /* @__PURE__ */ jsxRuntime.jsx(
1632
1652
  reactNative.View,
1633
1653
  {
1634
1654
  accessibilityLabel: resolvedLabel,
@@ -1638,7 +1658,7 @@ var AccordionItem = ({
1638
1658
  testID: bodyTestID,
1639
1659
  children
1640
1660
  }
1641
- ) : null
1661
+ ) })
1642
1662
  ] });
1643
1663
  };
1644
1664