Skip to content
This repository was archived by the owner on May 1, 2025. It is now read-only.

Commit a17a780

Browse files
committed
feat: improve command palette
1 parent 6df5f8a commit a17a780

File tree

3 files changed

+46
-6
lines changed

3 files changed

+46
-6
lines changed

components/ColorSchemeToggle.vue

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@ const colorMode = useColorMode()
44
function toggleMode() {
55
colorMode.preference = colorMode.value === 'light' ? 'dark' : 'light'
66
}
7+
8+
addCommands(
9+
{
10+
id: 'toggle-color-mode',
11+
title: colorMode.value === 'light'
12+
? 'Switch to dark mode'
13+
: 'Switch to light mode',
14+
handler: toggleMode,
15+
icon: colorMode.value === 'light'
16+
? 'i-ph-moon-stars-duotone'
17+
: 'i-ph-sun-dim-duotone',
18+
},
19+
)
720
</script>
821

922
<template>

components/TheNav.vue

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,28 @@ const runtime = useRuntimeConfig()
77
const repo = 'https://github.com/nuxt/learn.nuxt.com'
88
const buildTime = new Date(runtime.public.buildTime)
99
const timeAgo = useTimeAgo(buildTime)
10+
11+
addCommands(
12+
{
13+
id: 'download-zip',
14+
title: 'Download playground as ZIP',
15+
visible: () => {
16+
return play.status === 'ready' && guide.features.download !== false
17+
},
18+
handler: () => {
19+
downloadZip(play.webcontainer!)
20+
},
21+
icon: 'i-ph-download-duotone',
22+
},
23+
{
24+
id: 'toggle-terminal',
25+
title: 'Toggle terminal',
26+
handler: () => {
27+
ui.toggleTerminal()
28+
},
29+
icon: 'i-ph-terminal-window-duotone',
30+
},
31+
)
1032
</script>
1133

1234
<template>

stores/commands.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,17 @@ export const useCommandsStore = defineStore('commands', () => {
4242
})
4343

4444
const commandsResult = computed(() => {
45-
if (!search.value)
46-
return Array.from(commandsAll)
47-
return [
48-
...fuse.value.search(search.value).map(i => i.item),
49-
...guidesResult.value,
50-
]
45+
let result = !search.value
46+
? Array.from(commandsAll)
47+
: [
48+
...fuse.value.search(search.value).map(i => i.item),
49+
...guidesResult.value,
50+
]
51+
52+
result = result
53+
.filter(i => i.visible ? i.visible() : true)
54+
55+
return result
5156
})
5257

5358
return {

0 commit comments

Comments
 (0)