-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
668 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
111 changes: 111 additions & 0 deletions
111
packages/commercetools/theme/components/Header/HeaderNav.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
<template> | ||
<SfHeaderNavigation> | ||
<SfHeaderNavigationItem | ||
v-for="category in categories" | ||
:key="category.id" | ||
:label="category.name" | ||
@mouseenter="() => handleMouseEnter(category.slug)" | ||
@mouseleave="() => handleMouseLeave()" | ||
@click="handleMouseLeave()" | ||
:link="localePath(`/c/${category.slug}`)" | ||
> | ||
<SfMegaMenu | ||
is-absolute | ||
:visible="currentCatSlug === category.slug" | ||
:title="category.name" | ||
@close="currentCatSlug = ''" | ||
v-if="activeSubCategory && activeSubCategory[0] && activeSubCategory[0].children" | ||
> | ||
<SfMegaMenuColumn | ||
v-for="subCategory in activeSubCategory[0].children" | ||
:key="subCategory.id" | ||
:title="subCategory.name" | ||
> | ||
<SfLoader :loading="subCategoriesLoading"> | ||
<SfList> | ||
<SfListItem | ||
v-for="subCategoryChild in subCategory.children" | ||
:key="subCategoryChild.id" | ||
> | ||
<SfMenuItem :label="subCategoryChild.name" :link="localePath(`/c/${subCategoryChild.slug}`)"> | ||
<SfLink> | ||
{{ subCategoryChild.name }} | ||
</SfLink> | ||
</SfMenuItem> | ||
</SfListItem> | ||
</SfList> | ||
</SfLoader> | ||
</SfMegaMenuColumn> | ||
<NewCatBanners v-if="currentCatSlug === 'new'" /> | ||
</SfMegaMenu> | ||
</SfHeaderNavigationItem> | ||
</SfHeaderNavigation> | ||
</template> | ||
|
||
<script> | ||
import { SfMegaMenu, SfMenuItem, SfList, SfBanner, SfLoader } from '@storefront-ui/vue'; | ||
import { useCategory } from '@vue-storefront/commercetools'; | ||
import { onSSR } from '@vue-storefront/core'; | ||
import { reactive, ref } from '@vue/composition-api'; | ||
import debounce from 'lodash.debounce'; | ||
export default { | ||
name: 'HeaderNav', | ||
components: { | ||
SfMegaMenu, | ||
SfMenuItem, | ||
SfList, | ||
SfBanner, | ||
SfLoader, | ||
NewCatBanners: () => import('./NewCatBanners') | ||
}, | ||
setup (_, { emit }) { | ||
const { categories, search } = useCategory('menu-categories'); | ||
const { categories: subCategories, search: subCategoriesSearch, loading: subCategoriesLoading } = useCategory('menu-subCategories'); | ||
const currentCatSlug = ref(''); | ||
const activeSubCategory = ref(null); | ||
const fetchedSubCategories = reactive({}); | ||
const handleMouseEnter = debounce(async slug => { | ||
currentCatSlug.value = slug; | ||
const { childCount } = categories.value.find(category => category.slug === currentCatSlug.value); | ||
emit('setOverlay', Boolean(childCount)); | ||
if (!fetchedSubCategories[slug] && Boolean(childCount)) { | ||
await subCategoriesSearch({ slug }); | ||
fetchedSubCategories[slug] = subCategories.value; | ||
} | ||
activeSubCategory.value = fetchedSubCategories[currentCatSlug.value]; | ||
}, 200); | ||
const handleMouseLeave = debounce(() => { | ||
emit('setOverlay', false); | ||
currentCatSlug.value = ''; | ||
}, 200); | ||
onSSR(async () => { | ||
await search({ customQuery: { categories: 'root-categories-query' } }); | ||
}); | ||
return { | ||
categories, | ||
fetchedSubCategories, | ||
activeSubCategory, | ||
subCategories, | ||
currentCatSlug, | ||
subCategoriesLoading, | ||
handleMouseEnter, | ||
handleMouseLeave | ||
}; | ||
} | ||
}; | ||
</script> | ||
|
||
<style lang='scss'> | ||
.sf-mega-menu__bar.sf-bar { | ||
display: flex; | ||
@include for-desktop { | ||
display: none; | ||
} | ||
} | ||
</style> |
118 changes: 118 additions & 0 deletions
118
packages/commercetools/theme/components/Header/MobileMenu.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<template> | ||
<SfMegaMenu | ||
visible | ||
@close="toggleMobileMenu" | ||
> | ||
<SfMegaMenuColumn | ||
v-for="category in categories" | ||
:key="category.id" | ||
:title="category.name" | ||
> | ||
<template #title="{ title, changeActive }"> | ||
<SfMenuItem | ||
:label="title" | ||
class="sf-mega-menu-column__header" | ||
@click="changeActive(title); handleClickCategory(category.slug)" | ||
/> | ||
</template> | ||
<SfList v-if="activeCategory && activeCategory[0] && activeCategory[0].children"> | ||
<SfListItem | ||
v-for="subCategory in activeCategory[0].children" | ||
:key="subCategory.id" | ||
> | ||
<SfMenuItem | ||
:label="subCategory.name" | ||
@click.native="handleClickSubCategory(subCategory.slug)" | ||
> | ||
<SfLink> | ||
{{ subCategory.name }} | ||
</SfLink> | ||
</SfMenuItem> | ||
</SfListItem> | ||
</SfList> | ||
<NewCatBanners v-if="currentCatSlug === 'new'" /> | ||
</SfMegaMenuColumn> | ||
</SfMegaMenu> | ||
</template> | ||
|
||
<script> | ||
import { SfMegaMenu, SfMenuItem, SfList, SfLoader } from '@storefront-ui/vue'; | ||
import { useCategory } from '@vue-storefront/commercetools'; | ||
import { useUiState } from '~/composables'; | ||
import { onSSR } from '@vue-storefront/core'; | ||
import { ref } from '@vue/composition-api'; | ||
export default { | ||
name: 'MobileMenu', | ||
components: { | ||
SfMegaMenu, | ||
SfMenuItem, | ||
SfList, | ||
SfLoader, | ||
NewCatBanners: () => import('./NewCatBanners') | ||
}, | ||
setup (_, { root }) { | ||
const { categories, search } = useCategory('menu-categories'); | ||
const { categories: subCategories, search: subCategoriesSearch, loading: subCategoriesLoading } = useCategory('menu-subCategories'); | ||
const currentCatSlug = ref(''); | ||
const deepCatSlug = ref(''); | ||
const activeCategory = ref(null); | ||
const fetchedCategories = ref({}); | ||
const { toggleMobileMenu } = useUiState(); | ||
const getSubCategories = async (slug, childCount) => { | ||
if (!childCount) { | ||
root.$router.push(`/c/${slug}`); | ||
toggleMobileMenu(); | ||
} | ||
if (!fetchedCategories.value[slug]) { | ||
await subCategoriesSearch({ slug }); | ||
fetchedCategories.value = { | ||
...fetchedCategories.value, | ||
[slug]: subCategories.value | ||
}; | ||
} | ||
activeCategory.value = fetchedCategories.value[slug]; | ||
}; | ||
const handleClickCategory = async slug => { | ||
currentCatSlug.value = slug; | ||
const { childCount } = categories.value.find(category => category.slug === currentCatSlug.value); | ||
await getSubCategories(slug, childCount); | ||
}; | ||
const handleClickSubCategory = async slug => { | ||
deepCatSlug.value = slug; | ||
if (activeCategory.value && activeCategory.value[0] && activeCategory.value[0].children) { | ||
const { childCount } = activeCategory.value[0].children.find(child => child.slug === deepCatSlug.value); | ||
await getSubCategories(slug, childCount); | ||
} | ||
}; | ||
onSSR(async () => { | ||
await search({ customQuery: { categories: 'root-categories-query' } }); | ||
}); | ||
return { | ||
categories, | ||
activeCategory, | ||
currentCatSlug, | ||
handleClickCategory, | ||
handleClickSubCategory, | ||
toggleMobileMenu, | ||
subCategoriesLoading | ||
}; | ||
} | ||
}; | ||
</script> | ||
|
||
<style lang='scss'> | ||
.sf-mega-menu__bar.sf-bar { | ||
display: flex; | ||
@include for-desktop { | ||
display: none; | ||
} | ||
} | ||
</style> |
Oops, something went wrong.