signal-desktop/ts/components/BetterAvatarBubble.tsx

62 lines
1.3 KiB
TypeScript
Raw Normal View History

2021-08-06 00:17:05 +00:00
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import type { CSSProperties, MouseEvent, ReactNode } from 'react';
import React from 'react';
2021-08-06 00:17:05 +00:00
import classNames from 'classnames';
import type { AvatarColorType } from '../types/Colors';
import type { LocalizerType } from '../types/Util';
2021-08-06 00:17:05 +00:00
export type PropsType = {
children?: ReactNode;
color?: AvatarColorType;
i18n: LocalizerType;
isSelected?: boolean;
onDelete?: (ev: MouseEvent) => unknown;
onSelect: () => unknown;
style?: CSSProperties;
};
2022-11-18 00:45:19 +00:00
export function BetterAvatarBubble({
2021-08-06 00:17:05 +00:00
children,
color,
i18n,
isSelected,
onDelete,
onSelect,
style,
2022-11-18 00:45:19 +00:00
}: PropsType): JSX.Element {
2021-08-06 00:17:05 +00:00
return (
<div
className={classNames(
{
BetterAvatarBubble: true,
'BetterAvatarBubble--selected': isSelected,
},
color && `BetterAvatarBubble--${color}`
)}
onKeyDown={ev => {
if (ev.key === 'Enter') {
onSelect();
}
}}
onClick={onSelect}
role="button"
style={style}
tabIndex={0}
>
{onDelete && (
<button
aria-label={i18n('delete')}
className="BetterAvatarBubble__delete"
onClick={onDelete}
tabIndex={-1}
type="button"
/>
)}
{children}
</div>
);
2022-11-18 00:45:19 +00:00
}