Socket
Socket
Sign inDemoInstall

@bem-react/classname

Package Overview
Dependencies
0
Maintainers
7
Versions
35
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @bem-react/classname

BEM React ClassName


Version published
Weekly downloads
12K
decreased by-1.16%
Maintainers
7
Install size
34.9 kB
Created
Weekly downloads
 

Readme

Source

@bem-react/classname · npm (scoped) npm bundle size (minified + gzip)

Tiny helper for building CSS classes with BEM methodology.

Install

npm i -S @bem-react/classname

Usage

import { cn } from '@bem-react/classname'

const cat = cn('Cat')

cat() // Cat
cat({ size: 'm' }) // Cat Cat_size_m
cat('Tail') // Cat-Tail
cat('Tail', { length: 'small' }) // Cat-Tail Cat-Tail_length_small

const dogPaw = cn('Dog', 'Paw')

dogPaw() // Dog-Paw
dogPaw({ color: 'black', exists: true }) // Dog-Paw Dog-Paw_color_black Dog-Paw_exists

// mixes

cat(null, ['Dog']) // Cat Dog
cat({ size: 'm' }, ['Dog', 'Horse']) // Cat Cat_size_m Dog Horse

cat('Tail', [dogPaw()]) // Cat-Tail Dog-Paw
cat('Tail', { length: 'small' }, [dogPaw({ color: 'black' })]) // Cat-Tail Cat-Tail_length_small Dog-Paw Dog-Paw_color_black

Configure

By default classname uses React naming preset. But it's possible to use any.

import { withNaming } from '@bem-react/classname'

const cn = withNaming({ n: 'ns-', e: '__', m: '_', v: '_' })

cn('block', 'elem')({ theme: 'default' }) // ns-block__elem_theme_default

Keywords

FAQs

Last updated on 04 Apr 2023

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