Skip to content

Instantly share code, notes, and snippets.

@awinogradov
Last active September 29, 2016 20:52
Show Gist options
  • Save awinogradov/c32b3ce26e46242a0d19f5c677c52c98 to your computer and use it in GitHub Desktop.
Save awinogradov/c32b3ce26e46242a0d19f5c677c52c98 to your computer and use it in GitHub Desktop.
import {decl} from 'bem-react-core';
import ddsl from 'ddsl-react';
const bemhtml = ddsl(function() {
block('omg')(
tag()('span'),
attrs()({ href : '//yandex.ru' })
);
});
export default decl({
block : 'omg',
didMount() {
console.log('mounted');
},
onClick(e) {
console.log('clicked');
},
render() {
return bemhtml.match({
block : this.block,
attrs : {
onClick : this.onClick.bind(this)
},
text : this.props.text
}, this);
}
});
import { Component } from 'react';
import ddsl from 'ddsl-react';
const bemhtml = ddsl(function() {
block('omg').tag()('span');
});
export default class OMG extends Component {
render() {
return bemhtml.match({
block: 'omg',
content: this.props.children
}, this);
}
}
import {decl} from 'bem-react-core';
export default decl({
block : 'MyBlock',
tag : 'a',
mods({ disabled }) {
return { disabled };
},
attrs() {
return { href : '//yandex.ru' };
},
didMount() {
console.log(`${this.block} is mounted`);
}
});
import {decl} from 'bem-react-core';
export default decl({
block : 'TextInput',
elem : 'Control',
tag : 'input',
didMount() {
this.props.focused?
this._focus() :
this._blur();
},
didUpdate() {
this.props.focused?
this._focus() :
this._blur();
}
});
import {declMod} from 'bem-react-core';
export default declMod(({ myMod }) => myMod, {
block : 'MyBlock',
mods({ myMod }) {
return { ...this.__base.apply(this, arguments), myMod };
},
onClick() {
this.__base.apply(this, arguments);
console.log('with myMod');
},
didMount() {
this.__base();
console.log(`${this.block} with myMod is mounted`);
}
});
import { Component } from 'react';
import ReactDom from 'react-dom';
import Button from 'b:Button m:type=link';
import Icon from 'b:Icon';
class App extends Component {
render() {
const icon = <Icon url="https://yandex.st/lego/_/pDu9OWAQKB0s2J9IojKpiS_Eho.ico" />;
return (
<Button icon={icon} text="button with icon" />
);
}
}
ReactDom.render(<App/>, document.getElementById('root'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment