@bem/sdk.decl Usage examples: Select all checkboxes
const bemDecl = require('@bem/sdk.decl');
const bemCell = require('@bem/sdk.cell');
// Set state modifier for the entity
function select(entity) {
const selectedState = {
entity: { mod: { name: 'state', val: 'checked'}}
};
return bemDecl.assign(selectedState, entity);
};
// Set state modifier for the array of entities
function selectAll(entities) {
return entities.map(e => select(e));
};
// Define BEM cells that represents checkbox entities.
const checkboxes = [
bemCell.create({ block: 'checkbox', elem: '1', mod: { name: 'state', val: 'unchecked'}}),
bemCell.create({ block: 'checkbox', elem: '2', mod: { name: 'state', val: 'checked'}}),
bemCell.create({ block: 'checkbox', elem: '3', mod: { name: 'state'}}),
bemCell.create({ block: 'checkbox', elem: '4'}),
];
// Select all checkboxes.
selectAll(checkboxes).map(e => e.valueOf());
no comments