1.1.0 • Published 3 years ago

@pmwcs/top-app-bar v1.1.0

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

Top App Bar

Top App Bar acts as a container for items such as application title, navigation icon, and action items.

  • Module @pmwcs/top-app-bar
  • Import styles:
    • Using CSS Loader
      • import '@pmwcs/top-app-bar/styles';
    • Or include stylesheets
      • '@material/top-app-bar/dist/mdc.top-app-bar.css'
      • '@material/icon-button/dist/mdc.icon-button.css'
      • '@material/ripple/dist/mdc.ripple.css'
      • '@pmwcs/icon/icon.css'
  • MDC Docs: https://material.io/develop/web/components/top-app-bar/

Whats the difference between the TopAppBar and Toolbar? Toolbar is technically deprecated (although it still works just fine). TopAppBar functionality continues to be worked on by the material-components-web team.

Basic Usage

<>
  <TopAppBar>
    <TopAppBarRow>
      <TopAppBarSection>
        <TopAppBarTitle>Default</TopAppBarTitle>
      </TopAppBarSection>
    </TopAppBarRow>
  </TopAppBar>
  <TopAppBarFixedAdjust />

  <div style={{ height: '100rem', padding: '1rem' }}>Scroll Me</div>
</>
<>
  <TopAppBar>
    <TopAppBarRow>
      <TopAppBarSection alignStart>
        <TopAppBarNavigationIcon icon="menu" />
        <TopAppBarTitle>All Features</TopAppBarTitle>
      </TopAppBarSection>
      <TopAppBarSection alignEnd>
        <TopAppBarActionItem icon="favorite" />
        <TopAppBarActionItem icon="star" />
        <TopAppBarActionItem icon="mood" />
      </TopAppBarSection>
    </TopAppBarRow>
    <TopAppBarRow>
      <TopAppBarSection alignStart>
        <TopAppBarTitle>Another Row</TopAppBarTitle>
      </TopAppBarSection>
    </TopAppBarRow>
  </TopAppBar>
  <TopAppBarFixedAdjust />

  <div style={{ height: '100rem', padding: '1rem' }}>Scroll Me</div>
</>

Simplified Usage

You can use the SimpleTopAppBar component which contains a default template already laid out for you. Specify any actions you want as an array of props

<>
  <SimpleTopAppBar
    title="test"
    navigationIcon
    onNav={() => console.log('Navigate')}
    actionItems={[
      {
        icon: 'file_download',
        onClick: () => console.log('Do Something')
      },
      { icon: 'print', onClick: () => console.log('Do Something') },
      { icon: 'bookmark', onClick: () => console.log('Do Something') }
    ]}
  />
  <TopAppBarFixedAdjust />

  <div style={{ height: '100rem', padding: '1rem' }}>Scroll Me</div>
</>

Variants

<>
  <TopAppBar fixed>
    <TopAppBarRow>
      <TopAppBarSection>
        <TopAppBarTitle>Fixed</TopAppBarTitle>
      </TopAppBarSection>
    </TopAppBarRow>
  </TopAppBar>
  <TopAppBarFixedAdjust />

  <div style={{ height: '100rem', padding: '1rem' }}>Scroll Me</div>
</>
<>
  <TopAppBar dense>
    <TopAppBarRow>
      <TopAppBarSection>
        <TopAppBarTitle>Dense</TopAppBarTitle>
      </TopAppBarSection>
    </TopAppBarRow>
  </TopAppBar>
  <TopAppBarFixedAdjust />

  <div style={{ height: '100rem', padding: '1rem' }}>Scroll Me</div>
</>
<>
  {/** Additionally you can specify shortCollapsed to have it always minimized */}
  <TopAppBar short>
    <TopAppBarRow>
      <TopAppBarSection>
        <TopAppBarNavigationIcon icon="menu" />
        <TopAppBarTitle>Short</TopAppBarTitle>
      </TopAppBarSection>
      <TopAppBarSection alignEnd>
        <TopAppBarActionItem icon="favorite" />
      </TopAppBarSection>
    </TopAppBarRow>
  </TopAppBar>
  <TopAppBarFixedAdjust />

  <div style={{ height: '100rem', padding: '1rem' }}>Scroll Me</div>
</>
<>
  <TopAppBar prominent>
    <TopAppBarRow>
      <TopAppBarSection>
        <TopAppBarTitle>Prominent</TopAppBarTitle>
      </TopAppBarSection>
    </TopAppBarRow>
  </TopAppBar>
  <TopAppBarFixedAdjust />

  <div style={{ height: '100rem', padding: '1rem' }}>Scroll Me</div>
</>

TopAppBar

TopAppBar

Props

NameTypeDescription
denseundefined \| false \| trueStyles the top app bar to be dense.
fixedundefined \| false \| trueStyles the top app bar as a fixed top app bar.
foundationRefReact.Ref<MDCTopAppBarFoundation \| null>Advanced: A reference to the MDCFoundation.
onNavundefined \| (evt: TopAppBarOnNavEventT) => voidEmits when the navigation icon is clicked.
prominentundefined \| false \| trueStyles the top app bar as a prominent top app bar.
scrollTargetElement \| nullSet a scrollTarget other than the window when you are using the TopAppBar inside of a nested scrolling DOM Element. Please note that you should store your scrollTarget in a stateful variable. See example https://codesandbox.io/s/reverent-austin-16zzi.
shortundefined \| false \| trueStyles the top app bar as a short top app bar.
shortCollapsedundefined \| false \| trueStyles the top app bar to always be collapsed.

TopAppBarRow

A row for the app bar.

TopAppBarSection

A section for the app bar.

Props

NameTypeDescription
alignEndundefined \| false \| trueAligns the section to the end.
alignStartundefined \| false \| trueAligns the section to the start.

TopAppBarTitle

A title for the top app bar.

TopAppBarNavigationIcon

A navigation icon for the top app bar. This is an instance of the Icon component.

Props

NameTypeDescription
checkedundefined \| false \| trueControls the on / off state of the a toggleable button.
disabledundefined \| false \| trueMakes the button disabled
foundationRefReact.Ref<MDCIconButtonToggleFoundation>Advanced: A reference to the MDCFoundation. Only for Toggleable buttons.
iconPMWCS.IconPropTIcon for the button
labelundefined \| stringApply an aria label.
onChangeundefined \| (evt: IconButtonOnChangeEventT) => voidAn onChange callback that receives a custom event. evt.detail = { isOn: boolean }
onIconPMWCS.IconPropTIf specified, renders a toggle with this icon as the on state.
rippleRipplePropTAdds a ripple effect to the component

TopAppBarActionItem

Action items for the top app bar. This is an instance of the Icon component.

Props

NameTypeDescription
checkedundefined \| false \| trueControls the on / off state of the a toggleable button.
disabledundefined \| false \| trueMakes the button disabled
foundationRefReact.Ref<MDCIconButtonToggleFoundation>Advanced: A reference to the MDCFoundation. Only for Toggleable buttons.
iconPMWCS.IconPropTIcon for the button
labelundefined \| stringApply an aria label.
onChangeundefined \| (evt: IconButtonOnChangeEventT) => voidAn onChange callback that receives a custom event. evt.detail = { isOn: boolean }
onIconPMWCS.IconPropTIf specified, renders a toggle with this icon as the on state.
rippleRipplePropTAdds a ripple effect to the component

TopAppBarFixedAdjust

An optional component to fill the space when the TopAppBar is fixed. Place it directly after the TopAppBar.

Props

NameTypeDescription
denseundefined \| false \| trueClass used to style the content below the dense top app bar to prevent the top app bar from covering it.
denseProminentundefined \| false \| trueClass used to style the content below the top app bar when styled as both prominent and dense, to prevent the top app bar from covering it.
prominentundefined \| false \| trueClass used to style the content below the prominent top app bar to prevent the top app bar from covering it.
shortundefined \| false \| trueClass used to style the content below the short top app bar to prevent the top app bar from covering it.

SimpleTopAppBar

A simplified syntax for creating an AppBar.

Props

NameTypeDescription
actionItemsObject[]An array of props that will be used to create TopAppBarActionItems.
denseundefined \| false \| trueStyles the top app bar to be dense.
endContentReact.ReactNodeAdditional content to place in the end section.
fixedundefined \| false \| trueStyles the top app bar as a fixed top app bar.
foundationRefReact.Ref<MDCTopAppBarFoundation \| null>Advanced: A reference to the MDCFoundation.
navigationIconObject \| booleanProps for the NavigationIcon, which is an instance of the Icon component. You can also set this to true and use the onNav prop to handle interactions.
onNavundefined \| (evt: TopAppBarOnNavEventT) => voidEmits when the navigation icon is clicked.
prominentundefined \| false \| trueStyles the top app bar as a prominent top app bar.
scrollTargetElement \| nullSet a scrollTarget other than the window when you are using the TopAppBar inside of a nested scrolling DOM Element. Please note that you should store your scrollTarget in a stateful variable. See example https://codesandbox.io/s/reverent-austin-16zzi.
shortundefined \| false \| trueStyles the top app bar as a short top app bar.
shortCollapsedundefined \| false \| trueStyles the top app bar to always be collapsed.
startContentReact.ReactNodeAdditional content to place in the start section.
titleReact.ReactNodeThe title for the App Bar.