<style type="text/javascript">
tags.H1.color = "blue";
</style>
component-a button {
background: red;
}
component-b button {
color: green;
}
Lets use component B within component A.
<component-a>
<button>Button A</butotn>
<component-b>
<button>Button B</butotn>
</component-b>
</component-a>
Is only useful when you are never going to
compose components.
Is a bad practice and we all know why, right?
// component-a.js
module.exports = {
button: {
background: 'red'
}
}
// component-b.js
module.exports = {
button: {
color: 'green'
}
}
// app.js
var a = require('./component-a')
var b = require('./component-b')
jss.createStyleSheet(a, true).attach()
jss.createStyleSheet(b, true).attach()
<style>
.jss-0 {
background: red;
}
</style>
<style>
.jss-1 {
color: green;
}
</style>
Is infinitely flexible.
Done by "extend" plugin.
// base-button.js
module.exports = {
color: 'red'
}
// styles.js
var baseButton = require('./base-button')
module.exports = {
'.button': {
extend: baseButton,
float: 'left'
}
}
// app.js
var styles = require('./styles')
jss.createStyleSheet(styles).attach()
<style>
.button {
color: red;
float: left;
}
</style>
Done by "nested" plugin.
// styles.js
module.exports = {
'.button': {
float: 'left',
'&:hover': {
color: 'red'
},
'& .icon': {
border: '1px solid red'
}
}
}
// app.js
var styles = require('./styles')
jss.createStyleSheet(styles).attach()
<style>
.button {
float: left;
}
.button:hover {
color: red;
}
.button .icon {
width: 20px;
height: 20px
}
</style>
Done by "vendorPrefixer" plugin.
Added very efficiently at runtime.
// styles.js
module.exports = {
'.button': {
transform: 'translateX(100px)'
}
}
// app.js
var styles = require('./styles')
jss.createStyleSheet(styles).attach()
<style>
.button {
-webkit-transform: translate(100px);
}
</style>
Now it's really easy to reuse and access constants.
// vars.js
module.exports = {
color: '#fff',
height: 20
}
// styles.js
var vars = require('./vars')
module.exports = {
button: {
color: vars.color,
height: vars.height + 'px'
}
}
// app.js
var vars = require('./vars')
// Do something usefull
$('something').height(vars.height)
// styles.js
module.exports = {
button: {
padding: '20px',
background: 'blue'
}
}
// app.js
var styles = require('./styles')
var ss = jss.createStyleSheet(styles, true)
$('button').css(ss.rules.button.style)
JS layout engines will love it!
bootstrap css (134kb) vs. bootstrap jss:
http://jsstyles.github.io/jss/bench/bootstrap/css.html
http://jsstyles.github.io/jss/bench/bootstrap/jss.html
Jss overall overhead ~10-15ms on desktop chrome.
You might want to convert critical path
jss to css and inline it.
var ss = jss.createStyleSheet({
'a': {
color: 'red'
}
})
console.log(ss.toString())
// Output
a {
color: red;
}
Render jss styles only for components which are in the render tree.
Remove jss styles when components are detached.
https://github.com/jsstyles/jss
Examples
http://jsstyles.github.io/jss/examples/
By Oleg Slobodskoi @oleg008