lemmy-ui/src/shared/components/common/emoji-picker.tsx

68 lines
1.8 KiB
TypeScript
Raw Normal View History

2022-11-27 18:02:32 +00:00
import { Component, linkEvent } from "inferno";
import { i18n } from "../../i18next";
import { EmojiMart } from "./emoji-mart";
import { Icon } from "./icon";
interface EmojiPickerProps {
onEmojiClick?(val: any): any;
disabled?: boolean;
2022-11-27 18:02:32 +00:00
}
interface EmojiPickerState {
showPicker: boolean;
2022-11-27 18:02:32 +00:00
}
export class EmojiPicker extends Component<EmojiPickerProps, EmojiPickerState> {
private emptyState: EmojiPickerState = {
showPicker: false,
};
state: EmojiPickerState;
constructor(props: EmojiPickerProps, context: any) {
super(props, context);
this.state = this.emptyState;
this.handleEmojiClick = this.handleEmojiClick.bind(this);
}
render() {
return (
2023-06-20 18:46:16 +00:00
<span className="emoji-picker">
<button
className="btn btn-sm text-muted"
data-tippy-content={i18n.t("emoji")}
aria-label={i18n.t("emoji")}
disabled={this.props.disabled}
onClick={linkEvent(this, this.togglePicker)}
>
<Icon icon="smile" classes="icon-inline" />
</button>
2022-11-27 18:02:32 +00:00
{this.state.showPicker && (
<>
2023-06-21 18:44:37 +00:00
<div className="position-relative">
<div className="emoji-picker-container position-absolute w-100">
<EmojiMart
onEmojiClick={this.handleEmojiClick}
pickerOptions={{}}
></EmojiMart>
</div>
<div
onClick={linkEvent(this, this.togglePicker)}
className="click-away-container"
/>
</div>
</>
)}
</span>
);
}
2022-11-27 18:02:32 +00:00
togglePicker(i: EmojiPicker, e: any) {
e.preventDefault();
i.setState({ showPicker: !i.state.showPicker });
}
2022-11-27 18:02:32 +00:00
handleEmojiClick(e: any) {
this.props.onEmojiClick?.(e);
}
}