Last active
November 7, 2022 21:07
-
-
Save not-ivy/cf9de0758d783cc52bcd1240827dea83 to your computer and use it in GitHub Desktop.
json to css vars
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
import { useRef, useEffect, useState } from 'preact/hooks'; | |
export function App() { | |
const [keys, setKeys] = useState<string[]>([]); | |
const [obj, setObj] = useState<any>(); | |
return ( | |
<> | |
<textarea | |
onInput={(ev) => { | |
const vars = JSON.parse(ev.currentTarget.value); | |
setObj(vars); | |
setKeys((keyof vars)); | |
}} | |
/> | |
<div style={{ fontFamily: 'monospace' }}> | |
* { <br /> | |
{keys.map((k) => ( | |
<> | |
<span> | |
--{k}: {obj[k]}; | |
</span>{' '} | |
<br /> | |
</> | |
))} | |
} | |
</div> | |
</> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment