npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

hiding-header-react

v1.1.0

Published

Toggles header visibility on scroll.

Downloads

620

Readme

Hiding Header React npm npm type definitions

Toggles header visibility on scroll. Try interactive CodeSandbox demo.

UI example

Installation

npm install hiding-header-react

How to use

Component

import { HidingHeader } from 'hiding-header-react'
import 'hiding-header/dist/style.css'

const Header = () => {
	return (
		<HidingHeader>
			<header
				style={{ backgroundColor: 'black', color: 'white', padding: '1em' }}
			>
				Put your content here
			</header>
		</HidingHeader>
	)
}

CSS

Import hiding-header/dist/style.css to your CSS. It's few lines of code. You can alternatively copy paste it and adjust things like z-index to your needs.

Advanced use

<HidingHeader> accepts several optional props.

| property name | default | description | | ----------------------------- | ----------------------------------- | ------------------------------------------------------------------------- | | className | 'hidingHeader' | Wrapper class attribute. | | innerClassName | 'hidingHeader-in' | Offspring class name. | | component | div | Wrapper tag name. | | heightPropertyName | '--hidingHeader-height' | CSS property name. | | boundsHeightPropertyName | '--hidingHeader-bounds-height' | CSS property name. | | animationOffsetPropertyName | '--hidingHeader-animation-offset' | CSS property name. | | snap | true | Prevents only half of the header being visible when user stops scrolling. | | onHeightChange | noop | Callback. | | onVisibleHeightChange | noop | Callback. | | onHomeChange | noop | Callback which calls back when header enters or leaves initial position. |

Example

Changes header background to opaque when sticking / not home.

const MyApp = () => {
	const [isHome, setIsHome] = useState(true)

	return (
		<HidingHeader
			onHomeChange={(isHomeNew) => {
				setIsHome(isHomeNew)
			}}
		>
			<div style={{ backgroundColor: isHome ? 'transparent' : 'white' }}>
				Menu
			</div>
		</HidingHeader>
	)
}

For runtime manipulation you can use hooks.

| hook name | description | | ----------------------- | ---------------------------------------------------------------------------- | | useHidingHeader | Returns object with multiple functions to obtain or manipulate header state. | | usePauseHidingHeader | Returns function. When called won't react to scroll. | | useRunHidingHeader | Returns function. When called will react to scroll again. | | useRevealHidingHeader | Returns function. When called will force header to show. | | useHideHidingHeader | Returns function. When called will force header to hide. |