1
0
mirror of synced 2025-12-30 03:01:36 -05:00
Files
docs/components/landing/ArticleList.tsx
Grace Park 822fe2926b Megabranch: Upgrade primer/react (#28458)
* upgrade primer/react

* upgrade

* using deprecated

* remove lib"

* Upgrade primer/react: Upgrade Label (#28502)

update Label to primer/react 35.2.2

* fix merge conflicts

* primer/react v35: update ActionList (#28467)

* Update to v35 ActionList for LearningTrack

* Update to v35 ActionList for ArticleList

* Update to v35 ActionList for ProductArticleList

* Update to v35 ActionList for TableOfContents

* Update to v35 ActionList for ProductCollapsibleSection

* Update to v35 ActionList for RestCollapsibleSection

* Update to v35 ActionList for SidebarHomepage

* Update to v35 ActionList for MiniTocs

* Update to v35 ActionList for Search

* Extra div for rendering test

* One less div for rendering test

* All the style updates for v35 ActionList

* Works without setting as an li which is already the default (didn't before for some reason)

* Use deprecated ItemInput for now

* Picker update for primer/react (#28485)

* update picker

* inline picker for mobile

* set width to auto

* Update components/ui/Picker/Picker.tsx

Co-authored-by: Kevin Heis <heiskr@users.noreply.github.com>

* update

* Update Picker.tsx

* update onselect

* checking language code

* move language cookie setting to language picker

Co-authored-by: Kevin Heis <heiskr@users.noreply.github.com>

* Resolve package merge conflicts

* fresh npm install

* Primer update UnderlineNav (#28582)

* update underlinenav for primer/react update

* update tests

* update switches test

* update one last label

* update header test"

* remove href in underlinenav

* update rendering tests

* update cursor

* primer/react v35: update DropDownMenu to ActionMenu (#28576)

* Update to v35 ActionMenu for ArticleCards

* Update to v35 ActionMenu for Search

* Set button to inline-block

* Put the props on the overlay

* Update test for ActionMenu markup

* update package

* update package lock

* primer/react v35: CodeLanguagePicker update from SelectMenu to ActionMenu (#28625)

* Use octicon for menu down arrow

* Update to v35 ActionMenu for CodeLanguagePicker

* update to SubNav

Co-authored-by: Grace Park <gracepark@github.com>

* update package-lock

Co-authored-by: Robert Sese <734194+rsese@users.noreply.github.com>
Co-authored-by: Kevin Heis <heiskr@users.noreply.github.com>
2022-07-11 11:51:18 -07:00

106 lines
3.5 KiB
TypeScript

import cx from 'classnames'
import dayjs from 'dayjs'
import { ActionList } from '@primer/react'
import { useTranslation } from 'components/hooks/useTranslation'
import { Link } from 'components/Link'
import { ArrowRightIcon } from '@primer/octicons-react'
import { FeaturedLink } from 'components/context/ProductLandingContext'
import { useMainContext } from 'components/context/MainContext'
import { TruncateLines } from 'components/ui/TruncateLines'
import { BumpLink } from 'components/ui/BumpLink'
export type ArticleListPropsT = {
title?: string
viewAllHref?: string
viewAllTitleText?: string
articles: Array<FeaturedLink>
}
export const ArticleList = ({
title,
viewAllHref,
viewAllTitleText,
articles,
}: ArticleListPropsT) => {
const { t } = useTranslation('product_landing')
const { page } = useMainContext()
return (
<>
{title && (
<div className="mb-4 d-flex flex-items-baseline">
<h2 className={cx('f4 text-semibold')}>{title}</h2>
{viewAllHref && (
<Link
href={viewAllHref}
className="ml-4"
{...(viewAllTitleText ? { 'aria-label': `${page.title} - ${viewAllTitleText}` } : {})}
>
{t('view')} <ArrowRightIcon size={14} className="v-align-middle" />
</Link>
)}
</div>
)}
<ActionList as="ul" data-testid="article-list" variant="full">
{articles.map((link) => {
return (
<ActionList.Item
as="li"
key={link.href}
className={cx('width-full border-top')}
sx={{
borderRadius: 0,
':hover': {
borderRadius: 0,
},
}}
>
<BumpLink
as={Link}
href={link.href}
className="py-3"
title={
!link.hideIntro && link.intro ? (
<h3 className="f4" data-testid="link-with-intro-title">
<span
dangerouslySetInnerHTML={
link.fullTitle ? { __html: link.fullTitle } : { __html: link.title }
}
/>
</h3>
) : (
<span
className="f4 text-bold d-block"
data-testid="link-with-intro-title"
dangerouslySetInnerHTML={
link.fullTitle ? { __html: link.fullTitle } : { __html: link.title }
}
></span>
)
}
>
{!link.hideIntro && link.intro && (
<TruncateLines as="p" maxLines={2} className="color-fg-muted mb-0 mt-1">
<span
data-testid="link-with-intro-intro"
dangerouslySetInnerHTML={{ __html: link.intro }}
/>
</TruncateLines>
)}
{link.date && (
<time
className="tooltipped tooltipped-n color-fg-muted text-mono mt-1"
aria-label={dayjs(link.date).format('MMMM DD')}
>
{dayjs(link.date).format('MMMM DD')}
</time>
)}
</BumpLink>
</ActionList.Item>
)
})}
</ActionList>
</>
)
}