UNPKG

react-elegant-ui

Version:

Elegant UI components, made by BEM best practices for react

21 lines 757 B
import { canUseDOM } from '../../lib/canUseDOM'; import { cnTheme } from '..'; var prevClassName = ''; /** * Helper to set theme to root node. This theme will be global */ export var configureRootTheme = function (_a) { var theme = _a.theme, _b = _a.root, root = _b === void 0 ? canUseDOM() ? document.body : null : _b; if (!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 = cnTheme(theme !== null && theme !== void 0 ? theme : {}); root.className = "".concat(rootClassName, " ").concat(prevClassName); };