@chakra-ui/styled-system
Version:
Style function for css-in-js building component libraries
49 lines (45 loc) • 1.95 kB
JavaScript
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
import { analyzeBreakpoints } from "@chakra-ui/utils";
import { createThemeVars } from "./create-theme-vars";
import { extractTokens, omitVars } from "./theme-tokens";
export function toCSSVar(rawTheme) {
var _theme$config;
/**
* In the case the theme has already been converted to css-var (e.g extending the theme),
* we can omit the computed css vars and recompute it for the extended theme.
*/
var theme = omitVars(rawTheme); // omit components and breakpoints from css variable map
var tokens = extractTokens(theme);
var cssVarPrefix = (_theme$config = theme.config) == null ? void 0 : _theme$config.cssVarPrefix;
var {
/**
* This is more like a dictionary of tokens users will type `green.500`,
* and their equivalent css variable.
*/
cssMap,
/**
* The extracted css variables will be stored here, and used in
* the emotion's <Global/> component to attach variables to `:root`
*/
cssVars
} = createThemeVars(tokens, {
cssVarPrefix
});
var defaultCssVars = {
"--chakra-ring-inset": "var(--chakra-empty,/*!*/ /*!*/)",
"--chakra-ring-offset-width": "0px",
"--chakra-ring-offset-color": "#fff",
"--chakra-ring-color": "rgba(66, 153, 225, 0.6)",
"--chakra-ring-offset-shadow": "0 0 #0000",
"--chakra-ring-shadow": "0 0 #0000",
"--chakra-space-x-reverse": "0",
"--chakra-space-y-reverse": "0"
};
Object.assign(theme, {
__cssVars: _extends({}, defaultCssVars, cssVars),
__cssMap: cssMap,
__breakpoints: analyzeBreakpoints(theme.breakpoints)
});
return theme;
}
//# sourceMappingURL=to-css-var.js.map