All Projects → agudulin → dumb-bem

agudulin / dumb-bem

Licence: MIT license
Simple BEM react components generator

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to dumb-bem

Synergy
Synergy is a framework for building modular, configurable and scalable UI components for React-DOM projects
Stars: ✭ 146 (+356.25%)
Mutual labels:  bem, react-components
Bem React
A set of tools for developing user interfaces using the BEM methodology in React
Stars: ✭ 382 (+1093.75%)
Mutual labels:  bem, react-components
react-ui-components
React UI Components (npm @assenti/rui-components)
Stars: ✭ 21 (-34.37%)
Mutual labels:  react-components
socket.io-react
A High-Order component to connect React and Socket.io easily
Stars: ✭ 67 (+109.38%)
Mutual labels:  react-components
React-Netflix-Clone
A Fully Responsive clone of Netflix website built using React.JS as a Front-end & Firebase as a Back-end.
Stars: ✭ 91 (+184.38%)
Mutual labels:  react-components
lighthouse
Lighthouse is a continuous design system for integrating design with development workflows.
Stars: ✭ 25 (-21.87%)
Mutual labels:  react-components
quarkify
An awesome lightweight React UI Component library
Stars: ✭ 79 (+146.88%)
Mutual labels:  react-components
paragon
💎 An accessible, theme-ready design system built for learning applications and Open edX.
Stars: ✭ 85 (+165.63%)
Mutual labels:  react-components
shared-react-components-example
An example of a mono-repository of shared React components libraries!
Stars: ✭ 85 (+165.63%)
Mutual labels:  react-components
ts-react-boilerplate
A very opinionated (React/TypeScript/Redux/etc) frontend boilerplate
Stars: ✭ 43 (+34.38%)
Mutual labels:  bem
vue-simple-bem
A simple Vue.js directive to map BEM CSS class names.
Stars: ✭ 17 (-46.87%)
Mutual labels:  bem
next-qrcode
React hooks for generating QRCode for your next React apps.
Stars: ✭ 87 (+171.88%)
Mutual labels:  react-components
React-Jupyter-Viewer
A react component to embed .ipyb notebooks in a blog or something
Stars: ✭ 50 (+56.25%)
Mutual labels:  react-components
superglue
A productive library for Classic Rails, React and Redux
Stars: ✭ 106 (+231.25%)
Mutual labels:  react-components
bem-react-boilerplate
DEPRECATED! A bare minimum frontend boilerplate based on create-react-app and bem-react-core.
Stars: ✭ 32 (+0%)
Mutual labels:  bem
react-fundamentals
React fundamentals
Stars: ✭ 15 (-53.12%)
Mutual labels:  react-components
awesome-web-react
🚀 Awesome Web Based React 🚀 Develop online with React!
Stars: ✭ 31 (-3.12%)
Mutual labels:  react-components
hyper
🎨 Hyper: A component-first CSS design system.
Stars: ✭ 26 (-18.75%)
Mutual labels:  bem
luxe
Luxe is a WordPress starter theme using a modern workflow and best practices.
Stars: ✭ 22 (-31.25%)
Mutual labels:  bem
frontend-toolbox
Frontend tools which we used in snappmarket v2
Stars: ✭ 37 (+15.63%)
Mutual labels:  react-components

Dumb BEM

Dumb BEM is a simple BEM class name transformation for React components.

npm Build Status license js-standard-style Managed by Yarn Developed at Wimdu

Install

npm install --save dumb-bem

Usage

import dumbBem from 'dumb-bem'
import tx from 'transform-props-with'

const dumbHeader = dumbBem('header')
const Header = tx(dumbHeader)('div')
const HeaderTitle = tx([{ element: 'title' }, dumbHeader])('h1')

ReactDOM.render(
  <Header modifier='landing'>
    <HeaderTitle>Lorem Ipsum</HeaderTitle>
  </Header>
, node)
// Would render:
// <div className='header header--landing'>
//   <h1 className='header__title'>
//     Lorem Ipsum
//   </h1>
// </div>

API

dumbBem(block, options={})

Arguments

  • block (String): name of the base block.
  • options (Object): Override default options.
    • [plugins] (Array): array of plugins for modifying class names.

      Plugin is an object with two properties:

      • maker (function) Maker function takes block and props as arguments and should return anything suitable for classnames input. E.g. it can be a string, array of string or object.
      • [propsToRemove] (Array) An array of properties which are used in the plugin but should not be injected into the corresponding DOM element in the end.

      See also built-in makers.

Returns

A function which takes props object as a parameter, transforms className prop on execution and returns back changed props object.

(props) => ({
  ...props,
  className: classNameModifiedByMakers
})

Examples

Use built-in maker function

import dumbBem from 'dumb-bem'
import { makeStates } from 'dumb-bem/lib/plugins'
import tx from 'transform-props-with'

const dumbList = dumbBem('list', { plugins: [makeStates] })
const List = tx(dumbList)('ul')
const ListItem = tx([{ element: 'item' }, dumbList])('li')

ReactDOM.render(
  <List>
    <ListItem active={true}>Item 1</ListItem>
    <ListItem disabled={true}>Item 2</ListItem>
    <ListItem hidden={true}>Item 3</ListItem>
    <ListItem loading={true}>Item 4</ListItem>
  </List>
, node)

// Would render:
// <ul class='list'>
//   <li class='list__item is-active'>Item 1</li>
//   <li class='list__item is-disabled'>Item 2</li>
//   <li class='list__item is-hidden'>Item 3</li>
//   <li class='list__item is-loading'>Item 4</li>
// </ul>

Use custom maker function

import dumbBem from 'dumb-bem'
import tx from 'transform-props-with'

const colorModifierPlugin = {
  maker: (block, props) => {
    if (props.color) {
      return `${block}--${props.color}`
    }
  },
  propsToRemove: ['color']
}

const dumbList = dumbBem('list', { plugins: [colorModifierPlugin] })
const List = tx(dumbList)('ul')
const ListItem = tx([{ element: 'item' }, dumbList])('li')

ReactDOM.render(
  <List>
    <ListItem color='black'>Item 1</ListItem>
    <ListItem color='white'>Item 2</ListItem>
  </List>
, node)

// Would render:
// <ul class='list'>
//   <li class='list__item list__item--black'>Item 1</li>
//   <li class='list__item list__item--white'>Item 2</li>
// </ul>

Built-in Plugins

License

MIT © Alexander Gudulin

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].