Skip to content
Snippets Groups Projects
Commit ab6297f3 authored by Emmanuel Salomon's avatar Emmanuel Salomon :fist:
Browse files

Added search in header

parent eb4c1dbc
No related branches found
No related tags found
No related merge requests found
...@@ -8,7 +8,10 @@ ...@@ -8,7 +8,10 @@
v-bind="$attrs" v-bind="$attrs"
v-on="$listeners" v-on="$listeners"
/> />
<div class="absolute flex items-center ml-3 bottom-0 top-0"> <div
class="absolute flex items-center ml-3 bottom-0 top-0"
:class="iconWrapperClass"
>
<fa slot="icon" :icon="icon" :class="iconClass" /> <fa slot="icon" :icon="icon" :class="iconClass" />
</div> </div>
</div> </div>
...@@ -26,6 +29,10 @@ export default { ...@@ -26,6 +29,10 @@ export default {
type: String, type: String,
default: null, default: null,
}, },
iconWrapperClass: {
type: String,
default: null,
},
iconClass: { iconClass: {
type: String, type: String,
default: null, default: null,
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
<LayoutHeaderLogo /> <LayoutHeaderLogo />
<div class="flex justify-end items-center relative"> <div class="flex justify-end items-center relative">
<LayoutHeaderMenuSearch />
<LayoutHeaderMenu /> <LayoutHeaderMenu />
<AppDarkMode /> <AppDarkMode />
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
<nuxt-link <nuxt-link
v-if="item.url.startsWith('/')" v-if="item.url.startsWith('/')"
:key="index" :key="index"
class="inline-flex items-center relative cursor-pointer whitespace-nowrap py-2 px-3 text-gray-600 hover:text-gray-700 hover:bg-hover-light dark:text-gray-200 rounded-full focus:outline-none focus:ring-2" class="menu-item"
:to="item.url" :to="item.url"
> >
{{ item.title }} {{ item.title }}
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
> >
<a <a
slot="trigger" slot="trigger"
class="inline-flex items-center relative cursor-pointer whitespace-nowrap py-2 px-3 text-gray-600 hover:text-gray-700 hover:bg-hover-light dark:text-gray-200 rounded-full focus:outline-none focus:ring-2" class="menu-item"
href="https://forum.monnaie-libre.fr/" href="https://forum.monnaie-libre.fr/"
target="_blank" target="_blank"
rel="noopener noreferrer" rel="noopener noreferrer"
...@@ -49,4 +49,8 @@ export default { ...@@ -49,4 +49,8 @@ export default {
} }
</script> </script>
<style lang="scss" scoped></style> <style lang="postcss" scoped>
.menu-item {
@apply inline-flex items-center relative cursor-pointer whitespace-nowrap py-2 px-3 text-gray-600 hover:text-gray-700 hover:bg-hover-light dark:text-gray-200 rounded-full focus:outline-none focus:ring-2;
}
</style>
...@@ -15,7 +15,11 @@ ...@@ -15,7 +15,11 @@
aria-haspopup="true" aria-haspopup="true"
class="h-8 w-8 focus:ring-2 focus:outline-none rounded-full" class="h-8 w-8 focus:ring-2 focus:outline-none rounded-full"
> >
<img v-if="user" :src="user.avatar_url" class="rounded-full" /> <img
v-if="user && user.avatar_url"
:src="user.avatar_url"
class="rounded-full"
/>
<fa v-else icon="user-circle" class="text-3xl" /> <fa v-else icon="user-circle" class="text-3xl" />
</button> </button>
<fa icon="caret-down" class="pl-1.5" /> <fa icon="caret-down" class="pl-1.5" />
......
<template>
<div :class="isVisible && 'mr-2'">
<t-input
ref="search"
v-model="query"
:class="!isVisible && 'hidden'"
type="search"
:placeholder="$t('search') + ' (ctrl + F)'"
class="pl-12 w-full text-base rounded-full"
@keyup.enter="search()"
@blur="isVisible = false"
@focus="$event.target.select()"
/>
<div
class="flex items-center bottom-0 top-0"
:class="[
isVisible
? `absolute ml-3 text-2xl text-blue-100 dark:text-gray-600`
: 'text-2xl text-blue-300 dark:text-blue-800 hover:text-blue-400 dark-hover:text-blue-700 cursor-text py-3 pr-3 pl-48',
]"
@click="setVisible()"
>
<fa slot="icon" icon="search" :class="[isVisible ? `` : '', '']" />
</div>
</div>
</template>
<script>
export default {
data() {
return {
query: '',
isVisible: false,
}
},
mounted() {
document.addEventListener('keydown', this.searchShortcut)
},
beforeDestroy() {
document.removeEventListener('keydown', this.searchShortcut)
},
methods: {
setVisible() {
this.isVisible = true
this.$nextTick(() => {
this.$refs.search.$el.focus()
})
},
search() {
if (this.$route.path !== '/recherche') {
this.$router.push(`/recherche?q=${this.query}`)
} else {
this.$nuxt.$emit('global-search', this.query)
}
},
searchShortcut(e) {
if (e.key === 'f' && e.ctrlKey) {
// (e.ctrlKey || e.metaKey)) {
e.preventDefault() // present "Save Page" from getting triggered.
this.setVisible()
}
},
},
}
</script>
<style lang="postcss" scoped></style>
{ {
"menu_header": [ "menu_header": [
{
"title": "Lexique",
"url": "/lexique"
},
{ {
"title": "FAQ", "title": "FAQ",
"url": "/faq" "url": "/faq"
...@@ -13,8 +9,8 @@ ...@@ -13,8 +9,8 @@
"url": "/ressources" "url": "/ressources"
}, },
{ {
"title": "Blog", "title": "Lexique",
"url": "/blog" "url": "/lexique"
}, },
{ {
"title": "Forum", "title": "Forum",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment