Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render navbar interactives clientside #202

Merged
merged 1 commit into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
157 changes: 87 additions & 70 deletions src/components/HeaderNavbar/Product/index.tsx
Original file line number Diff line number Diff line change
@@ -1,70 +1,87 @@
import React, { useRef, useEffect } from "react"
import clsx from "clsx"
import { Link } from "gatsby"
import { isDesktop } from "react-device-detect"

import Chevron from "@mui/icons-material/ChevronRight"
import NavbarImage from "../../../svgs/navbar-image-1.svg"

import { products, compare } from "./items"

import Card from "../Card"
import CardItem from "../CardItem"

const HeaderNavbarProduct = ({ active, setActive }) => {
const wrapperRef = useRef(null);

const onClick = (ev) => {
ev.preventDefault()
if (!isDesktop) setActive((prev) => prev === 'product' ? '' : 'product')
}

const onMouseEnter = (ev) => {
ev.preventDefault()
if (isDesktop) setActive('product')
}

const onMouseLeave = (ev) => {
ev.preventDefault()
if (isDesktop) setActive('')
}

useEffect(() => {
function handleClickOutside(event) {
if (isDesktop && wrapperRef.current && !wrapperRef.current.contains(event.target) && !event.target.className?.includes?.('active')) {
setActive('')
}
}

if (active) document.addEventListener("mousedown", handleClickOutside)

return () => {
document.removeEventListener("mousedown", handleClickOutside)
};
}, [active]);

return (
<>
<Link className={clsx("global-header-link", active && "active")} to="#" onClick={onClick} onMouseEnter={onMouseEnter}>
Product
<Chevron className="menu-chevron" fontSize="small" />
</Link>
<Card customRef={wrapperRef} show={active} onMouseLeave={onMouseLeave}>
<CardItem title="PRODUCT" onlyContent items={products} />
<CardItem title="COMPARE" items={compare} />
<CardItem className="hide-on-mobile" title="CASE STUDY">
<NavbarImage />
<Link
target="_blank"
to="/customers/connectngo"
className="cta-button"
>
Read Customer Story
</Link>
</CardItem>
</Card>
</>
)
}

export default HeaderNavbarProduct
import React, { useRef, useEffect } from "react"
import clsx from "clsx"
import { Link } from "gatsby"
import { isDesktop } from "react-device-detect"

import Chevron from "@mui/icons-material/ChevronRight"
import NavbarImage from "../../../svgs/navbar-image-1.svg"

import { products, compare } from "./items"

import CardItem from "../CardItem"

const Card = React.lazy(() => import("../Card"))

const HeaderNavbarProduct = ({ active, setActive }) => {
const wrapperRef = useRef(null)

const onClick = ev => {
ev.preventDefault()
if (!isDesktop) setActive(prev => (prev === "product" ? "" : "product"))
}

const onMouseEnter = ev => {
ev.preventDefault()
if (isDesktop) setActive("product")
}

const onMouseLeave = ev => {
ev.preventDefault()
if (isDesktop) setActive("")
}

useEffect(() => {
function handleClickOutside(event) {
if (
isDesktop &&
wrapperRef.current &&
!wrapperRef.current.contains(event.target) &&
!event.target.className?.includes?.("active")
) {
setActive("")
}
}

if (active) document.addEventListener("mousedown", handleClickOutside)

return () => {
document.removeEventListener("mousedown", handleClickOutside)
}
}, [active])

return (
<>
<Link
className={clsx("global-header-link", active && "active")}
to="#"
onClick={onClick}
onMouseEnter={onMouseEnter}
>
Product
<Chevron className="menu-chevron" fontSize="small" />
</Link>
<React.Suspense fallback={<div>Loading...</div>}>
<Card
customRef={wrapperRef}
show={active}
onMouseLeave={onMouseLeave}
>
<CardItem title="PRODUCT" onlyContent items={products} />
<CardItem title="COMPARE" items={compare} />
<CardItem className="hide-on-mobile" title="CASE STUDY">
<NavbarImage />
<Link
target="_blank"
to="/customers/connectngo"
className="cta-button"
>
Read Customer Story
</Link>
</CardItem>
</Card>
</React.Suspense>
</>
)
}

export default HeaderNavbarProduct
127 changes: 78 additions & 49 deletions src/components/HeaderNavbar/Resources/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,64 +9,93 @@ import NavbarImage from "../../../svgs/navbar-image-2.svg"

import { read, listen, tour, caseStudies } from "./items"

import Card from "../Card"
import CardItem from "../CardItem"
const Card = React.lazy(() => import("../Card"))

const HeaderNavbarResources = ({ active, setActive }) => {
const wrapperRef = useRef(null);
const wrapperRef = useRef(null)

const onClick = (ev) => {
ev.preventDefault()
if (!isDesktop) setActive((prev) => prev === 'resources' ? '' : 'resources')
}

const onMouseEnter = (ev) => {
ev.preventDefault()
if (isDesktop) setActive('resources')
}
const onClick = ev => {
ev.preventDefault()
if (!isDesktop)
setActive(prev => (prev === "resources" ? "" : "resources"))
}

const onMouseLeave = (ev) => {
ev.preventDefault()
if (isDesktop) setActive('')
}
const onMouseEnter = ev => {
ev.preventDefault()
if (isDesktop) setActive("resources")
}

useEffect(() => {
function handleClickOutside(event) {
if (wrapperRef.current && !wrapperRef.current.contains(event.target) && !event.target.className?.includes?.('active')) {
setActive('')
}
const onMouseLeave = ev => {
ev.preventDefault()
if (isDesktop) setActive("")
}

if (active) document.addEventListener("mousedown", handleClickOutside);
return () => {
document.removeEventListener("mousedown", handleClickOutside);
};
}, [active]);
useEffect(() => {
function handleClickOutside(event) {
if (
wrapperRef.current &&
!wrapperRef.current.contains(event.target) &&
!event.target.className?.includes?.("active")
) {
setActive("")
}
}

if (active) document.addEventListener("mousedown", handleClickOutside)
return () => {
document.removeEventListener("mousedown", handleClickOutside)
}
}, [active])

return (
<>
<Link className={clsx("global-header-link", active && "active")} to="#" onClick={onClick} onMouseEnter={onMouseEnter}>
Resources
<Chevron className="menu-chevron" fontSize="small" />
</Link>
<Card customRef={wrapperRef} show={active} onMouseLeave={onMouseLeave}>
<CardItem title="READ" onlyContent items={read} />
<CardItem className="no-padding" title="LISTEN" onlyContent items={listen} />
<CardItem className="hide-on-mobile" title="TOUR" items={tour} />
<CardItem className="hide-on-mobile" title="CASE STUDIES" items={caseStudies} />
<CardItem className="hide-on-mobile" title="WEBINAR">
<NavbarImage />
<OutboundLink
target="_blank"
href="https://try.estuary.dev/webinar-estuary101-ondemand"
className="cta-button"
return (
<>
<Link
className={clsx("global-header-link", active && "active")}
to="#"
onClick={onClick}
onMouseEnter={onMouseEnter}
>
Watch Estuary 101
</OutboundLink>
</CardItem>
</Card>
</>
)
Resources
<Chevron className="menu-chevron" fontSize="small" />
</Link>
<React.Suspense fallback={<div>Loading...</div>}>
<Card
customRef={wrapperRef}
show={active}
onMouseLeave={onMouseLeave}
>
<CardItem title="READ" onlyContent items={read} />
<CardItem
className="no-padding"
title="LISTEN"
onlyContent
items={listen}
/>
<CardItem
className="hide-on-mobile"
title="TOUR"
items={tour}
/>
<CardItem
className="hide-on-mobile"
title="CASE STUDIES"
items={caseStudies}
/>
<CardItem className="hide-on-mobile" title="WEBINAR">
<NavbarImage />
<OutboundLink
target="_blank"
href="https://try.estuary.dev/webinar-estuary101-ondemand"
className="cta-button"
>
Watch Estuary 101
</OutboundLink>
</CardItem>
</Card>
</React.Suspense>
</>
)
}

export default HeaderNavbarResources
export default HeaderNavbarResources
Loading