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

babel-plugin-jsx-classnames

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-jsx-classnames

babel plugin for automatically adding `classnames()` to `className` attribute.

  • 1.0.1
  • latest
  • npm
  • Socket score

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

babel-plugin-jsx-classnames

babel plugin for automatically adding classnames() to className attribute.

transform

<div className={expression}></div>

to

<div className={classNames(expression)}></div>

Why

classNames

In React, when you need to render conditionally classNames, you can write code like this:

<button className={`${active ? 'btn-active' : ''} ${disabled ? 'btn-disabled' : ''}`}>
</button>

classnames can help you write clear conditionally classNames:

<button
  className={classNames({
    'btn-active': active,
    'btn-disabled': disabled,
  })}>
</button>

babel-plugin-jsx-classnames

This babel plugin will keep you away from writing many classNames, make the code clean and easy to read.

Usage

Install:

npm i babel-plugin-jsx-classnames --save-dev

Use plugin (example .babelrc):

{
  "presets": [
    "env",
    "react"
  ],
  "plugins": [
    ...
    "jsx-classnames"
  ]
}

Write your jsx:

<button
  className={{
    'btn-active': active,
    'btn-disabled': disabled,
  }}>
</button>

It will be transformed to:

import classNames from 'classnames'

<button
  className={classNames({
    'btn-active': active,
    'btn-disabled': disabled,
  })}>
</button>

FAQs

Package last updated on 21 Sep 2017

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