1
0
mirror of synced 2025-12-19 18:10:59 -05:00
Files
docs/components/guides/LearningTrack.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

129 lines
5.0 KiB
TypeScript

import cx from 'classnames'
import { useTranslation } from 'components/hooks/useTranslation'
import { ArrowRightIcon } from '@primer/octicons-react'
import { ActionList } from '@primer/react'
import { useState } from 'react'
import { FeaturedTrack } from 'components/context/ProductGuidesContext'
import { TruncateLines } from 'components/ui/TruncateLines'
import slugger from 'github-slugger'
import styles from './LearningTrack.module.scss'
type Props = {
track: FeaturedTrack
}
const DEFAULT_VISIBLE_GUIDES = 4
export const LearningTrack = ({ track }: Props) => {
const [numVisible, setNumVisible] = useState(DEFAULT_VISIBLE_GUIDES)
const { t } = useTranslation('product_guides')
const slug = track?.title ? slugger.slug(track?.title) : ''
const showAll = () => {
setNumVisible(track?.guides?.length || 0)
}
return (
<div data-testid="learning-track" className="my-3 px-4 col-12 col-md-6">
<div className="Box d-flex flex-column">
<div className="Box-header color-bg-subtle p-4 d-flex flex-1 flex-items-start flex-wrap">
<div className="d-flex flex-auto flex-items-start col-7 col-md-7 col-xl-7">
<div className="my-xl-0 mr-xl-3">
<h3 id={slug} className={cx('mb-3 color-text f3 text-semibold', styles.hashAnchor)}>
<a className="color-unset" href={`#${slug}`}>
{track?.title}
</a>
</h3>
<TruncateLines as="p" maxLines={3} className="color-text">
{track?.description}
</TruncateLines>
</div>
</div>
<a
{...{ 'aria-label': `${track?.title} - ${t('start_path')}` }}
className="d-inline-flex btn no-wrap mt-3 mt-md-0 flex-items-center flex-justify-center"
href={`${track?.guides && track?.guides[0].href}?learn=${
track?.trackName
}&learnProduct=${track?.trackProduct}`}
>
<span>{t('start_path')}</span>
<ArrowRightIcon size={20} className="ml-2" />
</a>
</div>
{track && track.guides && (
<div style={{ counterReset: 'li' }}>
<ActionList as="ol" variant="full">
{track?.guides?.slice(0, numVisible).map((guide) => {
return (
<ActionList.Item
as="li"
key={guide.href + track?.trackName}
className="width-full p-0"
sx={{
position: 'relative',
borderRadius: 0,
':hover': {
borderRadius: 0,
},
':before': {
width: 'calc(1.5rem - 0px)',
height: 'calc(1.5rem - 0px)',
fontSize: 'calc(1rem - 1px)',
margin: '22px 0 0 1rem',
content: 'counter(li)',
counterIncrement: 'li',
position: 'absolute',
left: 0,
color: 'var(--color-canvas-default)',
fontWeight: 500,
textAlign: 'center',
borderRadius: '50%',
backgroundColor: 'var(--color-fg-default)',
},
}}
>
<a
className="rounded-0 pl-7 py-4 width-full d-block Box-row d-flex flex-items-center color-fg-default no-underline"
href={`${guide.href}?learn=${track?.trackName}&learnProduct=${track?.trackProduct}`}
>
<h4
className="flex-auto pr-2 f5"
dangerouslySetInnerHTML={{ __html: guide.title }}
/>
<div className="color-fg-muted h6 text-uppercase flex-shrink-0">
{t('guide_types')[guide.page?.type || '']}
</div>
</a>
</ActionList.Item>
)
})}
</ActionList>
</div>
)}
{
<button
className={
'Box-footer btn-link border-top-0 position-relative text-center text-bold color-fg-accent pt-1 pb-3 col-12 ' +
((track?.guides?.length || 0) <= numVisible && cx(styles.removeHoverEvents))
}
onClick={showAll}
>
{(track?.guides?.length || 0) > numVisible ? (
<div>
<div
className={cx('position-absolute left-0 right-0 py-5', styles.fadeBottom)}
style={{ bottom: '50px' }}
/>
<span>
Show {(track?.guides?.length || 0) - numVisible} {t(`more_guides`)}
</span>
</div>
) : (
<span className="color-fg-default">All guides shown</span>
)}
</button>
}
</div>
</div>
)
}