Functions for using BEM in CSS and CSS Modules.
# NPM
npm install @jahed/bem
# Yarn
yarn add @jahed/bemimport { bem } from '@jahed/bem'
const className = bem('MyElement', {
color: 'red',
active: true,
disabled: false
})
console.log(className)
// .MyElement .MyElement--color--red .MyElement--activeThe example below assumes you've configured CSS Modules to render classes with a -hash suffix.
import { bemModule } from '@jahed/bem'
import styles from 'styles.module.css'
const bem = bemModule(styles)
const className = bem('MyElement', {
color: 'red',
active: true,
disabled: false
})
console.log(className)
// .MyElement-hash .MyElement-hash--color--red .MyElement-hash--activeFor more thorough examples, see the tests and blog posts linked above.
For complete API documentation, see the documentation website.
bem(block: string, modifiers: object<string, (boolean|number|string)?>): string
Generates BEM-compliant class names for the given block (or element) with modifiers.
bemModule(cssModuleLocals): bem
Generates a bem-compliant function which maps the resulting class names to the given
cssModuleLocals map.
join(...string): string
Joins the given strings with a whitespace ( ), filtering any falsy
values (such as undefined, null, false, '').