Socket
Socket
Sign inDemoInstall

css-in-js

Package Overview
Dependencies
3
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    css-in-js

Write stylesheets in JS. Works with any stack.


Version published
Weekly downloads
4
decreased by-50%
Maintainers
1
Install size
20.3 kB
Created
Weekly downloads
 

Readme

Source

Travis – build status
Coveralls – test coverage
David – status of dependencies
Code style: airbnb

css-in-js

Write stylesheets in JS.
Works with any stack.

There are many ways of writing styles as JS (Free Style, restyle and babel-plugin-css-in-js – just to name a few). But none of them has the option to compile to a good old interoperable CSS stylesheet, or the new and shiny CSS module. I wanted an easy way to take advantage of JS goodness when writing stylesheets – a way compatible with any tech stack.

 

Installation

npm install [--save] css-in-js

 

Usage

const cssInJs = require('css-in-js');

const indigo = '#3F51B5';

▸ cssInJs({
    '.my-button': {
      'width': '50px',
      'background-color': indigo,
    },

    '@media screen and (min-width: 80em)': {
      '.my-button': {
        'width': '100%',
      },
    },
  });
◂ `
  .my-button {
    width: 50px;
    background-color: #3F51B5;
  }

  @media screen and (min-width: 80em) {
    .my-button {
      width: 100%;
    }
  }
  `

 

Syntax

Any JS object is translated recursively to a CSS tree. To ensure two-way compatibility, we only support git.io/orthodox style objects.

Fallbacks

When using fancy things which need a CSS fallback, you might want to set the same property more than once:

.drag-me {
  cursor: pointer;
  cursor: -webkit-grab;
  cursor: grab;
}

To cover these cases, we allow passing an array of style objects:

cssInJs({
    '.drag-me': [{
      cursor: 'pointer',
    }, {
      cursor: '-webkit-grab',
    }, {
      cursor: 'grab',
    }],
  });
◂ `
  .drag-me {
    cursor: pointer;
    cursor: -webkit-grab;
    cursor: grab;
  }
  `

 

Credits

css-in-js is heavily inspired by the great elm-css by Richard Feldman. The name is inspired by the disrupting React talk CSS in JS by Christopher Chedeau.

 

License

MIT © Tomek Wiszniewski

FAQs

Last updated on 16 Mar 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc