Skip to content

Commit 55bf50e

Browse files
feat: surface kb shortcuts (#1221)
Co-authored-by: Daniel Roe <daniel@roe.dev>
1 parent de2f5e3 commit 55bf50e

File tree

4 files changed

+130
-3
lines changed

4 files changed

+130
-3
lines changed

app/components/AppFooter.vue

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<script setup lang="ts">
22
const route = useRoute()
33
const isHome = computed(() => route.name === 'index')
4+
5+
const modalRef = useTemplateRef('modalRef')
6+
const showModal = () => modalRef.value?.showModal?.()
47
</script>
58

69
<template>
@@ -33,6 +36,73 @@ const isHome = computed(() => route.name === 'index')
3336
<LinkBase to="https://chat.npmx.dev">
3437
{{ $t('footer.chat') }}
3538
</LinkBase>
39+
40+
<button
41+
type="button"
42+
class="group inline-flex gap-x-1 items-center justify-center underline-offset-[0.2rem] underline decoration-1 decoration-fg/30 font-mono text-fg hover:(decoration-accent text-accent) focus-visible:(decoration-accent text-accent) transition-colors duration-200"
43+
@click.prevent="showModal"
44+
aria-haspopup="dialog"
45+
>
46+
{{ $t('footer.keyboard_shortcuts') }}
47+
</button>
48+
49+
<Modal
50+
ref="modalRef"
51+
:modalTitle="$t('footer.keyboard_shortcuts')"
52+
class="w-auto max-w-lg"
53+
>
54+
<p class="mb-2 font-mono text-fg-subtle">
55+
{{ $t('shortcuts.section.global') }}
56+
</p>
57+
<ul class="mb-6 flex flex-col gap-2">
58+
<li class="flex gap-2 items-center">
59+
<kbd class="kbd">/</kbd>
60+
<span>{{ $t('shortcuts.focus_search') }}</span>
61+
</li>
62+
<li class="flex gap-2 items-center">
63+
<kbd class="kbd">?</kbd>
64+
<span>{{ $t('shortcuts.show_kbd_hints') }}</span>
65+
</li>
66+
<li class="flex gap-2 items-center">
67+
<kbd class="kbd">,</kbd>
68+
<span>{{ $t('shortcuts.settings') }}</span>
69+
</li>
70+
<li class="flex gap-2 items-center">
71+
<kbd class="kbd">c</kbd>
72+
<span>{{ $t('shortcuts.compare') }}</span>
73+
</li>
74+
</ul>
75+
<p class="mb-2 font-mono text-fg-subtle">
76+
{{ $t('shortcuts.section.search') }}
77+
</p>
78+
<ul class="mb-6 flex flex-col gap-2">
79+
<li class="flex gap-2 items-center">
80+
<kbd class="kbd">↑</kbd>/<kbd class="kbd">↓</kbd>
81+
<span>{{ $t('shortcuts.navigate_results') }}</span>
82+
</li>
83+
<li class="flex gap-2 items-center">
84+
<kbd class="kbd">Enter</kbd>
85+
<span>{{ $t('shortcuts.go_to_result') }}</span>
86+
</li>
87+
</ul>
88+
<p class="mb-2 font-mono text-fg-subtle">
89+
{{ $t('shortcuts.section.package') }}
90+
</p>
91+
<ul class="mb-6 flex flex-col gap-2">
92+
<li class="flex gap-2 items-center">
93+
<kbd class="kbd">.</kbd>
94+
<span>{{ $t('shortcuts.open_code_view') }}</span>
95+
</li>
96+
<li class="flex gap-2 items-center">
97+
<kbd class="kbd">d</kbd>
98+
<span>{{ $t('shortcuts.open_docs') }}</span>
99+
</li>
100+
<li class="flex gap-2 items-center">
101+
<kbd class="kbd">c</kbd>
102+
<span>{{ $t('shortcuts.compare_from_package') }}</span>
103+
</li>
104+
</ul>
105+
</Modal>
36106
</div>
37107
</div>
38108
<p class="text-xs text-fg-muted text-center sm:text-start m-0">
@@ -42,3 +112,9 @@ const isHome = computed(() => route.name === 'index')
42112
</div>
43113
</footer>
44114
</template>
115+
116+
<style scoped>
117+
.kbd {
118+
@apply items-center justify-center text-sm text-fg bg-bg-muted border border-border rounded px-2;
119+
}
120+
</style>

i18n/locales/en.json

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,24 @@
1515
"docs": "docs",
1616
"source": "source",
1717
"social": "social",
18-
"chat": "chat"
18+
"chat": "chat",
19+
"keyboard_shortcuts": "keyboard shortcuts"
20+
},
21+
"shortcuts": {
22+
"section": {
23+
"global": "Global",
24+
"search": "Search",
25+
"package": "Package"
26+
},
27+
"focus_search": "Focus search",
28+
"show_kbd_hints": "Highlight keyboard hints",
29+
"settings": "Open settings",
30+
"compare": "Open compare",
31+
"compare_from_package": "Open compare (prefilled with current package)",
32+
"navigate_results": "Navigate results",
33+
"go_to_result": "Go to result",
34+
"open_code_view": "Open code view",
35+
"open_docs": "Open docs"
1936
},
2037
"search": {
2138
"label": "Search npm packages",

lunaria/files/en-GB.json

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,24 @@
1515
"docs": "docs",
1616
"source": "source",
1717
"social": "social",
18-
"chat": "chat"
18+
"chat": "chat",
19+
"keyboard_shortcuts": "keyboard shortcuts"
20+
},
21+
"shortcuts": {
22+
"section": {
23+
"global": "Global",
24+
"search": "Search",
25+
"package": "Package"
26+
},
27+
"focus_search": "Focus search",
28+
"show_kbd_hints": "Highlight keyboard hints",
29+
"settings": "Open settings",
30+
"compare": "Open compare",
31+
"compare_from_package": "Open compare (prefilled with current package)",
32+
"navigate_results": "Navigate results",
33+
"go_to_result": "Go to result",
34+
"open_code_view": "Open code view",
35+
"open_docs": "Open docs"
1936
},
2037
"search": {
2138
"label": "Search npm packages",

lunaria/files/en-US.json

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,24 @@
1515
"docs": "docs",
1616
"source": "source",
1717
"social": "social",
18-
"chat": "chat"
18+
"chat": "chat",
19+
"keyboard_shortcuts": "keyboard shortcuts"
20+
},
21+
"shortcuts": {
22+
"section": {
23+
"global": "Global",
24+
"search": "Search",
25+
"package": "Package"
26+
},
27+
"focus_search": "Focus search",
28+
"show_kbd_hints": "Highlight keyboard hints",
29+
"settings": "Open settings",
30+
"compare": "Open compare",
31+
"compare_from_package": "Open compare (prefilled with current package)",
32+
"navigate_results": "Navigate results",
33+
"go_to_result": "Go to result",
34+
"open_code_view": "Open code view",
35+
"open_docs": "Open docs"
1936
},
2037
"search": {
2138
"label": "Search npm packages",

0 commit comments

Comments
 (0)