Fix spacing, add isActive method

This commit is contained in:
Oliver Davies 2018-12-19 20:30:35 +00:00
parent ca612a276f
commit 15d8cadbda

View file

@ -22,7 +22,7 @@
:href="item.href" :href="item.href"
class="block text-black focus:text-white focus:no-underline focus-within:bg-blue p-4 border-l-3 sm:border-l-0 sm:border-b-3 border-transparent hover:border-grey-light sm:ml-4 sm:mr-0 sm:p-0 hover:no-underline" class="block text-black focus:text-white focus:no-underline focus-within:bg-blue p-4 border-l-3 sm:border-l-0 sm:border-b-3 border-transparent hover:border-grey-light sm:ml-4 sm:mr-0 sm:p-0 hover:no-underline"
:class="{ :class="{
'border-blue hover:border-blue': pageUrl.match(new RegExp(item.pattern)), 'border-blue hover:border-blue': isActive(item),
}" }"
> >
<span class="flex items-center h-full"> <span class="flex items-center h-full">
@ -35,41 +35,47 @@
</template> </template>
<script> <script>
export default { export default {
props: ['siteName', 'pageUrl'], props: ['siteName', 'pageUrl'],
methods: {
isActive(item) {
return this.pageUrl.match(new RegExp(item.pattern))
}
},
data() { data() {
return { return {
mobileNavHidden: true, mobileNavHidden: true,
navItems: [ navItems: [
{ {
title: 'About', title: 'About',
href: '/', href: '/',
pattern: '^/.$', pattern: '^/.$',
}, },
{ {
title: 'Talks', title: 'Talks',
href: '/talks', href: '/talks',
pattern: '^/talks/?', pattern: '^/talks/?',
}, },
{ {
title: 'Blog', title: 'Blog',
href: '/blog', href: '/blog',
pattern: '^/blog/?', pattern: '^/blog/?',
}, },
{ {
title: 'Book', title: 'Book',
href: '/test-driven-drupal', href: '/test-driven-drupal',
pattern: '^/test-driven-drupal/?$', pattern: '^/test-driven-drupal/?$',
}, },
{ {
title: 'Contact', title: 'Contact',
href: '/contact', href: '/contact',
pattern: '^/contact/?', pattern: '^/contact/?',
} }
] ]
} }
} }
} }
</script> </script>