6.0.1 • Published 8 years ago

jss-nested v6.0.1

Weekly downloads
285,805
License
MIT
Repository
github
Last release
8 years ago

JSS plugin enables support for nested rules

Gitter

Make sure you read how to use plugins in general.

Use & to reference selector of the parent rule.

const styles = {
  container: {
    padding: 20,
    '&: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'
    }
  }
}

Compiles to:

.container-3775999496 {
  padding: 20px;
}
.container-3775999496:hover {
  background: blue;
}
.container-3775999496.clear {
  clear: both;
}
.container-3775999496 .button {
  background: red;
}
.container-3775999496.selected, .container-3775999496.active {
  border: 1px solid red;
}

Use $ruleName to reference a local rule within the same style sheet.

const styles = {
  container: {
    // Reference the local rule "button".
    '& $button': {
      padding: '10px'
    },
    // Multiple local refs in one rule.
    '&:hover $button, &:active $button': {
      color: 'red',
    },
    '&:focus $button': {
      color: 'blue'
    }
  },
  button: {
    color: 'grey'
  }
}

Compiles to:

.button-3940538223 {
  color: grey;
}
.container-2645419599 .button-3940538223 {
  padding: 10px;
}
.container-2645419599:hover .button-3940538223, .container-2645419599:active .button-3940538223 {
  color: red;
}
.container-2645419599:focus .button-3940538223 {
  color: blue;
}

Use at-rules inside of regular rules.

const styles = {
  button: {
    color: 'red',
    '@media (min-width: 1024px)': {
      width: 200
    }
  }
}

Compiles to:

.button-2683044438 {
  color: red;
}
@media (min-width: 1024px) {
  .button-2683044438 {
    width: 200px;
  }
}

Deep nesting

const styles = {
  button: {
    '&$warn': {
      color: 'red',
      '&:hover, &:focus': {
        color: 'white',
        background: 'red'
      }
    }
  },
  warn: {}
}

Compiles to:

.button-274964227.warn-2315792072 {
  color: red;
}
.button-274964227.warn-2315792072:hover, .button-274964227.warn-2315792072:focus {
  color: white;
  background: red;
}

Demo

Simple

Issues

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

Run tests

npm i
npm run test

License

MIT

@marketmuse/redux-devtools-inspectorcrehana-material-uiredux-devtools-inspector-maintainedfdt-react-styleguidisthexidave-material-ui-coresagira-jssunless-material-ui@everything-registry/sub-chunk-1990@unless.com/material-ui-corevue-component-docsvdux-material@docly/webjimmaaay-vue-styleguidist-testjss-angular-materialisomorf@fondi/material-uiubiatar-material-uitonchidot-react-modal-dialog@akira_fes/core@axelhzf/react-styleguidist-ts@afonso360/react-input-enhancements@bitionaire/react-styleguidist@6thquake/react-materialyet-another-datetime-pickeryet-another-datetime-picker2vue-styleguidist-jimmyvue-styleguidist2@gsmlg/com@elementum/sheet@getstation/theme@infinitebrahmanuniverse/nolb-jss@influitive/profile-details@maka/material-ui@nestio/cheryl@matthieulemoine/react-styleguidist@minh.nguyen/material-ui@minedeljkovic/redux-devtools-inspector@mavenlink/react-styleguidist@ixinwu-ngp/web-framework@ixinwu-ngp/web-styles@ixinwu-ngp/web-system@dulemon/react-tooltip@othera-dev/material-ui@roistat/ui@rollup-umd/react-styleguidistmui-coremoblee-uip-react-native-webpatternitypatternity-evoruikrdi-examplesreact-made-by-getapperreact-jss-preset-civicsourceseanthchao-testredux-devtools-inspector2semanticui-reactperdidopipe-documentationspolicygenius-react-styleguidistremotedev-inspector-monitorremotedev-inspector-monitor-support-navigatiomredux-inspector-monitorredux-devtools-inspector-check-type-fixredux-devtools-inspector-ie8redux-form-semantic-uireact-popover-controlreact-redux-provide-themereact-wobbly-spinnerreact-styleguidist-extendedreact-stylerreact-tooltip2infamousleoek-material-ui-core-forkmaterial-ui-nextleaderboard-femax-ui@weareroam/cake-ui-v1@wombocompo/dialog@troglotit/vue-styleguidist@uikit/stylesheet@toughland/kc-utils@vmo-fed/react-tooltip@zalastax/nolb-jss@zeelo/feui@sur-la-table/slt-ui@techstacker/stacked-uialchemy-uiarena-building-antd-uidaredevildeat-mui-corebetter-popoverbootstrap-css-in-jsdocsnowdoctorlink-design-systemdoctorlinkdselementum-tools-cli
6.0.1

8 years ago

6.0.0

8 years ago

5.0.0

8 years ago

4.0.1

8 years ago

4.0.0

8 years ago

3.0.1

8 years ago

3.0.0

9 years ago

2.5.0

9 years ago

2.4.3

9 years ago

2.4.2

9 years ago

2.4.1

9 years ago

2.4.0

9 years ago

2.2.1

9 years ago

2.3.0

9 years ago

2.1.0

9 years ago

2.0.0

9 years ago

1.0.3

9 years ago

1.0.2

9 years ago

1.0.1

10 years ago

1.0.0

10 years ago

0.2.0

10 years ago

0.1.8

10 years ago

0.1.7

10 years ago

0.1.6

10 years ago

0.1.5

10 years ago

0.1.4

11 years ago

0.1.3

11 years ago

0.1.2

11 years ago

0.1.1

11 years ago

0.1.0

11 years ago