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 = { |
type ActivityTopicTitlesProps = { |
||||||
topicTitles: string[]; |
topicTitles: string[]; |
||||||
|
className?: string; |
||||||
onSelectActivity?: () => void; |
onSelectActivity?: () => void; |
||||||
}; |
}; |
||||||
|
|
||||||
export function ActivityTopicTitles(props: ActivityTopicTitlesProps) { |
export function ActivityTopicTitles(props: ActivityTopicTitlesProps) { |
||||||
const { topicTitles, onSelectActivity } = props; |
const { topicTitles, onSelectActivity, className } = props; |
||||||
const firstThreeTopics = topicTitles?.slice(0, 3); |
|
||||||
const remainingTopics = topicTitles?.slice(3); |
const [showAll, setShowAll] = useState(false); |
||||||
|
const filteredTopicTitles = topicTitles.slice( |
||||||
|
0, |
||||||
|
showAll ? topicTitles.length : 3, |
||||||
|
); |
||||||
|
|
||||||
|
const shouldShowButton = topicTitles.length > 3; |
||||||
|
|
||||||
return ( |
return ( |
||||||
<> |
<div |
||||||
{firstThreeTopics.map((topicTitle, index) => { |
className={cn( |
||||||
return ( |
'flex flex-wrap gap-1 text-sm font-normal text-gray-600', |
||||||
<span className="font-medium" key={`topic-${topicTitle}-${index}`}> |
className, |
||||||
<> |
)} |
||||||
{index > 0 && ', '} |
> |
||||||
{index === firstThreeTopics.length - 1 && |
{filteredTopicTitles.map((topicTitle, index) => ( |
||||||
remainingTopics?.length === 0 && |
<span key={index} className="rounded-md bg-gray-200 px-1"> |
||||||
firstThreeTopics.length > 1 |
|
||||||
? 'and ' |
|
||||||
: ''} |
|
||||||
{topicTitle} |
{topicTitle} |
||||||
</> |
|
||||||
</span> |
</span> |
||||||
); |
))} |
||||||
})} |
{shouldShowButton && ( |
||||||
|
|
||||||
{remainingTopics?.length > 0 && ( |
|
||||||
<> |
|
||||||
, and |
|
||||||
<button |
<button |
||||||
className="font-medium underline underline-offset-2 hover:text-black" |
onClick={() => setShowAll(!showAll)} |
||||||
onClick={onSelectActivity} |
className="text-gray-600 underline underline-offset-2 hover:text-black" |
||||||
> |
> |
||||||
{remainingTopics.length} more topic |
{showAll ? '- Show less' : `+${topicTitles.length - 3} more`} |
||||||
{remainingTopics.length > 1 ? 's' : ''} |
|
||||||
</button> |
</button> |
||||||
</> |
|
||||||
)} |
)} |
||||||
</> |
</div> |
||||||
); |
); |
||||||
} |
} |
||||||
|
Loading…
Reference in new issue