Twig function that inserts static classes into Pattern Lab and adds them to the Attributes object in Drupal
To use in Pattern Lab, simply place in the _twig-components/functions
directory. Drupal needs to recognize the Twig function, so something like Unified Twig Extensions module can be helpful for that.
<h1 {{ bem('title') }}>
This creates:
<h1 class="title">
<h1 {{ bem('title', ['small', 'red']) }}>
This creates:
<h1 class="title title--small title--red">
<h1 {{ bem('title', ['small', 'red'], 'card') }}>
This creates:
<h1 class="card__title card__title--small card__title--red">
<h1 {{ bem('title', '', 'card') }}>
This creates:
<h1 class="card__title">
<h1 {{ bem('title', ['small', 'red'], 'card', ['js-click', 'something-else']) }}>
This creates:
<h1 class="card__title card__title--small card__title--red js-click something-else">
<h1 {{ bem('title', '', '', ['js-click']) }}>
This creates:
<h1 class="title js-click">