JSFiddle - React, Tailwind, and code Playground
HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>bem-components as a library</title>
<link rel="stylesheet" href="https://yastatic.net/bem-components/latest/desktop/bem-components.css">
<script src="https://yastatic.net/bem-components/latest/desktop/bem-components.no-autoinit.js+bemhtml.js"></script>
</head>
<body class="page page_theme_islands">
<!-- Блок hello для создания формы приветствия -->
<form class="hello i-bem" data-bem='{ "hello": {} }'>
<div class="hello__greeting">Hello, %user name%!</div>
</form>
</body>
</html>
CSS
.hello {
padding: 10%;
}
.hello__greeting {
margin-bottom: 12px;
}
JavaScript
console.log(modules)
modules.define('hello', ['i-bem-dom', 'BEMHTML', 'input', 'button'],
function(provide, bemDom, BEMHTML, Input, Button) {
provide(bemDom.declBlock('hello', {
onSetMod: {
js: {
inited: function() {
bemDom.append(this.domElem, BEMHTML.apply([
{
block: 'input',
mods: {
theme: 'islands',
size: 'm'
},
placeholder: 'User name'
},
{
block: 'button',
mods: {
theme: 'islands',
size: 'm',
type: 'submit'
},
text: 'Say hello'
}
]));
this._input = this.findChildBlock(Input);
}
}
},
_onSubmit: function(e) {
e.preventDefault();
this._elem('greeting').domElem.text('Hello, ' + this._input.getVal() + '!');
}
}, {
onInit: function() {
this._domEvents().on('submit', this.prototype._onSubmit);
}
}));
});
// Вызов `init();`
modules.require('i-bem-dom__init', function(init) { init(); });