@fluentui-react-native/experimental-shadow 0.6.19 → 0.7.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.
Files changed (40) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/SPEC.md +1 -1
  3. package/lib/Shadow.d.ts +2 -2
  4. package/lib/Shadow.d.ts.map +1 -1
  5. package/lib/Shadow.js +108 -78
  6. package/lib/Shadow.js.map +1 -1
  7. package/lib/Shadow.types.d.ts +6 -3
  8. package/lib/Shadow.types.d.ts.map +1 -1
  9. package/lib/Shadow.types.js +1 -1
  10. package/lib/Shadow.types.js.map +1 -1
  11. package/lib/__tests__/Shadow.test.d.ts +1 -1
  12. package/lib/__tests__/Shadow.test.js +144 -89
  13. package/lib/__tests__/Shadow.test.js.map +1 -1
  14. package/lib/index.d.ts +1 -1
  15. package/lib/index.js +1 -1
  16. package/lib/shadowStyle.d.ts +17 -17
  17. package/lib/shadowStyle.js +29 -29
  18. package/lib/shadowStyle.js.map +1 -1
  19. package/lib-commonjs/Shadow.d.ts +2 -2
  20. package/lib-commonjs/Shadow.d.ts.map +1 -1
  21. package/lib-commonjs/Shadow.js +164 -107
  22. package/lib-commonjs/Shadow.js.map +1 -1
  23. package/lib-commonjs/Shadow.types.d.ts +6 -3
  24. package/lib-commonjs/Shadow.types.d.ts.map +1 -1
  25. package/lib-commonjs/Shadow.types.js +3 -3
  26. package/lib-commonjs/Shadow.types.js.map +1 -1
  27. package/lib-commonjs/__tests__/Shadow.test.d.ts +1 -1
  28. package/lib-commonjs/__tests__/Shadow.test.js +207 -119
  29. package/lib-commonjs/__tests__/Shadow.test.js.map +1 -1
  30. package/lib-commonjs/index.d.ts +1 -1
  31. package/lib-commonjs/index.js +17 -7
  32. package/lib-commonjs/index.js.map +1 -1
  33. package/lib-commonjs/shadowStyle.d.ts +17 -17
  34. package/lib-commonjs/shadowStyle.js +36 -33
  35. package/lib-commonjs/shadowStyle.js.map +1 -1
  36. package/package.json +60 -59
  37. package/src/Shadow.tsx +8 -17
  38. package/src/Shadow.types.ts +4 -0
  39. package/src/__tests__/Shadow.test.tsx +83 -34
  40. package/src/__tests__/__snapshots__/Shadow.test.tsx.snap +0 -4
package/package.json CHANGED
@@ -1,79 +1,88 @@
1
1
  {
2
2
  "name": "@fluentui-react-native/experimental-shadow",
3
- "version": "0.6.19",
3
+ "version": "0.7.0",
4
4
  "description": "A cross-platform Shadow component using the Fluent Design System",
5
- "main": "lib-commonjs/index.js",
6
- "module": "lib/index.js",
7
- "react-native": "src/index.ts",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/microsoft/fluentui-react-native.git",
8
+ "directory": "packages/experimental/Shadow"
9
+ },
10
+ "license": "MIT",
11
+ "author": "",
8
12
  "exports": {
9
13
  ".": {
14
+ "types": "./lib/index.d.ts",
10
15
  "import": "./lib/index.js",
11
- "require": "./lib-commonjs/index.js",
12
- "types": "./lib/index.d.ts"
16
+ "require": "./lib-commonjs/index.js"
13
17
  }
14
18
  },
15
- "typings": "lib/index.d.ts",
19
+ "main": "lib-commonjs/index.js",
20
+ "module": "lib/index.js",
21
+ "types": "lib/index.d.ts",
16
22
  "scripts": {
17
23
  "build": "fluentui-scripts build",
24
+ "build-cjs": "tsgo --outDir lib-commonjs",
25
+ "build-esm": "tsgo --outDir lib --module esnext --moduleResolution bundler",
18
26
  "clean": "fluentui-scripts clean",
19
27
  "depcheck": "fluentui-scripts depcheck",
20
- "just": "fluentui-scripts",
21
28
  "lint": "fluentui-scripts eslint",
22
- "test": "fluentui-scripts jest",
23
- "update-snapshots": "fluentui-scripts jest -u",
29
+ "lint-package": "fluentui-scripts lint-package",
24
30
  "prettier": "fluentui-scripts prettier",
25
- "prettier-fix": "fluentui-scripts prettier --fix true"
26
- },
27
- "repository": {
28
- "type": "git",
29
- "url": "https://github.com/microsoft/fluentui-react-native.git",
30
- "directory": "packages/experimental/Shadow"
31
+ "test": "fluentui-scripts jest",
32
+ "update-snapshots": "fluentui-scripts jest -u"
31
33
  },
32
34
  "dependencies": {
33
- "@fluentui-react-native/framework": "0.14.17",
34
- "@fluentui-react-native/pressable": "0.12.19",
35
- "@fluentui-react-native/theme-types": "0.43.0"
35
+ "@fluentui-react-native/framework": "0.15.0",
36
+ "@fluentui-react-native/framework-base": "0.3.0",
37
+ "@fluentui-react-native/pressable": "0.13.0",
38
+ "@fluentui-react-native/theme-types": "0.44.0"
36
39
  },
37
40
  "devDependencies": {
38
41
  "@babel/core": "^7.20.0",
39
42
  "@fluentui-react-native/babel-config": "0.1.1",
40
43
  "@fluentui-react-native/eslint-config-rules": "0.1.1",
41
44
  "@fluentui-react-native/jest-config": "0.1.1",
42
- "@fluentui-react-native/scripts": "0.1.1",
45
+ "@fluentui-react-native/kit-config": "0.1.2",
46
+ "@fluentui-react-native/scripts": "0.1.2",
43
47
  "@fluentui-react-native/test-tools": "0.1.1",
44
- "@react-native/babel-preset": "^0.74.0",
45
- "@react-native/metro-config": "^0.74.0",
46
- "@types/react": "~18.2.0",
47
- "@types/react-test-renderer": "^18.2.0",
48
- "react": "18.2.0",
49
- "react-native": "^0.74.0",
50
- "react-native-macos": "^0.74.0",
51
- "react-native-windows": "^0.74.0",
52
- "react-test-renderer": "18.2.0"
48
+ "@react-native-community/cli": "^20.0.0",
49
+ "@react-native-community/cli-platform-android": "^20.0.0",
50
+ "@react-native-community/cli-platform-ios": "^20.0.0",
51
+ "@react-native/babel-preset": "^0.81.0",
52
+ "@react-native/metro-config": "^0.81.0",
53
+ "@types/react": "~19.1.0",
54
+ "@types/react-test-renderer": "^19.1.0",
55
+ "react": "19.1.0",
56
+ "react-native": "^0.81.0",
57
+ "react-native-macos": "^0.81.0",
58
+ "react-native-windows": "^0.81.0",
59
+ "react-test-renderer": "19.1.0"
53
60
  },
54
61
  "peerDependencies": {
55
62
  "@office-iss/react-native-win32": "^0.74.0",
56
- "react": "18.2.0",
57
- "react-native": "^0.73.0 || ^0.74.0",
58
- "react-native-macos": "^0.73.0 || ^0.74.0",
59
- "react-native-windows": "^0.73.0 || ^0.74.0"
63
+ "@types/react": "~18.2.0 || ~19.0.0 || ~19.1.0",
64
+ "react": "18.2.0 || 19.0.0 || 19.1.0",
65
+ "react-native": "^0.73.0 || ^0.74.0 || ^0.78.0 || ^0.81.0",
66
+ "react-native-macos": "^0.73.0 || ^0.74.0 || ^0.78.0 || ^0.81.0",
67
+ "react-native-windows": "^0.73.0 || ^0.74.0 || ^0.78.0 || ^0.81.0"
68
+ },
69
+ "peerDependenciesMeta": {
70
+ "@office-iss/react-native-win32": {
71
+ "optional": true
72
+ },
73
+ "@types/react": {
74
+ "optional": true
75
+ },
76
+ "react-native-macos": {
77
+ "optional": true
78
+ },
79
+ "react-native-windows": {
80
+ "optional": true
81
+ }
60
82
  },
61
- "author": "",
62
- "license": "MIT",
63
83
  "rnx-kit": {
64
84
  "kitType": "library",
65
85
  "alignDeps": {
66
- "presets": [
67
- "microsoft/react-native"
68
- ],
69
- "requirements": {
70
- "development": [
71
- "react-native@0.74"
72
- ],
73
- "production": [
74
- "react-native@0.73 || 0.74"
75
- ]
76
- },
77
86
  "capabilities": [
78
87
  "babel-preset-react-native",
79
88
  "core",
@@ -82,19 +91,11 @@
82
91
  "core-macos",
83
92
  "core-windows",
84
93
  "react",
85
- "react-test-renderer"
94
+ "react-test-renderer",
95
+ "tools-core",
96
+ "tools-jest"
86
97
  ]
87
- }
88
- },
89
- "peerDependenciesMeta": {
90
- "@office-iss/react-native-win32": {
91
- "optional": true
92
98
  },
93
- "react-native-macos": {
94
- "optional": true
95
- },
96
- "react-native-windows": {
97
- "optional": true
98
- }
99
+ "extends": "@fluentui-react-native/kit-config"
99
100
  }
100
- }
101
+ }
package/src/Shadow.tsx CHANGED
@@ -2,39 +2,30 @@ import * as React from 'react';
2
2
  import type { ViewStyle } from 'react-native';
3
3
  import { View } from 'react-native';
4
4
 
5
- import { mergeProps, stagedComponent } from '@fluentui-react-native/framework';
6
- import { memoize } from '@fluentui-react-native/framework';
5
+ import { memoize, mergeProps, phasedComponent, directComponent } from '@fluentui-react-native/framework-base';
7
6
  import type { ShadowToken } from '@fluentui-react-native/theme-types';
8
7
 
9
8
  import type { ShadowProps } from './Shadow.types';
10
9
  import { shadowName } from './Shadow.types';
11
10
  import { getShadowTokenStyleSet } from './shadowStyle';
12
11
 
13
- export const Shadow = stagedComponent((props: ShadowProps) => {
14
- return (final: ShadowProps, children: React.ReactNode) => {
12
+ export const Shadow = phasedComponent((props: ShadowProps) => {
13
+ return directComponent<ShadowProps>((final: ShadowProps) => {
14
+ const { children, ...rest } = final;
15
15
  if (!props.shadowToken) {
16
16
  return <>{children}</>;
17
17
  }
18
18
 
19
- const childrenArray = React.Children.toArray(children) as React.ReactElement[];
20
- const child = childrenArray[0];
21
-
22
- if (__DEV__) {
23
- if (childrenArray.length !== 1) {
24
- console.warn('Shadow must only have one child');
25
- }
26
- }
27
-
28
- const { style: childStyle, ...restOfChildProps } = child.props;
19
+ const { style: childStyle, ...restOfChildProps } = children.props as { style?: ViewStyle };
29
20
 
30
21
  const shadowViewStyleProps = getStylePropsForShadowViews(childStyle, props.shadowToken);
31
22
  const innerShadowViewProps = mergeProps(restOfChildProps, shadowViewStyleProps.inner);
32
- const outerShadowViewProps = mergeProps(final, shadowViewStyleProps.outer);
23
+ const outerShadowViewProps = mergeProps(rest, shadowViewStyleProps.outer);
33
24
 
34
- const childWithInnerShadow = React.cloneElement(child, innerShadowViewProps);
25
+ const childWithInnerShadow = React.cloneElement(children, innerShadowViewProps);
35
26
 
36
27
  return <View {...outerShadowViewProps}>{childWithInnerShadow}</View>;
37
- };
28
+ });
38
29
  });
39
30
 
40
31
  const getStylePropsForShadowViews = memoize(getStylePropsForShadowViewsWorker);
@@ -1,3 +1,4 @@
1
+ import type React from 'react';
1
2
  import type { ViewProps } from 'react-native';
2
3
 
3
4
  import type { ShadowToken } from '@fluentui-react-native/theme-types';
@@ -6,4 +7,7 @@ export const shadowName = 'Shadow';
6
7
 
7
8
  export interface ShadowProps extends ViewProps {
8
9
  shadowToken?: ShadowToken;
10
+
11
+ /** Exactly one child */
12
+ children: React.ReactElement;
9
13
  }
@@ -1,5 +1,6 @@
1
1
  import * as React from 'react';
2
- import { Text, View } from 'react-native';
2
+ import { act } from 'react';
3
+ import { Text, View, type ViewStyle } from 'react-native';
3
4
 
4
5
  import { mergeStyles, useFluentTheme } from '@fluentui-react-native/framework';
5
6
  import { Pressable } from '@fluentui-react-native/pressable';
@@ -46,7 +47,7 @@ const TestShadowOnChildViewWithProps: React.FunctionComponent<ShadowOnChildViewW
46
47
  const theme = useFluentTheme();
47
48
  return (
48
49
  <Shadow shadowToken={theme.shadows['shadow16']}>
49
- <View style={mergeStyles(props.childViewStyleProps, backgroundColor)}>
50
+ <View style={mergeStyles<ViewStyle>(props.childViewStyleProps, backgroundColor)}>
50
51
  <Text>{JSON.stringify(props.childViewStyleProps)}</Text>
51
52
  </View>
52
53
  </Shadow>
@@ -62,83 +63,131 @@ describe('Shadow component tests', () => {
62
63
  });
63
64
 
64
65
  it('Shadow (depth=2)', () => {
65
- const tree = renderer.create(<TestShadow displayText="Shadow (depth=2)" depth="shadow2" />).toJSON();
66
- expect(tree).toMatchSnapshot();
66
+ let component: renderer.ReactTestRenderer;
67
+ act(() => {
68
+ component = renderer.create(<TestShadow displayText="Shadow (depth=2)" depth="shadow2" />);
69
+ });
70
+ expect(component!.toJSON()).toMatchSnapshot();
67
71
  });
68
72
 
69
73
  it('Shadow (depth=4)', () => {
70
- const tree = renderer.create(<TestShadow displayText="Shadow (depth=4)" depth="shadow4" />).toJSON();
71
- expect(tree).toMatchSnapshot();
74
+ let component: renderer.ReactTestRenderer;
75
+ act(() => {
76
+ component = renderer.create(<TestShadow displayText="Shadow (depth=4)" depth="shadow4" />);
77
+ });
78
+ expect(component!.toJSON()).toMatchSnapshot();
72
79
  });
73
80
 
74
81
  it('Shadow (depth=8)', () => {
75
- const tree = renderer.create(<TestShadow displayText="Shadow (depth=8)" depth="shadow8" />).toJSON();
76
- expect(tree).toMatchSnapshot();
82
+ let component: renderer.ReactTestRenderer;
83
+ act(() => {
84
+ component = renderer.create(<TestShadow displayText="Shadow (depth=8)" depth="shadow8" />);
85
+ });
86
+ expect(component!.toJSON()).toMatchSnapshot();
77
87
  });
78
88
 
79
89
  it('Shadow (depth=16)', () => {
80
- const tree = renderer.create(<TestShadow displayText="Shadow (depth=16)" depth="shadow16" />).toJSON();
81
- expect(tree).toMatchSnapshot();
90
+ let component: renderer.ReactTestRenderer;
91
+ act(() => {
92
+ component = renderer.create(<TestShadow displayText="Shadow (depth=16)" depth="shadow16" />);
93
+ });
94
+ expect(component!.toJSON()).toMatchSnapshot();
82
95
  });
83
96
 
84
97
  it('Shadow (depth=28)', () => {
85
- const tree = renderer.create(<TestShadow displayText="Shadow (depth=28)" depth="shadow28" />).toJSON();
86
- expect(tree).toMatchSnapshot();
98
+ let component: renderer.ReactTestRenderer;
99
+ act(() => {
100
+ component = renderer.create(<TestShadow displayText="Shadow (depth=28)" depth="shadow28" />);
101
+ });
102
+ expect(component!.toJSON()).toMatchSnapshot();
87
103
  });
88
104
 
89
105
  it('Shadow (depth=64)', () => {
90
- const tree = renderer.create(<TestShadow displayText="Shadow (depth=64)" depth="shadow64" />).toJSON();
91
- expect(tree).toMatchSnapshot();
106
+ let component: renderer.ReactTestRenderer;
107
+ act(() => {
108
+ component = renderer.create(<TestShadow displayText="Shadow (depth=64)" depth="shadow64" />);
109
+ });
110
+ expect(component!.toJSON()).toMatchSnapshot();
92
111
  });
93
112
 
94
113
  it('Brand shadow (depth=2)', () => {
95
- const tree = renderer.create(<TestShadow displayText="Brand shadow (depth=2)" depth="shadow2brand" />).toJSON();
96
- expect(tree).toMatchSnapshot();
114
+ let component: renderer.ReactTestRenderer;
115
+ act(() => {
116
+ component = renderer.create(<TestShadow displayText="Brand shadow (depth=2)" depth="shadow2brand" />);
117
+ });
118
+ expect(component!.toJSON()).toMatchSnapshot();
97
119
  });
98
120
 
99
121
  it('Brand shadow (depth=4)', () => {
100
- const tree = renderer.create(<TestShadow displayText="Brand shadow (depth=4)" depth="shadow4brand" />).toJSON();
101
- expect(tree).toMatchSnapshot();
122
+ let component: renderer.ReactTestRenderer;
123
+ act(() => {
124
+ component = renderer.create(<TestShadow displayText="Brand shadow (depth=4)" depth="shadow4brand" />);
125
+ });
126
+ expect(component!.toJSON()).toMatchSnapshot();
102
127
  });
103
128
 
104
129
  it('Brand shadow (depth=8)', () => {
105
- const tree = renderer.create(<TestShadow displayText="Brand shadow (depth=8)" depth="shadow8brand" />).toJSON();
106
- expect(tree).toMatchSnapshot();
130
+ let component: renderer.ReactTestRenderer;
131
+ act(() => {
132
+ component = renderer.create(<TestShadow displayText="Brand shadow (depth=8)" depth="shadow8brand" />);
133
+ });
134
+ expect(component!.toJSON()).toMatchSnapshot();
107
135
  });
108
136
 
109
137
  it('Brand shadow (depth=16)', () => {
110
- const tree = renderer.create(<TestShadow displayText="Brand shadow (depth=16)" depth="shadow16brand" />).toJSON();
111
- expect(tree).toMatchSnapshot();
138
+ let component: renderer.ReactTestRenderer;
139
+ act(() => {
140
+ component = renderer.create(<TestShadow displayText="Brand shadow (depth=16)" depth="shadow16brand" />);
141
+ });
142
+ expect(component!.toJSON()).toMatchSnapshot();
112
143
  });
113
144
 
114
145
  it('Brand shadow (depth=28)', () => {
115
- const tree = renderer.create(<TestShadow displayText="Brand shadow (depth=28)" depth="shadow28brand" />).toJSON();
116
- expect(tree).toMatchSnapshot();
146
+ let component: renderer.ReactTestRenderer;
147
+ act(() => {
148
+ component = renderer.create(<TestShadow displayText="Brand shadow (depth=28)" depth="shadow28brand" />);
149
+ });
150
+ expect(component!.toJSON()).toMatchSnapshot();
117
151
  });
118
152
 
119
153
  it('Brand shadow (depth=64)', () => {
120
- const tree = renderer.create(<TestShadow displayText="Brand shadow (depth=64)" depth="shadow64brand" />).toJSON();
121
- expect(tree).toMatchSnapshot();
154
+ let component: renderer.ReactTestRenderer;
155
+ act(() => {
156
+ component = renderer.create(<TestShadow displayText="Brand shadow (depth=64)" depth="shadow64brand" />);
157
+ });
158
+ expect(component!.toJSON()).toMatchSnapshot();
122
159
  });
123
160
 
124
161
  it('Pressable that has a shadow vs. pressable without shadow', () => {
125
- const tree = renderer.create(<TestPressableWithAndWithoutShadow />).toJSON();
126
- expect(tree).toMatchSnapshot();
162
+ let component: renderer.ReactTestRenderer;
163
+ act(() => {
164
+ component = renderer.create(<TestPressableWithAndWithoutShadow />);
165
+ });
166
+ expect(component!.toJSON()).toMatchSnapshot();
127
167
  });
128
168
 
129
169
  it('Shadow on a child with margin and padding', () => {
130
- const tree = renderer.create(<TestShadowOnChildViewWithProps childViewStyleProps={{ margin: 2, padding: 2 }} />).toJSON();
131
- expect(tree).toMatchSnapshot();
170
+ let component: renderer.ReactTestRenderer;
171
+ act(() => {
172
+ component = renderer.create(<TestShadowOnChildViewWithProps childViewStyleProps={{ margin: 2, padding: 2 }} />);
173
+ });
174
+ expect(component!.toJSON()).toMatchSnapshot();
132
175
  });
133
176
 
134
177
  it('Shadow on a child with border radius', () => {
135
- const tree = renderer.create(<TestShadowOnChildViewWithProps childViewStyleProps={{ borderRadius: 2 }} />).toJSON();
136
- expect(tree).toMatchSnapshot();
178
+ let component: renderer.ReactTestRenderer;
179
+ act(() => {
180
+ component = renderer.create(<TestShadowOnChildViewWithProps childViewStyleProps={{ borderRadius: 2 }} />);
181
+ });
182
+ expect(component!.toJSON()).toMatchSnapshot();
137
183
  });
138
184
 
139
185
  it('Shadow on a child with border width', () => {
140
- const tree = renderer.create(<TestShadowOnChildViewWithProps childViewStyleProps={{ borderWidth: 2 }} />).toJSON();
141
- expect(tree).toMatchSnapshot();
186
+ let component: renderer.ReactTestRenderer;
187
+ act(() => {
188
+ component = renderer.create(<TestShadowOnChildViewWithProps childViewStyleProps={{ borderWidth: 2 }} />);
189
+ });
190
+ expect(component!.toJSON()).toMatchSnapshot();
142
191
  });
143
192
 
144
193
  afterAll(() => {
@@ -236,8 +236,6 @@ exports[`Shadow component tests Pressable that has a shadow vs. pressable withou
236
236
  onBlur={[Function]}
237
237
  onClick={[Function]}
238
238
  onFocus={[Function]}
239
- onMouseEnter={[Function]}
240
- onMouseLeave={[Function]}
241
239
  onResponderGrant={[Function]}
242
240
  onResponderMove={[Function]}
243
241
  onResponderRelease={[Function]}
@@ -263,8 +261,6 @@ exports[`Shadow component tests Pressable that has a shadow vs. pressable withou
263
261
  onBlur={[Function]}
264
262
  onClick={[Function]}
265
263
  onFocus={[Function]}
266
- onMouseEnter={[Function]}
267
- onMouseLeave={[Function]}
268
264
  onResponderGrant={[Function]}
269
265
  onResponderMove={[Function]}
270
266
  onResponderRelease={[Function]}