From 2c889f9b454480ad6c62b23a89681c42382ae3ae Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Mon, 11 Nov 2024 12:53:25 +0000 Subject: [PATCH] Add expander for reactions view --- src/button/ReactionToggleButton.module.css | 14 +--- src/button/ReactionToggleButton.tsx | 77 +++------------------- 2 files changed, 11 insertions(+), 80 deletions(-) diff --git a/src/button/ReactionToggleButton.module.css b/src/button/ReactionToggleButton.module.css index 7c97c2de..51d97392 100644 --- a/src/button/ReactionToggleButton.module.css +++ b/src/button/ReactionToggleButton.module.css @@ -22,6 +22,8 @@ display: flex; flex-wrap: wrap; gap: var(--cpd-separator-spacing); + max-height: 10em; + max-width: 22.5em; } .reactionPopupMenu section { @@ -63,18 +65,6 @@ margin-left: var(--cpd-separator-spacing); margin-right: var(--cpd-separator-spacing); } - -.searchForm { - display: flex; - flex-direction: row; - gap: var(--cpd-separator-spacing); - margin-bottom: var(--cpd-space-3x); -} - -.searchForm > label { - flex: auto; -} - .alert { margin-bottom: var(--cpd-space-3x); animation: grow-in 200ms; diff --git a/src/button/ReactionToggleButton.tsx b/src/button/ReactionToggleButton.tsx index 984d2f4c..6e74eb90 100644 --- a/src/button/ReactionToggleButton.tsx +++ b/src/button/ReactionToggleButton.tsx @@ -13,16 +13,14 @@ import { Alert, } from "@vector-im/compound-web"; import { - SearchIcon, - CloseIcon, RaisedHandSolidIcon, ReactionIcon, + ChevronDownIcon, + ChevronUpIcon, } from "@vector-im/compound-design-tokens/assets/web/icons"; import { - ChangeEventHandler, ComponentPropsWithoutRef, FC, - KeyboardEventHandler, ReactNode, useCallback, useEffect, @@ -84,44 +82,14 @@ export function ReactionPopupMenu({ canReact: boolean; }): ReactNode { const { t } = useTranslation(); - const [searchText, setSearchText] = useState(""); - const [isSearching, setIsSearching] = useState(false); - const onSearch = useCallback>((ev) => { - ev.preventDefault(); - setSearchText(ev.target.value.trim().toLocaleLowerCase()); - }, []); + const [isFullyExpanded, setExpanded] = useState(false); const filteredReactionSet = useMemo( () => - ReactionSet.filter( - (reaction) => - !isSearching || - (!!searchText && - (reaction.name.startsWith(searchText) || - reaction.alias?.some((a) => a.startsWith(searchText)))), - ).slice(0, 6), - [searchText, isSearching], + isFullyExpanded ? ReactionSet : ReactionSet.slice(0, 6), + [isFullyExpanded], ); - const onSearchKeyDown = useCallback>( - (ev) => { - if (ev.key === "Enter") { - ev.preventDefault(); - if (!canReact) { - return; - } - if (filteredReactionSet.length !== 1) { - return; - } - sendReaction(filteredReactionSet[0]); - setIsSearching(false); - } else if (ev.key === "Escape") { - ev.preventDefault(); - setIsSearching(false); - } - }, - [sendReaction, filteredReactionSet, canReact, setIsSearching], - ); const label = isHandRaised ? t("action.lower_hand") : t("action.raise_hand"); return ( <> @@ -149,31 +117,6 @@ export function ReactionPopupMenu({
- {isSearching ? ( - <> - - - setIsSearching(false)} - /> - - - ) : null} {filteredReactionSet.map((reaction) => (
  • @@ -191,21 +134,19 @@ export function ReactionPopupMenu({ ))}
  • - {!isSearching ? (
  • - + setIsSearching(true)} + onClick={() => setExpanded(!isFullyExpanded)} />
  • - ) : null}
    );