Skip to content

Commit

Permalink
Render navbar interactives clientside
Browse files Browse the repository at this point in the history
  • Loading branch information
jshearer committed Feb 22, 2024
1 parent 8ec8966 commit e12659a
Show file tree
Hide file tree
Showing 2 changed files with 165 additions and 119 deletions.
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

0 comments on commit e12659a

Please sign in to comment.