Simple React components with built in BEM css class naming conventions, now in Typescript
npm install react-bem-components-tsjavascript
import React, { Component } from 'react'
import { Wrapper, Title, Text, Button } from 'react-bem-components';
class MyBEMComponent extends Component {
clickHandler(e) {
console.log('clicked');
}
render() {
const block = 'my-component';
render (
//the first element should use the block as its element. All children use it as the block
Cool Title
Some large text
);
}
}
/**
rendering this component outputs:
Cool Title
Some large text
*/
`
Props
Each BEM props comes with the same basic prop types:
`javascript
const propTypes = {
// the element tag e.g. div, h1, p, etc
tag: PropTypes.string,
block: PropTypes.string,
element: PropTypes.string.isRequired,
modifier: PropTypes.string,
// for elements with multiple modifiers required
modifiers: PropTypes.arrayOf(PropTypes.string),
// any non bem related classes
extraClasses: PropTypes.string,
id: PropTypes.string,
// data-attributes
attributes: PropTypes.object
};
``