@dloizides/ui-layout 1.22.1 → 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 +38 -0
- package/dist/index.js +54 -39
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +56 -41
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -2
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,6 +674,8 @@ 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: {
|
|
@@ -747,6 +755,16 @@ var ModalDropdown = ({
|
|
|
747
755
|
const anchorRef = React10.useRef(null);
|
|
748
756
|
const dialogRef = React10.useRef(null);
|
|
749
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
|
+
});
|
|
750
768
|
const selectedLabel = React10.useMemo(() => {
|
|
751
769
|
const found = options.find((opt) => opt.value === value);
|
|
752
770
|
return found?.label ?? t(LAYOUT_I18N.selectPlaceholder);
|
|
@@ -821,10 +839,11 @@ var ModalDropdown = ({
|
|
|
821
839
|
] }) : /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles7.selectedText, { color: colors.text }], children: selectedLabel }),
|
|
822
840
|
hintNode
|
|
823
841
|
] }),
|
|
824
|
-
isMenu &&
|
|
842
|
+
isMenu && menuAnim.mounted ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
825
843
|
InlineMenu,
|
|
826
844
|
{
|
|
827
845
|
accessibilityLabel,
|
|
846
|
+
animatedStyle: menuAnim.style,
|
|
828
847
|
containerRef: anchorRef,
|
|
829
848
|
menuMinWidth,
|
|
830
849
|
optionTestID: optionTestIDFor,
|
|
@@ -835,7 +854,7 @@ var ModalDropdown = ({
|
|
|
835
854
|
onSelect: handleSelect
|
|
836
855
|
}
|
|
837
856
|
) : null,
|
|
838
|
-
!isMenu ? /* @__PURE__ */ jsxRuntime.jsx(reactNative.Modal, { transparent: true,
|
|
857
|
+
!isMenu ? /* @__PURE__ */ jsxRuntime.jsx(reactNative.Modal, { transparent: true, visible: modalAnim.mounted, onRequestClose: handleClose, children: /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles7.modalOverlay, children: [
|
|
839
858
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
840
859
|
reactNative.TouchableOpacity,
|
|
841
860
|
{
|
|
@@ -850,13 +869,13 @@ var ModalDropdown = ({
|
|
|
850
869
|
}
|
|
851
870
|
),
|
|
852
871
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
853
|
-
reactNative.View,
|
|
872
|
+
reactNative.Animated.View,
|
|
854
873
|
{
|
|
855
874
|
ref: dialogRef,
|
|
856
875
|
accessibilityViewIsModal: true,
|
|
857
876
|
"aria-label": accessibilityLabel,
|
|
858
877
|
role: "dialog",
|
|
859
|
-
style: modalContentStyle,
|
|
878
|
+
style: [modalContentStyle, modalAnim.style],
|
|
860
879
|
children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.FlatList, { data: [...options], keyExtractor, renderItem: renderModalOption })
|
|
861
880
|
}
|
|
862
881
|
)
|
|
@@ -1122,7 +1141,9 @@ var UpgradePrompt = ({
|
|
|
1122
1141
|
);
|
|
1123
1142
|
};
|
|
1124
1143
|
var CLOSE_ICON_SIZE = 18;
|
|
1144
|
+
var PANEL_ENTER_SCALE = 0.96;
|
|
1125
1145
|
var styles10 = reactNative.StyleSheet.create({
|
|
1146
|
+
animatedFill: { flex: 1 },
|
|
1126
1147
|
container: {
|
|
1127
1148
|
flex: 1,
|
|
1128
1149
|
padding: 16
|
|
@@ -1146,6 +1167,7 @@ var ModalShell = ({
|
|
|
1146
1167
|
showClose = true
|
|
1147
1168
|
}) => {
|
|
1148
1169
|
const { theme, t } = uiFeedback.useUi();
|
|
1170
|
+
const { style: sheetStyle, mounted } = uiMotion.useEnterExit({ visible, fromScale: PANEL_ENTER_SCALE });
|
|
1149
1171
|
const containerStyle = React10__default.default.useMemo(
|
|
1150
1172
|
() => [styles10.container, { backgroundColor: theme.colors.background }, contentStyle],
|
|
1151
1173
|
[theme.colors.background, contentStyle]
|
|
@@ -1155,11 +1177,11 @@ var ModalShell = ({
|
|
|
1155
1177
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1156
1178
|
reactNative.Modal,
|
|
1157
1179
|
{
|
|
1158
|
-
|
|
1180
|
+
transparent: true,
|
|
1159
1181
|
testID: LAYOUT_TEST_IDS.modalShell,
|
|
1160
|
-
visible,
|
|
1182
|
+
visible: mounted,
|
|
1161
1183
|
onRequestClose: onCancel,
|
|
1162
|
-
children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1184
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Animated.View, { style: [styles10.animatedFill, sheetStyle], children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1163
1185
|
reactNative.ScrollView,
|
|
1164
1186
|
{
|
|
1165
1187
|
accessibilityViewIsModal: true,
|
|
@@ -1185,7 +1207,7 @@ var ModalShell = ({
|
|
|
1185
1207
|
children
|
|
1186
1208
|
]
|
|
1187
1209
|
}
|
|
1188
|
-
)
|
|
1210
|
+
) })
|
|
1189
1211
|
}
|
|
1190
1212
|
);
|
|
1191
1213
|
};
|
|
@@ -1219,15 +1241,20 @@ var HEADER_GAP = 12;
|
|
|
1219
1241
|
var FOOTER_MARGIN = 16;
|
|
1220
1242
|
var HEADER_MARGIN = 12;
|
|
1221
1243
|
var DIALOG_MAX_HEIGHT = "90%";
|
|
1244
|
+
var PANEL_ENTER_SCALE2 = 0.96;
|
|
1222
1245
|
var SIZE_MAX_WIDTH = { sm: 360, md: 480, lg: 640 };
|
|
1223
1246
|
var styles11 = reactNative.StyleSheet.create({
|
|
1224
1247
|
overlay: {
|
|
1225
1248
|
flex: 1,
|
|
1226
1249
|
justifyContent: "center",
|
|
1227
1250
|
alignItems: "center",
|
|
1228
|
-
padding: OVERLAY_PADDING
|
|
1229
|
-
backgroundColor: uiFeedback.MODAL_OVERLAY_COLOR
|
|
1251
|
+
padding: OVERLAY_PADDING
|
|
1230
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" },
|
|
1231
1258
|
dialog: {
|
|
1232
1259
|
width: "100%",
|
|
1233
1260
|
borderRadius: DIALOG_RADIUS,
|
|
@@ -1258,6 +1285,9 @@ var Modal3 = ({
|
|
|
1258
1285
|
}) => {
|
|
1259
1286
|
const { theme, t } = uiFeedback.useUi();
|
|
1260
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;
|
|
1261
1291
|
useFocusTrap(dialogRef, visible);
|
|
1262
1292
|
useEscapeKey(visible, onClose);
|
|
1263
1293
|
useScrollLock(visible);
|
|
@@ -1268,7 +1298,13 @@ var Modal3 = ({
|
|
|
1268
1298
|
[theme.colors.surface, size]
|
|
1269
1299
|
);
|
|
1270
1300
|
const hasHeader = title !== void 0 || showClose;
|
|
1271
|
-
return /* @__PURE__ */ jsxRuntime.jsx(reactNative.Modal, { transparent: true,
|
|
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
|
+
),
|
|
1272
1308
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1273
1309
|
reactNative.TouchableOpacity,
|
|
1274
1310
|
{
|
|
@@ -1283,13 +1319,13 @@ var Modal3 = ({
|
|
|
1283
1319
|
}
|
|
1284
1320
|
),
|
|
1285
1321
|
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1286
|
-
reactNative.View,
|
|
1322
|
+
reactNative.Animated.View,
|
|
1287
1323
|
{
|
|
1288
1324
|
ref: dialogRef,
|
|
1289
1325
|
accessibilityViewIsModal: true,
|
|
1290
1326
|
"aria-label": accessibleName,
|
|
1291
1327
|
role: "dialog",
|
|
1292
|
-
style: dialogStyle,
|
|
1328
|
+
style: [dialogStyle, panel.style],
|
|
1293
1329
|
testID,
|
|
1294
1330
|
children: [
|
|
1295
1331
|
hasHeader ? /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles11.headerRow, children: [
|
|
@@ -1386,26 +1422,6 @@ function useAccordionContext() {
|
|
|
1386
1422
|
}
|
|
1387
1423
|
return value;
|
|
1388
1424
|
}
|
|
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
1425
|
var BOXED_GAP = 12;
|
|
1410
1426
|
var styles13 = reactNative.StyleSheet.create({
|
|
1411
1427
|
container: { alignSelf: "stretch" },
|
|
@@ -1446,7 +1462,6 @@ var Accordion = ({
|
|
|
1446
1462
|
);
|
|
1447
1463
|
const toggle = React10.useCallback(
|
|
1448
1464
|
(id) => {
|
|
1449
|
-
animateNextLayout();
|
|
1450
1465
|
const next = new Set(openSet);
|
|
1451
1466
|
const willOpen = !next.has(id);
|
|
1452
1467
|
if (!allowMultiple) next.clear();
|
|
@@ -1633,7 +1648,7 @@ var AccordionItem = ({
|
|
|
1633
1648
|
]
|
|
1634
1649
|
}
|
|
1635
1650
|
),
|
|
1636
|
-
expanded
|
|
1651
|
+
/* @__PURE__ */ jsxRuntime.jsx(uiMotion.Collapse, { open: expanded, testID: `${headerTestID}-collapse`, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1637
1652
|
reactNative.View,
|
|
1638
1653
|
{
|
|
1639
1654
|
accessibilityLabel: resolvedLabel,
|
|
@@ -1643,7 +1658,7 @@ var AccordionItem = ({
|
|
|
1643
1658
|
testID: bodyTestID,
|
|
1644
1659
|
children
|
|
1645
1660
|
}
|
|
1646
|
-
)
|
|
1661
|
+
) })
|
|
1647
1662
|
] });
|
|
1648
1663
|
};
|
|
1649
1664
|
|