@fluentui-react-native/experimental-shadow 0.7.0 → 0.7.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/CHANGELOG.md +35 -0
- package/lib/Shadow.d.ts +2 -2
- package/lib/Shadow.js +70 -106
- package/lib/Shadow.types.d.ts +5 -5
- package/lib/Shadow.types.js +1 -1
- package/lib/__tests__/Shadow.test.d.ts +1 -1
- package/lib/__tests__/Shadow.test.js +131 -143
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/shadowStyle.d.ts +17 -17
- package/lib/shadowStyle.js +29 -29
- package/lib-commonjs/Shadow.d.ts +2 -2
- package/lib-commonjs/Shadow.js +106 -159
- package/lib-commonjs/Shadow.types.d.ts +5 -5
- package/lib-commonjs/Shadow.types.js +3 -3
- package/lib-commonjs/__tests__/Shadow.test.d.ts +1 -1
- package/lib-commonjs/__tests__/Shadow.test.js +168 -203
- package/lib-commonjs/index.d.ts +1 -1
- package/lib-commonjs/index.js +7 -17
- package/lib-commonjs/shadowStyle.d.ts +17 -17
- package/lib-commonjs/shadowStyle.js +33 -36
- package/package.json +26 -25
- package/eslint.config.js +0 -3
package/lib/shadowStyle.js
CHANGED
|
@@ -10,37 +10,37 @@ const appleShadowBlurAdjustment = 0.5;
|
|
|
10
10
|
const defaultShadowBlurAdjustment = 1;
|
|
11
11
|
export const getShadowTokenStyleSet = memoize(getShadowTokenStyleSetWorker);
|
|
12
12
|
function getShadowTokenStyleSetWorker(shadowToken) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
13
|
+
const keyShadow = shadowToken.key;
|
|
14
|
+
const ambientShadow = shadowToken.ambient;
|
|
15
|
+
const shadowBlurAdjustment = Platform.OS === 'macos' || Platform.OS === 'ios' ? appleShadowBlurAdjustment : defaultShadowBlurAdjustment;
|
|
16
|
+
return {
|
|
17
|
+
key: {
|
|
18
|
+
shadowColor: shadowColorFromRGBAColor(keyShadow.color),
|
|
19
|
+
shadowOpacity: shadowOpacityFromRGBAColor(keyShadow.color),
|
|
20
|
+
shadowRadius: keyShadow.blur * shadowBlurAdjustment,
|
|
21
|
+
shadowOffset: {
|
|
22
|
+
width: keyShadow.x,
|
|
23
|
+
height: keyShadow.y,
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
ambient: {
|
|
27
|
+
shadowColor: shadowColorFromRGBAColor(ambientShadow.color),
|
|
28
|
+
shadowOpacity: shadowOpacityFromRGBAColor(ambientShadow.color),
|
|
29
|
+
shadowRadius: ambientShadow.blur * shadowBlurAdjustment,
|
|
30
|
+
shadowOffset: {
|
|
31
|
+
width: ambientShadow.x,
|
|
32
|
+
height: ambientShadow.y,
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
36
|
}
|
|
37
37
|
const shadowColorFromRGBAColor = (rgbaColor) => {
|
|
38
|
-
|
|
38
|
+
return rgbaColor.toString().substring(0, 7);
|
|
39
39
|
};
|
|
40
40
|
const shadowOpacityFromRGBAColor = (rgbaColor) => {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
const opacityAsHex = '0x' + rgbaColor.toString().substring(7);
|
|
42
|
+
const opacityAsDecimal = Number(opacityAsHex) / 255.0;
|
|
43
|
+
// Round to two decimal places
|
|
44
|
+
return Math.round(opacityAsDecimal * 100) / 100;
|
|
45
45
|
};
|
|
46
|
-
//# sourceMappingURL=shadowStyle.js.map
|
|
46
|
+
//# sourceMappingURL=shadowStyle.js.map
|
package/lib-commonjs/Shadow.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { ShadowProps } from './Shadow.types';
|
|
2
|
-
export declare const Shadow: import(
|
|
2
|
+
export declare const Shadow: import("@fluentui-react-native/framework-base").FunctionComponent<ShadowProps>;
|
|
3
3
|
export default Shadow;
|
|
4
|
-
//# sourceMappingURL=Shadow.d.ts.map
|
|
4
|
+
//# sourceMappingURL=Shadow.d.ts.map
|
package/lib-commonjs/Shadow.js
CHANGED
|
@@ -1,176 +1,123 @@
|
|
|
1
|
-
|
|
2
|
-
var __createBinding =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
var
|
|
23
|
-
|
|
24
|
-
(Object.create
|
|
25
|
-
? function (o, v) {
|
|
26
|
-
Object.defineProperty(o, 'default', { enumerable: true, value: v });
|
|
27
|
-
}
|
|
28
|
-
: function (o, v) {
|
|
29
|
-
o['default'] = v;
|
|
30
|
-
});
|
|
31
|
-
var __importStar =
|
|
32
|
-
(this && this.__importStar) ||
|
|
33
|
-
(function () {
|
|
34
|
-
var ownKeys = function (o) {
|
|
35
|
-
ownKeys =
|
|
36
|
-
Object.getOwnPropertyNames ||
|
|
37
|
-
function (o) {
|
|
38
|
-
var ar = [];
|
|
39
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
40
|
-
return ar;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
41
24
|
};
|
|
42
|
-
|
|
25
|
+
return ownKeys(o);
|
|
43
26
|
};
|
|
44
27
|
return function (mod) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
50
33
|
};
|
|
51
|
-
|
|
52
|
-
Object.defineProperty(exports,
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
36
|
exports.Shadow = void 0;
|
|
54
|
-
const jsx_runtime_1 = require(
|
|
55
|
-
const React = __importStar(require(
|
|
56
|
-
const react_native_1 = require(
|
|
57
|
-
const framework_base_1 = require(
|
|
58
|
-
const Shadow_types_1 = require(
|
|
59
|
-
const shadowStyle_1 = require(
|
|
37
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
38
|
+
const React = __importStar(require("react"));
|
|
39
|
+
const react_native_1 = require("react-native");
|
|
40
|
+
const framework_base_1 = require("@fluentui-react-native/framework-base");
|
|
41
|
+
const Shadow_types_1 = require("./Shadow.types");
|
|
42
|
+
const shadowStyle_1 = require("./shadowStyle");
|
|
60
43
|
exports.Shadow = (0, framework_base_1.phasedComponent)((props) => {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
44
|
+
return (0, framework_base_1.directComponent)((final) => {
|
|
45
|
+
const { children, ...rest } = final;
|
|
46
|
+
if (!props.shadowToken) {
|
|
47
|
+
return jsx_runtime_1.jsx(jsx_runtime_1.Fragment, { children: children });
|
|
48
|
+
}
|
|
49
|
+
const { style: childStyle, ...restOfChildProps } = children.props;
|
|
50
|
+
const shadowViewStyleProps = getStylePropsForShadowViews(childStyle, props.shadowToken);
|
|
51
|
+
const innerShadowViewProps = (0, framework_base_1.mergeProps)(restOfChildProps, shadowViewStyleProps.inner);
|
|
52
|
+
const outerShadowViewProps = (0, framework_base_1.mergeProps)(rest, shadowViewStyleProps.outer);
|
|
53
|
+
const childWithInnerShadow = React.cloneElement(children, innerShadowViewProps);
|
|
54
|
+
return jsx_runtime_1.jsx(react_native_1.View, { ...outerShadowViewProps, children: childWithInnerShadow });
|
|
55
|
+
});
|
|
73
56
|
});
|
|
74
57
|
const getStylePropsForShadowViews = (0, framework_base_1.memoize)(getStylePropsForShadowViewsWorker);
|
|
75
58
|
function getStylePropsForShadowViewsWorker(childStyleProps = {}, shadowToken) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
59
|
+
const shadowTokenStyleSet = (0, shadowStyle_1.getShadowTokenStyleSet)(shadowToken);
|
|
60
|
+
if (__DEV__) {
|
|
61
|
+
if (!childStyleProps.backgroundColor) {
|
|
62
|
+
console.warn('The View that the Shadow is set on must have a background color set');
|
|
63
|
+
}
|
|
80
64
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
-
borderTopWidth,
|
|
128
|
-
borderWidth,
|
|
129
|
-
padding,
|
|
130
|
-
paddingBottom,
|
|
131
|
-
paddingEnd,
|
|
132
|
-
paddingHorizontal,
|
|
133
|
-
paddingLeft,
|
|
134
|
-
paddingRight,
|
|
135
|
-
paddingStart,
|
|
136
|
-
paddingTop,
|
|
137
|
-
paddingVertical,
|
|
138
|
-
alignItems,
|
|
139
|
-
flexWrap,
|
|
140
|
-
flexDirection,
|
|
141
|
-
...shadowTokenStyleSet.key,
|
|
142
|
-
...restOfChildStyleProps,
|
|
143
|
-
});
|
|
144
|
-
const outerStyle = removeUndefinedProperties({
|
|
145
|
-
margin,
|
|
146
|
-
marginBottom,
|
|
147
|
-
marginEnd,
|
|
148
|
-
marginHorizontal,
|
|
149
|
-
marginLeft,
|
|
150
|
-
marginRight,
|
|
151
|
-
marginStart,
|
|
152
|
-
marginTop,
|
|
153
|
-
marginVertical,
|
|
154
|
-
start,
|
|
155
|
-
end,
|
|
156
|
-
left,
|
|
157
|
-
right,
|
|
158
|
-
top,
|
|
159
|
-
bottom,
|
|
160
|
-
...shadowTokenStyleSet.ambient,
|
|
161
|
-
...restOfChildStyleProps,
|
|
162
|
-
});
|
|
163
|
-
return { inner: { style: innerStyle }, outer: { style: outerStyle } };
|
|
65
|
+
const { borderBottomWidth, borderEndWidth, borderLeftWidth, borderRightWidth, borderStartWidth, borderTopWidth, borderWidth, margin, marginBottom, marginEnd, marginHorizontal, marginLeft, marginRight, marginStart, marginTop, marginVertical, padding, paddingBottom, paddingEnd, paddingHorizontal, paddingLeft, paddingRight, paddingStart, paddingTop, paddingVertical, alignItems, flexWrap, flexDirection, start, end, left, right, top, bottom, ...restOfChildStyleProps } = childStyleProps;
|
|
66
|
+
// Remove undefined properties, otherwise every prop will be added and be set to
|
|
67
|
+
// undefined, which can cause unexpected behaviour with some of the styles
|
|
68
|
+
const innerStyle = removeUndefinedProperties({
|
|
69
|
+
borderBottomWidth,
|
|
70
|
+
borderEndWidth,
|
|
71
|
+
borderLeftWidth,
|
|
72
|
+
borderRightWidth,
|
|
73
|
+
borderStartWidth,
|
|
74
|
+
borderTopWidth,
|
|
75
|
+
borderWidth,
|
|
76
|
+
padding,
|
|
77
|
+
paddingBottom,
|
|
78
|
+
paddingEnd,
|
|
79
|
+
paddingHorizontal,
|
|
80
|
+
paddingLeft,
|
|
81
|
+
paddingRight,
|
|
82
|
+
paddingStart,
|
|
83
|
+
paddingTop,
|
|
84
|
+
paddingVertical,
|
|
85
|
+
alignItems,
|
|
86
|
+
flexWrap,
|
|
87
|
+
flexDirection,
|
|
88
|
+
...shadowTokenStyleSet.key,
|
|
89
|
+
...restOfChildStyleProps,
|
|
90
|
+
});
|
|
91
|
+
const outerStyle = removeUndefinedProperties({
|
|
92
|
+
margin,
|
|
93
|
+
marginBottom,
|
|
94
|
+
marginEnd,
|
|
95
|
+
marginHorizontal,
|
|
96
|
+
marginLeft,
|
|
97
|
+
marginRight,
|
|
98
|
+
marginStart,
|
|
99
|
+
marginTop,
|
|
100
|
+
marginVertical,
|
|
101
|
+
start,
|
|
102
|
+
end,
|
|
103
|
+
left,
|
|
104
|
+
right,
|
|
105
|
+
top,
|
|
106
|
+
bottom,
|
|
107
|
+
...shadowTokenStyleSet.ambient,
|
|
108
|
+
...restOfChildStyleProps,
|
|
109
|
+
});
|
|
110
|
+
return { inner: { style: innerStyle }, outer: { style: outerStyle } };
|
|
164
111
|
}
|
|
165
112
|
function withObjectAssign(object, [key, value]) {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
113
|
+
if (value !== undefined) {
|
|
114
|
+
return Object.assign(object, { [key]: value });
|
|
115
|
+
}
|
|
116
|
+
return object;
|
|
170
117
|
}
|
|
171
118
|
const removeUndefinedProperties = (object) => {
|
|
172
|
-
|
|
119
|
+
return Object.entries(object).reduce(withObjectAssign, {});
|
|
173
120
|
};
|
|
174
121
|
exports.Shadow.displayName = Shadow_types_1.shadowName;
|
|
175
122
|
exports.default = exports.Shadow;
|
|
176
|
-
//# sourceMappingURL=Shadow.js.map
|
|
123
|
+
//# sourceMappingURL=Shadow.js.map
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type React from 'react';
|
|
2
2
|
import type { ViewProps } from 'react-native';
|
|
3
3
|
import type { ShadowToken } from '@fluentui-react-native/theme-types';
|
|
4
|
-
export declare const shadowName =
|
|
4
|
+
export declare const shadowName = "Shadow";
|
|
5
5
|
export interface ShadowProps extends ViewProps {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
shadowToken?: ShadowToken;
|
|
7
|
+
/** Exactly one child */
|
|
8
|
+
children: React.ReactElement;
|
|
9
9
|
}
|
|
10
|
-
//# sourceMappingURL=Shadow.types.d.ts.map
|
|
10
|
+
//# sourceMappingURL=Shadow.types.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.shadowName = void 0;
|
|
4
4
|
exports.shadowName = 'Shadow';
|
|
5
|
-
//# sourceMappingURL=Shadow.types.js.map
|
|
5
|
+
//# sourceMappingURL=Shadow.types.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export {};
|
|
2
|
-
//# sourceMappingURL=Shadow.test.d.ts.map
|
|
2
|
+
//# sourceMappingURL=Shadow.test.d.ts.map
|