Socket
Socket
Sign inDemoInstall

@material/button

Package Overview
Dependencies
Maintainers
11
Versions
1701
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@material/button

The Material Components for the web button component


Version published
Weekly downloads
713K
decreased by-20%
Maintainers
11
Weekly downloads
 
Created
Source

Buttons

The MDC Button component is a spec-aligned button component adhering to the Material Design button requirements. It works without JavaScript with basic functionality for all states. You can enhance the button to have ripple effects by instantiating MDCRipple on the button element. See MDC Ripple and Demo for details.

Design & API Documentation

Installation

npm install --save @material/button

Usage

HTML Structure

<button class="mdc-button">
  Button
</button>

Note: Examples and documents use generic <button>, but users can also apply mdc-button to <a class="mdc-button">Link Button</a> in cases where it is semantically correct.

Adding Icon

Users can nest mdc-button__icon inside the button element to add an icon. The icon in button is set to 18px to meet legibility requirements.

We recommend you load Material Icons from Google Fonts

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

<button class="mdc-button">
  <i class="material-icons mdc-button__icon">favorite</i>
  Button
</button>

CSS Classes

CSS ClassDescription
mdc-buttonMandatory, defaults to a text button that is flush with the surface
mdc-button__iconOptional, for the icon element
mdc-button--raisedOptional, a contained button that is elevated upon the surface
mdc-button--unelevatedOptional, a contained button that is flush with the surface
mdc-button--strokedOptional, a contained button that is flush with the surface and has a visible border
mdc-button--denseOptional, compresses the button text to make it slightly smaller
mdc-button--compactOptional, reduces the amount of horizontal padding in the button

Disabled Button

Users can add disabled directly to the button element or set the fieldset containing the button to disabled to disable a button. Disabled buttons cannot be interacted with and have no visual interaction effect.

<button class="mdc-button mdc-button--raised" disabled>
  Raised disabled button
</button>

Adding MDC Ripple

To add the ink ripple effect to a button, attach a ripple instance to the button element.

mdc.ripple.MDCRipple.attachTo(document.querySelector('.mdc-button'));

You can also do this declaratively when using the material-components-web package.

<button class="mdc-button" data-mdc-auto-init="MDCRipple">
  Flat button
</button>

Buttons are fully aware of ripple styles, so no DOM or CSS changes are required to use them.

Sass Mixins

By default an MDC Button will inherit its color from the theme and align with Material Design button requirements. To customize a Button's color and properties, you can use the following mixins.

mdc-button-filled-accessible($container-fill-color)

This mixin is provided for customizing a raised or unelevated button's color. It changes the Button's container color to the given color, and updates the Button's ink and ripple color to meet accessibility standards.

Advanced Sass Mixins

A note about advanced mixins, The following mixins are intended for advanced users. These mixins will override the color of the container, ink, stroke or ripple. You can use all of them if you want to completely customize a Button. Or you can use only one of them, e.g. if you only need to override the ripple color. It is up to you to pick container, ink, stroke and ripple colors that work together, and meet accessibility standards.

MixinDescription
mdc-button-container-fill-colorSets the container color to the given color
mdc-button-ink-colorSets the ink color to the given color
mdc-button-stroke-colorSets the stroke color to the given color
mdc-button-corner-radiusSets the corner radius to the given number (defaults to 2px)
mdc-button-stroke-widthSets the stroke width to the given number (defaults to 2px)

The ripple effect for the Button component is styled using MDC Ripple mixins.

Caveat: Edge and CSS Variables

In browsers that fully support CSS variables, the above mixins will hook up styles using CSS variables if a theme property is passed. However, due to Edge's buggy CSS variable support, mdc-button-container-fill-color will not honor CSS variables in Edge. This means you will need to override button container styles manually for Edge if you are altering the affected CSS variables for theme properties (raised and unelevated buttons use primary by default for the container fill color).

Keywords

FAQs

Package last updated on 20 Feb 2018

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc