diff --git a/extensions/react-widget/src/components/QuerySources.tsx b/extensions/react-widget/src/components/QuerySources.tsx index 325930df8..a619a822d 100644 --- a/extensions/react-widget/src/components/QuerySources.tsx +++ b/extensions/react-widget/src/components/QuerySources.tsx @@ -1,6 +1,7 @@ import {Query} from "../types/index" import styled from 'styled-components'; import { ExternalLinkIcon } from '@radix-ui/react-icons' +import { useEffect, useMemo, useState } from "react"; const SourcesWrapper = styled.div` @@ -57,16 +58,41 @@ const SourceLinkText = styled.p` line-height: 1rem; ` +const OtherSources = styled.button` +cursor: pointer; +background: transparent; +color: #8860DB; +border: none; +outline: none; +margin-top: 0.5rem; +align-self: flex-start; +` + type TQuerySources = { sources: Pick["sources"], } const QuerySources = ({sources}:TQuerySources) => { - return ( - +const [showAllSources, setShowAllSources] = useState(false) + +const visibleSources = useMemo(() => { + if(!sources) return []; + + return showAllSources? sources : sources.slice(0, 3) +}, [sources, showAllSources]) + +const handleToggleShowAll = () => { + setShowAllSources(prev => !prev) +} +if(!sources || sources.length === 0){ + return null; +} + +return ( + - {sources?.slice(0, 3)?.map((source, index) => ( + {visibleSources?.map((source, index) => ( @@ -86,6 +112,15 @@ const QuerySources = ({sources}:TQuerySources) => { ))} + + { + sources.length > 3 && ( + { + showAllSources ? `Show less` : `+ ${sources.length - 3} more` + } + + ) +} ) }