@chakra-ui/styled-system
Version:
Style function for css-in-js building component libraries
41 lines (38 loc) • 1.3 kB
JavaScript
import { analyzeBreakpoints } from '@chakra-ui/utils';
import { createThemeVars } from './create-theme-vars.mjs';
import { omitVars } from './theme-tokens.mjs';
import { isStylePropFn } from '../system.mjs';
function toCSSVar(rawTheme) {
const theme = omitVars(rawTheme);
const {
/**
* 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(theme);
const 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"
};
const isStyleProp = isStylePropFn(theme);
Object.assign(theme, {
__cssVars: { ...defaultCssVars, ...cssVars },
__cssMap: cssMap,
__breakpoints: analyzeBreakpoints(theme.breakpoints),
__isStyleProp: isStyleProp
});
return theme;
}
export { toCSSVar };