bem / bem-react

A set of tools for developing user interfaces using the BEM methodology in React
http://bem.github.io/bem-react
Other
439 stars 64 forks source link

Initial scope #1

Closed veged closed 7 years ago

veged commented 8 years ago
// MyBlock.js

import Bem from 'bem:Bem';
import MyElem from 'bem:MyBlock-MyElem';
import OtherBlock from 'bem:OtherBlock';
import WrapBlock from 'bem:WrapBlock';

export default Bem.decl({
    block : 'MyBlock',
    tag : 'a', 
    mods({ disabled }) {
        return { disabled };
    },
    // ... etc. about html
    attrs({ disabled, onChange }) {
        return {
            disabled,
            onChange,
            onFocus: this.onFocus,
        }
    },

    content() { // children?
        return [
            <Bem block={this} elem="MyElem" tag="span"/>,
            <OtherBlock>{ this.props.children }</OtherBlock>,
            <Bem block="OtherBlock" elem="OtherElem" tag="span"/>,
            <MyElem .../>,
            // ...
        ]
    },

    render() {
        return WrapBlock({}, [this.__base()]);
    },

    componentWillMount,
    componentDidMount,
    componentWillReceiveProps,
    shouldComponentUpdate,
    // ... all React lifecycle methods
});

// MyBlock_myMod.js

import MyBlock from 'bem:MyBlock'

export default MyBlock.decl({
    block : 'MyBlock',
    mod : ({ myMod }) => myMod /* some predicate */, 
    tag : 'span',
    // ... any other methods will be guarded by modifier predicate
});
qfox commented 8 years ago

Do you mind to use bemhtml templates for vidom? https://github.com/bem/bem-xjst/pull/235

krvital commented 8 years ago

So, are you going to rewrite bem-core blocks like "page", "dom", "cookie" as react components? It would be great if you clarify the purpose and main idea of this repository.

veged commented 8 years ago

@zxqfox no, just plain React

veged commented 8 years ago

@krvital bem-react-* will be whole separate implementation of base modules and components on top of React — the main purpose is to bring declarative BEM way for writing code with React, with easy redefinitions by modifiers and levels (see https://en.bem.info/methodology/filesystem/ and https://en.bem.info/methodology/js/)

dfilatov commented 8 years ago

We have some doubts about MyBlock({ elem : 'myElem2', tag : '...', mods : {} }):