Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-object-styles-to-template

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-object-styles-to-template

Babel plugin to transpile object styles to template literal

  • 0.2.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
16
decreased by-15.79%
Maintainers
1
Weekly downloads
 
Created
Source

babel-plugin-object-styles-to-template

Babel plugin to transpile object styles to template literal.

The plugin will convert styles written in object syntax to tagged template literal which libraries like linaria and styled-components can consume.

Usage

Install the plugin:

yarn add --dev babel-plugin-object-styles-to-template

Then include it in your .babelrc:

{
  "plugins": ["object-styles-to-template"]
}

Example

When you write the following:

const container = css({
  flex: 1,
  padding: 10,
  backgroundColor: 'orange',
  color: colors.white,

  '&:hover': {
    backgroundColor: 'tomato',
  },
});

It's transpiled to:

const container = css`
  flex: 1;
  padding: 10px;
  background-color: orange;
  color: ${colors.white};

  &:hover {
    background-color: tomato;
  }
`;

The styled components syntax is also supported. So when you write the following:

const FancyButton = styled(Button)({
  backgroundColor: 'papayawhip',
});

It's transpiled to:

const FancyButton = styled(Button)`
  background-color: papayawhip;
`;

Options

You can selectively enable/disable the tags transpiled by the plugin:

  • css: boolean: Whether to transpile css tags. Default: true.
  • styled: boolean: Whether to transpile styled components like styled tags. Default true.

To pass options to the plugin, you can use the following syntax:

{
  "plugins": [
    ["object-styles-to-template", { "css": true, "styled": false }]
  ]
}

Keywords

FAQs

Package last updated on 22 Sep 2018

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc