Skip to content

JSS plugin that enables support for nested selectors and pseudo selectors.

License

Notifications You must be signed in to change notification settings

vass-david/jss-nested

 
 

Repository files navigation

JSS logo

JSS plugin that enables support for nested selectors

Put an & before a selector within a rule and it will be replaced by the parent selector and extracted to a separate rule.

You can also reference a local rule within the style sheet by using $ruleName.

Make sure you read how to use plugins in general.

Demo - JSS

![Gitter](https://badges.gitter.im/Join Chat.svg)

Usage example

import jss from 'jss'
import nested from 'jss-nested'

jss.use(nested())

const sheet = jss.createStyleSheet({
  container: {
    padding: '20px',
    '&:hover': {
      background: 'blue'
    },
    // Add a global .clear class to the container.
    '&.clear': {
      clear: 'both'
    },
    // Reference a global .button scoped to the container.
    '& .button': {
      background: 'red'
    },
    // Use multiple container refs in one selector
    '&.selected, &.active': {
      border: '1px solid red'
    },
    // Reference the local rule "button".
    '& $button': {
      padding: '10px'
    }
  },
  button: {
    color: 'red'
  }
})
console.log(sheet.toString())
.container-12345 {
  padding: 20px;
}
.container-12345:hover {
  background: blue;
}
.container-12345.clear {
  clear: both;
}
.container-12345 .button {
  background: red;
}
.container-12345.selected, .container-12345.active {
  border: 1px solid red;
}
.button-12341 {
  color: red;
}
.container-12345 .button-12341 {
  padding: 10px;
}
console.log(sheet.classes)
{ container: "jss-0-0" }

Issues

File a bug against cssinjs/jss prefixed with [jss-nested].

Run tests

npm i
npm run test

License

MIT

About

JSS plugin that enables support for nested selectors and pseudo selectors.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 95.1%
  • HTML 4.9%