0.27.0 • Published 2 years ago

@material/mwc-fab v0.27.0

Weekly downloads
3,628
License
Apache-2.0
Repository
github
Last release
2 years ago

<mwc-fab> Published on npm

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

A floating action button (FAB) represents the primary action of a screen.

npm.io npm.io npm.io npm.io

Material Design Guidelines: Floating Action Button

Demo

Installation

npm install @material/mwc-fab

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

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

<mwc-fab icon="edit"></mwc-fab>

<script type="module">
  import '@material/mwc-fab/mwc-fab.js';
  const fab = document.querySelector('mwc-fab');
  fab.addEventListener('click', () => {
    edit();
  });
</script>

Standard - slotted

npm.io

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

<mwc-fab label="edit">
  <mwc-icon slot="icon">edit</mwc-icon>
</mwc-fab>

<script type="module">
  import '@material/mwc-fab/mwc-fab.js';
  import '@material/mwc-icon/mwc-icon.js';
</script>

Note: label should still be set for button accessibility purposes.

Mini

npm.io

<mwc-fab mini icon="add"></mwc-fab>

Extended

npm.io

<mwc-fab extended icon="shopping_cart" label="Add to cart"></mwc-fab>

Customize colors

npm.io

mwc-fab {
  --mdc-theme-secondary: white;
  --mdc-theme-on-secondary: black;
}

API

Slots

NameDescription
iconAn icon to be slotted into the fab. Note: the label property should still be set for button accessibility.

Properties/Attributes

NameTypeDescription
iconstringThe icon to display.
labelstringThe label to display when using the extended layout, and the aria-label attribute in all layouts.
minibooleanModifies the FAB to be a smaller size, for use on smaller screens. Defaults to false.
reducedTouchTargetbooleanSets the minimum touch target of the default-sized mini fab to recommended 48x48px.
extendedbooleanEnable the extended layout which includes a text label. Defaults to false.
showIconAtEndbooleanWhen in the extended layout, position the icon after the label, instead of before. Defaults to false.

Methods

None

Events

None

CSS Custom Properties

NameDefaultDescription
--mdc-fab-box-shadowmdc elevation 6, 8, 12Sets the box shadow of the fab. Elevation 6 when idle, 8 when focused or hovered, and 12 when active.
--mdc-fab-extended-label-padding20pxSets the padding on either horizontal side of an extended fab.
--mdc-fab-extended-icon-padding12pxSets the padding between the icon and the label of an extended fab.
--mdc-fab-focus-outline-colorinitialThe color of the focus outline ring (off by default).
--mdc-fab-focus-outline-width0pxSets the width of the focus outline ring.

Elevation values

Elevation LevelCSS Value
60px 3px 5px -1px rgba(0, 0, 0, 0.2), 0px 6px 10px 0px rgba(0, 0, 0, 0.14), 0px 1px 18px 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)
120px 7px 8px -4px rgba(0, 0, 0, 0.2), 0px 12px 17px 2px rgba(0, 0, 0, 0.14), 0px 5px 22px 4px rgba(0, 0, 0, 0.12)

Global Custom Properties

This component exposes the following global theming custom properties.

NameDescription
--mdc-icon-fontFont to use for the icon.
--mdc-theme-secondaryBackground color of the FAB.
--mdc-theme-on-secondaryForeground color of the label and icon.

Additional references

0.27.0

2 years ago

0.26.1

2 years ago

0.26.0

2 years ago

0.25.3

3 years ago

0.25.2

3 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.22.0

3 years ago

0.21.0

3 years ago

0.20.0

3 years ago

0.19.1

4 years ago

0.19.0

4 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

5 years ago

0.9.1

5 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

6 years ago

0.3.0

6 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