0.0.14 • Published 2 years ago

react-active-menu v0.0.14

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

react-active-menu

A React hook to build an active scrolling menu navigation.

Installation

npm i react-active-menu

Getting Started

Initialize hook:

const {
  activeId,
  registerContainer,
  registerSection,
  registerTrigger,
} = useActiveMenu();

Register triggers with unique IDs:

<button ref={registerTrigger('section-1')}>
  Section 1
</button>

Register sections with unique IDs:

<section ref={registerSection('section-1')}>
  <h2>Section 2</h2>
  <p>Lorem ipsum dolor sit amet.</p>
</section>

Register scrollable container:

<div ref={registerContainer}>
  <section ref={registerSection('section-1')}>
    <h2>Section 2</h2>
    <p>Lorem ipsum dolor sit amet.</p>
  </section>
  <section ref={registerSection('section-1')}>
    <h2>Section 2</h2>
    <p>Lorem ipsum dolor sit amet.</p>
  </section>
</div>

API

const {
  activeId,
  registerContainer,
  registerSection,
  registerTrigger,
} = useActiveMenu({
  activeClassName,
  offset,
  smooth,
});

Options |Key|Type|Default|Description| |-|-|-|-| |activeClassName|string|'active'|Specifies the className that gets added to the active trigger.| |offset|number|0|Specifies the threshold distance (px) from the container top where the active section detection gets triggered.| |smooth|boolean|false|Specifies whether scrolling to each section should animate smoothly or not when a trigger is clicked.|

Demos

Without Container

Edit react-active-menu / Full Screen

With Container

Edit react-active-menu / Containerized

https://user-images.githubusercontent.com/1900645/176918185-0fbf7484-f703-416f-8a32-fb624b3ea428.mp4

0.0.15-beta.0

2 years ago

0.0.14

2 years ago

0.0.13

2 years ago

0.0.12

2 years ago

0.0.12-beta.1

2 years ago

0.0.12-beta.0

2 years ago

0.0.11

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago