material-web/packages/fab
2019-08-15 14:51:43 -07:00
..
images New README for mwc-fab. 2019-08-12 18:30:20 -07:00
src Extends ESLint from @typescript-eslint (#371) 2019-08-15 14:51:43 -07:00
.npmignore Add an .npmignore to every package. 2019-08-13 10:24:31 -07:00
package.json chore: add repository.directory in package.json for all packages 2019-07-17 00:54:39 +03:00
README.md New README for mwc-fab. 2019-08-12 18:30:20 -07:00
tsconfig.json Update dependencies 2019-04-04 15:36:55 -07:00

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

Material Design Guidelines: Floating Action Button

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 Edge and IE11. See here for detailed instructions.

Example usage

Standard

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

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

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

Mini

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

Extended

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

Customize colors

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

API

Slots

None

Properties/Attributes

Name Type Description
icon string The icon to display.
label string The label to display when using the extended layout, and the aria-label attribute in all layouts.
mini boolean Modifies the FAB to be a smaller size, for use on smaller screens. Defaults to false.
extended boolean Enable the extended layout which includes a text label. Defaults to false.
showIconAtEnd boolean When in the extended layout, position the icon after the label, instead of before. Defaults to false.

Methods

None

Events

None

CSS Custom Properties

Name Default Description
--mdc-icon-font Material Icons Font to use for the icon.
--mdc-theme-on-secondary #ffffff Foreground color of the label and icon.
--mdc-theme-secondary #018786 Background color of the FAB.

Additional references