-
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.
Merge pull request #5283 from lukaszjedrasik/mega-menu-in-app-header
Next: Mega menu in app header
- Loading branch information
Showing
17 changed files
with
419 additions
and
68 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.
21 changes: 4 additions & 17 deletions
21
packages/commercetools/api-client/src/api/getCategory/defaultQuery.ts
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
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
95 changes: 95 additions & 0 deletions
95
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,95 @@ | ||
<template> | ||
<SfHeaderNavigation> | ||
<SfHeaderNavigationItem | ||
v-for="(category, index) in categories" | ||
:key="index" | ||
:label="category.name" | ||
@mouseenter="() => handleMouseEnter(category.slug)" | ||
@mouseleave="() => handleMouseLeave()" | ||
@click="handleMouseLeave()" | ||
:link="localePath(`/c/${category.slug}`)" | ||
> | ||
<SfMegaMenu | ||
:is-absolute="true" | ||
:visible="currentCatSlug === category.slug" | ||
:title="category.name" | ||
@close="currentCatSlug = ''" | ||
v-if="category && category.children.length" | ||
> | ||
<SfMegaMenuColumn | ||
v-for="(subCategory, subIndex) in category.children" | ||
:key="subIndex" | ||
:title="subCategory.name" | ||
> | ||
<SfLoader :loading="subCategoriesLoading"> | ||
<SfList> | ||
<SfListItem | ||
v-for="(subCategoryChild, childIndex) in subCategory.children" | ||
:key="childIndex" | ||
> | ||
<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 { ref } from '@vue/composition-api'; | ||
import { rootCategoriesQuery } from '../../queries/topCategories'; | ||
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 handleMouseEnter = debounce((slug) => { | ||
if (currentCatSlug.value) return; | ||
emit('setOverlay', true); | ||
currentCatSlug.value = slug; | ||
subCategoriesSearch({ slug }); | ||
}, 200); | ||
const handleMouseLeave = debounce(() => { | ||
emit('setOverlay', false); | ||
currentCatSlug.value = ''; | ||
}, 200); | ||
onSSR(async () => { | ||
await search({ customQuery: rootCategoriesQuery }); | ||
}); | ||
return { | ||
categories, | ||
subCategories, | ||
currentCatSlug, | ||
subCategoriesLoading, | ||
handleMouseEnter, | ||
handleMouseLeave | ||
}; | ||
} | ||
}; | ||
</script> |
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,36 @@ | ||
import gql from 'graphql-tag'; | ||
import { CategoryFragment } from '@vue-storefront/commercetools-api'; | ||
|
||
const customQuery = gql` | ||
${CategoryFragment} | ||
fragment Children on Category { | ||
id | ||
slug(acceptLanguage: $acceptLanguage) | ||
name(acceptLanguage: $acceptLanguage) | ||
childCount | ||
} | ||
query categories($where: String, $sort: [String!], $limit: Int, $offset: Int, $acceptLanguage: [Locale!]) { | ||
categories(where: $where, sort: $sort, limit: $limit, offset: $offset) { | ||
offset | ||
count | ||
total | ||
results { | ||
...DefaultCategory | ||
} | ||
} | ||
} | ||
`; | ||
|
||
export const rootCategoriesQuery = (query, variables) => { | ||
const customVariables = { | ||
...variables, | ||
where: 'parent is not defined' | ||
}; | ||
|
||
return { | ||
query: customQuery, | ||
variables: customVariables | ||
}; | ||
}; |
Binary file not shown.
Binary file not shown.
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
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
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 |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
"access": "public" | ||
}, | ||
"dependencies": { | ||
"lodash.debounce": "^4.0.8", | ||
"lodash.merge": "^4.6.2" | ||
} | ||
} |
Oops, something went wrong.