Socket
Book a DemoInstallSign in
Socket

@material/linear-progress

Package Overview
Dependencies
Maintainers
15
Versions
1675
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@material/linear-progress

The Material Components for the web linear progress indicator component

Source
npmnpm
Version
15.0.0-canary.826a3d8be.0
Version published
Weekly downloads
453K
-1.56%
Maintainers
15
Weekly downloads
 
Created
Source

Linear Progress

The MDC Linear Progress component is a spec-aligned linear progress indicator component adhering to the Material Design progress & activity requirements.

Design & API Documentation

  • Guidelines
  • Demo

Installation

npm install @material/linear-progress

Basic Usage

HTML Structure

<div role="progressbar" class="mdc-linear-progress" aria-label="Example Progress Bar" aria-valuemin="0" aria-valuemax="1" aria-valuenow="0">
  <div class="mdc-linear-progress__buffer">
    <div class="mdc-linear-progress__buffer-bar"></div>
    <div class="mdc-linear-progress__buffer-dots"></div>
  </div>
  <div class="mdc-linear-progress__bar mdc-linear-progress__primary-bar">
    <span class="mdc-linear-progress__bar-inner"></span>
  </div>
  <div class="mdc-linear-progress__bar mdc-linear-progress__secondary-bar">
    <span class="mdc-linear-progress__bar-inner"></span>
  </div>
</div>

Accessibility

Progress bars conform to the WAI-ARIA Progressbar Specification. The supported ARIA attributes for this progress bar are:

AttributeDescription
aria-labelLabel indicating how the progress bar should be announced to the user.
aria-valueminThe minimum numeric value of the progress bar, which should always be 0.
aria-valuemaxThe maximum numeric value of the progress bar, which should always be 1.
aria-valuenowA numeric value between aria-valuemin and aria-valuemax indicating the progress value of the primary progress bar. This attribute is removed in indeterminate progress bars.

Note that aria-label, aria-valuemin, and aria-valuemax are static and must be configured in the HTML. aria-valuenow is updated dynamically by the foundation when the progress value is updated in determinate progress bars.

RTL Localization

The direction of the progress bar follows the dir attribute on its nearest ancestor. For example, setting dir="rtl" on the progress root reverses the direction of the indicator. Where multiple dir attributes are specified in the tree, the one on the progress bar root takes precedence.

Styles

@use "@material/linear-progress";

@include linear-progress.core-styles;

JavaScript Instantiation

import { MDCLinearProgress } from '@material/linear-progress';

const linearProgress = new MDCLinearProgress(document.querySelector('.mdc-linear-progress'));

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

CSS Modifiers

The provided modifiers are:

ClassDescription
mdc-linear-progress--indeterminatePuts the linear progress indicator in an indeterminate state.
mdc-linear-progress--closedHides the linear progress indicator.

Sass Mixins

MixinDescription
bar-color($color)Sets the color of the progress bar
buffer-color($color)Sets the color of the buffer bar and dots

Using the Foundation Class

MDC Linear Progress ships with an MDCLinearProgressFoundation class that external frameworks and libraries can use to integrate the component. As with all foundation classes, an adapter object must be provided. The adapter for linear progress must provide the following functions, with correct signatures:

Method SignatureDescription
addClass(className: string) => voidAdds a class to the root element.
removeAttribute(attributeName: string) => voidRemoves the specified attribute from the root element.
removeClass(className: string) => voidRemoves a class from the root element.
hasClass(className: string) => booleanReturns boolean indicating whether the root element has a given class.
forceLayout() => voidForce-trigger a layout on the root element. This is needed to restart animations correctly.
setAttribute(attributeName: string, value: string) => voidSets the specified attribute on the root element.
setBufferBarStyle(styleProperty: string, value: string) => voidSets the inline style on the buffer bar.
setPrimaryBarStyle(styleProperty: string, value: string) => voidSets the inline style on the primary bar.
attachResizeObserver(callback: ResizeObserverCallback) => ResizeObserver | nullReturns a ResizeObserver that has had observe called on the root with the given callback (for animation performance gains on modern browsers). null if ResizeObserver is not implemented or polyfilled.
setStyle(styleProperty: string, value: string) => voidSets the inline style on the root element.
getWidth() => numberReturns the width of the root.

MDCLinearProgressFoundation API

MDC Linear Progress Foundation exposes the following methods:

Method SignatureDescription
setDeterminate(value: boolean) => voidToggles the component between the determinate and indeterminate state.
isDeterminate() => booleanWhether or not the component is in determinate state.
setProgress(value: number) => voidSets the progress bar to this value. Value should be between [0, 1].
getProgress() => numberThe current progress value in the interval [0,1].
setBuffer(value: number) => voidSets the buffer bar to this value. Value should be between [0, 1].
getBuffer() => numberThe current buffer value in the interval [0,1].
open() => voidPuts the component in the open state.
close() => voidPuts the component in the closed state.
isClosed() => booleanWhether or not the progress indicator is closed.

MDCLinearProgress API

MDC Linear Progress exposes the following methods:

Method SignatureDescription
set determinate(value: boolean) => voidToggles the component between the determinate and indeterminate state.
set progress(value: number) => voidSets the progress bar to this value. Value should be between [0, 1].
set buffer(value: number) => voidSets the buffer bar to this value. Value should be between [0, 1].
open() => voidPuts the component in the open state.
close() => voidPuts the component in the closed state.

Keywords

material components

FAQs

Package last updated on 06 Jul 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts