Skip to content

Commit 4640f27

Browse files
RYGRITdanielroe
andauthored
fix: clickable rows & mobile scrollbar overflow & dynamic line width (#1080)
Co-authored-by: Daniel Roe <daniel@roe.dev>
1 parent fb225fe commit 4640f27

File tree

3 files changed

+22
-15
lines changed

3 files changed

+22
-15
lines changed

app/components/Code/DirectoryListing.vue

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,15 @@ function getCodeRoute(nodePath?: string): RouteLocationRaw {
7474
v-if="parentPath !== null"
7575
class="border-b border-border hover:bg-bg-subtle transition-colors"
7676
>
77-
<td class="py-2 px-4">
77+
<td colspan="2">
7878
<NuxtLink
7979
:to="getCodeRoute(parentPath || undefined)"
80-
class="flex items-center gap-2 font-mono text-sm text-fg-muted hover:text-fg transition-colors"
80+
class="flex items-center gap-2 py-2 px-4 font-mono text-sm text-fg-muted hover:text-fg transition-colors"
8181
>
8282
<span class="i-carbon:folder w-4 h-4 text-yellow-600" />
8383
<span>..</span>
8484
</NuxtLink>
8585
</td>
86-
<td />
8786
</tr>
8887

8988
<!-- Directory/file rows -->
@@ -92,25 +91,26 @@ function getCodeRoute(nodePath?: string): RouteLocationRaw {
9291
:key="node.path"
9392
class="border-b border-border hover:bg-bg-subtle transition-colors"
9493
>
95-
<td class="py-2 px-4">
94+
<td colspan="2">
9695
<NuxtLink
9796
:to="getCodeRoute(node.path)"
98-
class="flex items-center gap-2 font-mono text-sm hover:text-fg transition-colors"
97+
class="flex items-center gap-2 py-2 px-4 font-mono text-sm hover:text-fg transition-colors"
9998
:class="node.type === 'directory' ? 'text-fg' : 'text-fg-muted'"
10099
>
101100
<span
102101
v-if="node.type === 'directory'"
103102
class="i-carbon:folder w-4 h-4 text-yellow-600"
104103
/>
105104
<span v-else class="w-4 h-4" :class="getFileIcon(node.name)" />
106-
<span>{{ node.name }}</span>
105+
<span class="flex-1">{{ node.name }}</span>
106+
<span
107+
v-if="node.type === 'file' && node.size"
108+
class="text-end font-mono text-xs text-fg-subtle"
109+
>
110+
{{ formatBytes(node.size) }}
111+
</span>
107112
</NuxtLink>
108113
</td>
109-
<td class="py-2 px-4 text-end font-mono text-xs text-fg-subtle">
110-
<span v-if="node.type === 'file' && node.size">
111-
{{ formatBytes(node.size) }}
112-
</span>
113-
</td>
114114
</tr>
115115
</tbody>
116116
</table>

app/components/Code/Viewer.vue

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ const lineNumbers = computed(() => {
1616
return Array.from({ length: props.lines }, (_, i) => i + 1)
1717
})
1818
19+
// Used for CSS calculation of line number column width
20+
const lineDigits = computed(() => {
21+
return String(props.lines).length
22+
})
23+
1924
// Check if a line is selected
2025
function isLineSelected(lineNum: number): boolean {
2126
if (!props.selectedLines) return false
@@ -55,10 +60,11 @@ watch(
5560
</script>
5661

5762
<template>
58-
<div class="code-viewer flex min-h-full">
63+
<div class="code-viewer flex min-h-full max-w-full">
5964
<!-- Line numbers column -->
6065
<div
61-
class="line-numbers shrink-0 bg-bg-subtle border-ie border-border text-end select-none"
66+
class="line-numbers shrink-0 bg-bg-subtle border-ie border-solid border-border text-end select-none relative"
67+
:style="{ '--line-digits': lineDigits }"
6268
aria-hidden="true"
6369
>
6470
<a
@@ -94,7 +100,8 @@ watch(
94100
}
95101
96102
.line-numbers {
97-
min-width: 3.5rem;
103+
/* 1ch per digit + 1.5rem (px-3 * 2) padding */
104+
min-width: calc(var(--line-digits) * 1ch + 1.5rem);
98105
}
99106
100107
.code-content :deep(pre) {

app/pages/package-code/[...path].vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ defineOgImageComponent('Default', {
408408

409409
<!-- File content / Directory listing - sticky with internal scroll on desktop -->
410410
<div
411-
class="flex-1 min-w-0 md:sticky md:top-28 md:self-start md:h-[calc(100vh-7rem)] md:overflow-y-auto"
411+
class="flex-1 min-w-0 overflow-x-hidden sticky top-28 self-start h-[calc(100vh-7rem)] overflow-y-auto"
412412
>
413413
<!-- File viewer -->
414414
<template v-if="isViewingFile && fileContent">

0 commit comments

Comments
 (0)