xref: /aosp_15_r20/external/chromium-trace/catapult/third_party/polymer/components/paper-fab/paper-fab.html (revision 1fa4b3da657c0e9ad43c0220bacf9731820715a5)
1<!--
2@license
3Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
4This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
5The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
6The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
7Code distributed by Google as part of the polymer project is also
8subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
9-->
10
11<link rel="import" href="../polymer/polymer.html">
12<link rel="import" href="../iron-flex-layout/iron-flex-layout.html">
13<link rel="import" href="../iron-icon/iron-icon.html">
14<link rel="import" href="../paper-behaviors/paper-button-behavior.html">
15<link rel="import" href="../paper-material/paper-material-shared-styles.html">
16<link rel="import" href="../paper-styles/color.html">
17<link rel="import" href="../paper-styles/default-theme.html">
18
19<!--
20Material design: [Floating Action Button](https://www.google.com/design/spec/components/buttons-floating-action-button.html)
21
22`paper-fab` is a floating action button. It contains an image placed in the center and
23comes in two sizes: regular size and a smaller size by applying the attribute `mini`. When
24the user touches the button, a ripple effect emanates from the center of the button.
25
26You may import `iron-icons` to use with this element, or provide a URL to a custom icon.
27See `iron-iconset` for more information about how to use a custom icon set.
28
29Example:
30
31    <link href="path/to/iron-icons/iron-icons.html" rel="import">
32
33    <paper-fab icon="add"></paper-fab>
34    <paper-fab mini icon="favorite"></paper-fab>
35    <paper-fab src="star.png"></paper-fab>
36
37
38### Styling
39
40The following custom properties and mixins are available for styling:
41
42Custom property | Description | Default
43----------------|-------------|----------
44`--paper-fab-background` | The background color of the button | `--accent-color`
45`--paper-fab-keyboard-focus-background` | The background color of the button when focused | `--paper-pink-900`
46`--paper-fab-disabled-background` | The background color of the button when it's disabled | `--paper-grey-300`
47`--paper-fab-disabled-text` | The text color of the button when it's disabled | `--paper-grey-500`
48`--paper-fab` | Mixin applied to the button | `{}`
49`--paper-fab-mini` | Mixin applied to a mini button | `{}`
50`--paper-fab-disabled` | Mixin applied to a disabled button | `{}`
51`--paper-fab-iron-icon` | Mixin applied to the iron-icon within the button | `{}`
52`--paper-fab-label` | Mixin applied to the label within the button | `{}`
53
54@group Paper Elements
55@demo demo/index.html
56-->
57
58<dom-module id="paper-fab">
59  <template strip-whitespace>
60    <style include="paper-material-shared-styles">
61      :host {
62        @apply(--layout-vertical);
63        @apply(--layout-center-center);
64
65        background: var(--paper-fab-background, --accent-color);
66        border-radius: 50%;
67        box-sizing: border-box;
68        color: var(--text-primary-color);
69        cursor: pointer;
70        height: 56px;
71        min-width: 0;
72        outline: none;
73        padding: 16px;
74        position: relative;
75        -moz-user-select: none;
76        -ms-user-select: none;
77        -webkit-user-select: none;
78        user-select: none;
79        width: 56px;
80        z-index: 0;
81
82        /* NOTE: Both values are needed, since some phones require the value `transparent`. */
83        -webkit-tap-highlight-color: rgba(0,0,0,0);
84        -webkit-tap-highlight-color: transparent;
85
86        @apply(--paper-fab);
87      }
88
89      [hidden] {
90        display: none !important;
91      }
92
93      :host([mini]) {
94        width: 40px;
95        height: 40px;
96        padding: 8px;
97
98        @apply(--paper-fab-mini);
99      }
100
101      :host([disabled]) {
102        color: var(--paper-fab-disabled-text, --paper-grey-500);
103        background: var(--paper-fab-disabled-background, --paper-grey-300);
104
105        @apply(--paper-fab-disabled);
106      }
107
108      iron-icon {
109        @apply(--paper-fab-iron-icon);
110      }
111
112      span {
113        width: 100%;
114        white-space: nowrap;
115        overflow: hidden;
116        text-overflow: ellipsis;
117        text-align: center;
118
119        @apply(--paper-fab-label);
120      }
121
122      :host(.keyboard-focus) {
123        background: var(--paper-fab-keyboard-focus-background, --paper-pink-900);
124      }
125    </style>
126
127    <iron-icon id="icon" hidden$="{{!_computeIsIconFab(icon, src)}}" src="[[src]]" icon="[[icon]]"></iron-icon>
128    <span hidden$="{{_computeIsIconFab(icon, src)}}">{{label}}</span>
129  </template>
130
131  <script>
132    Polymer({
133      is: 'paper-fab',
134
135      behaviors: [
136        Polymer.PaperButtonBehavior
137      ],
138
139      properties: {
140        /**
141         * The URL of an image for the icon. If the src property is specified,
142         * the icon property should not be.
143         */
144        src: {
145          type: String,
146          value: ''
147        },
148
149        /**
150         * Specifies the icon name or index in the set of icons available in
151         * the icon's icon set. If the icon property is specified,
152         * the src property should not be.
153         */
154        icon: {
155          type: String,
156          value: ''
157        },
158
159        /**
160         * Set this to true to style this is a "mini" FAB.
161         */
162        mini: {
163          type: Boolean,
164          value: false,
165          reflectToAttribute: true
166        },
167
168        /**
169         * The label displayed in the badge. The label is centered, and ideally
170         * should have very few characters.
171         */
172        label: {
173          type: String,
174          observer: '_labelChanged'
175        }
176      },
177
178      _labelChanged: function() {
179        this.setAttribute('aria-label', this.label);
180      },
181
182      _computeIsIconFab: function(icon, src) {
183        return (icon.length > 0) || (src.length > 0);
184      }
185    });
186  </script>
187</dom-module>
188