Skip to content

Commit d64a7fd

Browse files
committed
feat: code preview page add scroll to top button
1 parent 4ed4254 commit d64a7fd

7 files changed

Lines changed: 30 additions & 5 deletions

File tree

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
@@ -699,7 +699,8 @@
699699
"preview": "preview",
700700
"code": "code"
701701
},
702-
"file_path": "File path"
702+
"file_path": "File path",
703+
"scroll_to_top": "Scroll to top"
703704
},
704705
"badges": {
705706
"provenance": {

i18n/locales/zh-CN.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,8 @@
663663
"preview": "预览",
664664
"code": "代码"
665665
},
666-
"file_path": "文件路径"
666+
"file_path": "文件路径",
667+
"scroll_to_top": "滚动到顶部"
667668
},
668669
"badges": {
669670
"provenance": {

i18n/schema.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2103,6 +2103,9 @@
21032103
},
21042104
"file_path": {
21052105
"type": "string"
2106+
},
2107+
"scroll_to_top": {
2108+
"type": "string"
21062109
}
21072110
},
21082111
"additionalProperties": false

lunaria/files/en-GB.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,8 @@
698698
"preview": "preview",
699699
"code": "code"
700700
},
701-
"file_path": "File path"
701+
"file_path": "File path",
702+
"scroll_to_top": "Scroll to top"
702703
},
703704
"badges": {
704705
"provenance": {

lunaria/files/en-US.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,8 @@
698698
"preview": "preview",
699699
"code": "code"
700700
},
701-
"file_path": "File path"
701+
"file_path": "File path",
702+
"scroll_to_top": "Scroll to top"
702703
},
703704
"badges": {
704705
"provenance": {

lunaria/files/zh-CN.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,8 @@
662662
"preview": "预览",
663663
"code": "代码"
664664
},
665-
"file_path": "文件路径"
665+
"file_path": "文件路径",
666+
"scroll_to_top": "滚动到顶部"
666667
},
667668
"badges": {
668669
"provenance": {

0 commit comments

Comments
 (0)