2024-12-22 16:46:54 -05:00
|
|
|
import {
|
|
|
|
Action,
|
|
|
|
ActionPanel,
|
|
|
|
Content,
|
|
|
|
Icons,
|
|
|
|
Inline,
|
|
|
|
} from "@project-gauntlet/api/components";
|
2024-12-22 12:11:24 -05:00
|
|
|
import React, { ReactNode } from "react";
|
2024-10-18 12:43:53 -04:00
|
|
|
import { Clipboard, showHud } from "@project-gauntlet/api/helpers";
|
|
|
|
import * as UnicodeEmoji from "unicode-emoji";
|
|
|
|
|
2024-12-22 12:11:24 -05:00
|
|
|
// @ts-expect-error gauntlet uses deno and not node
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
2024-10-18 12:43:53 -04:00
|
|
|
const denoCore: DenoCore = Deno[Deno.internal].core;
|
|
|
|
|
2024-12-22 16:46:54 -05:00
|
|
|
export default function EmojiPicker(props: {
|
|
|
|
text: string;
|
|
|
|
}): ReactNode | undefined {
|
|
|
|
const text = props.text.trim();
|
2024-10-18 12:43:53 -04:00
|
|
|
|
2024-12-22 16:46:54 -05:00
|
|
|
if (text.length < 3) {
|
|
|
|
return undefined;
|
|
|
|
}
|
2024-10-18 12:43:53 -04:00
|
|
|
|
2024-12-22 16:46:54 -05:00
|
|
|
const emoji = UnicodeEmoji.getEmojis().find((emoji) =>
|
|
|
|
emoji.keywords.includes(text),
|
|
|
|
);
|
|
|
|
if (!emoji) {
|
|
|
|
return undefined;
|
|
|
|
}
|
2024-10-18 13:05:48 -04:00
|
|
|
|
2024-12-22 16:46:54 -05:00
|
|
|
return (
|
|
|
|
<Inline
|
|
|
|
actions={
|
|
|
|
<ActionPanel>
|
|
|
|
<Action
|
|
|
|
label={`Copy ${emoji.emoji} to clipboard`}
|
|
|
|
onAction={async () => {
|
|
|
|
console.log(emoji.emoji);
|
|
|
|
await Clipboard.writeText(emoji.emoji);
|
|
|
|
showHud(`${emoji.emoji} copied to clipboard`);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</ActionPanel>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<Inline.Left>
|
|
|
|
<Content.H3>{text}</Content.H3>
|
|
|
|
</Inline.Left>
|
|
|
|
<Inline.Separator icon={Icons.ArrowRight} />
|
|
|
|
<Inline.Right>
|
|
|
|
<Content.Paragraph>{emoji.emoji}</Content.Paragraph>
|
|
|
|
</Inline.Right>
|
|
|
|
</Inline>
|
|
|
|
);
|
|
|
|
}
|