2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2020 Signal Messenger, LLC
|
2021-09-13 17:04:45 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { CSSProperties, ReactNode } from 'react';
|
|
|
|
import React, { forwardRef } from 'react';
|
2021-09-13 17:04:45 +00:00
|
|
|
import classNames from 'classnames';
|
|
|
|
|
|
|
|
import { Emoji } from './emoji/Emoji';
|
|
|
|
import type { LocalizerType } from '../types/Util';
|
|
|
|
|
|
|
|
export enum ReactionPickerPickerStyle {
|
|
|
|
Picker,
|
|
|
|
Menu,
|
|
|
|
}
|
|
|
|
|
|
|
|
export const ReactionPickerPickerEmojiButton = React.forwardRef<
|
|
|
|
HTMLButtonElement,
|
|
|
|
{
|
|
|
|
emoji: string;
|
|
|
|
isSelected: boolean;
|
|
|
|
onClick: () => unknown;
|
|
|
|
title?: string;
|
|
|
|
}
|
2022-11-18 00:45:19 +00:00
|
|
|
>(function ReactionPickerPickerEmojiButtonInner(
|
|
|
|
{ emoji, onClick, isSelected, title },
|
|
|
|
ref
|
|
|
|
) {
|
|
|
|
return (
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
ref={ref}
|
|
|
|
tabIndex={0}
|
|
|
|
className={classNames(
|
|
|
|
'module-ReactionPickerPicker__button',
|
|
|
|
'module-ReactionPickerPicker__button--emoji',
|
|
|
|
isSelected && 'module-ReactionPickerPicker__button--selected'
|
|
|
|
)}
|
|
|
|
onClick={event => {
|
2022-09-07 18:29:08 +00:00
|
|
|
event.stopPropagation();
|
|
|
|
onClick();
|
2022-11-18 00:45:19 +00:00
|
|
|
}}
|
|
|
|
onKeyDown={event => {
|
|
|
|
if (event.key === 'Enter' || event.key === 'Space') {
|
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
|
|
|
onClick();
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Emoji size={48} emoji={emoji} title={title} />
|
|
|
|
</button>
|
|
|
|
);
|
|
|
|
});
|
2021-09-13 17:04:45 +00:00
|
|
|
|
2022-11-18 00:45:19 +00:00
|
|
|
export function ReactionPickerPickerMoreButton({
|
2021-09-13 17:04:45 +00:00
|
|
|
i18n,
|
|
|
|
onClick,
|
|
|
|
}: Readonly<{
|
|
|
|
i18n: LocalizerType;
|
|
|
|
onClick: () => unknown;
|
2022-11-18 00:45:19 +00:00
|
|
|
}>): JSX.Element {
|
|
|
|
return (
|
|
|
|
<button
|
2023-03-30 00:03:25 +00:00
|
|
|
aria-label={i18n('icu:Reactions--more')}
|
2022-11-18 00:45:19 +00:00
|
|
|
className="module-ReactionPickerPicker__button module-ReactionPickerPicker__button--more"
|
|
|
|
onClick={event => {
|
2022-09-07 18:29:08 +00:00
|
|
|
event.stopPropagation();
|
|
|
|
onClick();
|
2022-11-18 00:45:19 +00:00
|
|
|
}}
|
|
|
|
onKeyDown={event => {
|
|
|
|
if (event.key === 'Enter' || event.key === 'Space') {
|
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
|
|
|
onClick();
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
tabIndex={0}
|
2023-03-30 00:03:25 +00:00
|
|
|
title={i18n('icu:Reactions--more')}
|
2022-11-18 00:45:19 +00:00
|
|
|
type="button"
|
2023-05-04 18:04:22 +00:00
|
|
|
/>
|
2022-11-18 00:45:19 +00:00
|
|
|
);
|
|
|
|
}
|
2021-09-13 17:04:45 +00:00
|
|
|
|
|
|
|
export const ReactionPickerPicker = forwardRef<
|
|
|
|
HTMLDivElement,
|
|
|
|
{
|
|
|
|
children: ReactNode;
|
|
|
|
isSomethingSelected: boolean;
|
|
|
|
pickerStyle: ReactionPickerPickerStyle;
|
|
|
|
style?: CSSProperties;
|
|
|
|
}
|
2022-11-18 00:45:19 +00:00
|
|
|
>(function ReactionPickerPickerInner(
|
|
|
|
{ children, isSomethingSelected, pickerStyle, style },
|
|
|
|
ref
|
|
|
|
) {
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className={classNames(
|
|
|
|
'module-ReactionPickerPicker',
|
|
|
|
isSomethingSelected &&
|
|
|
|
'module-ReactionPickerPicker--something-selected',
|
|
|
|
{
|
|
|
|
'module-ReactionPickerPicker--picker-style':
|
|
|
|
pickerStyle === ReactionPickerPickerStyle.Picker,
|
|
|
|
'module-ReactionPickerPicker--menu-style':
|
|
|
|
pickerStyle === ReactionPickerPickerStyle.Menu,
|
|
|
|
}
|
|
|
|
)}
|
|
|
|
ref={ref}
|
|
|
|
style={style}
|
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
});
|