|
| 1 | +--- |
| 2 | +import { ChevronLeft, ChevronRight } from '@lucide/astro'; |
| 3 | +import { useTranslations, type languages } from '../../i18n/ui'; |
| 4 | +
|
| 5 | +interface ChapterItem { |
| 6 | + id: string; |
| 7 | + name: string; |
| 8 | +} |
| 9 | +
|
| 10 | +interface Props { |
| 11 | + prevChapter?: ChapterItem | null; |
| 12 | + nextChapter?: ChapterItem | null; |
| 13 | + isFirstChapter?: boolean; |
| 14 | + activeLang?: keyof typeof languages; |
| 15 | +} |
| 16 | +
|
| 17 | +const { |
| 18 | + prevChapter, |
| 19 | + nextChapter, |
| 20 | + isFirstChapter = false, |
| 21 | + activeLang = 'en', |
| 22 | +} = Astro.props; |
| 23 | +
|
| 24 | +const t = useTranslations(activeLang); |
| 25 | +--- |
| 26 | + |
| 27 | +<nav class="chapter-nav" aria-label="Chapter navigation"> |
| 28 | + {isFirstChapter ? ( |
| 29 | + <a href={`/ultimate-python/${activeLang}/`} class="chapter-nav-btn prev"> |
| 30 | + <span class="nav-direction"> |
| 31 | + <ChevronLeft size={14} /> |
| 32 | + <span>{t('nav.home')}</span> |
| 33 | + </span> |
| 34 | + <span class="nav-title">{t('site.title')}</span> |
| 35 | + </a> |
| 36 | + ) : prevChapter ? ( |
| 37 | + <a |
| 38 | + href={`/ultimate-python/${activeLang}/${prevChapter.id}/`} |
| 39 | + class="chapter-nav-btn prev" |
| 40 | + > |
| 41 | + <span class="nav-direction"> |
| 42 | + <ChevronLeft size={14} /> |
| 43 | + <span>{t('chapter.prev')}</span> |
| 44 | + </span> |
| 45 | + <span class="nav-title">{prevChapter.name}</span> |
| 46 | + </a> |
| 47 | + ) : ( |
| 48 | + <div class="nav-spacer" /> |
| 49 | + )} |
| 50 | + |
| 51 | + {nextChapter ? ( |
| 52 | + <a |
| 53 | + href={`/ultimate-python/${activeLang}/${nextChapter.id}/`} |
| 54 | + class="chapter-nav-btn next" |
| 55 | + > |
| 56 | + <span class="nav-direction"> |
| 57 | + <span>{t('chapter.next')}</span> |
| 58 | + <ChevronRight size={14} /> |
| 59 | + </span> |
| 60 | + <span class="nav-title">{nextChapter.name}</span> |
| 61 | + </a> |
| 62 | + ) : ( |
| 63 | + <div class="nav-spacer" /> |
| 64 | + )} |
| 65 | +</nav> |
| 66 | + |
| 67 | +<style> |
| 68 | + .chapter-nav { |
| 69 | + display: flex; |
| 70 | + justify-content: space-between; |
| 71 | + gap: 1.5rem; |
| 72 | + padding-top: 2.5rem; |
| 73 | + border-top: 1px solid var(--border-color); |
| 74 | + margin-top: 3.5rem; |
| 75 | + width: 100%; |
| 76 | + } |
| 77 | + |
| 78 | + .chapter-nav-btn { |
| 79 | + display: flex; |
| 80 | + flex-direction: column; |
| 81 | + padding: 1rem 1.35rem; |
| 82 | + border-radius: 8px; |
| 83 | + background-color: var(--bg-secondary); |
| 84 | + border: 1px solid var(--border-color); |
| 85 | + color: var(--text-primary); |
| 86 | + transition: |
| 87 | + transform var(--transition-speed), |
| 88 | + border-color var(--transition-speed), |
| 89 | + box-shadow var(--transition-speed); |
| 90 | + min-width: 180px; |
| 91 | + max-width: 48%; |
| 92 | + text-decoration: none; |
| 93 | + } |
| 94 | + |
| 95 | + .chapter-nav-btn:hover { |
| 96 | + background-color: var(--bg-tertiary); |
| 97 | + border-color: var(--forest-green); |
| 98 | + transform: translateY(-2px); |
| 99 | + box-shadow: 0 4px 12px rgba(27, 67, 50, 0.08); |
| 100 | + } |
| 101 | + |
| 102 | + .chapter-nav-btn.next { |
| 103 | + margin-left: auto; |
| 104 | + align-items: flex-end; |
| 105 | + text-align: right; |
| 106 | + } |
| 107 | + |
| 108 | + .nav-direction { |
| 109 | + font-size: 0.75rem; |
| 110 | + color: var(--text-secondary); |
| 111 | + text-transform: uppercase; |
| 112 | + letter-spacing: 0.05em; |
| 113 | + font-family: var(--font-sans); |
| 114 | + margin-bottom: 0.35rem; |
| 115 | + display: inline-flex; |
| 116 | + align-items: center; |
| 117 | + gap: 0.35rem; |
| 118 | + font-weight: 500; |
| 119 | + } |
| 120 | + |
| 121 | + .chapter-nav-btn:hover .nav-direction { |
| 122 | + color: var(--forest-green); |
| 123 | + } |
| 124 | + |
| 125 | + .nav-title { |
| 126 | + font-size: 1.05rem; |
| 127 | + font-weight: 600; |
| 128 | + color: var(--forest-green); |
| 129 | + font-family: var(--font-serif); |
| 130 | + white-space: nowrap; |
| 131 | + overflow: hidden; |
| 132 | + text-overflow: ellipsis; |
| 133 | + max-width: 100%; |
| 134 | + } |
| 135 | + |
| 136 | + .nav-spacer { |
| 137 | + flex: 1; |
| 138 | + } |
| 139 | + |
| 140 | + @media (width <= 640px) { |
| 141 | + .chapter-nav { |
| 142 | + flex-direction: column; |
| 143 | + gap: 1rem; |
| 144 | + padding-top: 1.5rem; |
| 145 | + margin-top: 2rem; |
| 146 | + } |
| 147 | + |
| 148 | + .chapter-nav-btn { |
| 149 | + max-width: 100%; |
| 150 | + width: 100%; |
| 151 | + } |
| 152 | + |
| 153 | + .chapter-nav-btn.next { |
| 154 | + align-items: flex-start; |
| 155 | + text-align: left; |
| 156 | + } |
| 157 | + } |
| 158 | +</style> |
0 commit comments