@fluentui-react-native/experimental-shadow 0.2.69 → 0.2.71
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.json +49 -1
- package/CHANGELOG.md +21 -2
- package/lib/Shadow.d.ts.map +1 -1
- package/lib/Shadow.js +14 -11
- package/lib/Shadow.js.map +1 -1
- package/lib/Shadow.types.d.ts +1 -1
- package/lib/Shadow.types.d.ts.map +1 -1
- package/lib/Shadow.types.js.map +1 -1
- package/lib/__tests__/Shadow.test.js +11 -8
- package/lib/__tests__/Shadow.test.js.map +1 -1
- package/lib/shadowStyle.d.ts.map +1 -1
- package/lib/shadowStyle.js +1 -1
- package/lib/shadowStyle.js.map +1 -1
- package/lib-commonjs/Shadow.d.ts.map +1 -1
- package/lib-commonjs/Shadow.js +14 -11
- package/lib-commonjs/Shadow.js.map +1 -1
- package/lib-commonjs/Shadow.types.d.ts +1 -1
- package/lib-commonjs/Shadow.types.d.ts.map +1 -1
- package/lib-commonjs/Shadow.types.js.map +1 -1
- package/lib-commonjs/__tests__/Shadow.test.js +11 -8
- package/lib-commonjs/__tests__/Shadow.test.js.map +1 -1
- package/lib-commonjs/shadowStyle.d.ts.map +1 -1
- package/lib-commonjs/shadowStyle.js +1 -1
- package/lib-commonjs/shadowStyle.js.map +1 -1
- package/package.json +4 -4
- package/src/Shadow.tsx +67 -62
- package/src/Shadow.types.ts +2 -1
- package/src/__tests__/Shadow.test.tsx +16 -9
- package/src/__tests__/__snapshots__/Shadow.test.tsx.snap +52 -571
- package/src/shadowStyle.ts +3 -2
package/src/Shadow.tsx
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import type { ViewStyle } from 'react-native';
|
|
3
3
|
import { View } from 'react-native';
|
|
4
|
-
|
|
5
|
-
import { shadowName } from './Shadow.types';
|
|
4
|
+
|
|
6
5
|
import { mergeProps, stagedComponent } from '@fluentui-react-native/framework';
|
|
7
|
-
import { getShadowTokenStyleSet } from './shadowStyle';
|
|
8
6
|
import { memoize } from '@fluentui-react-native/framework';
|
|
9
7
|
import type { ShadowToken } from '@fluentui-react-native/theme-types';
|
|
10
8
|
|
|
9
|
+
import type { ShadowProps } from './Shadow.types';
|
|
10
|
+
import { shadowName } from './Shadow.types';
|
|
11
|
+
import { getShadowTokenStyleSet } from './shadowStyle';
|
|
12
|
+
|
|
11
13
|
export const Shadow = stagedComponent((props: ShadowProps) => {
|
|
12
14
|
return (final: ShadowProps, children: React.ReactNode) => {
|
|
13
15
|
if (!props.shadowToken) {
|
|
@@ -39,6 +41,12 @@ const getStylePropsForShadowViews = memoize(getStylePropsForShadowViewsWorker);
|
|
|
39
41
|
function getStylePropsForShadowViewsWorker(childStyleProps: ViewStyle = {}, shadowToken: ShadowToken) {
|
|
40
42
|
const shadowTokenStyleSet = getShadowTokenStyleSet(shadowToken);
|
|
41
43
|
|
|
44
|
+
if (__DEV__) {
|
|
45
|
+
if (!childStyleProps.backgroundColor) {
|
|
46
|
+
console.warn('The View that the Shadow is set on must have a background color set');
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
42
50
|
const {
|
|
43
51
|
borderBottomWidth,
|
|
44
52
|
borderEndWidth,
|
|
@@ -83,68 +91,65 @@ function getStylePropsForShadowViewsWorker(childStyleProps: ViewStyle = {}, shad
|
|
|
83
91
|
...restOfChildStyleProps
|
|
84
92
|
} = childStyleProps;
|
|
85
93
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
94
|
+
// Remove undefined properties, otherwise every prop will be added and be set to
|
|
95
|
+
// undefined, which can cause unexpected behaviour with some of the styles
|
|
96
|
+
const innerStyle = removeUndefinedProperties({
|
|
97
|
+
borderBottomWidth,
|
|
98
|
+
borderEndWidth,
|
|
99
|
+
borderLeftWidth,
|
|
100
|
+
borderRightWidth,
|
|
101
|
+
borderStartWidth,
|
|
102
|
+
borderTopWidth,
|
|
103
|
+
borderWidth,
|
|
91
104
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
start,
|
|
135
|
-
end,
|
|
136
|
-
left,
|
|
137
|
-
right,
|
|
138
|
-
top,
|
|
139
|
-
bottom,
|
|
140
|
-
|
|
141
|
-
...shadowTokenStyleSet.ambient,
|
|
142
|
-
...restOfChildStyleProps,
|
|
143
|
-
},
|
|
144
|
-
},
|
|
145
|
-
};
|
|
105
|
+
padding,
|
|
106
|
+
paddingBottom,
|
|
107
|
+
paddingEnd,
|
|
108
|
+
paddingHorizontal,
|
|
109
|
+
paddingLeft,
|
|
110
|
+
paddingRight,
|
|
111
|
+
paddingStart,
|
|
112
|
+
paddingTop,
|
|
113
|
+
paddingVertical,
|
|
114
|
+
|
|
115
|
+
alignItems,
|
|
116
|
+
|
|
117
|
+
flexWrap,
|
|
118
|
+
flexDirection,
|
|
119
|
+
|
|
120
|
+
...shadowTokenStyleSet.key,
|
|
121
|
+
...restOfChildStyleProps,
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
const outerStyle = removeUndefinedProperties({
|
|
125
|
+
margin,
|
|
126
|
+
marginBottom,
|
|
127
|
+
marginEnd,
|
|
128
|
+
marginHorizontal,
|
|
129
|
+
marginLeft,
|
|
130
|
+
marginRight,
|
|
131
|
+
marginStart,
|
|
132
|
+
marginTop,
|
|
133
|
+
marginVertical,
|
|
134
|
+
|
|
135
|
+
start,
|
|
136
|
+
end,
|
|
137
|
+
left,
|
|
138
|
+
right,
|
|
139
|
+
top,
|
|
140
|
+
bottom,
|
|
141
|
+
|
|
142
|
+
...shadowTokenStyleSet.ambient,
|
|
143
|
+
...restOfChildStyleProps,
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
return { inner: { style: innerStyle }, outer: { style: outerStyle } };
|
|
146
147
|
}
|
|
147
148
|
|
|
149
|
+
const removeUndefinedProperties = (object: any) => {
|
|
150
|
+
return Object.fromEntries(Object.entries(object).filter(([_, v]) => v != null));
|
|
151
|
+
};
|
|
152
|
+
|
|
148
153
|
Shadow.displayName = shadowName;
|
|
149
154
|
|
|
150
155
|
export default Shadow;
|
package/src/Shadow.types.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { ShadowToken } from '@fluentui-react-native/theme-types';
|
|
2
1
|
import type { ViewProps } from 'react-native';
|
|
3
2
|
|
|
3
|
+
import type { ShadowToken } from '@fluentui-react-native/theme-types';
|
|
4
|
+
|
|
4
5
|
export const shadowName = 'Shadow';
|
|
5
6
|
|
|
6
7
|
export interface ShadowProps extends ViewProps {
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { Text, View } from 'react-native';
|
|
3
|
-
|
|
3
|
+
|
|
4
4
|
import { mergeStyles, useFluentTheme } from '@fluentui-react-native/framework';
|
|
5
|
-
import * as renderer from 'react-test-renderer';
|
|
6
|
-
import { checkRenderConsistency, checkReRender } from '@fluentui-react-native/test-tools';
|
|
7
5
|
import { Pressable } from '@fluentui-react-native/pressable';
|
|
6
|
+
import { checkRenderConsistency, checkReRender } from '@fluentui-react-native/test-tools';
|
|
7
|
+
import * as renderer from 'react-test-renderer';
|
|
8
|
+
|
|
9
|
+
import { Shadow } from '../Shadow';
|
|
8
10
|
|
|
9
11
|
const backgroundColor = { backgroundColor: 'red' };
|
|
10
12
|
interface ShadowTestProps {
|
|
@@ -23,12 +25,17 @@ const TestShadow: React.FunctionComponent<ShadowTestProps> = (props: ShadowTestP
|
|
|
23
25
|
);
|
|
24
26
|
};
|
|
25
27
|
|
|
26
|
-
const
|
|
28
|
+
const TestPressableWithAndWithoutShadow: React.FunctionComponent = () => {
|
|
27
29
|
const theme = useFluentTheme();
|
|
28
30
|
return (
|
|
29
|
-
<
|
|
30
|
-
<
|
|
31
|
-
|
|
31
|
+
<View>
|
|
32
|
+
<Shadow shadowToken={theme.shadows['shadow16']}>
|
|
33
|
+
<Pressable style={backgroundColor} />
|
|
34
|
+
</Shadow>
|
|
35
|
+
<View>
|
|
36
|
+
<Pressable style={backgroundColor} />
|
|
37
|
+
</View>
|
|
38
|
+
</View>
|
|
32
39
|
);
|
|
33
40
|
};
|
|
34
41
|
|
|
@@ -115,8 +122,8 @@ describe('Shadow component tests', () => {
|
|
|
115
122
|
expect(tree).toMatchSnapshot();
|
|
116
123
|
});
|
|
117
124
|
|
|
118
|
-
it('Pressable that has a shadow', () => {
|
|
119
|
-
const tree = renderer.create(<
|
|
125
|
+
it('Pressable that has a shadow vs. pressable without shadow', () => {
|
|
126
|
+
const tree = renderer.create(<TestPressableWithAndWithoutShadow />).toJSON();
|
|
120
127
|
expect(tree).toMatchSnapshot();
|
|
121
128
|
});
|
|
122
129
|
|