UNPKG

2.08 kBJavaScriptView Raw
1import { __extends } from "tslib";
2import * as React from 'react';
3import { Customizations } from './Customizations';
4import { CustomizerContext } from './CustomizerContext';
5import { mergeCustomizations } from './mergeCustomizations';
6/**
7 * The Customizer component allows for default props to be mixed into components which
8 * are decorated with the customizable() decorator, or use the styled HOC. This enables
9 * injection scenarios like:
10 *
11 * 1. render svg icons instead of the icon font within all buttons
12 * 2. inject a custom theme object into a component
13 *
14 * Props are provided via the settings prop which should be one of the following:
15 * - A json map which contains 1 or more name/value pairs representing injectable props.
16 * - A function that receives the current settings and returns the new ones that apply to the scope
17 *
18 * @public
19 */
20var Customizer = /** @class */ (function (_super) {
21 __extends(Customizer, _super);
22 function Customizer() {
23 var _this = _super !== null && _super.apply(this, arguments) || this;
24 _this._onCustomizationChange = function () { return _this.forceUpdate(); };
25 return _this;
26 }
27 Customizer.prototype.componentDidMount = function () {
28 Customizations.observe(this._onCustomizationChange);
29 };
30 Customizer.prototype.componentWillUnmount = function () {
31 Customizations.unobserve(this._onCustomizationChange);
32 };
33 Customizer.prototype.render = function () {
34 var _this = this;
35 var contextTransform = this.props.contextTransform;
36 return (React.createElement(CustomizerContext.Consumer, null, function (parentContext) {
37 var newContext = mergeCustomizations(_this.props, parentContext);
38 if (contextTransform) {
39 newContext = contextTransform(newContext);
40 }
41 return React.createElement(CustomizerContext.Provider, { value: newContext }, _this.props.children);
42 }));
43 };
44 return Customizer;
45}(React.Component));
46export { Customizer };
47//# sourceMappingURL=Customizer.js.map
\No newline at end of file