blakeembrey / free-style

Make CSS easier and more maintainable by using JavaScript
MIT License
707 stars 29 forks source link

base tag selectors like `body`, `h1` not styleable #12

Closed queckezz closed 8 years ago

queckezz commented 8 years ago

Awesome library!

Currently it's not possible to style base tags like body, h1 etc:

style.registerStyle({
  body: {
    backgroundColor: 'red'
  }
})

Is there a reason behind this or an alternative method? If this is something that you want to add I'm happy to open a PR. I need to investigate into learning the typescript language before I can contribute tough.

blakeembrey commented 8 years ago

This is kind of intentional, since global styles go against the idea of having cleanly namespaced styles. What do you need it for? Technically, this does exist in an undocumented way using registerRule('body', {}).

queckezz commented 8 years ago

Right, I was just thinking about a base reset and some sane defaults like:

* {
  box-sizing: border-box
}

body {
  margin: 0;
  padding: 0
}

But it's totally fine to just put that in a <style> tag separately.

So you would advise against using the undocumented registerRule() even for base resets (or something along those lines)?

blakeembrey commented 8 years ago

If you want to use it, go ahead. I'll document it and add some tests so a regression doesn't occur.

registerRule('body', {
  margin: 0,
  padding: 0
})

Just not that this API doesn't do interpolation like registerStyle, but it's unlikely you need it anyhow.