npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@shortcm/top-app-bar

v0.44.1

Published

The Material Components for the web top app bar component

Downloads

6

Readme

Top App Bar

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

Design & API Documentation

Installation

npm install @material/top-app-bar

Basic Usage

HTML Structure

<header class="mdc-top-app-bar">
  <div class="mdc-top-app-bar__row">
    <section class="mdc-top-app-bar__section mdc-top-app-bar__section--align-start">
      <a href="#" class="material-icons mdc-top-app-bar__navigation-icon">menu</a>
      <span class="mdc-top-app-bar__title">Title</span>
    </section>
  </div>
</header>

Menu Icons

We recommend using Material Icons from Google Fonts:

<head>
  <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
</head>

However, you can also use SVG, Font Awesome, or any other icon library you wish.

Styles

@import "@material/top-app-bar/mdc-top-app-bar";

JavaScript Instantiation

import {MDCTopAppBar} from '@material/top-app-bar/index';

// Instantiation
const topAppBarElement = document.querySelector('.mdc-top-app-bar');
const topAppBar = new MDCTopAppBar(topAppBarElement);

See Importing the JS component for more information on how to import JavaScript.

Variants

Top App Bar With Action Items

Top app bars can contain action items which are placed on the side opposite the navigation icon.

<header class="mdc-top-app-bar">
  <div class="mdc-top-app-bar__row">
    <section class="mdc-top-app-bar__section mdc-top-app-bar__section--align-start">
      <a href="#" class="material-icons mdc-top-app-bar__navigation-icon">menu</a>
      <span class="mdc-top-app-bar__title">Title</span>
    </section>
    <section class="mdc-top-app-bar__section mdc-top-app-bar__section--align-end" role="toolbar">
      <a href="#" class="material-icons mdc-top-app-bar__action-item" aria-label="Download" alt="Download">file_download</a>
      <a href="#" class="material-icons mdc-top-app-bar__action-item" aria-label="Print this page" alt="Print this page">print</a>
      <a href="#" class="material-icons mdc-top-app-bar__action-item" aria-label="Bookmark this page" alt="Bookmark this page">bookmark</a>
    </section>
  </div>
</header>

Short

Short top app bars are top app bars that can collapse to the navigation icon side when scrolled.

<header class="mdc-top-app-bar mdc-top-app-bar--short">
  <div class="mdc-top-app-bar__row">
    <section class="mdc-top-app-bar__section mdc-top-app-bar__section--align-start">
      <a href="#" class="material-icons mdc-top-app-bar__navigation-icon">menu</a>
      <span class="mdc-top-app-bar__title">Title</span>
    </section>
    <section class="mdc-top-app-bar__section mdc-top-app-bar__section--align-end" role="toolbar">
      <a href="#" class="material-icons mdc-top-app-bar__action-item" aria-label="Bookmark this page" alt="Bookmark this page">bookmark</a>
    </section>
  </div>
</header>

Short top app bars should be used with no more than 1 action item.

Short - Always Closed

Short top app bars can be configured to always appear collapsed by applying the mdc-top-app-bar--short-collapsed before instantiating the component :

<header class="mdc-top-app-bar mdc-top-app-bar--short mdc-top-app-bar--short-collapsed">
  ...
</header>

Fixed

Fixed top app bars stay at the top of the page and elevate above the content when scrolled.

<header class="mdc-top-app-bar mdc-top-app-bar--fixed">
  ...
</header>

Prominent

The prominent top app bar is taller.

<header class="mdc-top-app-bar mdc-top-app-bar--prominent">
  ...
</header>

Dense

The dense top app bar is shorter.

<header class="mdc-top-app-bar mdc-top-app-bar--dense">
  ...
</header>

Style Customization

CSS Classes

Class | Description --- | --- mdc-top-app-bar | Mandatory. mdc-top-app-bar--fixed | Class used to style the top app bar as a fixed top app bar. mdc-top-app-bar--fixed-adjust | Class used to style the content below the standard and fixed top app bar to prevent the top app bar from covering it. mdc-top-app-bar--prominent | Class used to style the top app bar as a prominent top app bar. mdc-top-app-bar--prominent-fixed-adjust | Class used to style the content below the prominent top app bar to prevent the top app bar from covering it. mdc-top-app-bar--dense | Class used to style the top app bar as a dense top app bar. mdc-top-app-bar--dense-fixed-adjust | Class used to style the content below the dense top app bar to prevent the top app bar from covering it. mdc-top-app-bar--dense-prominent-fixed-adjust | Class 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. mdc-top-app-bar--short | Class used to style the top app bar as a short top app bar. mdc-top-app-bar--short-collapsed | Class used to indicate the short top app bar is collapsed. mdc-top-app-bar--short-fixed-adjust | Class used to style the content below the short top app bar to prevent the top app bar from covering it.

Sass Mixins

Mixin | Description --- | --- mdc-top-app-bar-ink-color($color) | Sets the ink color of the top app bar. mdc-top-app-bar-icon-ink-color($color) | Sets the ink color of the top app bar icons. mdc-top-app-bar-fill-color($color) | Sets the fill color of the top app bar. mdc-top-app-bar-fill-color-accessible($color) | Sets the fill color of the top app bar and automatically sets a high-contrast ink color. mdc-top-app-bar-short-shape-radius($radius, $rtl-reflexive) | Sets the rounded shape to short top app bar variant (when it is collapsed) with given radius size. Set $rtl-reflexive to true to flip radius values in RTL context, defaults to true.

MDCTopAppBar Properties and Methods

Method Signature | Description --- | --- setScrollTarget(target: element) => void | Sets scroll target to different DOM node (default is window).

Events

Event Name | Event Data Structure | Description --- | --- | --- MDCTopAppBar:nav | None | Emits when the navigation icon is clicked.

Usage within Web Frameworks

If you are using a JavaScript framework, such as React or Angular, you can create a Top App Bar for your framework. Depending on your needs, you can use the Simple Approach: Wrapping MDC Web Vanilla Components, or the Advanced Approach: Using Foundations and Adapters. Please follow the instructions here.

MDCTopAppBarAdapter

Method Signature | Description --- | --- hasClass(className: string) => boolean | Checks if the root element of the component has the given className. addClass(className: string) => void | Adds a class to the root element of the component. removeClass(className: string) => void | Removes a class from the root element of the component. registerNavigationIconInteractionHandler(evtType: string, handler: EventListener) => void | Registers an event listener on the native navigation icon element for a given event. deregisterNavigationIconInteractionHandler(evtType: string, handler: EventListener) => void | Deregisters an event listener on the native navigation icon element for a given event. notifyNavigationIconClicked() => void | Emits a custom event MDCTopAppBar:nav when the navigation icon is clicked. registerScrollHandler(handler) => void | Registers a handler to be called when user scrolls. Our default implementation adds the handler as a listener to the window's scroll event. deregisterScrollHandler(handler) => void | Unregisters a handler to be called when user scrolls. Our default implementation removes the handler as a listener to the window's scroll event. getViewportScrollY() => number | Gets the number of pixels that the content of body is scrolled from the top of the page. getTotalActionItems() => number | Gets the number of action items in the top app bar.

Foundations: MDCTopAppBarBaseFoundation, MDCTopAppBarFoundation, MDCFixedTopAppBarFoundation and MDCShortTopAppBarFoundation

Method Signature | Description --- | --- initScrollHandler(handler: function) => void | Registers a scroll handler on a specific target element. destroyScrollHandler(handler: function) => void | Deregisters the current scroll handler set by the foundation.