1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var tslib_1 = require("tslib");
|
4 | var React = require("react");
|
5 | var merge_styles_1 = require("@uifabric/merge-styles");
|
6 | var useCustomizationSettings_1 = require("./customizations/useCustomizationSettings");
|
7 | var DefaultFields = ['theme', 'styles'];
|
8 | function styled(Component, baseStyles, getProps, customizable, pure) {
|
9 | customizable = customizable || { scope: '', fields: undefined };
|
10 | var scope = customizable.scope, _a = customizable.fields, fields = _a === void 0 ? DefaultFields : _a;
|
11 | var Wrapped = React.forwardRef(function (props, forwardedRef) {
|
12 | var styles = React.useRef();
|
13 | var settings = useCustomizationSettings_1.useCustomizationSettings(fields, scope);
|
14 | var customizedStyles = settings.styles, dir = settings.dir, rest = tslib_1.__rest(settings, ["styles", "dir"]);
|
15 | var additionalProps = getProps ? getProps(props) : undefined;
|
16 |
|
17 | var cache = (styles.current && styles.current.__cachedInputs__) || [];
|
18 | if (!styles.current || customizedStyles !== cache[1] || props.styles !== cache[2]) {
|
19 |
|
20 | var concatenatedStyles = function (styleProps) {
|
21 | return merge_styles_1.concatStyleSetsWithProps(styleProps, baseStyles, customizedStyles, props.styles);
|
22 | };
|
23 |
|
24 |
|
25 | concatenatedStyles.__cachedInputs__ = [
|
26 | baseStyles,
|
27 | customizedStyles,
|
28 | props.styles,
|
29 | ];
|
30 | concatenatedStyles.__noStyleOverride__ =
|
31 | !customizedStyles && !props.styles;
|
32 | styles.current = concatenatedStyles;
|
33 | }
|
34 | return React.createElement(Component, tslib_1.__assign({ ref: forwardedRef }, rest, additionalProps, props, { styles: styles.current }));
|
35 | });
|
36 |
|
37 |
|
38 |
|
39 | Wrapped.displayName = "Styled" + (Component.displayName || Component.name);
|
40 |
|
41 | var pureComponent = pure ? React.memo(Wrapped) : Wrapped;
|
42 |
|
43 | if (Wrapped.displayName) {
|
44 | pureComponent.displayName = Wrapped.displayName;
|
45 | }
|
46 | return pureComponent;
|
47 | }
|
48 | exports.styled = styled;
|
49 |
|
\ | No newline at end of file |