@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 +38 -0
- package/dist/index.js +60 -40
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +63 -43
- 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
|
-
import { useA11y } from '@dloizides/a11y';
|
|
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,13 +668,20 @@ 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: {
|
|
668
676
|
borderWidth: BORDER_WIDTH4,
|
|
669
677
|
borderRadius: BORDER_RADIUS3,
|
|
670
678
|
paddingHorizontal: CONTAINER_PADDING_H,
|
|
671
|
-
paddingVertical: CONTAINER_PADDING_V
|
|
679
|
+
paddingVertical: CONTAINER_PADDING_V,
|
|
680
|
+
// Match the shared control height used by @dloizides/ui-forms inputs (same MIN_TOUCH_TARGET_PX
|
|
681
|
+
// floor from @dloizides/a11y), so a select trigger and a text/typeahead field sitting side by
|
|
682
|
+
// side in a filter bar are exactly the same height. Centre the label within that floor.
|
|
683
|
+
minHeight: MIN_TOUCH_TARGET_PX,
|
|
684
|
+
justifyContent: "center"
|
|
672
685
|
},
|
|
673
686
|
// Caret variant: a row with the label leading and the caret pinned to the trailing edge, at a
|
|
674
687
|
// phone-friendly minimum height. Only applied when `showCaret` is set, so field dropdowns are
|
|
@@ -736,6 +749,16 @@ var ModalDropdown = ({
|
|
|
736
749
|
const anchorRef = useRef(null);
|
|
737
750
|
const dialogRef = useRef(null);
|
|
738
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
|
+
});
|
|
739
762
|
const selectedLabel = useMemo(() => {
|
|
740
763
|
const found = options.find((opt) => opt.value === value);
|
|
741
764
|
return found?.label ?? t(LAYOUT_I18N.selectPlaceholder);
|
|
@@ -810,10 +833,11 @@ var ModalDropdown = ({
|
|
|
810
833
|
] }) : /* @__PURE__ */ jsx(Text, { style: [styles7.selectedText, { color: colors.text }], children: selectedLabel }),
|
|
811
834
|
hintNode
|
|
812
835
|
] }),
|
|
813
|
-
isMenu &&
|
|
836
|
+
isMenu && menuAnim.mounted ? /* @__PURE__ */ jsx(
|
|
814
837
|
InlineMenu,
|
|
815
838
|
{
|
|
816
839
|
accessibilityLabel,
|
|
840
|
+
animatedStyle: menuAnim.style,
|
|
817
841
|
containerRef: anchorRef,
|
|
818
842
|
menuMinWidth,
|
|
819
843
|
optionTestID: optionTestIDFor,
|
|
@@ -824,7 +848,7 @@ var ModalDropdown = ({
|
|
|
824
848
|
onSelect: handleSelect
|
|
825
849
|
}
|
|
826
850
|
) : null,
|
|
827
|
-
!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: [
|
|
828
852
|
/* @__PURE__ */ jsx(
|
|
829
853
|
TouchableOpacity,
|
|
830
854
|
{
|
|
@@ -839,13 +863,13 @@ var ModalDropdown = ({
|
|
|
839
863
|
}
|
|
840
864
|
),
|
|
841
865
|
/* @__PURE__ */ jsx(
|
|
842
|
-
View,
|
|
866
|
+
Animated.View,
|
|
843
867
|
{
|
|
844
868
|
ref: dialogRef,
|
|
845
869
|
accessibilityViewIsModal: true,
|
|
846
870
|
"aria-label": accessibilityLabel,
|
|
847
871
|
role: "dialog",
|
|
848
|
-
style: modalContentStyle,
|
|
872
|
+
style: [modalContentStyle, modalAnim.style],
|
|
849
873
|
children: /* @__PURE__ */ jsx(FlatList, { data: [...options], keyExtractor, renderItem: renderModalOption })
|
|
850
874
|
}
|
|
851
875
|
)
|
|
@@ -1111,7 +1135,9 @@ var UpgradePrompt = ({
|
|
|
1111
1135
|
);
|
|
1112
1136
|
};
|
|
1113
1137
|
var CLOSE_ICON_SIZE = 18;
|
|
1138
|
+
var PANEL_ENTER_SCALE = 0.96;
|
|
1114
1139
|
var styles10 = StyleSheet.create({
|
|
1140
|
+
animatedFill: { flex: 1 },
|
|
1115
1141
|
container: {
|
|
1116
1142
|
flex: 1,
|
|
1117
1143
|
padding: 16
|
|
@@ -1135,6 +1161,7 @@ var ModalShell = ({
|
|
|
1135
1161
|
showClose = true
|
|
1136
1162
|
}) => {
|
|
1137
1163
|
const { theme, t } = useUi();
|
|
1164
|
+
const { style: sheetStyle, mounted } = useEnterExit({ visible, fromScale: PANEL_ENTER_SCALE });
|
|
1138
1165
|
const containerStyle = React10.useMemo(
|
|
1139
1166
|
() => [styles10.container, { backgroundColor: theme.colors.background }, contentStyle],
|
|
1140
1167
|
[theme.colors.background, contentStyle]
|
|
@@ -1144,11 +1171,11 @@ var ModalShell = ({
|
|
|
1144
1171
|
return /* @__PURE__ */ jsx(
|
|
1145
1172
|
Modal,
|
|
1146
1173
|
{
|
|
1147
|
-
|
|
1174
|
+
transparent: true,
|
|
1148
1175
|
testID: LAYOUT_TEST_IDS.modalShell,
|
|
1149
|
-
visible,
|
|
1176
|
+
visible: mounted,
|
|
1150
1177
|
onRequestClose: onCancel,
|
|
1151
|
-
children: /* @__PURE__ */ jsxs(
|
|
1178
|
+
children: /* @__PURE__ */ jsx(Animated.View, { style: [styles10.animatedFill, sheetStyle], children: /* @__PURE__ */ jsxs(
|
|
1152
1179
|
ScrollView,
|
|
1153
1180
|
{
|
|
1154
1181
|
accessibilityViewIsModal: true,
|
|
@@ -1174,7 +1201,7 @@ var ModalShell = ({
|
|
|
1174
1201
|
children
|
|
1175
1202
|
]
|
|
1176
1203
|
}
|
|
1177
|
-
)
|
|
1204
|
+
) })
|
|
1178
1205
|
}
|
|
1179
1206
|
);
|
|
1180
1207
|
};
|
|
@@ -1208,15 +1235,20 @@ var HEADER_GAP = 12;
|
|
|
1208
1235
|
var FOOTER_MARGIN = 16;
|
|
1209
1236
|
var HEADER_MARGIN = 12;
|
|
1210
1237
|
var DIALOG_MAX_HEIGHT = "90%";
|
|
1238
|
+
var PANEL_ENTER_SCALE2 = 0.96;
|
|
1211
1239
|
var SIZE_MAX_WIDTH = { sm: 360, md: 480, lg: 640 };
|
|
1212
1240
|
var styles11 = StyleSheet.create({
|
|
1213
1241
|
overlay: {
|
|
1214
1242
|
flex: 1,
|
|
1215
1243
|
justifyContent: "center",
|
|
1216
1244
|
alignItems: "center",
|
|
1217
|
-
padding: OVERLAY_PADDING
|
|
1218
|
-
backgroundColor: MODAL_OVERLAY_COLOR
|
|
1245
|
+
padding: OVERLAY_PADDING
|
|
1219
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" },
|
|
1220
1252
|
dialog: {
|
|
1221
1253
|
width: "100%",
|
|
1222
1254
|
borderRadius: DIALOG_RADIUS,
|
|
@@ -1247,6 +1279,9 @@ var Modal3 = ({
|
|
|
1247
1279
|
}) => {
|
|
1248
1280
|
const { theme, t } = useUi();
|
|
1249
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;
|
|
1250
1285
|
useFocusTrap(dialogRef, visible);
|
|
1251
1286
|
useEscapeKey(visible, onClose);
|
|
1252
1287
|
useScrollLock(visible);
|
|
@@ -1257,7 +1292,13 @@ var Modal3 = ({
|
|
|
1257
1292
|
[theme.colors.surface, size]
|
|
1258
1293
|
);
|
|
1259
1294
|
const hasHeader = title !== void 0 || showClose;
|
|
1260
|
-
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
|
+
),
|
|
1261
1302
|
/* @__PURE__ */ jsx(
|
|
1262
1303
|
TouchableOpacity,
|
|
1263
1304
|
{
|
|
@@ -1272,13 +1313,13 @@ var Modal3 = ({
|
|
|
1272
1313
|
}
|
|
1273
1314
|
),
|
|
1274
1315
|
/* @__PURE__ */ jsxs(
|
|
1275
|
-
View,
|
|
1316
|
+
Animated.View,
|
|
1276
1317
|
{
|
|
1277
1318
|
ref: dialogRef,
|
|
1278
1319
|
accessibilityViewIsModal: true,
|
|
1279
1320
|
"aria-label": accessibleName,
|
|
1280
1321
|
role: "dialog",
|
|
1281
|
-
style: dialogStyle,
|
|
1322
|
+
style: [dialogStyle, panel.style],
|
|
1282
1323
|
testID,
|
|
1283
1324
|
children: [
|
|
1284
1325
|
hasHeader ? /* @__PURE__ */ jsxs(View, { style: styles11.headerRow, children: [
|
|
@@ -1375,26 +1416,6 @@ function useAccordionContext() {
|
|
|
1375
1416
|
}
|
|
1376
1417
|
return value;
|
|
1377
1418
|
}
|
|
1378
|
-
var androidEnabled = false;
|
|
1379
|
-
function enableAndroidLayoutAnimationOnce() {
|
|
1380
|
-
if (androidEnabled) return;
|
|
1381
|
-
androidEnabled = true;
|
|
1382
|
-
const isAndroid = Platform.OS === "android";
|
|
1383
|
-
const setter = UIManager.setLayoutAnimationEnabledExperimental;
|
|
1384
|
-
if (isAndroid && typeof setter === "function") {
|
|
1385
|
-
setter(true);
|
|
1386
|
-
}
|
|
1387
|
-
}
|
|
1388
|
-
function animateNextLayout() {
|
|
1389
|
-
if (prefersReducedMotion()) return;
|
|
1390
|
-
enableAndroidLayoutAnimationOnce();
|
|
1391
|
-
const configure = LayoutAnimation.configureNext;
|
|
1392
|
-
if (typeof configure !== "function") return;
|
|
1393
|
-
try {
|
|
1394
|
-
configure(LayoutAnimation.Presets.easeInEaseOut);
|
|
1395
|
-
} catch {
|
|
1396
|
-
}
|
|
1397
|
-
}
|
|
1398
1419
|
var BOXED_GAP = 12;
|
|
1399
1420
|
var styles13 = StyleSheet.create({
|
|
1400
1421
|
container: { alignSelf: "stretch" },
|
|
@@ -1435,7 +1456,6 @@ var Accordion = ({
|
|
|
1435
1456
|
);
|
|
1436
1457
|
const toggle = useCallback(
|
|
1437
1458
|
(id) => {
|
|
1438
|
-
animateNextLayout();
|
|
1439
1459
|
const next = new Set(openSet);
|
|
1440
1460
|
const willOpen = !next.has(id);
|
|
1441
1461
|
if (!allowMultiple) next.clear();
|
|
@@ -1622,7 +1642,7 @@ var AccordionItem = ({
|
|
|
1622
1642
|
]
|
|
1623
1643
|
}
|
|
1624
1644
|
),
|
|
1625
|
-
expanded
|
|
1645
|
+
/* @__PURE__ */ jsx(Collapse, { open: expanded, testID: `${headerTestID}-collapse`, children: /* @__PURE__ */ jsx(
|
|
1626
1646
|
View,
|
|
1627
1647
|
{
|
|
1628
1648
|
accessibilityLabel: resolvedLabel,
|
|
@@ -1632,7 +1652,7 @@ var AccordionItem = ({
|
|
|
1632
1652
|
testID: bodyTestID,
|
|
1633
1653
|
children
|
|
1634
1654
|
}
|
|
1635
|
-
)
|
|
1655
|
+
) })
|
|
1636
1656
|
] });
|
|
1637
1657
|
};
|
|
1638
1658
|
|