2024-04-13 19:34:26 +02:00
|
|
|
const ELEMENT_DELIMITER = '__';
|
|
|
|
const MODIFIER_DELIMITER = '--';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Utility function that allows to construct class names from block and element names
|
|
|
|
*
|
|
|
|
* @example bem('ce-popover)() -> 'ce-popover'
|
|
|
|
* @example bem('ce-popover)('container') -> 'ce-popover__container'
|
|
|
|
* @example bem('ce-popover)('container', 'hidden') -> 'ce-popover__container--hidden'
|
|
|
|
* @example bem('ce-popover)(null, 'hidden') -> 'ce-popover--hidden'
|
|
|
|
* @param blockName - string with block name
|
|
|
|
* @param elementName - string with element name
|
|
|
|
* @param modifier - modifier to be appended
|
|
|
|
*/
|
|
|
|
export function bem(blockName: string) {
|
2024-04-22 21:38:20 +02:00
|
|
|
return (elementName?: string | null, modifier?: string) => {
|
2024-04-13 19:34:26 +02:00
|
|
|
const className = [blockName, elementName]
|
|
|
|
.filter(x => !!x)
|
|
|
|
.join(ELEMENT_DELIMITER);
|
|
|
|
|
|
|
|
return [className, modifier]
|
|
|
|
.filter(x => !!x)
|
|
|
|
.join(MODIFIER_DELIMITER);
|
|
|
|
};
|
|
|
|
}
|