0.15.0 • Published 5 years ago

@material/react-top-app-bar v0.15.0

Weekly downloads
992
License
MIT
Repository
github
Last release
5 years ago

React Top App Bar

A React version of an MDC Top App Bar.

Installation

npm install @material/react-top-app-bar

Usage

Styles

with Sass:

import '@material/react-top-app-bar/index.scss';
import '@material/react-material-icon/index.scss';

with CSS:

import '@material/react-top-app-bar/dist/top-app-bar.css';
import '@material/react-material-icon/dist/material-icon.css';

Javascript Instantiation

import TopAppBar, {
  TopAppBarFixedAdjust, 
  TopAppBarIcon,
  TopAppBarRow,
  TopAppBarSection,
  TopAppBarTitle,
} from '@material/react-top-app-bar';
import MaterialIcon from '@material/react-material-icon';

const MyComponent = () => {
  return (
    <div>
      <TopAppBar>
        <TopAppBarRow>
          <TopAppBarSection align='start'>
            <TopAppBarIcon navIcon tabIndex={0}>
              <MaterialIcon hasRipple icon='menu' onClick={() => console.log('click')}/>
            </TopAppBarIcon>
            <TopAppBarTitle>Miami, FL</TopAppBarTitle>
          </TopAppBarSection>
          <TopAppBarSection align='end' role='toolbar'>
            <TopAppBarIcon actionItem tabIndex={0}>
              <MaterialIcon 
                aria-label="print page" 
                hasRipple 
                icon='print' 
                onClick={() => console.log('print')}
              />
            </TopAppBarIcon>
          </TopAppBarSection>
        </TopAppBarRow>
      </TopAppBar>
      <TopAppBarFixedAdjust>
        My exciting content!
      </TopAppBarFixedAdjust>
    </div>
  );
}

Use the <TopAppBarFixedAdjust /> component to give your content top-padding, so it isn't hidden on page render.

Props

TopAppBar

Prop NameTypeDescription
classNameStringClasses to be applied to the root element.
shortBooleanEnables short variant.
shortCollapsedBooleanEnables short collapsed variant.
prominentBooleanEnables prominent variant.
fixedBooleanEnables fixed variant.
denseBooleanEnables dense variant.
scrollTargetReact.RefObjectSets scroll target to different DOM node (default is window)
tagStringCustomizes the TopAppBar HTML tag. (default: <header>)

NOTES: As per design guidelines, prominent and dense variants should not be used with short or short collapsed. Additionally, dense variants should only be used on desktop. Additionally short top-app-bars should be used with no more than 1 action item.

TopAppBarRow

Prop NameTypeDescription
classNameStringClasses to be applied to the root element.
tagStringCustomizes the TopAppBarRow tag. (default: <div>)

TopAppBarSection

Prop NameTypeDescription
alignSring ('start' or 'end')optional property that aligns section content to either start or end of section
classNameStringClasses to be applied to the root element.
tagStringCustomizes the TopAppBarSection tag. (default: <section>)

Note: if section contains action items it is recommended to add property role='toolbar' for a11y purposes

TopAppBarTitle

Prop NameTypeDescription
classNameStringClasses to be applied to the root element.
tagStringCustomizes the TopAppBarTitle tag. (default: <span>)

TopAppBarIcon

Prop NameTypeDescription
classNameStringClasses to be applied to the root element.
actionItemBooleanapplies action-item class to icon
navIconBooleanapplies nav-icon class to icon
childrenReact.ReactElementcan be any icon. Material Icons are recommended

Notes: (1) consider adding aria-label to actionItem's. (2) you may need to manually add ripple or tabindex to icon. (3) Short top-app-bars should be used with no more than 1 action item.

TopAppBarFixedAdjust

Prop NameTypeDescription
classNameStringClasses to be applied to the root element.
denseBooleanEnables dense variant.
prominentBooleanEnables prominent variant.
shortBooleanEnables short variant.
tagStringCustomizes the TopAppBarFixedAdjust tag (defaults to <main>)

NOTE: if not dense, prominent, or short will apply mdc-top-app-bar--fixed-adjust

Icons

Use of Material Icon's for Action Items and Navigation Icons are recommended, since the Ripple is included with the Component. Using custom Components will require you to wrap the Component with the withRipple HOC. If you do decide to build your own custom Component, it is recommended to use the hasRipple prop to toggle between icons with and without ripple. See the Material Icon's implementation to see how to implement the hasRipple prop within your custom Component.

Navigation Icon

The navigation icon can be a <a>, <i>, <svg>, <image>, <span>, etc., but again must be wrapped with the withRipple HOC.

  <TopAppBarIcon navIcon>
    <i className='material-icons'>menu</i>
  </TopAppBarIcon>

If you decide to use a React Component please see Integrating with Components.

Action Items

Similar to the navigation icon, it can be <a>, <i>, <svg>, <image>, <span>, etc., and must be wrapped with the withRipple HOC.

  <TopAppBarIcon actionItem>
    <i className='material-icons'>bookmark</i>
  </TopAppBarIcon>

If you decide to use a React Component please see Integrating with Components.

Sass Mixins

Sass mixins may be available to customize various aspects of the Components. Please refer to the MDC Web repository for more information on what mixins are available, and how to use them.

Advanced Sass Mixins

Usage with Icons

Please see our Best Practices doc when importing or using icon fonts.

Usage with Drawer

Please see the docs in drawer to integrate with Top app bar

0.15.0

5 years ago

0.14.1

5 years ago

0.14.0

5 years ago

0.13.0

5 years ago

0.12.1

5 years ago

0.12.0

5 years ago

0.11.0

5 years ago

0.9.0

5 years ago

0.8.0

5 years ago

0.7.1

5 years ago

0.7.0

5 years ago

0.6.2

5 years ago

0.6.1

6 years ago

0.6.0

6 years ago

0.5.0

6 years ago

0.4.2

6 years ago

0.4.1

6 years ago

0.4.0

6 years ago

0.3.0

6 years ago

0.2.0

6 years ago

0.1.0

6 years ago