0.2.9 • Published 4 years ago

tbc-panda-header v0.2.9

Weekly downloads
309
License
-
Repository
-
Last release
4 years ago

TBC Panda React App Header

Header for all TBC Panda React apps

Install

npm install --save tbc-panda-header

Styles

As of version 0.2.0, to use the component included in this module, the following style file will need to be imported/included into the main App.scss after the colors.scss import:

@import "tbc-panda-header/dist/Component/styles/header.scss";

Header Component:

import HeaderContainer from "tbc-panda-header/dist/Component/HeaderContainer";

Then, in the highest level presentational component, place the following where it should appear:

<HeaderContainer pagesObject={pagesObject} />

This should be above any routing tags.

pagesObject

The Header module requires a pagesObject which describes what items appear in the header.

It is recommended that a pagesConfig.js file be created which hosts this object.

The pagesObject is made up of:

KeyTypeDefaultDescription
pagesArray[]key containing an array of page objects (see below for details)
utilsComponentsArray[]key contains an array of utility button components (items that appear in the far right of the header)
defaultNumber0value (index) used to determine the default page index
mobileThresholdNumber2value used to determine at which Bootstrap size does the header convert to "mobile"; defaults to 2 ("md") (options: 0 = "xs", 1 = "sm", 2 = "md", 3 = "lg", 4 = "xl")
maxWidthBooleanfalseif true, then header will be maximum width of screen for all sizes; else it will be limited to standard Bootstrap container size
searchObjectObject{ enabled: false}object controlling header search field (see below for details)

The objects within the pages key contains:

KeyTypeRequiredDescription
pathStringREQUIREDused for key and local path (if local link)
nameStringREQUIREDshort name (used in header and home tab)
longNameStringOPTIONALlong name (used in home tab)
iconStringREQUIREDicon classes for links
componentReact.ComponentOPTIONALthe container component for internal pages
linkStringOPTIONALexternal URL
targetStringOPTIONALanchor target for external URLs (defaults to "_new")
desktopOnlyBooleanOPTIONALflag whether link appears in header only for desktop implementations
mobileOnlyBooleanOPTIONALflag whether link appears in header `only for mobile implementations

The searchObject object is populated by the following keys:

KeyTypeDefaultDescription
enabledBooleanfalseflag determining if search field appears (and that the header is sized accordingly) NOTE: header height is 53px without search and 75px with
initialValuesObject{}determines if/what initial values appear in the search fields; NOTE: search term form fieldName/value keyes are searchTerm and searchScope (Example: {searchTerm: "", searchScope: "ID"})
placeholderString""placeholder text within empty search field
stickyValuesBooleanfalseby default, values clear upon search; setting this flag to true makes search values "sticky" (do not clear)
submitSearchFunction() => {}function fired when search field is submitted
prependScopeEnabledBooleanfalseflag determining if a prepended drop down occurs before the search bar (usually for determining search scope); NOTE: drop down option form fieldName/value key is searchScope
prependOptionsArray[]array of objects used for prepend drop down; objects include cd (value of selection) and nm (display name of option); example: [{cd: "ANY", nm: ""}, {cd: "NM", nm: "Name"}, {cd: "ID", nm: "ID"}]; NOTE: blank option will not be added automatically - the options provided in the option array are exactly what will be available
enableEmptySearchBooleanfalseflag determining if search icon is active when nothing is entered in field; allows for empty searches

See below for sample pagesConfig.js file.

Required NPM Packages

npm install --save bootstrap reactstrap @material-ui/core lodash formik

Testing

For any unit test file that deep renders ("mounts") this imported component, add the following:

jest.mock("tbc-panda-header/dist/Component/HeaderContainer", () => "div");

Sample pagesConfig.js file

/** @module pagesConfig */

import React from "react";

import Tab1 from "./Tab1";
import Tab2 from "./Tab2";
import UtilButton from "./UtilButton";

const pagesObject = {
 default: 0,
 mobileThreshold: 1, // "sm"
 pages: [
 {
 path: "tab1",
 name: "Tab 1",
 icon: "far fa-dice-one",
 component: () => <Tab1 />
 },
 {
 path: "tab2",
 name: "Tab 2",
 icon: "far fa-dice-two",
 component: () => <Tab2 />
 },
 {
 path: "sdo",
 name: "SDO",
 longName: "Seed Dealer Orders",
 icon: "fas fa-store-alt",
 link: `http://seed-staging.trinidadbenham.com`
 }
 ],
 utilComponents: [<UtilButton />],
 maxWidth: false,
 searchObject: {
 enabled: true,
 initialValues: { searchTerm: "Test" },
 placeholder: "Search by ID or Name",
 stickyValues: true,
 submitSearch: values => console.log(values),
 prependScopeEnabled: true,
 prependOptions: [
 {cd: "ANY", nm: ""},
 {cd: "NM", nm: "Name"},
 {cd: "ID", nm: "ID"}
 ]
 }
};

export default pagesObject;