0.2.0 • Published 6 years ago

react-sticky-header v0.2.0

Weekly downloads
983
License
MIT
Repository
github
Last release
6 years ago

react-sticky-header

NPM version NPM downloads Build Status codecov Dependency Status

Lightweight sticky header made for React that works with both colours and images. You can see an example implementation over at Guild Wars 2 Armory.

Installation

npm install react-sticky-header

Usage

// Import the base CSS, if you're using webpack just import them straight.
// Else import them into your base CSS.
import 'react-sticky-header/styles.css';
import StickyHeader from 'react-sticky-header';

const MyHeader = () => (
  <StickyHeader
    // This is the sticky part of the header.
    header={
      <div className="Header_root">
        <h1 className="Header_title">ReactStickyHeader</h1>

        <ul className="Header_links">
          <li className="Header_link">When</li>
          <li className="Header_link">Why</li>
          <li className="Header_link">About</li>
        </ul>
      </div>
    }
  >
    <section>
      <p>
        This section will be what the sticky header scrolls over before entering into
        sticky state. See the gif above or run the test story book to see examples.
      </p>
    </section>
  </StickyHeader>
);
proptyperequireddescription
headerChildrenyesA react element that will be the sticky part of the header.
childrenChildrennoElements that you want to appear under the sticky header.
headerOnlybooleannoUse this to force the header into "sticky" mode. It will automatically hide the children and calculate the height spacer for header.
onSticky(boolean) => voidnoCallback fired when the header enters/leaves sticky state. See Sticky State section.
backgroundImagestringnoSelf explanatory.
backgroundColorstringnoSelf explanatory.
classNamestringnoSelf explanatory.
stickyOffsetnumbernoThe number to offset the sticky header.

Sticky State

When the component enters sticky state, it will add a class name is-sticky to the root element of the header.

React Story Book

To run the component in various states, run the following command then go to http://localhost:6006/.

npm start

Testing

npm test
0.2.0

6 years ago

0.1.9

7 years ago

0.1.8

7 years ago

0.1.7

7 years ago

0.1.6

7 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.1

7 years ago