@dloizides/ui-layout 1.12.2 → 1.13.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/dist/index.js +21 -46
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +20 -45
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -2
package/dist/index.mjs
CHANGED
|
@@ -2,8 +2,10 @@ import React8, { createContext, useMemo, useRef, useEffect, useState, useCallbac
|
|
|
2
2
|
import { StyleSheet, Platform, View, Text, Pressable, TouchableOpacity, Modal, FlatList, ScrollView, Animated, Easing, useWindowDimensions, LayoutAnimation, UIManager } from 'react-native';
|
|
3
3
|
import { MODAL_OVERLAY_COLOR, useUi } from '@dloizides/ui-feedback';
|
|
4
4
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
5
|
+
import { useA11y } from '@dloizides/a11y';
|
|
5
6
|
import { createPortal } from 'react-dom';
|
|
6
7
|
import { SvgIcon } from '@dloizides/ui-icons';
|
|
8
|
+
import { useReducedMotion, prefersReducedMotion } from '@dloizides/rn-web-hooks';
|
|
7
9
|
|
|
8
10
|
// src/Section/Section.tsx
|
|
9
11
|
var styles = StyleSheet.create({
|
|
@@ -664,7 +666,6 @@ function useResolvedDropdownVariant(explicit) {
|
|
|
664
666
|
const { width } = useWindowDimensions();
|
|
665
667
|
return resolveDropdownVariant(explicit, width, Platform.OS);
|
|
666
668
|
}
|
|
667
|
-
var IS_WEB3 = Platform.OS === "web";
|
|
668
669
|
var BORDER_RADIUS3 = 8;
|
|
669
670
|
var BORDER_WIDTH4 = 1;
|
|
670
671
|
var BODY_FONT_SIZE2 = 14;
|
|
@@ -673,21 +674,8 @@ var MODAL_MIN_WIDTH = 200;
|
|
|
673
674
|
var MODAL_MAX_HEIGHT = 300;
|
|
674
675
|
var CONTAINER_PADDING_H = 12;
|
|
675
676
|
var CONTAINER_PADDING_V = 10;
|
|
676
|
-
var SR_ONLY_SIZE = 1;
|
|
677
|
-
var SR_ONLY_OFFSET = -1;
|
|
678
|
-
function buildHintProps(hint, hintId) {
|
|
679
|
-
return IS_WEB3 ? { "aria-describedby": hintId } : { accessibilityHint: hint };
|
|
680
|
-
}
|
|
681
677
|
var styles8 = StyleSheet.create({
|
|
682
678
|
anchor: { position: "relative" },
|
|
683
|
-
srOnly: {
|
|
684
|
-
position: "absolute",
|
|
685
|
-
width: SR_ONLY_SIZE,
|
|
686
|
-
height: SR_ONLY_SIZE,
|
|
687
|
-
margin: SR_ONLY_OFFSET,
|
|
688
|
-
padding: 0,
|
|
689
|
-
overflow: "hidden"
|
|
690
|
-
},
|
|
691
679
|
container: {
|
|
692
680
|
borderWidth: BORDER_WIDTH4,
|
|
693
681
|
borderRadius: BORDER_RADIUS3,
|
|
@@ -725,7 +713,13 @@ var ModalDropdown = ({
|
|
|
725
713
|
const resolvedVariant = useResolvedDropdownVariant(variant);
|
|
726
714
|
const isMenu = resolvedVariant === "menu" /* Menu */;
|
|
727
715
|
const [isOpen, setIsOpen] = useState(false);
|
|
728
|
-
const
|
|
716
|
+
const { a11yProps, hintNode } = useA11y({
|
|
717
|
+
label: accessibilityLabel,
|
|
718
|
+
hint: accessibilityHint,
|
|
719
|
+
role: "button",
|
|
720
|
+
state: { expanded: isOpen },
|
|
721
|
+
testID
|
|
722
|
+
});
|
|
729
723
|
const anchorRef = useRef(null);
|
|
730
724
|
const dialogRef = useRef(null);
|
|
731
725
|
useFocusTrap(dialogRef, isOpen && !isMenu);
|
|
@@ -776,22 +770,10 @@ var ModalDropdown = ({
|
|
|
776
770
|
);
|
|
777
771
|
const keyExtractor = useCallback((item) => String(item.value), []);
|
|
778
772
|
return /* @__PURE__ */ jsxs(View, { ref: anchorRef, style: anchorStyle, children: [
|
|
779
|
-
/* @__PURE__ */
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
...buildHintProps(accessibilityHint, hintId),
|
|
784
|
-
accessibilityLabel,
|
|
785
|
-
accessibilityRole: "button",
|
|
786
|
-
accessibilityState: { expanded: isOpen },
|
|
787
|
-
"aria-expanded": isOpen,
|
|
788
|
-
style: containerStyle,
|
|
789
|
-
testID,
|
|
790
|
-
onPress: handleToggle,
|
|
791
|
-
children: renderTrigger !== void 0 ? renderTrigger({ label: selectedLabel, isOpen }) : /* @__PURE__ */ jsx(Text, { style: [styles8.selectedText, { color: colors.text }], children: selectedLabel })
|
|
792
|
-
}
|
|
793
|
-
),
|
|
794
|
-
IS_WEB3 ? /* @__PURE__ */ jsx(Text, { nativeID: hintId, style: styles8.srOnly, testID: `${testID}-hint`, children: accessibilityHint }) : null,
|
|
773
|
+
/* @__PURE__ */ jsxs(TouchableOpacity, { ...a11yProps, style: containerStyle, onPress: handleToggle, children: [
|
|
774
|
+
renderTrigger !== void 0 ? renderTrigger({ label: selectedLabel, isOpen }) : /* @__PURE__ */ jsx(Text, { style: [styles8.selectedText, { color: colors.text }], children: selectedLabel }),
|
|
775
|
+
hintNode
|
|
776
|
+
] }),
|
|
795
777
|
isMenu && isOpen ? /* @__PURE__ */ jsx(
|
|
796
778
|
InlineMenu,
|
|
797
779
|
{
|
|
@@ -920,10 +902,6 @@ function enableAndroidLayoutAnimationOnce() {
|
|
|
920
902
|
setter(true);
|
|
921
903
|
}
|
|
922
904
|
}
|
|
923
|
-
function prefersReducedMotion() {
|
|
924
|
-
if (Platform.OS !== "web" || typeof window === "undefined" || typeof window.matchMedia !== "function") return false;
|
|
925
|
-
return window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
926
|
-
}
|
|
927
905
|
function animateNextLayout() {
|
|
928
906
|
if (prefersReducedMotion()) return;
|
|
929
907
|
enableAndroidLayoutAnimationOnce();
|
|
@@ -1049,10 +1027,6 @@ var styles11 = StyleSheet.create({
|
|
|
1049
1027
|
});
|
|
1050
1028
|
var ACTIVATION_KEYS = ["Enter", " ", "Spacebar"];
|
|
1051
1029
|
var INSTANT_DURATION_MS = 0;
|
|
1052
|
-
function prefersReducedMotion2() {
|
|
1053
|
-
if (Platform.OS !== "web" || typeof window === "undefined" || typeof window.matchMedia !== "function") return false;
|
|
1054
|
-
return window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
1055
|
-
}
|
|
1056
1030
|
var AccordionItem = ({
|
|
1057
1031
|
id,
|
|
1058
1032
|
title,
|
|
@@ -1074,14 +1048,15 @@ var AccordionItem = ({
|
|
|
1074
1048
|
const bodyTestID = `${headerTestID}-body`;
|
|
1075
1049
|
const chevronTestID = `${headerTestID}-chevron`;
|
|
1076
1050
|
const [rotation] = useState(() => new Animated.Value(expanded ? ROTATE_EXPANDED : ROTATE_COLLAPSED));
|
|
1051
|
+
const reducedMotion = useReducedMotion();
|
|
1077
1052
|
useEffect(() => {
|
|
1078
1053
|
Animated.timing(rotation, {
|
|
1079
1054
|
toValue: expanded ? ROTATE_EXPANDED : ROTATE_COLLAPSED,
|
|
1080
|
-
duration:
|
|
1055
|
+
duration: reducedMotion ? INSTANT_DURATION_MS : ROTATE_DURATION_MS,
|
|
1081
1056
|
easing: Easing.out(Easing.ease),
|
|
1082
1057
|
useNativeDriver: Platform.OS !== "web"
|
|
1083
1058
|
}).start();
|
|
1084
|
-
}, [expanded, rotation]);
|
|
1059
|
+
}, [expanded, rotation, reducedMotion]);
|
|
1085
1060
|
const rotate = rotation.interpolate({
|
|
1086
1061
|
inputRange: [ROTATE_COLLAPSED, ROTATE_EXPANDED],
|
|
1087
1062
|
outputRange: [COLLAPSED_DEG, boxed ? BOXED_EXPANDED_DEG : PLAIN_EXPANDED_DEG]
|
|
@@ -1199,7 +1174,7 @@ function formatUrlForDisplay(value) {
|
|
|
1199
1174
|
return trimmed.length > 0 ? trimmed : value;
|
|
1200
1175
|
}
|
|
1201
1176
|
var UNMEASURED = 0;
|
|
1202
|
-
var
|
|
1177
|
+
var IS_WEB3 = Platform.OS === "web";
|
|
1203
1178
|
function measureParentInnerWidth(node) {
|
|
1204
1179
|
const parent = node.parentElement;
|
|
1205
1180
|
if (parent === null) return UNMEASURED;
|
|
@@ -1211,12 +1186,12 @@ function useAvailableWidth() {
|
|
|
1211
1186
|
const [width, setWidth] = useState(UNMEASURED);
|
|
1212
1187
|
const nodeRef = useRef(null);
|
|
1213
1188
|
const measureRef = useCallback((node) => {
|
|
1214
|
-
if (!
|
|
1189
|
+
if (!IS_WEB3) return;
|
|
1215
1190
|
nodeRef.current = node;
|
|
1216
1191
|
if (nodeRef.current !== null) setWidth(measureParentInnerWidth(nodeRef.current));
|
|
1217
1192
|
}, []);
|
|
1218
1193
|
useEffect(() => {
|
|
1219
|
-
if (!
|
|
1194
|
+
if (!IS_WEB3) return void 0;
|
|
1220
1195
|
const remeasure = () => {
|
|
1221
1196
|
const node = nodeRef.current;
|
|
1222
1197
|
if (node !== null) setWidth(measureParentInnerWidth(node));
|
|
@@ -1225,7 +1200,7 @@ function useAvailableWidth() {
|
|
|
1225
1200
|
return () => window.removeEventListener("resize", remeasure);
|
|
1226
1201
|
}, []);
|
|
1227
1202
|
const onLayout = useCallback((event) => {
|
|
1228
|
-
if (
|
|
1203
|
+
if (IS_WEB3) return;
|
|
1229
1204
|
setWidth(event.nativeEvent.layout.width);
|
|
1230
1205
|
}, []);
|
|
1231
1206
|
return { width, measureRef, onLayout };
|