overlay and navigation changes
This commit is contained in:
1 parent
5ce5f9b751
commit
aa2522ba0f
3 files changed
+38
-50
No files matched your search
@@ -2,10 +2,11 @@ import { MenuToggle } from "../MenuToggle"
|
|||||||
import { useMobile } from "src/hooks/useMobile"
|
import { useMobile } from "src/hooks/useMobile"
|
||||||
import { Menu } from "../Menu"
|
import { Menu } from "../Menu"
|
||||||
import { Overlay } from "../Overlay"
|
import { Overlay } from "../Overlay"
|
||||||
import { useState, useCallback, useContext } from "react"
|
import { useContext } from "react"
|
||||||
import { ConfigContext } from "src/context/ConfigContext"
|
import { ConfigContext } from "src/context/ConfigContext"
|
||||||
import { Block } from "../Block"
|
import { Block } from "../Block"
|
||||||
import { Spacer } from "../Spacer"
|
import { Spacer } from "../Spacer"
|
||||||
|
import { useToggle } from "react-use"
|
||||||
|
|
||||||
export interface INavigationProps {
|
export interface INavigationProps {
|
||||||
style?: React.CSSProperties
|
style?: React.CSSProperties
|
||||||
@@ -13,26 +14,32 @@ export interface INavigationProps {
|
|||||||
|
|
||||||
export const Navigation: React.FC<INavigationProps> = props => {
|
export const Navigation: React.FC<INavigationProps> = props => {
|
||||||
const collapseMenu = useMobile()
|
const collapseMenu = useMobile()
|
||||||
const [open, setOpen] = useState(false)
|
const [open, toggleOpen] = useToggle(false)
|
||||||
const onClick = useCallback(
|
|
||||||
() => {
|
|
||||||
setOpen(!open)
|
|
||||||
},
|
|
||||||
[open]
|
|
||||||
)
|
|
||||||
const { menu } = useContext(ConfigContext)
|
const { menu } = useContext(ConfigContext)
|
||||||
|
|
||||||
|
if (!collapseMenu) {
|
||||||
|
return (
|
||||||
|
<nav style={props.style}>
|
||||||
|
<Menu
|
||||||
|
layout={"desktop"}
|
||||||
|
items={menu}
|
||||||
|
/>
|
||||||
|
</nav>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Overlay
|
<Overlay
|
||||||
show={open}
|
show={open}
|
||||||
onClickOverlay={onClick}
|
onClickOverlay={toggleOpen}
|
||||||
|
duration={250}
|
||||||
>
|
>
|
||||||
<Block direction={"horizontal"}>
|
<Block direction={"horizontal"}>
|
||||||
<Spacer />
|
<Spacer />
|
||||||
<MenuToggle
|
<MenuToggle
|
||||||
open={open}
|
open={open}
|
||||||
onClick={onClick}
|
onClick={toggleOpen}
|
||||||
style={{
|
style={{
|
||||||
margin: "var(--size-xs)",
|
margin: "var(--size-xs)",
|
||||||
}}
|
}}
|
||||||
@@ -52,25 +59,16 @@ export const Navigation: React.FC<INavigationProps> = props => {
|
|||||||
</Block>
|
</Block>
|
||||||
</Overlay>
|
</Overlay>
|
||||||
|
|
||||||
{collapseMenu ? (
|
<Block direction={"horizontal"}>
|
||||||
<Block direction={"horizontal"}>
|
<Spacer />
|
||||||
<Spacer />
|
<MenuToggle
|
||||||
<MenuToggle
|
open={open}
|
||||||
open={open}
|
onClick={toggleOpen}
|
||||||
onClick={onClick}
|
style={{
|
||||||
style={{
|
margin: "var(--size-xs)",
|
||||||
margin: "var(--size-xs)",
|
}}
|
||||||
}}
|
/>
|
||||||
/>
|
</Block>
|
||||||
</Block>
|
|
||||||
) : (
|
|
||||||
<nav style={props.style}>
|
|
||||||
<Menu
|
|
||||||
layout={"desktop"}
|
|
||||||
items={menu}
|
|
||||||
/>
|
|
||||||
</nav>
|
|
||||||
)}
|
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -2,30 +2,20 @@ import s from "./styles.module.css"
|
|||||||
|
|
||||||
import { Transition } from "./Transition"
|
import { Transition } from "./Transition"
|
||||||
import { useReducedMotion } from "../../hooks/useReducedMotion"
|
import { useReducedMotion } from "../../hooks/useReducedMotion"
|
||||||
import { useCallback, useEffect } from "react"
|
import { useLockBodyScroll } from "react-use"
|
||||||
|
|
||||||
export interface IOverlayProps {
|
export type OverlayProps = {
|
||||||
show: boolean
|
show: boolean
|
||||||
onClickOverlay: () => void
|
onClickOverlay: () => void
|
||||||
style?: React.CSSProperties
|
style?: React.CSSProperties
|
||||||
|
duration: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Overlay: React.FC<IOverlayProps> = props => {
|
export const Overlay: React.FC<OverlayProps> = props => {
|
||||||
const motionDisabled = useReducedMotion()
|
const motionDisabled = useReducedMotion()
|
||||||
const onClick = useCallback((event: React.MouseEvent<HTMLDivElement>) => {
|
const duration = motionDisabled ? 0 : props.duration
|
||||||
if (event.target === event.currentTarget) {
|
|
||||||
props.onClickOverlay()
|
|
||||||
}
|
|
||||||
}, [props.onClickOverlay])
|
|
||||||
const duration = motionDisabled ? 0 : 250
|
|
||||||
|
|
||||||
useEffect(() => {
|
useLockBodyScroll(props.show)
|
||||||
if (props.show) {
|
|
||||||
document.body.classList.add("noscroll")
|
|
||||||
} else {
|
|
||||||
document.body.classList.remove("noscroll")
|
|
||||||
}
|
|
||||||
}, [props.show])
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Transition
|
<Transition
|
||||||
@@ -33,7 +23,11 @@ export const Overlay: React.FC<IOverlayProps> = props => {
|
|||||||
show={props.show}
|
show={props.show}
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
onClick={onClick}
|
onClick={(event) => {
|
||||||
|
if (event.target === event.currentTarget) {
|
||||||
|
props.onClickOverlay()
|
||||||
|
}
|
||||||
|
}}
|
||||||
className={s.overlay}
|
className={s.overlay}
|
||||||
style={props.style}
|
style={props.style}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -136,10 +136,6 @@ a.invisible {
|
|||||||
border-bottom-color: var(--color-text-opposite);
|
border-bottom-color: var(--color-text-opposite);
|
||||||
}
|
}
|
||||||
|
|
||||||
.noscroll {
|
|
||||||
overflow: hidden;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* RC TOOLTIP OVERRIDE */
|
/* RC TOOLTIP OVERRIDE */
|
||||||
.hudozka.rc-tooltip {
|
.hudozka.rc-tooltip {
|
||||||
|
|||||||
Reference in new issue
Block a user