|
| 1 | +import { ArrowRightIcon } from '@primer/octicons-react' |
| 2 | + |
1 | 3 | import { Link } from '@/frame/components/Link' |
2 | 4 | import type { JourneyContext } from '@/journeys/lib/journey-path-resolver' |
3 | 5 | import { useTranslation } from '@/languages/components/useTranslation' |
| 6 | +import styles from './JourneyTrackNav.module.scss' |
4 | 7 |
|
5 | 8 | type Props = { |
6 | 9 | context: JourneyContext |
7 | 10 | } |
8 | 11 |
|
9 | 12 | export function JourneyTrackNav({ context }: Props) { |
10 | 13 | const { t } = useTranslation('journey_track_nav') |
11 | | - const { prevGuide, nextGuide, nextTrackFirstGuide } = context |
| 14 | + const { nextGuide, nextTrackFirstGuide, currentGuideIndex, numberOfGuides, trackTitle } = context |
| 15 | + |
| 16 | + const upNext = nextGuide ?? nextTrackFirstGuide |
| 17 | + if (!upNext) return null |
| 18 | + |
| 19 | + // In-track: show the next article's title. Crossing into a new track: show the |
| 20 | + // track's name so the reader knows they're moving on to a new track. |
| 21 | + const label = nextGuide ? nextGuide.title : nextTrackFirstGuide!.trackTitle |
| 22 | + |
| 23 | + const progress = t('up_next_progress') |
| 24 | + .replace('{i}', `${currentGuideIndex + 1}`) |
| 25 | + .replace('{n}', `${numberOfGuides}`) |
| 26 | + .replace('{track}', trackTitle) |
12 | 27 |
|
13 | 28 | return ( |
14 | | - <div |
15 | | - data-testid="journey-track-nav" |
16 | | - className="py-3 px-4 rounded color-bg-default border d-flex flex-justify-between" |
17 | | - > |
18 | | - <span className="f5 d-flex flex-column"> |
19 | | - {prevGuide && ( |
20 | | - <> |
21 | | - <span className="color-fg-default" aria-hidden="true"> |
22 | | - {t('prev_article')} |
23 | | - </span> |
24 | | - <Link |
25 | | - href={prevGuide.href} |
26 | | - className="text-bold color-fg" |
27 | | - aria-label={`${t('prev_article')}: ${prevGuide.title}`} |
28 | | - > |
29 | | - {prevGuide.title} |
30 | | - </Link> |
31 | | - </> |
32 | | - )} |
33 | | - </span> |
| 29 | + <nav data-testid="journey-track-nav" aria-label={t('up_next')} className={styles.upNext}> |
| 30 | + <div className={styles.lead}> |
| 31 | + <p className={styles.eyebrow}>{t('up_next')}</p> |
| 32 | + <Link href={upNext.href} className={styles.link} aria-label={`${t('up_next')}: ${label}`}> |
| 33 | + <span className={styles.title}>{label}</span> |
| 34 | + <ArrowRightIcon size={16} /> |
| 35 | + </Link> |
| 36 | + </div> |
34 | 37 |
|
35 | | - <span className="f5 d-flex flex-column flex-items-end"> |
36 | | - {nextGuide ? ( |
37 | | - <> |
38 | | - <span className="color-fg-default" aria-hidden="true"> |
39 | | - {t('next_article')} |
40 | | - </span> |
41 | | - <Link |
42 | | - href={nextGuide.href} |
43 | | - className="text-bold color-fg text-right" |
44 | | - aria-label={`${t('next_article')}: ${nextGuide.title}`} |
45 | | - > |
46 | | - {nextGuide.title} |
47 | | - </Link> |
48 | | - </> |
49 | | - ) : nextTrackFirstGuide ? ( |
50 | | - <> |
51 | | - <span className="color-fg-default" aria-hidden="true"> |
52 | | - {t('next_article')} |
53 | | - </span> |
54 | | - <Link |
55 | | - href={nextTrackFirstGuide.href} |
56 | | - className="text-bold color-fg text-right" |
57 | | - aria-label={`${t('next_article')}: ${nextTrackFirstGuide.trackTitle}`} |
58 | | - > |
59 | | - {nextTrackFirstGuide.trackTitle} |
60 | | - </Link> |
61 | | - </> |
62 | | - ) : null} |
63 | | - </span> |
64 | | - </div> |
| 38 | + <p className={styles.progress}>{progress}</p> |
| 39 | + </nav> |
65 | 40 | ) |
66 | 41 | } |
0 commit comments