Skip to content

Commit e7670f8

Browse files
authored
feat: generate sprite for file view (#1347)
1 parent 6c1083f commit e7670f8

File tree

7 files changed

+418
-286
lines changed

7 files changed

+418
-286
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ test-results/
3939

4040
# generated files
4141
shared/types/lexicons
42+
file-tree-sprite.svg
4243

4344
**/__screenshots__/**
4445

app/components/Code/DirectoryListing.vue

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script setup lang="ts">
22
import type { PackageFileTree } from '#shared/types'
33
import type { RouteLocationRaw } from 'vue-router'
4-
import { getFileIcon } from '~/utils/file-icons'
4+
import { ADDITIONAL_ICONS, getFileIcon } from '~/utils/file-icons'
55
66
const props = defineProps<{
77
tree: PackageFileTree[]
@@ -80,8 +80,15 @@ const bytesFormatter = useBytesFormatter()
8080
:to="getCodeRoute(parentPath || undefined)"
8181
class="py-2 px-4 font-mono text-sm w-full"
8282
no-underline
83-
classicon="i-carbon:folder text-yellow-600"
8483
>
84+
<svg
85+
class="size-[1em] me-1 shrink-0 text-yellow-600"
86+
viewBox="0 0 16 16"
87+
fill="currentColor"
88+
aria-hidden="true"
89+
>
90+
<use :href="`/file-tree-sprite.svg#${ADDITIONAL_ICONS['folder']}`" />
91+
</svg>
8592
<span class="w-full flex justify-self-stretch items-center gap-2"> .. </span>
8693
</LinkBase>
8794
</td>
@@ -98,12 +105,18 @@ const bytesFormatter = useBytesFormatter()
98105
:to="getCodeRoute(node.path)"
99106
class="py-2 px-4 font-mono text-sm w-full"
100107
no-underline
101-
:classicon="
102-
node.type === 'directory'
103-
? 'i-carbon:folder text-yellow-600'
104-
: getFileIcon(node.name)
105-
"
106108
>
109+
<svg
110+
class="size-[1em] me-1 shrink-0"
111+
viewBox="0 0 16 16"
112+
fill="currentColor"
113+
:class="node.type === 'directory' ? 'text-yellow-600' : undefined"
114+
aria-hidden="true"
115+
>
116+
<use
117+
:href="`/file-tree-sprite.svg#${node.type === 'directory' ? ADDITIONAL_ICONS['folder'] : getFileIcon(node.name)}`"
118+
/>
119+
</svg>
107120
<span class="w-full flex justify-self-stretch items-center gap-2">
108121
<span class="flex-1">{{ node.name }}</span>
109122
<span

app/components/Code/FileTree.vue

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script setup lang="ts">
22
import type { PackageFileTree } from '#shared/types'
33
import type { RouteLocationRaw } from 'vue-router'
4-
import { getFileIcon } from '~/utils/file-icons'
4+
import { ADDITIONAL_ICONS, getFileIcon } from '~/utils/file-icons'
55
66
const props = defineProps<{
77
tree: PackageFileTree[]
@@ -57,14 +57,17 @@ watch(
5757
@click="toggleDir(node.path)"
5858
:classicon="isExpanded(node.path) ? 'i-carbon:chevron-down' : 'i-carbon:chevron-right'"
5959
>
60-
<span
61-
class="w-4 h-4 shrink-0"
62-
:class="
63-
isExpanded(node.path)
64-
? 'i-carbon:folder-open text-yellow-500'
65-
: 'i-carbon:folder text-yellow-600'
66-
"
67-
/>
60+
<svg
61+
class="size-[1em] me-1 shrink-0"
62+
:class="isExpanded(node.path) ? 'text-yellow-500' : 'text-yellow-600'"
63+
viewBox="0 0 16 16"
64+
fill="currentColor"
65+
aria-hidden="true"
66+
>
67+
<use
68+
:href="`/file-tree-sprite.svg#${isExpanded(node.path) ? ADDITIONAL_ICONS['folder-open'] : ADDITIONAL_ICONS['folder']}`"
69+
/>
70+
</svg>
6871
<span class="truncate">{{ node.name }}</span>
6972
</ButtonBase>
7073
<CodeFileTree
@@ -86,8 +89,15 @@ watch(
8689
class="w-full justify-start! rounded-none! border-none!"
8790
block
8891
:style="{ paddingLeft: `${depth * 12 + 32}px` }"
89-
:classicon="getFileIcon(node.name)"
9092
>
93+
<svg
94+
class="size-[1em] me-1 shrink-0"
95+
viewBox="0 0 16 16"
96+
fill="currentColor"
97+
aria-hidden="true"
98+
>
99+
<use :href="`/file-tree-sprite.svg#${getFileIcon(node.name)}`" />
100+
</svg>
91101
<span class="truncate">{{ node.name }}</span>
92102
</LinkBase>
93103
</template>

0 commit comments

Comments
 (0)