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