@fluentui-react-native/experimental-shadow 0.2.0 → 0.2.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.
Files changed (45) hide show
  1. package/CHANGELOG.json +46 -1
  2. package/CHANGELOG.md +26 -2
  3. package/lib/Shadow.d.ts +2 -2
  4. package/lib/Shadow.d.ts.map +1 -1
  5. package/lib/Shadow.js +24 -22
  6. package/lib/Shadow.js.map +1 -1
  7. package/lib/Shadow.types.d.ts +2 -1
  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.js +86 -5
  12. package/lib/__tests__/Shadow.test.js.map +1 -1
  13. package/lib/index.d.ts +1 -0
  14. package/lib/index.d.ts.map +1 -1
  15. package/lib/index.js +1 -0
  16. package/lib/index.js.map +1 -1
  17. package/lib/shadowStyle.d.ts +25 -0
  18. package/lib/shadowStyle.d.ts.map +1 -0
  19. package/lib/shadowStyle.js +51 -0
  20. package/lib/shadowStyle.js.map +1 -0
  21. package/lib-commonjs/Shadow.d.ts +2 -2
  22. package/lib-commonjs/Shadow.d.ts.map +1 -1
  23. package/lib-commonjs/Shadow.js +24 -23
  24. package/lib-commonjs/Shadow.js.map +1 -1
  25. package/lib-commonjs/Shadow.types.d.ts +2 -1
  26. package/lib-commonjs/Shadow.types.d.ts.map +1 -1
  27. package/lib-commonjs/Shadow.types.js +2 -0
  28. package/lib-commonjs/Shadow.types.js.map +1 -1
  29. package/lib-commonjs/__tests__/Shadow.test.js +86 -5
  30. package/lib-commonjs/__tests__/Shadow.test.js.map +1 -1
  31. package/lib-commonjs/index.d.ts +1 -0
  32. package/lib-commonjs/index.d.ts.map +1 -1
  33. package/lib-commonjs/index.js +3 -1
  34. package/lib-commonjs/index.js.map +1 -1
  35. package/lib-commonjs/shadowStyle.d.ts +25 -0
  36. package/lib-commonjs/shadowStyle.d.ts.map +1 -0
  37. package/lib-commonjs/shadowStyle.js +54 -0
  38. package/lib-commonjs/shadowStyle.js.map +1 -0
  39. package/package.json +4 -1
  40. package/src/Shadow.tsx +19 -26
  41. package/src/Shadow.types.ts +15 -1
  42. package/src/__tests__/Shadow.test.tsx +137 -5
  43. package/src/__tests__/__snapshots__/Shadow.test.tsx.snap +402 -4
  44. package/src/index.ts +1 -0
  45. package/src/shadowStyle.ts +60 -0
@@ -1,10 +1,408 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
- exports[`Shadow component tests Shadow default 1`] = `
4
- <View>
5
- <View>
3
+ exports[`Shadow component tests Brand shadow (depth=2) 1`] = `
4
+ <View
5
+ style={
6
+ Object {
7
+ "shadowColor": "#000000",
8
+ "shadowOffset": Object {
9
+ "height": 0,
10
+ "width": 0,
11
+ },
12
+ "shadowOpacity": 0.3,
13
+ "shadowRadius": 2,
14
+ }
15
+ }
16
+ >
17
+ <View
18
+ style={
19
+ Object {
20
+ "shadowColor": "#000000",
21
+ "shadowOffset": Object {
22
+ "height": 1,
23
+ "width": 0,
24
+ },
25
+ "shadowOpacity": 0.25,
26
+ "shadowRadius": 2,
27
+ }
28
+ }
29
+ >
6
30
  <Text>
7
- Shadow default test
31
+ Brand shadow (depth=2)
32
+ </Text>
33
+ </View>
34
+ </View>
35
+ `;
36
+
37
+ exports[`Shadow component tests Brand shadow (depth=4) 1`] = `
38
+ <View
39
+ style={
40
+ Object {
41
+ "shadowColor": "#000000",
42
+ "shadowOffset": Object {
43
+ "height": 0,
44
+ "width": 0,
45
+ },
46
+ "shadowOpacity": 0.3,
47
+ "shadowRadius": 2,
48
+ }
49
+ }
50
+ >
51
+ <View
52
+ style={
53
+ Object {
54
+ "shadowColor": "#000000",
55
+ "shadowOffset": Object {
56
+ "height": 2,
57
+ "width": 0,
58
+ },
59
+ "shadowOpacity": 0.25,
60
+ "shadowRadius": 4,
61
+ }
62
+ }
63
+ >
64
+ <Text>
65
+ Brand shadow (depth=4)
66
+ </Text>
67
+ </View>
68
+ </View>
69
+ `;
70
+
71
+ exports[`Shadow component tests Brand shadow (depth=8) 1`] = `
72
+ <View
73
+ style={
74
+ Object {
75
+ "shadowColor": "#000000",
76
+ "shadowOffset": Object {
77
+ "height": 0,
78
+ "width": 0,
79
+ },
80
+ "shadowOpacity": 0.3,
81
+ "shadowRadius": 2,
82
+ }
83
+ }
84
+ >
85
+ <View
86
+ style={
87
+ Object {
88
+ "shadowColor": "#000000",
89
+ "shadowOffset": Object {
90
+ "height": 4,
91
+ "width": 0,
92
+ },
93
+ "shadowOpacity": 0.25,
94
+ "shadowRadius": 8,
95
+ }
96
+ }
97
+ >
98
+ <Text>
99
+ Brand shadow (depth=8)
100
+ </Text>
101
+ </View>
102
+ </View>
103
+ `;
104
+
105
+ exports[`Shadow component tests Brand shadow (depth=16) 1`] = `
106
+ <View
107
+ style={
108
+ Object {
109
+ "shadowColor": "#000000",
110
+ "shadowOffset": Object {
111
+ "height": 0,
112
+ "width": 0,
113
+ },
114
+ "shadowOpacity": 0.3,
115
+ "shadowRadius": 2,
116
+ }
117
+ }
118
+ >
119
+ <View
120
+ style={
121
+ Object {
122
+ "shadowColor": "#000000",
123
+ "shadowOffset": Object {
124
+ "height": 8,
125
+ "width": 0,
126
+ },
127
+ "shadowOpacity": 0.25,
128
+ "shadowRadius": 16,
129
+ }
130
+ }
131
+ >
132
+ <Text>
133
+ Brand shadow (depth=16)
134
+ </Text>
135
+ </View>
136
+ </View>
137
+ `;
138
+
139
+ exports[`Shadow component tests Brand shadow (depth=28) 1`] = `
140
+ <View
141
+ style={
142
+ Object {
143
+ "shadowColor": "#000000",
144
+ "shadowOffset": Object {
145
+ "height": 0,
146
+ "width": 0,
147
+ },
148
+ "shadowOpacity": 0.3,
149
+ "shadowRadius": 8,
150
+ }
151
+ }
152
+ >
153
+ <View
154
+ style={
155
+ Object {
156
+ "shadowColor": "#000000",
157
+ "shadowOffset": Object {
158
+ "height": 14,
159
+ "width": 0,
160
+ },
161
+ "shadowOpacity": 0.25,
162
+ "shadowRadius": 28,
163
+ }
164
+ }
165
+ >
166
+ <Text>
167
+ Brand shadow (depth=28)
168
+ </Text>
169
+ </View>
170
+ </View>
171
+ `;
172
+
173
+ exports[`Shadow component tests Brand shadow (depth=64) 1`] = `
174
+ <View
175
+ style={
176
+ Object {
177
+ "shadowColor": "#000000",
178
+ "shadowOffset": Object {
179
+ "height": 0,
180
+ "width": 0,
181
+ },
182
+ "shadowOpacity": 0.3,
183
+ "shadowRadius": 8,
184
+ }
185
+ }
186
+ >
187
+ <View
188
+ style={
189
+ Object {
190
+ "shadowColor": "#000000",
191
+ "shadowOffset": Object {
192
+ "height": 32,
193
+ "width": 0,
194
+ },
195
+ "shadowOpacity": 0.25,
196
+ "shadowRadius": 64,
197
+ }
198
+ }
199
+ >
200
+ <Text>
201
+ Brand shadow (depth=64)
202
+ </Text>
203
+ </View>
204
+ </View>
205
+ `;
206
+
207
+ exports[`Shadow component tests Shadow (depth=2) 1`] = `
208
+ <View
209
+ style={
210
+ Object {
211
+ "shadowColor": "#000000",
212
+ "shadowOffset": Object {
213
+ "height": 0,
214
+ "width": 0,
215
+ },
216
+ "shadowOpacity": 0.12,
217
+ "shadowRadius": 2,
218
+ }
219
+ }
220
+ >
221
+ <View
222
+ style={
223
+ Object {
224
+ "shadowColor": "#000000",
225
+ "shadowOffset": Object {
226
+ "height": 1,
227
+ "width": 0,
228
+ },
229
+ "shadowOpacity": 0.14,
230
+ "shadowRadius": 2,
231
+ }
232
+ }
233
+ >
234
+ <Text>
235
+ Shadow (depth=2)
236
+ </Text>
237
+ </View>
238
+ </View>
239
+ `;
240
+
241
+ exports[`Shadow component tests Shadow (depth=4) 1`] = `
242
+ <View
243
+ style={
244
+ Object {
245
+ "shadowColor": "#000000",
246
+ "shadowOffset": Object {
247
+ "height": 0,
248
+ "width": 0,
249
+ },
250
+ "shadowOpacity": 0.12,
251
+ "shadowRadius": 2,
252
+ }
253
+ }
254
+ >
255
+ <View
256
+ style={
257
+ Object {
258
+ "shadowColor": "#000000",
259
+ "shadowOffset": Object {
260
+ "height": 2,
261
+ "width": 0,
262
+ },
263
+ "shadowOpacity": 0.14,
264
+ "shadowRadius": 4,
265
+ }
266
+ }
267
+ >
268
+ <Text>
269
+ Shadow (depth=4)
270
+ </Text>
271
+ </View>
272
+ </View>
273
+ `;
274
+
275
+ exports[`Shadow component tests Shadow (depth=8) 1`] = `
276
+ <View
277
+ style={
278
+ Object {
279
+ "shadowColor": "#000000",
280
+ "shadowOffset": Object {
281
+ "height": 0,
282
+ "width": 0,
283
+ },
284
+ "shadowOpacity": 0.12,
285
+ "shadowRadius": 2,
286
+ }
287
+ }
288
+ >
289
+ <View
290
+ style={
291
+ Object {
292
+ "shadowColor": "#000000",
293
+ "shadowOffset": Object {
294
+ "height": 4,
295
+ "width": 0,
296
+ },
297
+ "shadowOpacity": 0.14,
298
+ "shadowRadius": 8,
299
+ }
300
+ }
301
+ >
302
+ <Text>
303
+ Shadow (depth=8)
304
+ </Text>
305
+ </View>
306
+ </View>
307
+ `;
308
+
309
+ exports[`Shadow component tests Shadow (depth=16) 1`] = `
310
+ <View
311
+ style={
312
+ Object {
313
+ "shadowColor": "#000000",
314
+ "shadowOffset": Object {
315
+ "height": 0,
316
+ "width": 0,
317
+ },
318
+ "shadowOpacity": 0.12,
319
+ "shadowRadius": 2,
320
+ }
321
+ }
322
+ >
323
+ <View
324
+ style={
325
+ Object {
326
+ "shadowColor": "#000000",
327
+ "shadowOffset": Object {
328
+ "height": 8,
329
+ "width": 0,
330
+ },
331
+ "shadowOpacity": 0.14,
332
+ "shadowRadius": 16,
333
+ }
334
+ }
335
+ >
336
+ <Text>
337
+ Shadow (depth=16)
338
+ </Text>
339
+ </View>
340
+ </View>
341
+ `;
342
+
343
+ exports[`Shadow component tests Shadow (depth=28) 1`] = `
344
+ <View
345
+ style={
346
+ Object {
347
+ "shadowColor": "#000000",
348
+ "shadowOffset": Object {
349
+ "height": 0,
350
+ "width": 0,
351
+ },
352
+ "shadowOpacity": 0.2,
353
+ "shadowRadius": 8,
354
+ }
355
+ }
356
+ >
357
+ <View
358
+ style={
359
+ Object {
360
+ "shadowColor": "#000000",
361
+ "shadowOffset": Object {
362
+ "height": 14,
363
+ "width": 0,
364
+ },
365
+ "shadowOpacity": 0.24,
366
+ "shadowRadius": 28,
367
+ }
368
+ }
369
+ >
370
+ <Text>
371
+ Shadow (depth=28)
372
+ </Text>
373
+ </View>
374
+ </View>
375
+ `;
376
+
377
+ exports[`Shadow component tests Shadow (depth=64) 1`] = `
378
+ <View
379
+ style={
380
+ Object {
381
+ "shadowColor": "#000000",
382
+ "shadowOffset": Object {
383
+ "height": 0,
384
+ "width": 0,
385
+ },
386
+ "shadowOpacity": 0.2,
387
+ "shadowRadius": 8,
388
+ }
389
+ }
390
+ >
391
+ <View
392
+ style={
393
+ Object {
394
+ "shadowColor": "#000000",
395
+ "shadowOffset": Object {
396
+ "height": 32,
397
+ "width": 0,
398
+ },
399
+ "shadowOpacity": 0.24,
400
+ "shadowRadius": 64,
401
+ }
402
+ }
403
+ >
404
+ <Text>
405
+ Shadow (depth=64)
8
406
  </Text>
9
407
  </View>
10
408
  </View>
package/src/index.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export { Shadow } from './Shadow';
2
2
  export { ShadowDepth, ShadowProps } from './Shadow.types';
3
+ export { getShadowTokenStyleSet } from './shadowStyle';
@@ -0,0 +1,60 @@
1
+ import { Theme, memoize } from '@fluentui-react-native/framework';
2
+ import { ColorValue } from 'react-native';
3
+ import { ShadowDepth } from './Shadow.types';
4
+
5
+ export const getShadowTokenStyleSet = memoize(getShadowTokenStyleSetWorker);
6
+
7
+ function getShadowTokenStyleSetWorker(t: Theme, depth: ShadowDepth) {
8
+ if (!depth) {
9
+ return {
10
+ key: emptyShadowStyle,
11
+ ambient: emptyShadowStyle,
12
+ };
13
+ }
14
+
15
+ const keyShadow = t.shadows[depth.toString()].key;
16
+ const ambientShadow = t.shadows[depth.toString()].ambient;
17
+
18
+ return {
19
+ key: {
20
+ shadowColor: shadowColorFromRGBAColor(keyShadow.color),
21
+ shadowOpacity: shadowOpacityFromRGBAColor(keyShadow.color),
22
+ shadowRadius: keyShadow.blur,
23
+ shadowOffset: {
24
+ width: keyShadow.x,
25
+ height: keyShadow.y,
26
+ },
27
+ },
28
+ ambient: {
29
+ shadowColor: shadowColorFromRGBAColor(ambientShadow.color),
30
+ shadowOpacity: shadowOpacityFromRGBAColor(ambientShadow.color),
31
+ shadowRadius: ambientShadow.blur,
32
+ shadowOffset: {
33
+ width: ambientShadow.x,
34
+ height: ambientShadow.y,
35
+ },
36
+ },
37
+ };
38
+ }
39
+
40
+ const shadowColorFromRGBAColor = (rgbaColor: ColorValue) => {
41
+ return rgbaColor.toString().substring(0, 7);
42
+ };
43
+
44
+ const shadowOpacityFromRGBAColor = (rgbaColor: ColorValue) => {
45
+ const opacityAsHex = '0x' + rgbaColor.toString().substring(7);
46
+ const opacityAsDecimal = Number(opacityAsHex) / 255.0;
47
+
48
+ // Round to two decimal places
49
+ return Math.round(opacityAsDecimal * 100) / 100;
50
+ };
51
+
52
+ const emptyShadowStyle = {
53
+ shadowColor: '000000',
54
+ shadowOpacity: 0,
55
+ shadowRadius: 0,
56
+ shadowOffset: {
57
+ width: 0,
58
+ height: 0,
59
+ },
60
+ };