Skip to content
Snippets Groups Projects
Commit a5ec58f6 authored by Julien MARGAIL's avatar Julien MARGAIL
Browse files

fix Menu (0.7.2)

parent 9f2cbf93
No related branches found
No related tags found
No related merge requests found
...@@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ...@@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added ### Added
- Hero add options.class - Hero add options.class
- Menu fix check type 'page' / 'url', add target blank for external links
- Update @onegeo-suite/gatsby-plugin-auth to 0.2.1 - Update @onegeo-suite/gatsby-plugin-auth to 0.2.1
## [0.7.1] - 2023-04-04 ## [0.7.1] - 2023-04-04
... ...
......
...@@ -92,6 +92,7 @@ interface LinkProps { ...@@ -92,6 +92,7 @@ interface LinkProps {
partiallyActive?: string partiallyActive?: string
onClick?: any onClick?: any
className?: any className?: any
target?: string
} }
export function Link(props: LinkProps): JSX.Element export function Link(props: LinkProps): JSX.Element
... ...
......
...@@ -10,6 +10,7 @@ interface Props { ...@@ -10,6 +10,7 @@ interface Props {
partiallyActive?: any partiallyActive?: any
onClick?: any onClick?: any
className?: any className?: any
target?: string
} }
// Since DOM elements <a> cannot receive activeClassName // Since DOM elements <a> cannot receive activeClassName
... ...
......
...@@ -15,6 +15,7 @@ const Menu = (props: Imenu) => { ...@@ -15,6 +15,7 @@ const Menu = (props: Imenu) => {
const data = useStaticQuery(graphql` const data = useStaticQuery(graphql`
fragment MenuItem on DirectusData_menus { fragment MenuItem on DirectusData_menus {
name name
type
url url
page { page {
slug slug
...@@ -50,21 +51,22 @@ const Menu = (props: Imenu) => { ...@@ -50,21 +51,22 @@ const Menu = (props: Imenu) => {
(menu: any) => name?.toLowerCase() === menu.name?.toLowerCase() (menu: any) => name?.toLowerCase() === menu.name?.toLowerCase()
)?.children || [] )?.children || []
const goto = (item) => {
if (!item) return "/"
if (item?.type === "page") {
const slug = item?.page?.slug || ""
if (slug.at(0) === "/") return slug
return "/" + slug
}
return item.url
}
const items = (item: any) => { const items = (item: any) => {
return ( return (
<ul className="bg-base-100 z-50 p-2 shadow-md"> <ul className="bg-base-100 z-50 p-2 shadow-md">
{item.children.map((itemChild: any, idx: number) => { {item.children.map((itemChild: any, idx: number) => {
return ( return (
<li key={idx}> <li key={idx}>
<Link <Link to={goto(itemChild)} target="_blank">
to={
itemChild.url
? itemChild.url
: itemChild.page?.slug
? itemChild.page?.slug
: "#"
}
>
{itemChild.name} {itemChild.name}
</Link> </Link>
{itemChild?.children?.length > 0 && {itemChild?.children?.length > 0 &&
...@@ -83,15 +85,7 @@ const Menu = (props: Imenu) => { ...@@ -83,15 +85,7 @@ const Menu = (props: Imenu) => {
{menu?.map((item: any, key: number) => { {menu?.map((item: any, key: number) => {
return ( return (
<li key={key}> <li key={key}>
<Link <Link to={goto(item)} target="_blank">
to={
item.url
? item.url
: item.page?.slug
? item.page?.slug
: "#"
}
>
{item.name} {item.name}
{item?.children.length > 0 && ( {item?.children.length > 0 && (
<svg <svg
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment