Skip to content

Instantly share code, notes, and snippets.

@crswll
Created February 4, 2020 19:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crswll/de1a1703c07e47957dc6a212c7549edf to your computer and use it in GitHub Desktop.
Save crswll/de1a1703c07e47957dc6a212c7549edf to your computer and use it in GitHub Desktop.
const getTailwindExtend = themeUiConfig => {
const propertyMap = {
"borderStyles": ["borderStyle"],
"borderWidths": ["borderWidth"],
"breakpoints": ["screens"],
"colors": ["colors"],
"letterSpacings": ["letterSpacing"],
"lineHeights": ["lineHeight"],
"radii": ["borderRadius"],
"fontWeights": ["fontWeight"],
"fontSizes": ["fontSize"],
"shadows": ["boxShadow"],
"space": ["spacing"],
"zIndices": ["zIndex"],
"sizes": [
"width",
"minWidth",
"maxWidth",
"height",
"minHeight",
"maxHeight",
],
}
return Object.keys(themeUiConfig).reduce((tailwindConfig, themeUiKey) => {
const additionalTailwindConfig = propertyMap[themeUiKey] &&
propertyMap[themeUiKey].reduce((acc, tailwindConfigKey) => ({
...acc,
[tailwindConfigKey]: themeUiConfig[themeUiKey],
}), {})
return {
...tailwindConfig,
...(additionalTailwindConfig || {}),
}
}, {})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment