/
kaws
/
Telegram-Mini-Apps
Обзор
Документация
Войти
/
kaws
/
Telegram-Mini-Apps
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/css/bem.ts
48 строк
1 KB
Vladimir Ilyin
fix: codestyle, useLaunchParams
04 май 2025, 12:54
04 май 2025, 12:54
932575c
Код
Авторство
О чём код?
import { classNames, isRecord } from './classnames'; export interface BlockFn { (...mods: any): string; } export interface ElemFn { (elem: string, ...mods: any): string; } /** * Applies mods to the specified element. * @param element - element name. * @param mod - mod to apply. */ function applyMods(element: string, mod: any): string { if (Array.isArray(mod)) { return classNames(mod.map((m) => applyMods(element, m))); } if (isRecord(mod)) { return classNames( Object.entries(mod).map(([mod, v]) => v && applyMods(element, mod)), ); } const v = classNames(mod); return v && `${element}--${v}`; } /** * Computes final classname for the specified element. * @param element - element name. * @param mods - mod to apply. */ function computeClassnames(element: string, ...mods: any): string { return classNames(element, applyMods(element, mods)); } /** * @returns A tuple, containing two functions. The first one generates classnames list for the * block, the second one generates classnames for its elements. * @param block - BEM block name. */ export function bem(block: string): [BlockFn, ElemFn] { return [ (...mods) => computeClassnames(block, mods), (elem, ...mods) => computeClassnames(`${block}__${elem}`, mods), ]; }