fix: update activity stream design (#5615)
parent
89c6b36090
commit
e1c35d299d
5 changed files with 113 additions and 79 deletions
@ -1,43 +1,43 @@ |
||||
import { useState } from 'react'; |
||||
import { cn } from '../../lib/classname'; |
||||
|
||||
type ActivityTopicTitlesProps = { |
||||
topicTitles: string[]; |
||||
className?: string; |
||||
onSelectActivity?: () => void; |
||||
}; |
||||
|
||||
export function ActivityTopicTitles(props: ActivityTopicTitlesProps) { |
||||
const { topicTitles, onSelectActivity } = props; |
||||
const firstThreeTopics = topicTitles?.slice(0, 3); |
||||
const remainingTopics = topicTitles?.slice(3); |
||||
const { topicTitles, onSelectActivity, className } = props; |
||||
|
||||
const [showAll, setShowAll] = useState(false); |
||||
const filteredTopicTitles = topicTitles.slice( |
||||
0, |
||||
showAll ? topicTitles.length : 3, |
||||
); |
||||
|
||||
const shouldShowButton = topicTitles.length > 3; |
||||
|
||||
return ( |
||||
<> |
||||
{firstThreeTopics.map((topicTitle, index) => { |
||||
return ( |
||||
<span className="font-medium" key={`topic-${topicTitle}-${index}`}> |
||||
<> |
||||
{index > 0 && ', '} |
||||
{index === firstThreeTopics.length - 1 && |
||||
remainingTopics?.length === 0 && |
||||
firstThreeTopics.length > 1 |
||||
? 'and ' |
||||
: ''} |
||||
<div |
||||
className={cn( |
||||
'flex flex-wrap gap-1 text-sm font-normal text-gray-600', |
||||
className, |
||||
)} |
||||
> |
||||
{filteredTopicTitles.map((topicTitle, index) => ( |
||||
<span key={index} className="rounded-md bg-gray-200 px-1"> |
||||
{topicTitle} |
||||
</> |
||||
</span> |
||||
); |
||||
})} |
||||
|
||||
{remainingTopics?.length > 0 && ( |
||||
<> |
||||
, and |
||||
))} |
||||
{shouldShowButton && ( |
||||
<button |
||||
className="font-medium underline underline-offset-2 hover:text-black" |
||||
onClick={onSelectActivity} |
||||
onClick={() => setShowAll(!showAll)} |
||||
className="text-gray-600 underline underline-offset-2 hover:text-black" |
||||
> |
||||
{remainingTopics.length} more topic |
||||
{remainingTopics.length > 1 ? 's' : ''} |
||||
{showAll ? '- Show less' : `+${topicTitles.length - 3} more`} |
||||
</button> |
||||
</> |
||||
)} |
||||
</> |
||||
</div> |
||||
); |
||||
} |
||||
|
Loading…
Reference in new issue