Skip to content

Commit

Permalink
fix(search): handle back docsearch properly
Browse files Browse the repository at this point in the history
Fix #965
  • Loading branch information
Atinux committed Aug 2, 2023
1 parent e1ed5c8 commit b5f3108
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 2 deletions.
14 changes: 13 additions & 1 deletion .starters/default/nuxt.config.ts
Expand Up @@ -7,5 +7,17 @@ export default defineNuxtConfig({
'@nuxtjs/plausible',
// https://github.com/nuxt/devtools
'@nuxt/devtools'
]
],
runtimeConfig: {
public: {
algolia: {
applicationId: 'Q46Q8609QS',
apiKey: '1661c72375532f074aedd9452a1270be',
langAttribute: 'lang',
docSearch: {
indexName: 'content-nuxtjs'
}
}
}
}
})
62 changes: 62 additions & 0 deletions components/app/AppDocSearch.vue
@@ -0,0 +1,62 @@
<script setup lang="ts">
const { element } = useDocSearch()
const onClick = () => element.value.querySelector('button').click()
</script>

<template>
<button
type="button"
aria-label="Search"
@click="onClick"
>
<span class="content">
<Icon name="heroicons-outline:search" />
<span>Search</span>
<span>
<kbd>⌘</kbd>
<kbd>K</kbd>
</span>
</span>
</button>
</template>

<style scoped lang="ts">
css({
button: {
padding: '{space.2} {space.2}',
'.content': {
borderRadius: '{radii.md}',
display: 'flex',
alignItems: 'center',
color: '{color.gray.500}',
borderStyle: 'solid',
borderWidth: '1px',
borderColor: '{color.gray.100}',
fontSize: '{fontSize.xs}',
gap: '{space.2}',
padding: '{space.rem.375}',
'@dark': {
color: '{color.gray.400}',
borderColor: '{color.gray.900}',
},
'&:hover': {
color: '{color.gray.700}',
borderColor: '{color.gray.400}',
'@dark': {
color: '{color.gray.200}',
borderColor: '{color.gray.700}',
}
},
span: {
flex: 'none',
display: 'none',
fontSize: '{fontSize.xs}',
'@lg': {
display: 'block'
}
}
}
},
})
</style>
4 changes: 3 additions & 1 deletion components/app/AppHeader.vue
Expand Up @@ -11,7 +11,7 @@ defineProps({
</script>

<template>
<header :class="{ 'has-dialog': hasDialog, 'has-doc-search': hasDocSearch }">
<header :class="{ 'has-dialog': hasDialog }">
<Container :fluid="config?.header?.fluid ">
<div class="section left">
<AppHeaderDialog v-if="hasDialog" />
Expand All @@ -24,7 +24,9 @@ defineProps({
</div>
<div class="section right">
<AppDocSearch v-if="hasDocSearch" />
<AppSearch
v-else
:fuse="config.fuse"
/>
<ThemeSelect />
Expand Down

0 comments on commit b5f3108

Please sign in to comment.