Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Idea: ability to set a default unit, then use Numbers instead of strings. #33

Closed
trusktr opened this issue Dec 28, 2014 · 9 comments
Closed

Comments

@trusktr
Copy link

trusktr commented Dec 28, 2014

px would be the default. For example, so that we can replace

var style = {
  '.button': {
    width: '20px'
  }
}

with

var style = {
  '.button': {
    width: 20
  }
}

but if a different unit than the default px is wanted, then perhaps something like

jss.defaultUnit = 'em';
// or
jss.createStyleSheet(style, {defaultUnit: 'em'})
@trusktr
Copy link
Author

trusktr commented Dec 28, 2014

Or perhaps even something more advanced that would let default units to be specified for specific properties, e.g.

jss.createStyleSheet(style, {
  units: {
    default: 'px',
    'font-size': 'em' // override default
  }
});

@kof
Copy link
Member

kof commented Dec 28, 2014

I already had a default for numbers - px. Removed it.

This is problematic, not all styles can be defined in em, not all in px

f.e. z-index is pure number
border can't be in %

Also more or less ok from the performance are values with just one definition, like height: 10, but if you get something like border: 1 solid red; you need to parse more to add unit to the number.

Maybe it is a task for a preprocessor.

@kof
Copy link
Member

kof commented Dec 28, 2014

By having more than 1 default unit, you make styles uncomposable in case you want to mix styles with different default units to create a new style.

@kof
Copy link
Member

kof commented Dec 28, 2014

I am not sure all the problems worth it.

@trusktr
Copy link
Author

trusktr commented Dec 28, 2014

True. I haven't tried composing yet. Closing since yeah, it sounds complicated. xD

@trusktr trusktr closed this as completed Dec 28, 2014
@kof
Copy link
Member

kof commented Dec 28, 2014

I am still thinking to make the px default similar to jquery as a jss plugin.

@trusktr
Copy link
Author

trusktr commented Jan 1, 2015

gss also uses a px default.

@kof
Copy link
Member

kof commented Jan 5, 2015

https://github.com/jsstyles/jss-px

works same way as in jquery.

@trusktr
Copy link
Author

trusktr commented Jan 7, 2015

OOOOhhhh yeaaaaah. Niiiice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants