UNPKG

react-elegant-ui

Version:

Elegant UI components, made by BEM best practices for react

28 lines (27 loc) 948 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.configureRootTheme = void 0; var _canUseDOM = require("../../lib/canUseDOM"); var _ = require(".."); var prevClassName = ''; /** * Helper to set theme to root node. This theme will be global */ var configureRootTheme = function (_a) { var theme = _a.theme, _b = _a.root, root = _b === void 0 ? (0, _canUseDOM.canUseDOM)() ? document.body : null : _b; if (!(0, _canUseDOM.canUseDOM)()) { return; } if (!root) { throw new Error("Property \"root\" is not DOM element. Can't set global theme."); } // Remove old className to prevent duplicates with repeated call var rootClassName = root.className.replace(prevClassName, ''); prevClassName = (0, _.cnTheme)(theme !== null && theme !== void 0 ? theme : {}); root.className = "".concat(rootClassName, " ").concat(prevClassName); }; exports.configureRootTheme = configureRootTheme;