diff --git a/src/stories/chat/parts/mentionList.tsx b/src/stories/chat/parts/mentionList.tsx index 3a7bc052..972c3824 100644 --- a/src/stories/chat/parts/mentionList.tsx +++ b/src/stories/chat/parts/mentionList.tsx @@ -1,4 +1,10 @@ -import { forwardRef, useEffect, useImperativeHandle, useState } from "react"; +import { + forwardRef, + useEffect, + useImperativeHandle, + useRef, + useState, +} from "react"; import type { SuggestionOptions, SuggestionProps } from "@tiptap/suggestion"; import { Card } from "../../cards"; import { Button } from "../../buttons/button"; @@ -6,6 +12,8 @@ import { styled } from "styled-components"; import { SuggestedUser } from "../_types"; import { MD } from "../../typography/typescale"; import { theme } from "../../theme"; +import { ButtonArgs } from "../../buttons/button/_types"; +import { getColor } from "../../theme/utils"; export type MentionListRef = { onKeyDown: NonNullable< @@ -31,20 +39,30 @@ const List = styled.div` overflow-y: auto; `; -const Item = styled(Button)` +const Item = styled(Button)` display: flex; align-items: flex-start; justify-content: center; flex-direction: column; -`; + ${({ isActive }) => + isActive && + ` + background-color: ${getColor( + theme.colors.primaryHue, + 600, + undefined, + 0.08 + )}; + `} +`; type MentionListProps = SuggestionProps; export const MentionList = forwardRef( (props, ref) => { const [selectedIndex, setSelectedIndex] = useState(0); - + const selectedRef = useRef(null); const selectItem = (index: number) => { const item = props.items[index]; @@ -68,6 +86,11 @@ export const MentionList = forwardRef( }; useEffect(() => setSelectedIndex(0), [props.items]); + useEffect(() => { + if (selectedRef.current) { + selectedRef.current.scrollIntoView({ behavior: "smooth" }); + } + }, [selectedIndex]); useImperativeHandle(ref, () => ({ onKeyDown: ({ event }) => { @@ -96,12 +119,14 @@ export const MentionList = forwardRef( {props.items.length ? ( props.items.map((item, index) => ( -
+
selectItem(index)} >