rtsao / csjs

:sparkles: Modular, scoped CSS with ES6
MIT License
576 stars 32 forks source link

Is it possible to define #id style even if that's considered bad practice? #55

Closed avesus closed 7 years ago

rtsao commented 7 years ago

Yep, you can use IDs! However, they won't be scoped (they'll just get passed through to the CSS untouched by csjs) Hope that helps 😄

avesus commented 7 years ago
const style = csjs`

  # some_id {
    color: yellow;
  }
`;

style.some_id === undefined

And so it wasn't work for me... What I miss?

rtsao commented 7 years ago

Ah yes, the ID is never parsed (since it isn't a class), so it isn't scoped and is thus not provided in the returned object (that maps unscoped to scoped).

const style = csjs`
  #some_id {
    color: yellow;
  }

  #another_id, .bar {
    color: green;
  }
`;

Then you can render something like:

<div id="some_id">foo</div>
<div class={styles.bar}>bar</div>

Since the ID is not scoped, you can just reference that ID directly.

avesus commented 7 years ago

Thank you very much fro the explanation! Great library, I use it in production and it's the only covers all composability patterns I was dreaming about. Very modular.