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