This repository has been archived by the owner on Oct 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add MegaMenu component * feat(helpers): getCategoryUrl Co-authored-by: Patryk Tomczyk <13100280+patzick@users.noreply.github.com> Co-authored-by: martaradziszewska <marta.radziszewskaa@gmail.com>
- Loading branch information
1 parent
b0ef05e
commit f6167d5
Showing
12 changed files
with
229 additions
and
45 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
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
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 |
---|---|---|
@@ -1,27 +1,47 @@ | ||
import Vue from "vue"; | ||
import { reactive, computed } from "@vue/composition-api"; | ||
import { reactive, computed, Ref } from "@vue/composition-api"; | ||
import { getNavigation } from "@shopware-pwa/shopware-6-client"; | ||
import { getNavigationRoutes } from "@shopware-pwa/helpers"; | ||
import { NavigationElement } from "@shopware-pwa/commons/interfaces/models/content/navigation/Navigation"; | ||
|
||
/** | ||
* @alpha | ||
*/ | ||
export interface UseNavigation { | ||
routes: Ref<Readonly<any>>; | ||
navigationElements: NavigationElement[]; | ||
fetchNavigationElements: (depth: number) => Promise<void>; | ||
fetchRoutes: () => Promise<void>; | ||
} | ||
|
||
const sharedNavigation = Vue.observable({ | ||
routes: null, | ||
navigationElements: [], | ||
} as any); | ||
|
||
/** | ||
* @alpha | ||
*/ | ||
export const useNavigation = (): any => { | ||
export const useNavigation = (): UseNavigation => { | ||
const localNavigation = reactive(sharedNavigation); | ||
const routes = computed(() => localNavigation.routes); | ||
|
||
const fetchRoutes = async (params?: any): Promise<void> => { | ||
const navigation = await getNavigation(params); | ||
if (typeof navigation.children === "undefined") return; | ||
sharedNavigation.routes = getNavigationRoutes(navigation.children); | ||
const { children } = await getNavigation(params); | ||
if (typeof children === "undefined") return; | ||
sharedNavigation.routes = getNavigationRoutes(children); | ||
}; | ||
|
||
const fetchNavigationElements = async (depth: number) => { | ||
const { children } = await getNavigation({ depth }); | ||
localNavigation.navigationElements.length = 0; | ||
localNavigation.navigationElements.push(...children); | ||
}; | ||
|
||
return { | ||
routes, | ||
navigationElements: localNavigation.navigationElements, | ||
fetchNavigationElements, | ||
fetchRoutes, | ||
}; | ||
}; |
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,77 @@ | ||
<template> | ||
<SfMegaMenu :visible="visible" :title="category.name" class="sw-mega-menu"> | ||
<div class="sw-mega-menu__content"> | ||
<div | ||
class="sw-mega-menu__content-section" | ||
v-for="subcategory in category.children" | ||
:key="subcategory.name" | ||
> | ||
<nuxt-link | ||
class="sf-header__link" | ||
:to="getCategoryUrl(subcategory)" | ||
> | ||
<SfHeading | ||
:title="subcategory.name" | ||
:subtitle="subcategory.description" | ||
:level="4" | ||
/> | ||
</nuxt-link> | ||
<SfList> | ||
<SfListItem v-for="child in subcategory.children" :key="child.label"> | ||
<nuxt-link | ||
class="sf-header__link" | ||
:to="getCategoryUrl(child)" | ||
> | ||
<SfMenuItem :label="child.name" /> | ||
</nuxt-link> | ||
</SfListItem> | ||
</SfList> | ||
</div> | ||
</div> | ||
</SfMegaMenu> | ||
</template> | ||
|
||
<script> | ||
import { SfMegaMenu, SfMenuItem, SfList, SfHeading } from '@storefront-ui/vue' | ||
import { getCategoryUrl } from '@shopware-pwa/helpers' | ||
export default { | ||
name: 'SwMegaMenu', | ||
components: { SfMegaMenu, SfMenuItem, SfList, SfHeading }, | ||
props: { | ||
category: { | ||
type: Object, | ||
default: () => ({}), | ||
}, | ||
visible: { | ||
type: Boolean, | ||
default: false, | ||
}, | ||
}, | ||
setup() { | ||
return { getCategoryUrl } | ||
}, | ||
} | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
.sw-mega-menu { | ||
position: absolute; | ||
left: 0; | ||
width: 100%; | ||
top: 100%; | ||
&__content { | ||
flex-wrap: wrap; | ||
display: flex; | ||
max-width: 80vw; | ||
&-section { | ||
padding: 1rem; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: flex-start; | ||
align-items: flex-start; | ||
} | ||
} | ||
} | ||
</style> |
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
Oops, something went wrong.
f6167d5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to following URLs: