1.0.1 • Published 3 years ago

material-ui-responsive-nav v1.0.1

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

material-ui-responsive-nav

An easy-to-use component that allows you to add responsive navigation with minimum fuss.

Install

npm i material-ui-responsive-nav @material-ui/core

NOTE: This component requires Material-UI to work.

Usage

import React from "react"
import { MaterialUINav } from "material-ui-responsive-nav"
// you will need to import the icons from an external source to use with external links
import { Facebook, Twitter } from "mdi-material-ui"

const Layout = ({children}) => {

  const links = {
    internal: [
      {
        label: "Home",
        link: "/",
      },
      {
        label: "About",
        link: "/about",
      },
      {
        label: "Contact",
        link: "/contact",
      },
    ],
    external: [
      {
        label: "Facebook",
        icon: Facebook,
        link: "https://www.facebook.com",
      },
      {
        label: "Twitter",
        icon: Twitter,
        link: "https://www.twitter.com",
      },
    ],
  }

  return (
    <>
      <MaterialUINav
        global={{
          siteTitle: "My cool site",
          mobileBreakpoint: "xs",
        }}
        navbarConfig={{
          elevate: false,
        }}
        mobileMenuConfig={{
          slideTransition: true,
        }}
        links={links}
      />
      {children}
    </>
  )
}

API

links (required)

PropertyDescriptionTypeOptionsDefault
internalAn array of internal links to include in the navigationarray[ { label: string, link: string, navbarLinkProps: object (pass props to the Button component), mobileMenuProps: object (pass props to the ListItem component), mobileMenuTextProps: object (pass props to the ListItemText component) } ]N/A
externalAn array of external links to include in the navigationarray[ { label: string, link: string, icon: node, navbarLinkProps: object (pass props to the IconButton component), mobileMenuProps: object (pass props to the IconButton component) } ]N/A

global

PropertyDescriptionTypeOptionsDefault
siteTitleThe title to show on the navbar and the mobile menustringN/A"My site"
mobileBreakpointThe point at which to display the mobile layoutstring"xs", "sm", "md", "lg", "xl""sm"

navbarConfig

PropertyDescriptionTypeOptionsDefault
colorBackground color of the navbarstring"primary", "secondary", "transparent""primary"
fixedFix the navbar to the top of the screenbooleanN/Atrue
appBarPropsPass props to the AppBar componentobjectN/Anull
transparentAtTopMake the background of the navbar transparent if at the top of the page.booleanN/Afalse
elevateShow a box shadowbooleanN/Atrue
bashrinkOnScrollDownShrink the height of the navbar if not at the top of the pagebooleanN/Atrue
bashrinkTransitionDurationAdjust the duration in seconds of the shrink (and grow) animation. shrinkOnScrollDown must be true for this to work.numberN/A0.5
logoAdd a component to display a logocomponentN/Anull
titleTypographyVariantAdjust the typography variant for the site titlestring"h1", "h2", "h3", "h4", "h5", "h6", "subtitle1", "subtitle2", "body1", "body2", "overline", "button", "caption""h5"
alignLinksRightChange the alignment of internal linksbooleanN/Atrue
additionalLinkSpacingAdd more space (in pixels) between internal linksnumberN/A0
disableTitleClickDisables onClick functionality on the site titlebooleanN/Afalse
titleOnClickChange the onClick functionfunctionN/A()=>window.open("/")
titlePropsPass props to the Typography componentobjectN/Anull
titleRightMarginAdjust the right margin of the site title. Only works if alignLinksRight is false.numberN/A4
linksTextTransformChange the case of the linksstring"uppercase", "lowercase", "capitalize""uppercase"
bashowTooltipsShow tooltips on external linksbooleanN/Atrue
mobileMenuButtonPropsPass props to the IconButton componentobjectN/A{}

mobileMenuConfig

PropertyDescriptionTypeOptionsDefault
bgcolorBackground color of the mobile menustring"primary", "secondary", "error", "warning", "info", "success"null
logoAdd a component to display a logocomponentN/Anull
bashowTitleShow the siteTitle (defined in global)booleanN/Atrue
titleTypographyVariantAdjust the typography variant for the site title. showTitle must be true for this to workstring"h1", "h2", "h3", "h4", "h5", "h6", "subtitle1", "subtitle2", "body1", "body2", "overline", "button", "caption""h4"
titlePropsPass props to to the Typography componentobjectN/Anull
linksTextTransformChange the case of the linksstring"uppercase", "lowercase", "capitalize""uppercase"
internalLinksPropsPass props to the List componentobjectN/A{}
externalLinksPropsPass props to the Box componentobjectN/A{}
externalLinksAdditionalSpacingAdd extra space to the bottom of the internal linksnumberN/A0
slideTransitionOpen/close the mobile menu with a slide transition instead of the default fade transitionbooleanN/Afalse
closeButtonPropsPass props to the Fab componentobjectN/A{}

Contribute

This is one of the first components I have created. There is a lot of scope for improvement and I happily invite you to contribute!