Skip to content
36 changes: 36 additions & 0 deletions frontend/src/components/ShowMoreButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { faChevronDown, faChevronUp } from '@fortawesome/free-solid-svg-icons'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { Button } from '@heroui/button'

const ShowMoreButton = ({
isExpanded,
onToggle,
showMoreText = 'Show more',
showLessText = 'Show less',
}: {
isExpanded: boolean
onToggle: () => void
showMoreText?: string
showLessText?: string
}) => (
<div className="mt-4 flex justify-start">
<Button
type="button"
disableAnimation
onPress={onToggle}
className="flex items-center bg-transparent text-blue-400"
>
{isExpanded ? (
<>
{showLessText} <FontAwesomeIcon icon={faChevronUp} className="ml-2 text-sm" />
</>
) : (
<>
{showMoreText} <FontAwesomeIcon icon={faChevronDown} className="ml-2 text-sm" />
</>
)}
</Button>
</div>
)

export default ShowMoreButton
29 changes: 10 additions & 19 deletions frontend/src/components/ToggleableList.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { IconDefinition } from '@fortawesome/fontawesome-svg-core'
import { faChevronDown, faChevronUp } from '@fortawesome/free-solid-svg-icons'
import type { IconDefinition } from '@fortawesome/fontawesome-svg-core'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { Button } from '@heroui/button'
import { useRouter } from 'next/navigation'
import React, { useState } from 'react'
import type React from 'react'
import { useState } from 'react'
import ShowMoreButton from 'components/ShowMoreButton'

const ToggleableList = ({
items,
Expand Down Expand Up @@ -45,21 +45,12 @@ const ToggleableList = ({
))}
</div>
{items.length > limit && (
<Button
disableAnimation
onPress={toggleShowAll}
className="mt-4 flex items-center bg-transparent text-blue-400 hover:underline"
>
{showAll ? (
<>
Show less <FontAwesomeIcon icon={faChevronUp} className="ml-1" />
</>
) : (
<>
Show more <FontAwesomeIcon icon={faChevronDown} className="ml-1" />
</>
)}
</Button>
<ShowMoreButton
isExpanded={showAll}
onToggle={toggleShowAll}
showMoreText="Show more"
showLessText="Show less"
/>
)}
</div>
)
Expand Down
27 changes: 8 additions & 19 deletions frontend/src/components/TopContributorsList.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import { IconProp } from '@fortawesome/fontawesome-svg-core'
import { faChevronDown, faChevronUp } from '@fortawesome/free-solid-svg-icons'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { Button } from '@heroui/button'
import type { IconProp } from '@fortawesome/fontawesome-svg-core'
import Image from 'next/image'
import Link from 'next/link'
import { useState } from 'react'
Expand All @@ -10,6 +7,7 @@ import { capitalize } from 'utils/capitalize'
import { getMemberUrl } from 'utils/urlFormatter'
import AnchorTitle from 'components/AnchorTitle'
import SecondaryCard from 'components/SecondaryCard'
import ShowMoreButton from 'components/ShowMoreButton'

const TopContributorsList = ({
contributors,
Expand Down Expand Up @@ -67,21 +65,12 @@ const TopContributorsList = ({
))}
</div>
{contributors.length > maxInitialDisplay && (
<Button
disableAnimation
onPress={toggleContributors}
className="mt-4 flex items-center bg-transparent text-blue-400 hover:underline"
>
{showAllContributors ? (
<>
Show less <FontAwesomeIcon icon={faChevronUp} className="ml-1" />
</>
) : (
<>
Show more <FontAwesomeIcon icon={faChevronDown} className="ml-1" />
</>
)}
</Button>
<ShowMoreButton
isExpanded={showAllContributors}
onToggle={toggleContributors}
showMoreText="Show more"
showLessText="Show less"
/>
)}
</SecondaryCard>
)
Expand Down