Created
February 5, 2020 05:41
-
-
Save uto-usui/a53cbb9de6526ea8b288835787f8521b to your computer and use it in GitHub Desktop.
Creating and setting CSS variables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const SetVar = ({propertyName, value, el, pre = 'my'}) => { | |
if (!el) { | |
document.documentElement.style.setProperty(`--${pre}-${propertyName}`, value) | |
} else { | |
el.style.setProperty(`--${pre}-${propertyName}`, value) | |
} | |
} | |
export default SetVar |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment