@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.js
CHANGED
|
@@ -4,8 +4,10 @@ var React8 = require('react');
|
|
|
4
4
|
var reactNative = require('react-native');
|
|
5
5
|
var uiFeedback = require('@dloizides/ui-feedback');
|
|
6
6
|
var jsxRuntime = require('react/jsx-runtime');
|
|
7
|
+
var a11y = require('@dloizides/a11y');
|
|
7
8
|
var reactDom = require('react-dom');
|
|
8
9
|
var uiIcons = require('@dloizides/ui-icons');
|
|
10
|
+
var rnWebHooks = require('@dloizides/rn-web-hooks');
|
|
9
11
|
|
|
10
12
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
13
|
|
|
@@ -670,7 +672,6 @@ function useResolvedDropdownVariant(explicit) {
|
|
|
670
672
|
const { width } = reactNative.useWindowDimensions();
|
|
671
673
|
return resolveDropdownVariant(explicit, width, reactNative.Platform.OS);
|
|
672
674
|
}
|
|
673
|
-
var IS_WEB3 = reactNative.Platform.OS === "web";
|
|
674
675
|
var BORDER_RADIUS3 = 8;
|
|
675
676
|
var BORDER_WIDTH4 = 1;
|
|
676
677
|
var BODY_FONT_SIZE2 = 14;
|
|
@@ -679,21 +680,8 @@ var MODAL_MIN_WIDTH = 200;
|
|
|
679
680
|
var MODAL_MAX_HEIGHT = 300;
|
|
680
681
|
var CONTAINER_PADDING_H = 12;
|
|
681
682
|
var CONTAINER_PADDING_V = 10;
|
|
682
|
-
var SR_ONLY_SIZE = 1;
|
|
683
|
-
var SR_ONLY_OFFSET = -1;
|
|
684
|
-
function buildHintProps(hint, hintId) {
|
|
685
|
-
return IS_WEB3 ? { "aria-describedby": hintId } : { accessibilityHint: hint };
|
|
686
|
-
}
|
|
687
683
|
var styles8 = reactNative.StyleSheet.create({
|
|
688
684
|
anchor: { position: "relative" },
|
|
689
|
-
srOnly: {
|
|
690
|
-
position: "absolute",
|
|
691
|
-
width: SR_ONLY_SIZE,
|
|
692
|
-
height: SR_ONLY_SIZE,
|
|
693
|
-
margin: SR_ONLY_OFFSET,
|
|
694
|
-
padding: 0,
|
|
695
|
-
overflow: "hidden"
|
|
696
|
-
},
|
|
697
685
|
container: {
|
|
698
686
|
borderWidth: BORDER_WIDTH4,
|
|
699
687
|
borderRadius: BORDER_RADIUS3,
|
|
@@ -731,7 +719,13 @@ var ModalDropdown = ({
|
|
|
731
719
|
const resolvedVariant = useResolvedDropdownVariant(variant);
|
|
732
720
|
const isMenu = resolvedVariant === "menu" /* Menu */;
|
|
733
721
|
const [isOpen, setIsOpen] = React8.useState(false);
|
|
734
|
-
const
|
|
722
|
+
const { a11yProps, hintNode } = a11y.useA11y({
|
|
723
|
+
label: accessibilityLabel,
|
|
724
|
+
hint: accessibilityHint,
|
|
725
|
+
role: "button",
|
|
726
|
+
state: { expanded: isOpen },
|
|
727
|
+
testID
|
|
728
|
+
});
|
|
735
729
|
const anchorRef = React8.useRef(null);
|
|
736
730
|
const dialogRef = React8.useRef(null);
|
|
737
731
|
useFocusTrap(dialogRef, isOpen && !isMenu);
|
|
@@ -782,22 +776,10 @@ var ModalDropdown = ({
|
|
|
782
776
|
);
|
|
783
777
|
const keyExtractor = React8.useCallback((item) => String(item.value), []);
|
|
784
778
|
return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { ref: anchorRef, style: anchorStyle, children: [
|
|
785
|
-
/* @__PURE__ */ jsxRuntime.
|
|
786
|
-
reactNative.
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
...buildHintProps(accessibilityHint, hintId),
|
|
790
|
-
accessibilityLabel,
|
|
791
|
-
accessibilityRole: "button",
|
|
792
|
-
accessibilityState: { expanded: isOpen },
|
|
793
|
-
"aria-expanded": isOpen,
|
|
794
|
-
style: containerStyle,
|
|
795
|
-
testID,
|
|
796
|
-
onPress: handleToggle,
|
|
797
|
-
children: renderTrigger !== void 0 ? renderTrigger({ label: selectedLabel, isOpen }) : /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles8.selectedText, { color: colors.text }], children: selectedLabel })
|
|
798
|
-
}
|
|
799
|
-
),
|
|
800
|
-
IS_WEB3 ? /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { nativeID: hintId, style: styles8.srOnly, testID: `${testID}-hint`, children: accessibilityHint }) : null,
|
|
779
|
+
/* @__PURE__ */ jsxRuntime.jsxs(reactNative.TouchableOpacity, { ...a11yProps, style: containerStyle, onPress: handleToggle, children: [
|
|
780
|
+
renderTrigger !== void 0 ? renderTrigger({ label: selectedLabel, isOpen }) : /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles8.selectedText, { color: colors.text }], children: selectedLabel }),
|
|
781
|
+
hintNode
|
|
782
|
+
] }),
|
|
801
783
|
isMenu && isOpen ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
802
784
|
InlineMenu,
|
|
803
785
|
{
|
|
@@ -926,12 +908,8 @@ function enableAndroidLayoutAnimationOnce() {
|
|
|
926
908
|
setter(true);
|
|
927
909
|
}
|
|
928
910
|
}
|
|
929
|
-
function prefersReducedMotion() {
|
|
930
|
-
if (reactNative.Platform.OS !== "web" || typeof window === "undefined" || typeof window.matchMedia !== "function") return false;
|
|
931
|
-
return window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
932
|
-
}
|
|
933
911
|
function animateNextLayout() {
|
|
934
|
-
if (prefersReducedMotion()) return;
|
|
912
|
+
if (rnWebHooks.prefersReducedMotion()) return;
|
|
935
913
|
enableAndroidLayoutAnimationOnce();
|
|
936
914
|
const configure = reactNative.LayoutAnimation.configureNext;
|
|
937
915
|
if (typeof configure !== "function") return;
|
|
@@ -1055,10 +1033,6 @@ var styles11 = reactNative.StyleSheet.create({
|
|
|
1055
1033
|
});
|
|
1056
1034
|
var ACTIVATION_KEYS = ["Enter", " ", "Spacebar"];
|
|
1057
1035
|
var INSTANT_DURATION_MS = 0;
|
|
1058
|
-
function prefersReducedMotion2() {
|
|
1059
|
-
if (reactNative.Platform.OS !== "web" || typeof window === "undefined" || typeof window.matchMedia !== "function") return false;
|
|
1060
|
-
return window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
1061
|
-
}
|
|
1062
1036
|
var AccordionItem = ({
|
|
1063
1037
|
id,
|
|
1064
1038
|
title,
|
|
@@ -1080,14 +1054,15 @@ var AccordionItem = ({
|
|
|
1080
1054
|
const bodyTestID = `${headerTestID}-body`;
|
|
1081
1055
|
const chevronTestID = `${headerTestID}-chevron`;
|
|
1082
1056
|
const [rotation] = React8.useState(() => new reactNative.Animated.Value(expanded ? ROTATE_EXPANDED : ROTATE_COLLAPSED));
|
|
1057
|
+
const reducedMotion = rnWebHooks.useReducedMotion();
|
|
1083
1058
|
React8.useEffect(() => {
|
|
1084
1059
|
reactNative.Animated.timing(rotation, {
|
|
1085
1060
|
toValue: expanded ? ROTATE_EXPANDED : ROTATE_COLLAPSED,
|
|
1086
|
-
duration:
|
|
1061
|
+
duration: reducedMotion ? INSTANT_DURATION_MS : ROTATE_DURATION_MS,
|
|
1087
1062
|
easing: reactNative.Easing.out(reactNative.Easing.ease),
|
|
1088
1063
|
useNativeDriver: reactNative.Platform.OS !== "web"
|
|
1089
1064
|
}).start();
|
|
1090
|
-
}, [expanded, rotation]);
|
|
1065
|
+
}, [expanded, rotation, reducedMotion]);
|
|
1091
1066
|
const rotate = rotation.interpolate({
|
|
1092
1067
|
inputRange: [ROTATE_COLLAPSED, ROTATE_EXPANDED],
|
|
1093
1068
|
outputRange: [COLLAPSED_DEG, boxed ? BOXED_EXPANDED_DEG : PLAIN_EXPANDED_DEG]
|
|
@@ -1205,7 +1180,7 @@ function formatUrlForDisplay(value) {
|
|
|
1205
1180
|
return trimmed.length > 0 ? trimmed : value;
|
|
1206
1181
|
}
|
|
1207
1182
|
var UNMEASURED = 0;
|
|
1208
|
-
var
|
|
1183
|
+
var IS_WEB3 = reactNative.Platform.OS === "web";
|
|
1209
1184
|
function measureParentInnerWidth(node) {
|
|
1210
1185
|
const parent = node.parentElement;
|
|
1211
1186
|
if (parent === null) return UNMEASURED;
|
|
@@ -1217,12 +1192,12 @@ function useAvailableWidth() {
|
|
|
1217
1192
|
const [width, setWidth] = React8.useState(UNMEASURED);
|
|
1218
1193
|
const nodeRef = React8.useRef(null);
|
|
1219
1194
|
const measureRef = React8.useCallback((node) => {
|
|
1220
|
-
if (!
|
|
1195
|
+
if (!IS_WEB3) return;
|
|
1221
1196
|
nodeRef.current = node;
|
|
1222
1197
|
if (nodeRef.current !== null) setWidth(measureParentInnerWidth(nodeRef.current));
|
|
1223
1198
|
}, []);
|
|
1224
1199
|
React8.useEffect(() => {
|
|
1225
|
-
if (!
|
|
1200
|
+
if (!IS_WEB3) return void 0;
|
|
1226
1201
|
const remeasure = () => {
|
|
1227
1202
|
const node = nodeRef.current;
|
|
1228
1203
|
if (node !== null) setWidth(measureParentInnerWidth(node));
|
|
@@ -1231,7 +1206,7 @@ function useAvailableWidth() {
|
|
|
1231
1206
|
return () => window.removeEventListener("resize", remeasure);
|
|
1232
1207
|
}, []);
|
|
1233
1208
|
const onLayout = React8.useCallback((event) => {
|
|
1234
|
-
if (
|
|
1209
|
+
if (IS_WEB3) return;
|
|
1235
1210
|
setWidth(event.nativeEvent.layout.width);
|
|
1236
1211
|
}, []);
|
|
1237
1212
|
return { width, measureRef, onLayout };
|