Skip to content

Commit 519afb7

Browse files
authored
feat: code preview page add scroll to top button (#1686)
1 parent d2dbe53 commit 519afb7

File tree

7 files changed

+30
-5
lines changed

7 files changed

+30
-5
lines changed

app/pages/package-code/[[org]]/[packageName]/v/[version]/[...filePath].vue

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,14 @@ function copyPermalinkUrl() {
249249
copyPermalink(url.toString())
250250
}
251251
252+
// Scroll to top of file content
253+
const contentContainer = useTemplateRef('contentContainer')
254+
function scrollToTop() {
255+
if (contentContainer.value) {
256+
contentContainer.value.scrollTo({ top: 0, behavior: 'smooth' })
257+
}
258+
}
259+
252260
// Canonical URL for this code page
253261
const canonicalUrl = computed(() => `https://npmx.dev${getCodeUrl(route.params)}`)
254262
@@ -410,6 +418,7 @@ defineOgImageComponent('Default', {
410418
<!-- File content / Directory listing - sticky with internal scroll on desktop -->
411419
<div
412420
class="flex-1 min-w-0 overflow-x-hidden sticky top-28 self-start h-[calc(100vh-7rem)] overflow-y-auto"
421+
ref="contentContainer"
413422
>
414423
<!-- File viewer -->
415424
<template v-if="isViewingFile && fileContent">
@@ -449,6 +458,14 @@ defineOgImageComponent('Default', {
449458
</div>
450459
</div>
451460
<div class="flex items-center gap-2">
461+
<button
462+
type="button"
463+
class="px-2 py-1 font-mono text-xs text-fg-muted bg-bg-subtle border border-border rounded hover:text-fg hover:border-border-hover transition-colors items-center inline-flex gap-1"
464+
@click="scrollToTop"
465+
>
466+
<span class="i-lucide:arrow-up w-3 h-3" />
467+
{{ $t('code.scroll_to_top') }}
468+
</button>
452469
<button
453470
v-if="selectedLines"
454471
type="button"

i18n/locales/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,8 @@
711711
"preview": "preview",
712712
"code": "code"
713713
},
714-
"file_path": "File path"
714+
"file_path": "File path",
715+
"scroll_to_top": "Scroll to top"
715716
},
716717
"badges": {
717718
"provenance": {

i18n/locales/zh-CN.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,8 @@
700700
"preview": "预览",
701701
"code": "代码"
702702
},
703-
"file_path": "文件路径"
703+
"file_path": "文件路径",
704+
"scroll_to_top": "滚动到顶部"
704705
},
705706
"badges": {
706707
"provenance": {

i18n/schema.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2139,6 +2139,9 @@
21392139
},
21402140
"file_path": {
21412141
"type": "string"
2142+
},
2143+
"scroll_to_top": {
2144+
"type": "string"
21422145
}
21432146
},
21442147
"additionalProperties": false

lunaria/files/en-GB.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,8 @@
710710
"preview": "preview",
711711
"code": "code"
712712
},
713-
"file_path": "File path"
713+
"file_path": "File path",
714+
"scroll_to_top": "Scroll to top"
714715
},
715716
"badges": {
716717
"provenance": {

lunaria/files/en-US.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,8 @@
710710
"preview": "preview",
711711
"code": "code"
712712
},
713-
"file_path": "File path"
713+
"file_path": "File path",
714+
"scroll_to_top": "Scroll to top"
714715
},
715716
"badges": {
716717
"provenance": {

lunaria/files/zh-CN.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,8 @@
699699
"preview": "预览",
700700
"code": "代码"
701701
},
702-
"file_path": "文件路径"
702+
"file_path": "文件路径",
703+
"scroll_to_top": "滚动到顶部"
703704
},
704705
"badges": {
705706
"provenance": {

0 commit comments

Comments
 (0)