Table of Contents

Introduction

React header is a simple header which can be incorporated within your react applications to be used as a header elements.
It provides :-
  • Fully responsive header
  • Full keyboard navigation
  • Built in Accessibility
  • Higher order components to change the behaviour of the header
  • Ability to customize as needed

Using library

To use this library download the the library from github and either use the source or the bundled versions present in the dist version. Inside the dist folder both the scritp and style files are present.

Once downloaded the library the components can be imported and used as below:-


import React from 'react';
import {render} from 'react-dom';
import ReactHeader from "react-header";
const Logo = ReactHeader.Logo;
const NavigationList = ReactHeader.NavigationList;
const NavigationItem = ReactHeader.NavigationItem;
const Header = ReactHeader.Header;
            

Basic Usage

Components

To use the header the pretty straightfoward. The component needs to be wrapped inside a Header.
The different elements can be used as below:-
  • Logo: Any Logo that needs to be provided is put under the Logo element.
  • NavigationList: Any menu, including any submenu is created using NavigationList element.
  • NavigationItem: All items inside menu is a created using NavigationItem element.
    • NavigationItem can have link and text attributes which is used for creating a link
    • NavigationItem supports nested NavigationList, which creates Sub Menus
  • Any other items can be added to the menu and will be displayed as it is.

Example

Link to actual example is : Basic Example

Basic Usage using the above components are given below:-


const header = (
    <Header>
<Logo title="My Logo" link="http://testing.com"/>
<NavigationList>
<NavigationItem link="#home" text="Home"/>
<NavigationItem text="Team">
<NavigationList>
<NavigationItem link="#local" text="Local"/>
<NavigationItem link="#" text="Remote"/>
<NavigationItem link="#" text="Desktop"/>
<NavigationItem link="#" text="Train"/>
</NavigationList>
</NavigationItem>
<NavigationItem link="#contact" text="Contact"/>
<NavigationItem link="#" text="About Us"/>
</NavigationList>
<input type="search" placeholder="Search..."/>
</Header> ) render(header, document.getElementById('header'));

Styling Header

There are multiple ways to style headers:-

Example - Overriding Variables

Link to actual example is : Styling Example

You can look at the _variables.scss and define the new values for for the variables present in the file.

Create a new file _override-variables.scss and specify new values for the variables you want to override

/**
* Header overides
*/
$header-height: 80px;
// background color for header
$header-bg-color: #f1f0f0;
// Default color for header components
$header-font-color: #66757f;
            
Then import that file in your main scss file followed by the react-header.scss files

@import "override-variables";
@import "{path-to-react-header-styles}/main";
// Other styles
            

Sticky Headers

There are couple of Higher order components which can be used to change the default behaviour of the Headers.

Example

Link to actual example is : Sticky on Scroll Header Example


import {render} from 'react-dom';
import React from 'react';
import Logo from './Logo.js';
import NavigationList from './navigation/NavigationList';
import NavigationItem from './navigation/NavigationItem';
import StickyOnScrollUpHeader from './header/StickyOnScrollUpHeader.js'

const header = (
  <StickyOnScrollUpHeader>
    <Logo title="My Logo" link="http://testing.com" />
    <NavigationList>
      <NavigationItem link="#home" text="Home"/>
      <NavigationItem text="Team">
      <NavigationItem link="#contact" text="Contact"/>
      <NavigationItem link="#" text="About Us"/>
    </NavigationList>
  </StickyOnScrollUpHeader>
);

render(header, document.getElementById('header'));
        

Events (TBA)

Fork me on GitHub