@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/dist/index.mjs
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import React10, { createContext, useMemo, useRef, useEffect, useState, useCallback, useContext, useLayoutEffect } from 'react';
|
|
2
|
-
import { StyleSheet, Platform, View, Text, Pressable, TouchableOpacity, Modal, FlatList, ScrollView,
|
|
2
|
+
import { StyleSheet, Platform, View, Text, Pressable, TouchableOpacity, Modal, Animated, FlatList, ScrollView, Easing, useWindowDimensions } from 'react-native';
|
|
3
3
|
import { MODAL_OVERLAY_COLOR, useUi } from '@dloizides/ui-feedback';
|
|
4
4
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
5
5
|
import { MIN_TOUCH_TARGET_PX, useA11y } from '@dloizides/a11y';
|
|
6
|
+
import { useEnterExit, Collapse } from '@dloizides/ui-motion';
|
|
6
7
|
import { createPortal } from 'react-dom';
|
|
7
8
|
import { SvgIcon } from '@dloizides/ui-icons';
|
|
8
9
|
import { IconButton, Button } from '@dloizides/ui-buttons';
|
|
9
|
-
import { useReducedMotion
|
|
10
|
+
import { useReducedMotion } from '@dloizides/rn-web-hooks';
|
|
10
11
|
|
|
11
12
|
// src/Section/Section.tsx
|
|
12
13
|
var styles = StyleSheet.create({
|
|
@@ -558,7 +559,11 @@ var styles6 = StyleSheet.create({
|
|
|
558
559
|
maxHeight: MENU_MAX_HEIGHT,
|
|
559
560
|
boxShadow: MENU_BOX_SHADOW,
|
|
560
561
|
elevation: MENU_ELEVATION
|
|
561
|
-
}
|
|
562
|
+
},
|
|
563
|
+
// The enter/exit fade+scale lives on an INNER wrapper so the outer popover keeps its raw DOM
|
|
564
|
+
// node (the `menuRef` outside-click / keyboard logic and the web portal target depend on it).
|
|
565
|
+
// `transformOrigin: 'top'` makes the scale grow downward FROM the anchor rather than the centre.
|
|
566
|
+
animated: { transformOrigin: "top" }
|
|
562
567
|
});
|
|
563
568
|
var InlineMenu = ({
|
|
564
569
|
testID,
|
|
@@ -568,6 +573,7 @@ var InlineMenu = ({
|
|
|
568
573
|
containerRef,
|
|
569
574
|
optionTestID,
|
|
570
575
|
menuMinWidth = 0,
|
|
576
|
+
animatedStyle,
|
|
571
577
|
onSelect,
|
|
572
578
|
onClose
|
|
573
579
|
}) => {
|
|
@@ -619,7 +625,7 @@ var InlineMenu = ({
|
|
|
619
625
|
"aria-label": accessibilityLabel,
|
|
620
626
|
style: popoverStyle,
|
|
621
627
|
testID: `${testID}-menu`,
|
|
622
|
-
children: /* @__PURE__ */ jsx(ScrollView, { keyboardShouldPersistTaps: "handled", children: options.map((option, index) => /* @__PURE__ */ jsx(
|
|
628
|
+
children: /* @__PURE__ */ jsx(Animated.View, { style: [styles6.animated, animatedStyle], children: /* @__PURE__ */ jsx(ScrollView, { keyboardShouldPersistTaps: "handled", children: options.map((option, index) => /* @__PURE__ */ jsx(
|
|
623
629
|
OptionRow,
|
|
624
630
|
{
|
|
625
631
|
isHighlighted: index === highlightedIndex,
|
|
@@ -629,7 +635,7 @@ var InlineMenu = ({
|
|
|
629
635
|
onSelect: () => onSelect(option.value)
|
|
630
636
|
},
|
|
631
637
|
String(option.value)
|
|
632
|
-
)) })
|
|
638
|
+
)) }) })
|
|
633
639
|
}
|
|
634
640
|
);
|
|
635
641
|
if (IS_WEB2) return createPortal(menu, document.body);
|
|
@@ -662,6 +668,8 @@ var HAMBURGER_GLYPH = "\u2630";
|
|
|
662
668
|
var HAMBURGER_FONT_SIZE = 18;
|
|
663
669
|
var CARET_OPEN_ROTATION = "180deg";
|
|
664
670
|
var CARET_CLOSED_ROTATION = "0deg";
|
|
671
|
+
var POPOVER_ENTER_SCALE = 0.96;
|
|
672
|
+
var POPOVER_MOTION_MS = 120;
|
|
665
673
|
var styles7 = StyleSheet.create({
|
|
666
674
|
anchor: { position: "relative" },
|
|
667
675
|
container: {
|
|
@@ -741,6 +749,16 @@ var ModalDropdown = ({
|
|
|
741
749
|
const anchorRef = useRef(null);
|
|
742
750
|
const dialogRef = useRef(null);
|
|
743
751
|
useFocusTrap(dialogRef, isOpen && !isMenu);
|
|
752
|
+
const menuAnim = useEnterExit({
|
|
753
|
+
visible: isMenu && isOpen,
|
|
754
|
+
fromScale: POPOVER_ENTER_SCALE,
|
|
755
|
+
duration: POPOVER_MOTION_MS
|
|
756
|
+
});
|
|
757
|
+
const modalAnim = useEnterExit({
|
|
758
|
+
visible: !isMenu && isOpen,
|
|
759
|
+
fromScale: POPOVER_ENTER_SCALE,
|
|
760
|
+
duration: POPOVER_MOTION_MS
|
|
761
|
+
});
|
|
744
762
|
const selectedLabel = useMemo(() => {
|
|
745
763
|
const found = options.find((opt) => opt.value === value);
|
|
746
764
|
return found?.label ?? t(LAYOUT_I18N.selectPlaceholder);
|
|
@@ -815,10 +833,11 @@ var ModalDropdown = ({
|
|
|
815
833
|
] }) : /* @__PURE__ */ jsx(Text, { style: [styles7.selectedText, { color: colors.text }], children: selectedLabel }),
|
|
816
834
|
hintNode
|
|
817
835
|
] }),
|
|
818
|
-
isMenu &&
|
|
836
|
+
isMenu && menuAnim.mounted ? /* @__PURE__ */ jsx(
|
|
819
837
|
InlineMenu,
|
|
820
838
|
{
|
|
821
839
|
accessibilityLabel,
|
|
840
|
+
animatedStyle: menuAnim.style,
|
|
822
841
|
containerRef: anchorRef,
|
|
823
842
|
menuMinWidth,
|
|
824
843
|
optionTestID: optionTestIDFor,
|
|
@@ -829,7 +848,7 @@ var ModalDropdown = ({
|
|
|
829
848
|
onSelect: handleSelect
|
|
830
849
|
}
|
|
831
850
|
) : null,
|
|
832
|
-
!isMenu ? /* @__PURE__ */ jsx(Modal, { transparent: true,
|
|
851
|
+
!isMenu ? /* @__PURE__ */ jsx(Modal, { transparent: true, visible: modalAnim.mounted, onRequestClose: handleClose, children: /* @__PURE__ */ jsxs(View, { style: styles7.modalOverlay, children: [
|
|
833
852
|
/* @__PURE__ */ jsx(
|
|
834
853
|
TouchableOpacity,
|
|
835
854
|
{
|
|
@@ -844,13 +863,13 @@ var ModalDropdown = ({
|
|
|
844
863
|
}
|
|
845
864
|
),
|
|
846
865
|
/* @__PURE__ */ jsx(
|
|
847
|
-
View,
|
|
866
|
+
Animated.View,
|
|
848
867
|
{
|
|
849
868
|
ref: dialogRef,
|
|
850
869
|
accessibilityViewIsModal: true,
|
|
851
870
|
"aria-label": accessibilityLabel,
|
|
852
871
|
role: "dialog",
|
|
853
|
-
style: modalContentStyle,
|
|
872
|
+
style: [modalContentStyle, modalAnim.style],
|
|
854
873
|
children: /* @__PURE__ */ jsx(FlatList, { data: [...options], keyExtractor, renderItem: renderModalOption })
|
|
855
874
|
}
|
|
856
875
|
)
|
|
@@ -1116,7 +1135,9 @@ var UpgradePrompt = ({
|
|
|
1116
1135
|
);
|
|
1117
1136
|
};
|
|
1118
1137
|
var CLOSE_ICON_SIZE = 18;
|
|
1138
|
+
var PANEL_ENTER_SCALE = 0.96;
|
|
1119
1139
|
var styles10 = StyleSheet.create({
|
|
1140
|
+
animatedFill: { flex: 1 },
|
|
1120
1141
|
container: {
|
|
1121
1142
|
flex: 1,
|
|
1122
1143
|
padding: 16
|
|
@@ -1140,6 +1161,7 @@ var ModalShell = ({
|
|
|
1140
1161
|
showClose = true
|
|
1141
1162
|
}) => {
|
|
1142
1163
|
const { theme, t } = useUi();
|
|
1164
|
+
const { style: sheetStyle, mounted } = useEnterExit({ visible, fromScale: PANEL_ENTER_SCALE });
|
|
1143
1165
|
const containerStyle = React10.useMemo(
|
|
1144
1166
|
() => [styles10.container, { backgroundColor: theme.colors.background }, contentStyle],
|
|
1145
1167
|
[theme.colors.background, contentStyle]
|
|
@@ -1149,11 +1171,11 @@ var ModalShell = ({
|
|
|
1149
1171
|
return /* @__PURE__ */ jsx(
|
|
1150
1172
|
Modal,
|
|
1151
1173
|
{
|
|
1152
|
-
|
|
1174
|
+
transparent: true,
|
|
1153
1175
|
testID: LAYOUT_TEST_IDS.modalShell,
|
|
1154
|
-
visible,
|
|
1176
|
+
visible: mounted,
|
|
1155
1177
|
onRequestClose: onCancel,
|
|
1156
|
-
children: /* @__PURE__ */ jsxs(
|
|
1178
|
+
children: /* @__PURE__ */ jsx(Animated.View, { style: [styles10.animatedFill, sheetStyle], children: /* @__PURE__ */ jsxs(
|
|
1157
1179
|
ScrollView,
|
|
1158
1180
|
{
|
|
1159
1181
|
accessibilityViewIsModal: true,
|
|
@@ -1179,7 +1201,7 @@ var ModalShell = ({
|
|
|
1179
1201
|
children
|
|
1180
1202
|
]
|
|
1181
1203
|
}
|
|
1182
|
-
)
|
|
1204
|
+
) })
|
|
1183
1205
|
}
|
|
1184
1206
|
);
|
|
1185
1207
|
};
|
|
@@ -1213,15 +1235,20 @@ var HEADER_GAP = 12;
|
|
|
1213
1235
|
var FOOTER_MARGIN = 16;
|
|
1214
1236
|
var HEADER_MARGIN = 12;
|
|
1215
1237
|
var DIALOG_MAX_HEIGHT = "90%";
|
|
1238
|
+
var PANEL_ENTER_SCALE2 = 0.96;
|
|
1216
1239
|
var SIZE_MAX_WIDTH = { sm: 360, md: 480, lg: 640 };
|
|
1217
1240
|
var styles11 = StyleSheet.create({
|
|
1218
1241
|
overlay: {
|
|
1219
1242
|
flex: 1,
|
|
1220
1243
|
justifyContent: "center",
|
|
1221
1244
|
alignItems: "center",
|
|
1222
|
-
padding: OVERLAY_PADDING
|
|
1223
|
-
backgroundColor: MODAL_OVERLAY_COLOR
|
|
1245
|
+
padding: OVERLAY_PADDING
|
|
1224
1246
|
},
|
|
1247
|
+
// The scrim is its OWN animated layer (behind the tap-catcher and the panel) so its opacity
|
|
1248
|
+
// can fade independently of the panel's fade+scale. `animationType` is a native-only no-op on
|
|
1249
|
+
// react-native-web, which is why the fade is driven by `Animated` instead. `pointerEvents` lives
|
|
1250
|
+
// in style (not the deprecated prop) so taps fall through to the sibling tap-catcher below.
|
|
1251
|
+
scrim: { backgroundColor: MODAL_OVERLAY_COLOR, pointerEvents: "none" },
|
|
1225
1252
|
dialog: {
|
|
1226
1253
|
width: "100%",
|
|
1227
1254
|
borderRadius: DIALOG_RADIUS,
|
|
@@ -1252,6 +1279,9 @@ var Modal3 = ({
|
|
|
1252
1279
|
}) => {
|
|
1253
1280
|
const { theme, t } = useUi();
|
|
1254
1281
|
const dialogRef = useRef(null);
|
|
1282
|
+
const backdrop = useEnterExit({ visible });
|
|
1283
|
+
const panel = useEnterExit({ visible, fromScale: PANEL_ENTER_SCALE2 });
|
|
1284
|
+
const mounted = panel.mounted || backdrop.mounted;
|
|
1255
1285
|
useFocusTrap(dialogRef, visible);
|
|
1256
1286
|
useEscapeKey(visible, onClose);
|
|
1257
1287
|
useScrollLock(visible);
|
|
@@ -1262,7 +1292,13 @@ var Modal3 = ({
|
|
|
1262
1292
|
[theme.colors.surface, size]
|
|
1263
1293
|
);
|
|
1264
1294
|
const hasHeader = title !== void 0 || showClose;
|
|
1265
|
-
return /* @__PURE__ */ jsx(Modal, { transparent: true,
|
|
1295
|
+
return /* @__PURE__ */ jsx(Modal, { transparent: true, visible: mounted, onRequestClose: onClose, children: /* @__PURE__ */ jsxs(View, { style: styles11.overlay, children: [
|
|
1296
|
+
/* @__PURE__ */ jsx(
|
|
1297
|
+
Animated.View,
|
|
1298
|
+
{
|
|
1299
|
+
style: [StyleSheet.absoluteFill, styles11.scrim, { opacity: backdrop.style.opacity }]
|
|
1300
|
+
}
|
|
1301
|
+
),
|
|
1266
1302
|
/* @__PURE__ */ jsx(
|
|
1267
1303
|
TouchableOpacity,
|
|
1268
1304
|
{
|
|
@@ -1277,13 +1313,13 @@ var Modal3 = ({
|
|
|
1277
1313
|
}
|
|
1278
1314
|
),
|
|
1279
1315
|
/* @__PURE__ */ jsxs(
|
|
1280
|
-
View,
|
|
1316
|
+
Animated.View,
|
|
1281
1317
|
{
|
|
1282
1318
|
ref: dialogRef,
|
|
1283
1319
|
accessibilityViewIsModal: true,
|
|
1284
1320
|
"aria-label": accessibleName,
|
|
1285
1321
|
role: "dialog",
|
|
1286
|
-
style: dialogStyle,
|
|
1322
|
+
style: [dialogStyle, panel.style],
|
|
1287
1323
|
testID,
|
|
1288
1324
|
children: [
|
|
1289
1325
|
hasHeader ? /* @__PURE__ */ jsxs(View, { style: styles11.headerRow, children: [
|
|
@@ -1380,26 +1416,6 @@ function useAccordionContext() {
|
|
|
1380
1416
|
}
|
|
1381
1417
|
return value;
|
|
1382
1418
|
}
|
|
1383
|
-
var androidEnabled = false;
|
|
1384
|
-
function enableAndroidLayoutAnimationOnce() {
|
|
1385
|
-
if (androidEnabled) return;
|
|
1386
|
-
androidEnabled = true;
|
|
1387
|
-
const isAndroid = Platform.OS === "android";
|
|
1388
|
-
const setter = UIManager.setLayoutAnimationEnabledExperimental;
|
|
1389
|
-
if (isAndroid && typeof setter === "function") {
|
|
1390
|
-
setter(true);
|
|
1391
|
-
}
|
|
1392
|
-
}
|
|
1393
|
-
function animateNextLayout() {
|
|
1394
|
-
if (prefersReducedMotion()) return;
|
|
1395
|
-
enableAndroidLayoutAnimationOnce();
|
|
1396
|
-
const configure = LayoutAnimation.configureNext;
|
|
1397
|
-
if (typeof configure !== "function") return;
|
|
1398
|
-
try {
|
|
1399
|
-
configure(LayoutAnimation.Presets.easeInEaseOut);
|
|
1400
|
-
} catch {
|
|
1401
|
-
}
|
|
1402
|
-
}
|
|
1403
1419
|
var BOXED_GAP = 12;
|
|
1404
1420
|
var styles13 = StyleSheet.create({
|
|
1405
1421
|
container: { alignSelf: "stretch" },
|
|
@@ -1440,7 +1456,6 @@ var Accordion = ({
|
|
|
1440
1456
|
);
|
|
1441
1457
|
const toggle = useCallback(
|
|
1442
1458
|
(id) => {
|
|
1443
|
-
animateNextLayout();
|
|
1444
1459
|
const next = new Set(openSet);
|
|
1445
1460
|
const willOpen = !next.has(id);
|
|
1446
1461
|
if (!allowMultiple) next.clear();
|
|
@@ -1627,7 +1642,7 @@ var AccordionItem = ({
|
|
|
1627
1642
|
]
|
|
1628
1643
|
}
|
|
1629
1644
|
),
|
|
1630
|
-
expanded
|
|
1645
|
+
/* @__PURE__ */ jsx(Collapse, { open: expanded, testID: `${headerTestID}-collapse`, children: /* @__PURE__ */ jsx(
|
|
1631
1646
|
View,
|
|
1632
1647
|
{
|
|
1633
1648
|
accessibilityLabel: resolvedLabel,
|
|
@@ -1637,7 +1652,7 @@ var AccordionItem = ({
|
|
|
1637
1652
|
testID: bodyTestID,
|
|
1638
1653
|
children
|
|
1639
1654
|
}
|
|
1640
|
-
)
|
|
1655
|
+
) })
|
|
1641
1656
|
] });
|
|
1642
1657
|
};
|
|
1643
1658
|
|