1.1.1 • Published 7 months ago

hiding-header-react v1.1.1

Weekly downloads
53
License
ISC
Repository
github
Last release
7 months ago

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 namedefaultdescription
className'hidingHeader'Wrapper class attribute.
innerClassName'hidingHeader-in'Offspring class name.
componentdivWrapper tag name.
heightPropertyName'--hidingHeader-height'CSS property name.
boundsHeightPropertyName'--hidingHeader-bounds-height'CSS property name.
animationOffsetPropertyName'--hidingHeader-animation-offset'CSS property name.
snaptruePrevents only half of the header being visible when user stops scrolling.
onHeightChangenoopCallback.
onVisibleHeightChangenoopCallback.
onHomeChangenoopCallback 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 namedescription
useHidingHeaderReturns object with multiple functions to obtain or manipulate header state.
usePauseHidingHeaderReturns function. When called won't react to scroll.
useRunHidingHeaderReturns function. When called will react to scroll again.
useRevealHidingHeaderReturns function. When called will force header to show.
useHideHidingHeaderReturns function. When called will force header to hide.
1.1.1

7 months ago

1.1.0

1 year ago

1.0.0

1 year ago

0.6.6

2 years ago

0.6.5

2 years ago

0.6.3

2 years ago

0.6.4

2 years ago

0.6.2

3 years ago

0.6.1

3 years ago

0.6.0

3 years ago

0.3.0

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.5.0

4 years ago

0.1.4

4 years ago

0.4.0

4 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.3

5 years ago

0.0.4

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago