0.27.0 • Published 2 years ago

@material/mwc-button v0.27.0

Weekly downloads
7,786
License
Apache-2.0
Repository
github
Last release
2 years ago

<mwc-button> Published on npm

IMPORTANT: The Material Web Components are a work in progress and subject to major changes until 1.0 release.

Buttons allow users to take actions, and make choices, with a single tap.

Material Design Guidelines: Button

Demo

Installation

npm install @material/mwc-button

NOTE: The Material Web Components are distributed as ES2017 JavaScript Modules, and use the Custom Elements API. They are compatible with all modern browsers including Chrome, Firefox, Safari, Edge, and IE11, but an additional tooling step is required to resolve bare module specifiers, as well as transpilation and polyfills for IE11. See here for detailed instructions.

Example Usage

Standard

npm.io npm.io

<mwc-button label="standard"></mwc-button>
<mwc-button label="standard" icon="code"></mwc-button>

Outlined

npm.io npm.io

<mwc-button outlined label="outlined"></mwc-button>
<mwc-button outlined label="outlined" icon="code"></mwc-button>

Warning: Do not attempt to use multiple variant attributes on the same button to achieve intended styles. For example, <mwc-button raised outlined>. Doing so may subject you to future breaking changes. Instead, pick the single variant most appropriate for the use-case and write Sass to customize the buttons individually.

Raised

npm.io npm.io

<mwc-button raised label="raised"></mwc-button>
<mwc-button raised label="raised" icon="code"></mwc-button>

Unelevated

npm.io npm.io

<mwc-button unelevated label="unelevated"></mwc-button>
<mwc-button unelevated label="unelevated" icon="code"></mwc-button>

Dense

npm.io npm.io

<mwc-button dense unelevated label="dense"></mwc-button>
<mwc-button dense unelevated label="dense" icon="code"></mwc-button>

Trailing Icon

npm.io

<mwc-button label="trailing icon" icon="code" trailingIcon></mwc-button>

Disabled

npm.io npm.io

<mwc-button disabled label="disabled"></mwc-button>
<mwc-button disabled label="disabled" icon="code"></mwc-button>

Customize Colors

npm.io

mwc-button {
  --mdc-theme-primary: #e9437a;
  --mdc-theme-on-primary: white;
}

API

Slots

NameDescription
iconLeading icon. Overrides icon property. Use label or the icon property to set the aria-label.
trailingIconIcon to show after the label. Overrides trailingIcon property. Use label or the trailingIcon property to set the aria-label.
defaultDefault content to display between both icons and after label. NOTE: It is highly recommended to set the label property instead of projecting text as it will also set the aria-label

Properties/Attributes

NameTypeDefaultDescription
aria-haspopupstringundefinedIndicates the availability and type of an interactive popup element, such as menu or dialog, that can be triggered by the button.
iconstring''Icon to display, and aria-label value when label is not defined.
labelstring''Label to display for the button, and aria-label.
raisedbooleanfalseCreates a contained button that is elevated above the surface.
unelevatedbooleanfalseCreates a contained button that is flush with the surface.
outlinedbooleanfalseCreates an outlined button that is flush with the surface.
densebooleanfalseMakes the button text and container slightly smaller.
disabledbooleanfalseDisabled buttons cannot be interacted with and have no visual interaction effect.
trailingIconbooleanfalseWhen true, icon will be displayed after label.
expandContentbooleanfalseWhen true, the space after the label and before any trailing icon, where default slotted content is rendered, is expanded to fit the available space inside the button.
fullwidthbooleanfalseWhen true, the button is expanded to fit the entire available space.

Methods

None

Events

None

CSS Custom Properties

NameDefaultDescription
--mdc-button-horizontal-paddingfilled: 16px outlined: 15px default: 8pxLeft and right padding of the button label (for outlined buttons the outline width is automatically subtracted).
--mdc-button-outline-width1pxwidth of the outline of an outlined button and attempts to keep the component size constant.
--mdc-button-outline-colornpm.ioColor of the outline of an outlined element.
--mdc-button-disabled-fill-colornpm.io rgba(0,0,0,0.12)Background fill color of a disabled raised or unelevated button.
--mdc-button-disabled-ink-colornpm.io rgba(0,0,0,0.37)Text color of a disabled button as well as the outline color of a disabled outlined button.
--mdc-button-disabled-outline-colornpm.ioSets the color of the outline of a disabled outlined button.
--mdc-button-raised-box-shadowmdc elevation 2Sets the box shadow of the raised button.
--mdc-button-raised-box-shadow-hovermdc elevation 4Sets the box shadow of the raised button when focused or hovered.
--mdc-button-raised-box-shadow-focus--mdc-button-raised-box-shadow-hoverSets the box shadow of the raised button when focused. Note, if button is both focused and hovered, then hover will override focus box-shadow.
--mdc-button-raised-box-shadow-activemdc elevation 8Sets the box shadow of the raised button when active.
--mdc-button-raised-box-shadow-disabledmdc elevation 0Sets the box shadow of the raised button when disabled.

Global Custom Properties

This component exposes the following global theming custom properties.

NameDescription
--mdc-theme-primaryColor of a flat or outlined button. Background color of a raised button.
--mdc-theme-on-primaryText color of a raised button.
--mdc-icon-fontFont to use for the icon.
--mdc-typography-button-<PROPERTY>Styles the typography of the button label.

Elevation values

Elevation LevelCSS Value
20px 3px 1px -2px rgba(0, 0, 0, 0.2), 0px 2px 2px 0px rgba(0, 0, 0, 0.14), 0px 1px 5px 0px rgba(0, 0, 0, 0.12)
40px 2px 4px -1px rgba(0, 0, 0, 0.2), 0px 4px 5px 0px rgba(0, 0, 0, 0.14), 0px 1px 10px 0px rgba(0, 0, 0, 0.12)
80px 5px 5px -3px rgba(0, 0, 0, 0.2), 0px 8px 10px 1px rgba(0, 0, 0, 0.14), 0px 3px 14px 2px rgba(0, 0, 0, 0.12)
00px 0px 0px 0px rgba(0, 0, 0, 0.2), 0px 0px 0px 0px rgba(0, 0, 0, 0.14), 0px 0px 0px 0px rgba(0, 0, 0, 0.12)

Additional references

@material/mwc-dialogzagenzagen-productionyidotiny-stepperiso-elements@kr05/tiny-stepperbf-forms@glade-software/glade-annotateablesimplr-components@netzoio/web-components@mbsmebye/boligmappa-test@mbsmebye/wc-connect@mbsmebye/wc-search@cryptobash/kernelopenstamanager@everything-registry/sub-chunk-584@boluabraham/fhir-login@andy99316/andy_wc_poc@ascenso/crca-stepper@allenporter/recurrence-rule-editorapp-datepickerapp-datepicker-rtl@accordion/accordion-graphapp-datepicker-with-highlightcloudbees-casc-server-plugin-ui@batchforce/core@backlight-dev/aodocs.aodocs-design-system@binar/search-dialog@blackpurl/web-componentsbred-stencil-starter-project-name@bfchain/dweb-browser@bluetensor/annotatorboo-wysiwyg-e@boluabraham/fhir-new-patient@boluabraham/fhir-create-patient2@glade-software/glade-annotatableplayground-elementsplayground-elements-ashruhil-uirestu-garzon-virtualvve-breakoutvwc-dialeryew-material-scriptswhatsapp-buttonyido-elementsshadow-prototypetangy-form-editortaskana-workplace-libtasmota-esp-web-toolsstencil-web-elementssaby-customizerscoped-material-components@chain-lib/cardano-components@cortexcloud/cortex-ui-legacycorgy-frontend@dotcms/dotcms-uicortex-ui-legacy@dman777/lit-time-picker@dreamworld/dw-buttondaosmind@apollo-elements-demos/spacex-launches@equinor/fusion-wc-button@erixhens/annotator@exmg/test-exmg-button@frag-crypto/frag-default-plugins@holochain-open-dev/calendar-events@hass-ada/frontend-lite@hatiolab/things-shell@_lucky/app-datepicker@infinitebrahmanuniverse/nolb-_mate@iooxa/components@iooxa/ink-basicdirewolf-modelerdotcms-ui@dwane-vonage/cityjs-india@dwane-vonage/dwanes-keypad@dwane-vonage/whatever-you-like-keypad@eds-practice/service_practice@feezal/feezal-element-mwc-button@esui/material-components@finastra/chip@flatmax/lit-jrpc-node@flatmax/lit-jrpc-swig@dhruval/dk-button@jcdomber/grte-man-cat-menu@jcdomber/grte-tab-cat-menu@jrg-material/material@jsview/material-components@jrg/main-ui-private@jrg/ubuntu-ui@leavittsoftware/leavittbook@leavittsoftware/profile-picture@leavittsoftware/titanium-address-input@leavittsoftware/titanium-card@leavittsoftware/titanium-dialog@leavittsoftware/leavitt-elements@leavittsoftware/leavitt-file-explorer@leavittsoftware/titanium-image-input@leavittsoftware/titanium-show-hide@leavittsoftware/titanium-smart-attachment-input
0.27.0

2 years ago

0.26.1

2 years ago

0.26.0

2 years ago

0.25.3

2 years ago

0.25.2

2 years ago

0.25.1

3 years ago

0.25.0

3 years ago

0.23.0

3 years ago

0.22.1

3 years ago

0.21.0

3 years ago

0.20.0

3 years ago

0.19.1

3 years ago

0.19.0

3 years ago

0.18.0

4 years ago

0.17.2

4 years ago

0.17.0

4 years ago

0.16.1

4 years ago

0.15.0

4 years ago

0.14.1

4 years ago

0.14.0

4 years ago

0.13.0

4 years ago

0.12.0

4 years ago

0.11.1

4 years ago

0.11.0

4 years ago

0.10.0

4 years ago

0.9.1

4 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.0

5 years ago

0.5.0

5 years ago

0.4.0

5 years ago

0.3.6

5 years ago

0.3.5

5 years ago

0.3.4

5 years ago

0.3.3

5 years ago

0.3.2

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago