Change CSS variable helper to proxy

This commit is contained in:
Talia 2021-08-18 11:35:54 +02:00
parent 05a673cb59
commit 545d6afa0e
No known key found for this signature in database
GPG key ID: AD727AD22802D0D6

11
css.js
View file

@ -33,4 +33,13 @@ export const style = styles => {
return style return style
} }
export const v = name => `var(--${keyToPropName(name)})` const mkVar = name => {
const v = (def) => `var(--${name}, ${def})`
v.toString = () => `var(--${name})`
return v
}
export const v = new Proxy(Window, {
get: (target, name, receiver) => mkVar(name),
apply: (target, object, [name]) => `var(--${keyToPropName(name)})`,
})