1. jss-extend
JSS plugin that enables mixing in styles.
jss-extend
Package: jss-extend
Created by: cssinjs
Last modified: Sun, 19 Jun 2022 06:56:39 GMT
Version: 6.2.0
License: MIT
Downloads: 239,592
Repository: https://github.com/cssinjs/jss-extend

Install

npm install jss-extend
yarn add jss-extend

JSS plugin that enables mixing in styles

Gitter

This plugin implements a custom property extend which allows you to mix in styles in various ways.

Style object own properties always take precedence over extended objects, so you can always override the extended definition. Exception is function values.

Use style object reference

 
const buttonColor = {
  color: 'green'
}
const buttonTheme = {
  extend: buttonColor
  background: 'red'
}
const styles = {
  button: {
    extend: buttonTheme,
    fontSize: '20px'
  }
}

Use rule name from the current styles object

 const styles = {
  buttonColor: {
    background: 'red'
  },
  button: {
    extend: 'buttonColor',
    fontSize: '20px'
  }
}

Use array of style objects

 const styles = {
  button: {
    extend: [{background: 'red'}, {color: 'green'}],
    fontSize: '20px'
  }
}
 
const background = {background: 'red'}
const color = {color: 'green'}

const styles = {
  button: {
    extend: [background, color],
    fontSize: '20px'
  }
}

Use function which returns a style object

Nested extend inside of the function is not supported. Will override other properties defined in the same rule.

 const styles = {
  button: {
    extend: (data) => ({
      color: data.theme.color
    }),
    fontSize: '20px'
  }
}

Demo

Simple demo

Multi objects demo

Issues

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

Run tests

 npm i
npm run test

License

MIT

Dependencies

Dependencies

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code