emoji.tsx 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import EmojiPicker, {
  2. Emoji,
  3. EmojiStyle,
  4. Theme as EmojiTheme,
  5. } from "emoji-picker-react";
  6. import { ModelType } from "../store";
  7. import BotIcon from "../icons/bot.svg";
  8. import BlackBotIcon from "../icons/black-bot.svg";
  9. export function getEmojiUrl(unified: string, style: EmojiStyle) {
  10. return `https://cdn.staticfile.org/emoji-datasource-apple/14.0.0/img/${style}/64/${unified}.png`;
  11. }
  12. export function AvatarPicker(props: {
  13. onEmojiClick: (emojiId: string) => void;
  14. }) {
  15. return (
  16. <EmojiPicker
  17. lazyLoadEmojis
  18. theme={EmojiTheme.AUTO}
  19. getEmojiUrl={getEmojiUrl}
  20. onEmojiClick={(e) => {
  21. props.onEmojiClick(e.unified);
  22. }}
  23. />
  24. );
  25. }
  26. export function Avatar(props: { model?: ModelType; avatar?: string }) {
  27. if (props.model) {
  28. return (
  29. <div className="no-dark">
  30. {props.model?.startsWith("gpt-4") ? (
  31. <BlackBotIcon className="user-avatar" />
  32. ) : (
  33. <BotIcon className="user-avatar" />
  34. )}
  35. </div>
  36. );
  37. }
  38. return (
  39. <div className="user-avatar">
  40. {props.avatar && <EmojiAvatar avatar={props.avatar} />}
  41. </div>
  42. );
  43. }
  44. export function EmojiAvatar(props: { avatar: string; size?: number }) {
  45. return (
  46. <Emoji
  47. unified={props.avatar}
  48. size={props.size ?? 18}
  49. getEmojiUrl={getEmojiUrl}
  50. />
  51. );
  52. }