From 4eac8322958d66d510b0c73bacbcbbec9277a6dd Mon Sep 17 00:00:00 2001 From: Maria Rushkova <66270386+mrushkova@users.noreply.github.com> Date: Mon, 17 Jan 2022 15:53:09 +0100 Subject: [PATCH] Input alignment (#193) * Fix buttons alignment * Add message reaction key * Add click outside picker --- .../src/components/Chat/ChatInput.tsx | 33 ++++++++++--------- .../src/components/Chat/EmojiPicker.tsx | 3 -- .../components/Messages/MessageReactions.tsx | 1 + 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/packages/react-chat/src/components/Chat/ChatInput.tsx b/packages/react-chat/src/components/Chat/ChatInput.tsx index e0312e14..03b8a51c 100644 --- a/packages/react-chat/src/components/Chat/ChatInput.tsx +++ b/packages/react-chat/src/components/Chat/ChatInput.tsx @@ -11,6 +11,7 @@ import { useIdentity } from "../../contexts/identityProvider"; import { useMessengerContext } from "../../contexts/messengerProvider"; import { useModal } from "../../contexts/modalProvider"; import { useNarrow } from "../../contexts/narrowProvider"; +import { useClickOutside } from "../../hooks/useClickOutside"; import { Reply } from "../../hooks/useReply"; import { uintToImgUrl } from "../../utils/uintToImgUrl"; import { ClearBtn } from "../Form/inputStyles"; @@ -54,14 +55,8 @@ export function ChatInput({ reply, setReply }: ChatInputProps) { const inputRef = useRef(null); - useEffect(() => { - if (showEmoji) { - window.addEventListener("click", () => setShowEmoji(false)); - } - return () => { - window.removeEventListener("click", () => setShowEmoji(false)); - }; - }, [showEmoji]); + const ref = useRef(null); + useClickOutside(ref, () => setShowEmoji(false)); const image = useMemo( () => (imageUint ? uintToImgUrl(imageUint) : ""), @@ -211,7 +206,10 @@ export function ChatInput({ reply, setReply }: ChatInputProps) { return ( - + + + + { - e.stopPropagation(); - if (!disabled) { - setShowEmoji(!showEmoji); - } + onClick={() => { + if (!disabled) setShowEmoji(!showEmoji); }} disabled={disabled} > @@ -325,9 +320,15 @@ const InputWrapper = styled.div` position: relative; `; +const EmojiWrapper = styled.div` + position: absolute; + bottom: calc(100% - 6px); + right: 8px; +`; + const View = styled.div` display: flex; - align-items: center; + align-items: flex-end; padding: 6px 8px 6px 10px; position: relative; `; @@ -356,7 +357,7 @@ const Row = styled.div` const InputButtons = styled.div` display: flex; - align-items: center; + align-self: flex-end; button + button { margin-left: 4px; diff --git a/packages/react-chat/src/components/Chat/EmojiPicker.tsx b/packages/react-chat/src/components/Chat/EmojiPicker.tsx index 042c4dff..46542bf3 100644 --- a/packages/react-chat/src/components/Chat/EmojiPicker.tsx +++ b/packages/react-chat/src/components/Chat/EmojiPicker.tsx @@ -23,9 +23,6 @@ export function EmojiPicker({ showEmoji, addEmoji }: EmojiPickerProps) { color={theme.tertiary} emojiSize={26} style={{ - position: "absolute", - bottom: "100%", - right: "0", color: theme.secondary, height: low ? "200px" : "355px", overflow: "auto", diff --git a/packages/react-chat/src/components/Messages/MessageReactions.tsx b/packages/react-chat/src/components/Messages/MessageReactions.tsx index 15dbf442..19b13a75 100644 --- a/packages/react-chat/src/components/Messages/MessageReactions.tsx +++ b/packages/react-chat/src/components/Messages/MessageReactions.tsx @@ -21,6 +21,7 @@ export function MessageReactions({ {messageReactions.map((reaction) => (

1