1. jss-default-unit
JSS plugin that adds default custom unit to numeric values where needed
jss-default-unit
Package: jss-default-unit
Created by: cssinjs
Last modified: Sun, 19 Jun 2022 06:56:37 GMT
Version: 8.0.2
License: MIT
Downloads: 514,487
Repository: https://github.com/cssinjs/jss-default-unit

Install

npm install jss-default-unit
yarn add jss-default-unit

JSS plugin that adds units to numeric values

Gitter

Provide plain numeric values in your JSS style definitions, and the plugin will insert the apposite units. Defaults to px for sizes, ms for durations, and % for transform origins, and these can be customized easily (see Usage Example).

Make sure you read how to use
plugins

in general.

Setup

 import jss from 'jss'
import defaultUnit from 'jss-default-unit'

// Optionally you can customize default units.
const options = {
  'line-height': 'rem',
  'font-size': 'rem'
}

jss.use(defaultUnit(options))

Example

 const styles = {
  container: {
    'line-height': 3,
    'font-size': 1.7,
    'height': 200,
    'z-index': 1
  }
}

Compiles to:

 .container-sdf345 {
  line-height: 3rem;
  font-size: 1.7rem;
  height: 200px;
  z-index: 1;
}

Demo

Simple

Issues

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

Run tests

 npm i
npm run test

License

MIT

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