@utilitywarehouse/hearth-react-native 0.28.6 → 0.29.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/.storybook/preview.tsx +7 -4
- package/.turbo/turbo-build.log +1 -1
- package/.turbo/turbo-lint.log +15 -18
- package/CHANGELOG.md +44 -0
- package/build/components/Combobox/Combobox.js +1 -1
- package/build/components/Modal/Modal.d.ts +1 -1
- package/build/components/Modal/Modal.js +6 -95
- package/build/components/Modal/Modal.props.d.ts +2 -31
- package/build/components/Modal/Modal.shared.types.d.ts +22 -0
- package/build/components/Modal/Modal.web.d.ts +1 -1
- package/build/components/Modal/Modal.web.js +6 -71
- package/build/components/NavModal/NavModal.d.ts +3 -0
- package/build/components/NavModal/NavModal.js +190 -0
- package/build/components/NavModal/NavModal.props.d.ts +15 -0
- package/build/components/NavModal/NavModal.props.js +1 -0
- package/build/components/NavModal/index.d.ts +2 -0
- package/build/components/NavModal/index.js +1 -0
- package/build/components/Select/Select.js +1 -1
- package/build/components/index.d.ts +2 -1
- package/build/components/index.js +2 -1
- package/docs/changelog.mdx +34 -0
- package/docs/components/AllComponents.web.tsx +709 -689
- package/package.json +3 -1
- package/src/components/Combobox/Combobox.tsx +1 -1
- package/src/components/Modal/Modal.docs.mdx +5 -122
- package/src/components/Modal/Modal.props.ts +2 -34
- package/src/components/Modal/Modal.shared.types.ts +23 -0
- package/src/components/Modal/Modal.stories.tsx +0 -1
- package/src/components/Modal/Modal.tsx +11 -174
- package/src/components/Modal/Modal.web.tsx +29 -127
- package/src/components/NavModal/NavModal.docs.mdx +178 -0
- package/src/components/NavModal/NavModal.figma.tsx +13 -0
- package/src/components/NavModal/NavModal.props.ts +23 -0
- package/src/components/NavModal/NavModal.stories.tsx +131 -0
- package/src/components/NavModal/NavModal.tsx +375 -0
- package/src/components/NavModal/index.ts +2 -0
- package/src/components/Select/Select.tsx +1 -1
- package/src/components/index.ts +3 -1
- package/build/components/SafeAreaView/SafeAreaView.d.ts +0 -5
- package/build/components/SafeAreaView/SafeAreaView.js +0 -117
- package/build/components/SafeAreaView/SafeAreaView.props.d.ts +0 -17
- package/build/components/SafeAreaView/index.d.ts +0 -2
- package/build/components/SafeAreaView/index.js +0 -1
- package/src/components/SafeAreaView/SafeAreaView.props.ts +0 -20
- package/src/components/SafeAreaView/SafeAreaView.tsx +0 -173
- package/src/components/SafeAreaView/index.ts +0 -2
- /package/build/components/{SafeAreaView/SafeAreaView.props.js → Modal/Modal.shared.types.js} +0 -0
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
import React, { forwardRef, useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
LayoutChangeEvent,
|
|
4
|
-
StyleSheet as RNStyleSheet,
|
|
5
|
-
useWindowDimensions,
|
|
6
|
-
View,
|
|
7
|
-
ViewStyle,
|
|
8
|
-
} from 'react-native';
|
|
9
|
-
import { UnistylesRuntime } from '../../core';
|
|
10
|
-
import SafeAreaViewProps, { SafeAreaEdge } from './SafeAreaView.props';
|
|
11
|
-
|
|
12
|
-
type EdgeInsets = Record<SafeAreaEdge, number>;
|
|
13
|
-
|
|
14
|
-
const DEFAULT_EDGES: SafeAreaEdge[] = ['top', 'right', 'bottom', 'left'];
|
|
15
|
-
const EMPTY_INSETS: EdgeInsets = { top: 0, right: 0, bottom: 0, left: 0 };
|
|
16
|
-
const EDGE_EPSILON = 1;
|
|
17
|
-
|
|
18
|
-
const getNumericStyleValue = (value: unknown): number => {
|
|
19
|
-
return typeof value === 'number' ? value : 0;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const getStyleInsetValue = (
|
|
23
|
-
style: ViewStyle | undefined,
|
|
24
|
-
mode: SafeAreaViewProps['mode'],
|
|
25
|
-
edge: SafeAreaEdge
|
|
26
|
-
): number => {
|
|
27
|
-
const prefix = mode === 'margin' ? 'margin' : 'padding';
|
|
28
|
-
|
|
29
|
-
if (!style) {
|
|
30
|
-
// No style specified at all; treat as zero inset for safe-area calculations.
|
|
31
|
-
return 0;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (edge === 'top') {
|
|
35
|
-
const raw = style[`${prefix}Top`] ?? style[`${prefix}Vertical`] ?? style[prefix];
|
|
36
|
-
if (raw == null) {
|
|
37
|
-
return 0;
|
|
38
|
-
}
|
|
39
|
-
return getNumericStyleValue(raw);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (edge === 'bottom') {
|
|
43
|
-
const raw = style[`${prefix}Bottom`] ?? style[`${prefix}Vertical`] ?? style[prefix];
|
|
44
|
-
if (raw == null) {
|
|
45
|
-
return 0;
|
|
46
|
-
}
|
|
47
|
-
return getNumericStyleValue(raw);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (edge === 'left') {
|
|
51
|
-
const raw = style[`${prefix}Left`] ?? style[`${prefix}Horizontal`] ?? style[prefix];
|
|
52
|
-
if (raw == null) {
|
|
53
|
-
return 0;
|
|
54
|
-
}
|
|
55
|
-
return getNumericStyleValue(raw);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const raw = style[`${prefix}Right`] ?? style[`${prefix}Horizontal`] ?? style[prefix];
|
|
59
|
-
if (raw == null) {
|
|
60
|
-
return 0;
|
|
61
|
-
}
|
|
62
|
-
return getNumericStyleValue(raw);
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
const SafeAreaView = forwardRef<View, SafeAreaViewProps>(
|
|
66
|
-
({ children, edges = DEFAULT_EDGES, mode = 'padding', onLayout, style, ...props }, ref) => {
|
|
67
|
-
const viewRef = useRef<View>(null);
|
|
68
|
-
const { width: windowWidth, height: windowHeight } = useWindowDimensions();
|
|
69
|
-
const [edgeInsets, setEdgeInsets] = useState<EdgeInsets>(EMPTY_INSETS);
|
|
70
|
-
|
|
71
|
-
const flattenedStyle = useMemo(
|
|
72
|
-
() => RNStyleSheet.flatten(style) as ViewStyle | undefined,
|
|
73
|
-
[style]
|
|
74
|
-
);
|
|
75
|
-
|
|
76
|
-
const updateEdgeInsets = useCallback(() => {
|
|
77
|
-
const currentView = viewRef.current;
|
|
78
|
-
|
|
79
|
-
if (!currentView) {
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
currentView.measureInWindow((x, y, width, height) => {
|
|
84
|
-
const runtimeInsets = UnistylesRuntime.insets ?? EMPTY_INSETS;
|
|
85
|
-
const nextEdgeInsets: EdgeInsets = {
|
|
86
|
-
top: edges.includes('top') ? Math.max(runtimeInsets.top - Math.max(y, 0), 0) : 0,
|
|
87
|
-
right: edges.includes('right')
|
|
88
|
-
? Math.max(runtimeInsets.right - Math.max(windowWidth - (x + width), 0), 0)
|
|
89
|
-
: 0,
|
|
90
|
-
bottom: edges.includes('bottom')
|
|
91
|
-
? Math.max(runtimeInsets.bottom - Math.max(windowHeight - (y + height), 0), 0)
|
|
92
|
-
: 0,
|
|
93
|
-
left: edges.includes('left') ? Math.max(runtimeInsets.left - Math.max(x, 0), 0) : 0,
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
setEdgeInsets(previousInsets => {
|
|
97
|
-
const hasChanged = (Object.keys(nextEdgeInsets) as SafeAreaEdge[]).some(
|
|
98
|
-
edge => Math.abs(previousInsets[edge] - nextEdgeInsets[edge]) > EDGE_EPSILON
|
|
99
|
-
);
|
|
100
|
-
|
|
101
|
-
return hasChanged ? nextEdgeInsets : previousInsets;
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
}, [edges, windowHeight, windowWidth]);
|
|
105
|
-
|
|
106
|
-
useEffect(() => {
|
|
107
|
-
const frame = requestAnimationFrame(updateEdgeInsets);
|
|
108
|
-
|
|
109
|
-
return () => cancelAnimationFrame(frame);
|
|
110
|
-
}, [updateEdgeInsets]);
|
|
111
|
-
|
|
112
|
-
const handleRef = useCallback(
|
|
113
|
-
(node: View | null) => {
|
|
114
|
-
viewRef.current = node;
|
|
115
|
-
|
|
116
|
-
if (typeof ref === 'function') {
|
|
117
|
-
ref(node);
|
|
118
|
-
} else if (ref) {
|
|
119
|
-
ref.current = node;
|
|
120
|
-
}
|
|
121
|
-
},
|
|
122
|
-
[ref]
|
|
123
|
-
);
|
|
124
|
-
|
|
125
|
-
const handleLayout = useCallback(
|
|
126
|
-
(event: LayoutChangeEvent) => {
|
|
127
|
-
onLayout?.(event);
|
|
128
|
-
requestAnimationFrame(updateEdgeInsets);
|
|
129
|
-
},
|
|
130
|
-
[onLayout, updateEdgeInsets]
|
|
131
|
-
);
|
|
132
|
-
|
|
133
|
-
const safeAreaStyle = useMemo(() => {
|
|
134
|
-
const nextStyle: ViewStyle = {};
|
|
135
|
-
|
|
136
|
-
if (mode === 'padding') {
|
|
137
|
-
nextStyle.paddingTop = getStyleInsetValue(flattenedStyle, mode, 'top') + edgeInsets.top;
|
|
138
|
-
nextStyle.paddingRight =
|
|
139
|
-
getStyleInsetValue(flattenedStyle, mode, 'right') + edgeInsets.right;
|
|
140
|
-
nextStyle.paddingBottom =
|
|
141
|
-
getStyleInsetValue(flattenedStyle, mode, 'bottom') + edgeInsets.bottom;
|
|
142
|
-
nextStyle.paddingLeft = getStyleInsetValue(flattenedStyle, mode, 'left') + edgeInsets.left;
|
|
143
|
-
|
|
144
|
-
return nextStyle;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
nextStyle.marginTop = getStyleInsetValue(flattenedStyle, mode, 'top') + edgeInsets.top;
|
|
148
|
-
nextStyle.marginRight = getStyleInsetValue(flattenedStyle, mode, 'right') + edgeInsets.right;
|
|
149
|
-
nextStyle.marginBottom =
|
|
150
|
-
getStyleInsetValue(flattenedStyle, mode, 'bottom') + edgeInsets.bottom;
|
|
151
|
-
nextStyle.marginLeft = getStyleInsetValue(flattenedStyle, mode, 'left') + edgeInsets.left;
|
|
152
|
-
|
|
153
|
-
return nextStyle;
|
|
154
|
-
}, [
|
|
155
|
-
edgeInsets.bottom,
|
|
156
|
-
edgeInsets.left,
|
|
157
|
-
edgeInsets.right,
|
|
158
|
-
edgeInsets.top,
|
|
159
|
-
flattenedStyle,
|
|
160
|
-
mode,
|
|
161
|
-
]);
|
|
162
|
-
|
|
163
|
-
return (
|
|
164
|
-
<View ref={handleRef} onLayout={handleLayout} style={[style, safeAreaStyle]} {...props}>
|
|
165
|
-
{children}
|
|
166
|
-
</View>
|
|
167
|
-
);
|
|
168
|
-
}
|
|
169
|
-
);
|
|
170
|
-
|
|
171
|
-
SafeAreaView.displayName = 'SafeAreaView';
|
|
172
|
-
|
|
173
|
-
export default SafeAreaView;
|
/package/build/components/{SafeAreaView/SafeAreaView.props.js → Modal/Modal.shared.types.js}
RENAMED
|
File without changes
|