Skip to content

Commit cd12f91

Browse files
committed
feat(classname): add BEM wrapper functions
1 parent 697c431 commit cd12f91

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/common/className.ts

+21
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,24 @@ export function prefixClaName(name: string, prefix: string = APP_PREFIX) {
1313
export function classNames(...names) {
1414
return names.filter((name) => !!name).join(' ');
1515
}
16+
17+
/**
18+
* Element names may consist of Latin letters, digits, dashes and underscores.
19+
* CSS class is formed as block name plus two underscores plus element name: .block__elem
20+
* @param block
21+
* @param element
22+
*/
23+
export function getBEMElement(block: string, element: string) {
24+
return `${block}__${element}`;
25+
}
26+
27+
/**
28+
* CSS class is formed as block’s or element’s name plus two dashes:
29+
* .block--mod or .block__elem--mod and .block--color-black with .block--color-red.
30+
* Spaces in complicated modifiers are replaced by dash.
31+
* @param blockOrElement
32+
* @param modifier
33+
*/
34+
export function getBEMModifier(blockOrElement: string, modifier: string) {
35+
return `${blockOrElement}--${modifier}`;
36+
}

0 commit comments

Comments
 (0)