/
chat-center
/
server
Обзор
Документация
Войти
/
chat-center
/
server
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
master
packages/widget/src/createClassName.ts
35 строк
969 B
levkin_s
Перенес модуль для публикации
04 авг 2026, 17:47
04 авг 2026, 17:47
0ed10dd
Код
Авторство
О чём код?
const flatMap = <T, U>( arr: T[], mapFunc: (elem: T, index: number, arr: T[]) => U | U[], ) => { const result = []; for (let index = 0; index < arr.length; index++) { const elem = arr[index]; const x = mapFunc(elem, index, arr); // We allow mapFunc() to return non-Arrays if (Array.isArray(x)) { result.push(...x); } else { result.push(x); } } return result; }; export const createClassName = ( styles: Record<string, string>, elementName: string, modifiers = {}, classes: (string | undefined)[] = [], ) => { return [ styles[elementName], ...flatMap(Object.entries(modifiers), ([modifierKey, modifierValue]) => [ modifierValue && styles[`${elementName}--${modifierKey}`], typeof modifierValue !== 'boolean' && styles[`${elementName}--${modifierKey}-${modifierValue}`], ]).filter((className) => !!className), ...classes.filter((className) => !!className), ].join(' '); };