johanholmerin / style9

CSS-in-JS compiler inspired by Meta's stylex

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to define css variables?

edvinerikson opened this issue · comments

Hi Johan,
thank you so much for open-sourcing this library!

I'm using typescript and it complains about my CSS variables not existing on type "Style". At runtime it works fine though.
What's the recommended way of defining these variables?

const styles = style9.create({
  body: {
    margin: 0
  },
  lightTheme: {
    "--bg-color": "#CCC"
  }
});

Currently, there are two options:

  1. Module augmentation
declare module 'style9/Style' {
  interface StyleProperties {
    '--bg-color'?: string;
  }
}
  1. type assertion
const styles = style9.create({
  lightTheme: {
    ["--bg-color" as any]: "#CCC"
  }
});