6.0.1 • Published 7 years ago

jss-nested v6.0.1

Weekly downloads
285,805
License
MIT
Repository
github
Last release
7 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-corep-react-native-webmoblee-uiperdidopatternitypatternity-evopipe-documentationspolicygenius-react-styleguidistbetter-popover@docly/webbootstrap-css-in-js@zalastax/nolb-jss@uikit/stylesheet@vmo-fed/react-tooltip@zeelo/feuiarena-building-antd-ui@bitionaire/react-styleguidist@axelhzf/react-styleguidist-ts@getstation/theme@weareroam/cake-ui-v1yet-another-datetime-pickeryet-another-datetime-picker2ubiatar-material-ui@afonso360/react-input-enhancements@akira_fes/corevue-styleguidist-jimmyvue-styleguidist2@troglotit/vue-styleguidist@wombocompo/dialogvue-component-docs@techstacker/stacked-ui@toughland/kc-utilsjss-angular-materialleaderboard-feinfamousisomorfleoek-material-ui-core-forkmax-uimaterial-ui-nextjimmaaay-vue-styleguidist-testmui-corereact-jss-preset-civicsourcereact-styleguidist-extendedreact-stylerreact-tooltip2react-popover-controlrdi-examplesremotedev-inspector-monitorremotedev-inspector-monitor-support-navigatiomredux-form-semantic-uiredux-devtools-inspector-check-type-fixredux-devtools-inspector-ie8redux-devtools-inspector2redux-inspector-monitorreact-wobbly-spinnerreact-made-by-getappertonchidot-react-modal-dialogruiksemanticui-react@elementum/sheetseanthchao-testreact-redux-provide-theme@dulemon/react-tooltip@fondi/material-ui@sur-la-table/slt-ui@roistat/uivdux-material@rollup-umd/react-styleguidistalchemy-ui@6thquake/react-materialdocsnowdoctorlink-design-systemdoctorlinkds@infinitebrahmanuniverse/nolb-jss@influitive/profile-detailselementum-tools-cli@matthieulemoine/react-styleguidist@mavenlink/react-styleguidist@maka/material-ui@minedeljkovic/redux-devtools-inspector@minh.nguyen/material-ui@nestio/cheryl@gsmlg/comdaredevildeat-mui-core@ixinwu-ngp/web-framework@ixinwu-ngp/web-styles@ixinwu-ngp/web-system@othera-dev/material-ui
6.0.1

7 years ago

6.0.0

7 years ago

5.0.0

7 years ago

4.0.1

7 years ago

4.0.0

7 years ago

3.0.1

7 years ago

3.0.0

7 years ago

2.5.0

7 years ago

2.4.3

8 years ago

2.4.2

8 years ago

2.4.1

8 years ago

2.4.0

8 years ago

2.2.1

8 years ago

2.3.0

8 years ago

2.1.0

8 years ago

2.0.0

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

9 years ago

1.0.0

9 years ago

0.2.0

9 years ago

0.1.8

9 years ago

0.1.7

9 years ago

0.1.6

9 years ago

0.1.5

9 years ago

0.1.4

9 years ago

0.1.3

9 years ago

0.1.2

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago