Skip to content

Instantly share code, notes, and snippets.

@not-ivy
Last active November 7, 2022 21:07
Show Gist options
  • Save not-ivy/cf9de0758d783cc52bcd1240827dea83 to your computer and use it in GitHub Desktop.
Save not-ivy/cf9de0758d783cc52bcd1240827dea83 to your computer and use it in GitHub Desktop.
json to css vars
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' }}>
* &#123; <br />
{keys.map((k) => (
<>
<span>
--{k}: {obj[k]};
</span>{' '}
<br />
</>
))}
&#125;
</div>
</>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment