@iamstarkov/jss-sheets-manager
v8.0.0
Published
A lib for generating Style Sheets with JavaScript.
Downloads
2
Maintainers
Readme
JSS
JSS is a better abstraction over CSS. It uses JavaScript as a language to describe styles in a declarative and maintainable way. It is a high performance JS to CSS compiler which works at runtime and server-side. You can use it with React or with any other library. It is about 5KB (minified and gzipped) and is extensible via plugins API.
Integrations
Official
- React-JSS - HOC interface for React, try it on webpackbin.
- Styled-JSS - styled components interface for React, try it on webpackbin.
- Aphrodite-JSS - aphrodite like API.
External
- Theme Reactor - experimental React integration with theming.
- Aesthetic - a React style abstraction layer with theme support.
TOC
- Live examples.
- Benefits
- Setup
- JSON API (JSS Syntax)
- JavaScript API
- Server-side rendering
- Performance
- Plugins API
- Official plugins
- All related projects
- CLI Converter
- Contributing
Example
Try it out on webpackbin. You need to setup plugins before. You can use a preset for a quick setup with default plugins.
import jss from 'jss'
import preset from 'jss-preset-default'
import color from 'color'
// One time setup with default plugins and settings.
jss.setup(preset())
const styles = {
button: {
fontSize: 12,
'&:hover': {
background: 'blue'
}
},
ctaButton: {
extend: 'button',
'&:hover': {
background: color('blue').darken(0.3).hex()
}
},
'@media (min-width: 1024px)': {
button: {
width: 200
}
}
}
const {classes} = jss.createStyleSheet(styles).attach()
document.body.innerHTML = `
<button class="${classes.button}">Button</button>
<button class="${classes.ctaButton}">CTA Button</button>
`
Result
<head>
<style type="text/css">
.button-123456 {
font-size: 12px;
}
.button-123456:hover {
background: blue;
}
.ctaButton-789012 {
font-size: 12px;
}
.ctaButton-789012:hover {
background: red;
}
@media (min-width: 1024px) {
.button-123456 {
min-width: 200px;
}
}
</style>
</head>
<body>
<button class="button-123456">Button</button>
<button class="ctaButton-789012">CTA Button</button>
</body>
When should I use it?
- You build a JavaScript heavy application.
- You use components based architecture.
- You build a reusable UI library.
- You need a collision free CSS (external content, third-party UI components ...).
- You need code sharing between js and css.
- Minimal download size is important to you.
- Robustness and code reuse is important to you.
- Ease of maintenance is important to you.
- You just want to use any of its benefits
Roadmap
- ~~Make it easier for newcomers to setup jss with plugins (like presets).~~
- ~~Make JSON DSL even better, for e.g. jss-expand.~~
- ~~Make it easy to see when changes in the core break plugins (integrate plugins test suite).~~
- Make community create plugins (better plugins API documentation, infrastructure).
- Do more benchmarking, include plugins, always track perf regressions.
- Introduce a way for theming with react-jss or replace it by jss-theme-reactor
- Make SSR even better (vendor prefixer, smaller critical CSS)
- Make CLI tool better, allow integration of styles written in various preprocessing languages as well as pure css.
- React Native support.
- Add converters stylus, sass and co. to cli with constants reuse.
Browsers Support
We have automated tests running in real browsers.
License
MIT
Thanks
Thanks to BrowserStack for providing the infrastructure that allows us to run our tests in real browsers and to all awesome contributors.
Backers
Support us with a monthly donation and help us continue our activities. [Become a backer]
Sponsors
Become a sponsor and get your logo on our README on Github with a link to your site. [Become a sponsor]