2.1.1 • Published 3 years ago

react-hideandseekmenu v2.1.1

Weekly downloads
2
License
MIT
Repository
github
Last release
3 years ago

react-hideandseekmenu

npm version

A simple React hook to hide and show your site's menubar when scrolling.

GIF showing react-hideandseekmenu

Features

🪝React Hook

Installation

Install with NPM:

npm install react-hideandseekmenu --save

Usage

useHideAndSeekMenu

import { useHideAndSeekMenu } from 'react-hideandseekmenu'

You use this hook by passing in a ref. The hook will handle all the "hide and seek styling" for you by accessing ref.curent.style and setting inline-styles. You can pass in some options to change the CSS and behaviour of the menu hiding & showing.

useHideAndSeekMenu({
    ref: yourRef
})
import { useHideAndSeekMenu } from 'react-hideandseekmenu'
import { useRef } from 'react'

const Navigation = () => {
    const navref = useRef<HTMLElement>(null);
    useHideAndSeekMenu({
        ref: navref,
        offset: 120,
        transitionDuration: 0.3,
    })

    return (
        <Nav ref={navref} />
    )
}

The hook will then handle the "hide and seek styling" of your navigation bar.

Default stylings

position: sticky;
transition: top 0.3s ease;
top: 0;

Options

These options can be passed to the useHideAndSeekMenu hook:

OptionTypeDefaultDescription
offsetnumber90The offset at which the menu should disappear
debounceTimenumber10The debounce time for the hook to be fired
refRefObjectundefinedPass a ref to the hook to let the hook handle all the "hide and seek styling"
transitionDurationnumber0.3Set a transition duration for the CSS transition property
transitionTimingFunctionstringeaseSet a transition timing function for the CSS transition property