react-native-molecules 0.5.0-beta.2 → 0.5.0-beta.3
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/README.md +1 -1
- package/components/Button/Button.tsx +2 -2
- package/components/ElementGroup/ElementGroup.tsx +16 -14
- package/components/Surface/Surface.android.tsx +3 -2
- package/components/Surface/Surface.ios.tsx +8 -6
- package/components/Surface/utils.ts +0 -24
- package/package.json +1 -1
- package/utils/extractPropertiesFromStyles.ts +25 -0
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ React Native Molecules
|
|
|
4
4
|
|
|
5
5
|
<h3 align="center">
|
|
6
6
|
Material 3-powered primitives for React Native + Web.<br/>
|
|
7
|
-
<a href="https://
|
|
7
|
+
<a href="https://molecules.taylordb.ai">Explore the docs</a>
|
|
8
8
|
</h3>
|
|
9
9
|
|
|
10
10
|
---
|
|
@@ -12,11 +12,11 @@ import { type StyleProp, type TextStyle, View, type ViewProps, type ViewStyle }
|
|
|
12
12
|
import { useActionState } from '../../hooks';
|
|
13
13
|
import type { MD3Elevation } from '../../types/theme';
|
|
14
14
|
import { resolveStateVariant } from '../../utils';
|
|
15
|
+
import { extractPropertiesFromStyles } from '../../utils/extractPropertiesFromStyles';
|
|
15
16
|
import { ActivityIndicator } from '../ActivityIndicator';
|
|
16
17
|
import { Icon, type IconType } from '../Icon';
|
|
17
18
|
import { StateLayer } from '../StateLayer';
|
|
18
19
|
import { Surface, type SurfaceProps } from '../Surface';
|
|
19
|
-
import { extractProperties } from '../Surface/utils';
|
|
20
20
|
import { Text } from '../Text';
|
|
21
21
|
import { TouchableRipple } from '../TouchableRipple';
|
|
22
22
|
import type { ButtonSize, ButtonVariant } from './types';
|
|
@@ -209,7 +209,7 @@ const Button = (
|
|
|
209
209
|
defaultStyles;
|
|
210
210
|
|
|
211
211
|
// for mobile
|
|
212
|
-
const { borderRadius } =
|
|
212
|
+
const { borderRadius } = extractPropertiesFromStyles(
|
|
213
213
|
[defaultStyles.root, styleProp],
|
|
214
214
|
['borderRadius'],
|
|
215
215
|
);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Children, cloneElement, forwardRef, memo, type ReactElement, useMemo } from 'react';
|
|
2
2
|
import { View, type ViewProps, type ViewStyle } from 'react-native';
|
|
3
3
|
|
|
4
|
+
import { extractPropertiesFromStyles } from '../../utils/extractPropertiesFromStyles';
|
|
4
5
|
import { isNil } from '../../utils/lodash';
|
|
5
6
|
import { elementGroupStyles } from './utils';
|
|
6
7
|
|
|
@@ -44,24 +45,25 @@ export const ElementGroup = (
|
|
|
44
45
|
borderTopRightRadius,
|
|
45
46
|
borderBottomLeftRadius,
|
|
46
47
|
borderBottomRightRadius,
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
48
|
+
} = extractPropertiesFromStyles(
|
|
49
|
+
[elementGroupStyles.root, style],
|
|
50
|
+
[
|
|
51
|
+
'borderRadius',
|
|
52
|
+
'borderTopLeftRadius',
|
|
53
|
+
'borderTopRightRadius',
|
|
54
|
+
'borderBottomLeftRadius',
|
|
55
|
+
'borderBottomRightRadius',
|
|
56
|
+
],
|
|
57
|
+
);
|
|
56
58
|
|
|
57
59
|
return {
|
|
58
|
-
containerStyle: [
|
|
60
|
+
containerStyle: [elementGroupStyles.root, style],
|
|
59
61
|
borderRadius: borderRadiusProp || _borderRadius,
|
|
60
62
|
borderRadiuses: {
|
|
61
|
-
borderTopLeftRadius: borderTopLeftRadius
|
|
62
|
-
borderTopRightRadius: borderTopRightRadius
|
|
63
|
-
borderBottomLeftRadius: borderBottomLeftRadius
|
|
64
|
-
borderBottomRightRadius: borderBottomRightRadius
|
|
63
|
+
borderTopLeftRadius: borderTopLeftRadius,
|
|
64
|
+
borderTopRightRadius: borderTopRightRadius,
|
|
65
|
+
borderBottomLeftRadius: borderBottomLeftRadius,
|
|
66
|
+
borderBottomRightRadius: borderBottomRightRadius,
|
|
65
67
|
},
|
|
66
68
|
};
|
|
67
69
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -4,8 +4,9 @@ import { useUnistyles } from 'react-native-unistyles';
|
|
|
4
4
|
|
|
5
5
|
import { inputRange } from '../../styles/shadow';
|
|
6
6
|
import type { MD3Elevation } from '../../types/theme';
|
|
7
|
+
import { extractPropertiesFromStyles } from '../../utils/extractPropertiesFromStyles';
|
|
7
8
|
import { BackgroundContextWrapper } from './BackgroundContextWrapper';
|
|
8
|
-
import { defaultStyles,
|
|
9
|
+
import { defaultStyles, getElevationAndroid } from './utils';
|
|
9
10
|
|
|
10
11
|
export type Props = ViewProps & {
|
|
11
12
|
/**
|
|
@@ -43,7 +44,7 @@ const Surface = ({ elevation = 1, style, children, testID, ...props }: Props, re
|
|
|
43
44
|
elevation: getElevationAndroid(elevation, inputRange, elevationLevel),
|
|
44
45
|
},
|
|
45
46
|
] as StyleProp<ViewStyle>,
|
|
46
|
-
surfaceBackground:
|
|
47
|
+
surfaceBackground: extractPropertiesFromStyles(
|
|
47
48
|
[defaultStyles.root as ViewStyle, style],
|
|
48
49
|
['backgroundColor'],
|
|
49
50
|
).backgroundColor,
|
|
@@ -3,8 +3,9 @@ import { Animated, type StyleProp, View, type ViewStyle } from 'react-native';
|
|
|
3
3
|
import { useUnistyles } from 'react-native-unistyles';
|
|
4
4
|
|
|
5
5
|
import type { MD3Elevation } from '../../types/theme';
|
|
6
|
+
import { extractPropertiesFromStyles } from '../../utils/extractPropertiesFromStyles';
|
|
6
7
|
import { BackgroundContextWrapper } from './BackgroundContextWrapper';
|
|
7
|
-
import { defaultStyles,
|
|
8
|
+
import { defaultStyles, getStyleForShadowLayer } from './utils';
|
|
8
9
|
|
|
9
10
|
export type Props = ComponentPropsWithRef<typeof View> & {
|
|
10
11
|
/**
|
|
@@ -78,14 +79,15 @@ const Surface = ({ elevation = 1, style, children, testID, ...props }: Props, re
|
|
|
78
79
|
})();
|
|
79
80
|
|
|
80
81
|
const { surfaceBackground, sharedStyle, layer0Style, layer1Style } = useMemo(() => {
|
|
81
|
-
const { position, alignSelf, top, left, right, bottom, borderRadius } =
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
82
|
+
const { position, alignSelf, top, left, right, bottom, borderRadius } =
|
|
83
|
+
extractPropertiesFromStyles(
|
|
84
|
+
[defaultStyles.root as ViewStyle, style],
|
|
85
|
+
['position', 'alignSelf', 'top', 'left', 'right', 'bottom', 'borderRadius'],
|
|
86
|
+
);
|
|
85
87
|
const absoluteStyle = { position, alignSelf, top, right, bottom, left };
|
|
86
88
|
|
|
87
89
|
return {
|
|
88
|
-
surfaceBackground:
|
|
90
|
+
surfaceBackground: extractPropertiesFromStyles(
|
|
89
91
|
[defaultStyles.root as ViewStyle, style],
|
|
90
92
|
['backgroundColor'],
|
|
91
93
|
).backgroundColor,
|
|
@@ -15,30 +15,6 @@ export const defaultStyles = getRegisteredComponentStylesWithFallback(
|
|
|
15
15
|
defaultStylesDefault,
|
|
16
16
|
);
|
|
17
17
|
|
|
18
|
-
// TODO - abstract this
|
|
19
|
-
export function extractProperties(
|
|
20
|
-
_objectsArray: Record<string, any>,
|
|
21
|
-
propertiesToExtract: string[],
|
|
22
|
-
) {
|
|
23
|
-
const extracted: Record<string, any> = {};
|
|
24
|
-
|
|
25
|
-
const objectsArray = _objectsArray.flat();
|
|
26
|
-
|
|
27
|
-
for (let i = objectsArray.length - 1; i >= 0; i--) {
|
|
28
|
-
const obj = objectsArray[i];
|
|
29
|
-
|
|
30
|
-
for (const prop of propertiesToExtract) {
|
|
31
|
-
if (!obj) continue;
|
|
32
|
-
if (prop in obj) {
|
|
33
|
-
// @ts-ignore
|
|
34
|
-
extracted[prop] = obj[prop];
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return extracted;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
18
|
const _shadowColor = '#000';
|
|
43
19
|
|
|
44
20
|
const iOSShadowOutputRanges = [
|
package/package.json
CHANGED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { StyleSheet } from 'react-native-unistyles';
|
|
2
|
+
|
|
3
|
+
// TODO - abstract this
|
|
4
|
+
export function extractPropertiesFromStyles(
|
|
5
|
+
_objectsArray: Record<string, any>,
|
|
6
|
+
propertiesToExtract: string[],
|
|
7
|
+
) {
|
|
8
|
+
const extracted: Record<string, any> = {};
|
|
9
|
+
|
|
10
|
+
const objectsArray = StyleSheet.flatten(_objectsArray);
|
|
11
|
+
|
|
12
|
+
for (let i = objectsArray.length - 1; i >= 0; i--) {
|
|
13
|
+
const obj = objectsArray[i];
|
|
14
|
+
|
|
15
|
+
for (const prop of propertiesToExtract) {
|
|
16
|
+
if (!obj) continue;
|
|
17
|
+
if (prop in obj) {
|
|
18
|
+
// @ts-ignore
|
|
19
|
+
extracted[prop] = obj[prop];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return extracted;
|
|
25
|
+
}
|