signal-desktop/ts/components/conversation/conversation-details/util.ts

36 lines
846 B
TypeScript
Raw Normal View History

2021-03-11 21:29:31 +00:00
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import classNames from 'classnames';
2021-03-11 21:29:31 +00:00
export enum RequestState {
Inactive,
InactiveWithError,
Active,
}
2021-11-11 22:43:05 +00:00
export const bemGenerator =
(block: string) =>
(element: string, modifier?: string | Record<string, boolean>): string => {
const base = `${block}__${element}`;
const classes = [base];
2021-11-11 22:43:05 +00:00
let conditionals: Record<string, boolean> = {};
2021-11-11 22:43:05 +00:00
if (modifier) {
if (typeof modifier === 'string') {
classes.push(`${base}--${modifier}`);
} else {
conditionals = Object.keys(modifier).reduce(
(acc, key) => ({
...acc,
[`${base}--${key}`]: modifier[key],
}),
{} as Record<string, boolean>
);
}
}
2021-11-11 22:43:05 +00:00
return classNames(classes, conditionals);
};