Skip to content

Commit

Permalink
feat(classname): add BEM wrapper functions
Browse files Browse the repository at this point in the history
  • Loading branch information
wewoor committed Dec 2, 2020
1 parent 697c431 commit cd12f91
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/common/className.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,24 @@ export function prefixClaName(name: string, prefix: string = APP_PREFIX) {
export function classNames(...names) {
return names.filter((name) => !!name).join(' ');
}

/**
* Element names may consist of Latin letters, digits, dashes and underscores.
* CSS class is formed as block name plus two underscores plus element name: .block__elem
* @param block
* @param element
*/
export function getBEMElement(block: string, element: string) {
return `${block}__${element}`;
}

/**
* CSS class is formed as block’s or element’s name plus two dashes:
* .block--mod or .block__elem--mod and .block--color-black with .block--color-red.
* Spaces in complicated modifiers are replaced by dash.
* @param blockOrElement
* @param modifier
*/
export function getBEMModifier(blockOrElement: string, modifier: string) {
return `${blockOrElement}--${modifier}`;
}

0 comments on commit cd12f91

Please sign in to comment.