From 8794782a4e2a13dc2a17dfebbf3903ffa4f9ef0c Mon Sep 17 00:00:00 2001 From: Szymon Szlachtowicz <38212223+Szymx95@users.noreply.github.com> Date: Tue, 4 Jan 2022 10:39:15 +0100 Subject: [PATCH] Refactor emoji picker (#169) --- packages/react-chat-example/src/index.tsx | 2 +- .../src/components/Chat/ChatInput.tsx | 34 ++-------------- .../src/components/Chat/EmojiPicker.tsx | 40 +++++++++++++++++++ 3 files changed, 45 insertions(+), 31 deletions(-) create mode 100644 packages/react-chat/src/components/Chat/EmojiPicker.tsx diff --git a/packages/react-chat-example/src/index.tsx b/packages/react-chat-example/src/index.tsx index f346e8d..880fc5f 100644 --- a/packages/react-chat-example/src/index.tsx +++ b/packages/react-chat-example/src/index.tsx @@ -76,7 +76,7 @@ function DragDiv() { diff --git a/packages/react-chat/src/components/Chat/ChatInput.tsx b/packages/react-chat/src/components/Chat/ChatInput.tsx index 689364e..f101fb7 100644 --- a/packages/react-chat/src/components/Chat/ChatInput.tsx +++ b/packages/react-chat/src/components/Chat/ChatInput.tsx @@ -1,4 +1,3 @@ -import { Picker } from "emoji-mart"; import React, { useCallback, useEffect, @@ -6,13 +5,11 @@ import React, { useRef, useState, } from "react"; -import styled, { useTheme } from "styled-components"; +import styled from "styled-components"; import { useMessengerContext } from "../../contexts/messengerProvider"; import { useModal } from "../../contexts/modalProvider"; -import { useLow } from "../../contexts/narrowProvider"; import { Reply } from "../../hooks/useReply"; -import { lightTheme, Theme } from "../../styles/themes"; import { uintToImgUrl } from "../../utils/uintToImgUrl"; import { ClearSvg } from "../Icons/ClearIcon"; import { EmojiIcon } from "../Icons/EmojiIcon"; @@ -25,6 +22,8 @@ import { SizeLimitModal, SizeLimitModalName } from "../Modals/SizeLimitModal"; import { SearchBlock } from "../SearchBlock"; import { textMediumStyles, textSmallStyles } from "../Text"; +import { EmojiPicker } from "./EmojiPicker"; + interface ChatInputProps { reply: Reply | undefined; setReply: (val: Reply | undefined) => void; @@ -33,15 +32,12 @@ interface ChatInputProps { export function ChatInput({ reply, setReply, disabled }: ChatInputProps) { const { sendMessage, contacts } = useMessengerContext(); - const theme = useTheme() as Theme; const [content, setContent] = useState(""); const [clearComponent, setClearComponent] = useState(""); const [showEmoji, setShowEmoji] = useState(false); const [inputHeight, setInputHeight] = useState(40); const [imageUint, setImageUint] = useState(undefined); - const low = useLow(); - const { setModal } = useModal(SizeLimitModalName); const [query, setQuery] = useState(""); @@ -203,29 +199,7 @@ export function ChatInput({ reply, setReply, disabled }: ChatInputProps) { return ( - {showEmoji && ( -
- -
- )} - + void; +}; + +export function EmojiPicker({ showEmoji, addEmoji }: EmojiPickerProps) { + const theme = useTheme() as Theme; + const low = useLow(); + + if (showEmoji) { + return ( + + ); + } + return null; +}