-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
61 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,37 @@ | ||
import { Button, Link, Text } from '@dataesr/dsfr-plus'; | ||
import PropTypes from 'prop-types'; | ||
import { useState } from 'react'; | ||
|
||
const WORKS_LENGTH = 5; | ||
|
||
export default function WorksList({ works }) { | ||
const [showMore, setShowMore] = useState(false); | ||
|
||
const _works = showMore ? works : works.slice(0, 5); | ||
const displayedWorks = showMore ? works : works.slice(0, WORKS_LENGTH); | ||
|
||
return ( | ||
<Text size="sm" className="fr-my-1w fr-pl-1w" style={{ borderLeft: '5px solid #aaa' }}> | ||
<Text className="fr-my-1w fr-pl-1w" size="sm" style={{ borderLeft: '5px solid #aaa' }}> | ||
<i> | ||
<span className="fr-mr-1w"> | ||
works: | ||
Works: | ||
</span> | ||
{_works.map((work) => ( | ||
<Link className="fr-mr-1w" href={`https://openalex.org/${work}`} target="_blank"> | ||
{displayedWorks.map((work) => ( | ||
<Link className="fr-mr-1w" href={`https://openalex.org/${work}`} key={`works-list-${work}`} target="_blank"> | ||
{work} | ||
</Link> | ||
))} | ||
{ | ||
works.length > 5 && ( | ||
<Button variant="text" onClick={() => setShowMore(!showMore)}> | ||
{showMore ? 'show less works' : `show more works (${works.length - 5})`} | ||
<Button onClick={() => setShowMore(!showMore)} variant="text"> | ||
{showMore ? 'show less works' : `show more works (${works.length - WORKS_LENGTH})`} | ||
</Button> | ||
) | ||
} | ||
</i> | ||
</Text> | ||
|
||
); | ||
} | ||
|
||
WorksList.propTypes = { | ||
works: PropTypes.array.isRequired, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters