OLD | NEW |
1 <!-- | 1 <!-- |
2 @license | 2 @license |
3 Copyright (c) 2015 The Polymer Project Authors. All rights reserved. | 3 Copyright (c) 2015 The Polymer Project Authors. All rights reserved. |
4 This code may only be used under the BSD style license found at http://polymer.g
ithub.io/LICENSE | 4 This code may only be used under the BSD style license found at http://polymer.g
ithub.io/LICENSE |
5 The complete set of authors may be found at http://polymer.github.io/AUTHORS | 5 The complete set of authors may be found at http://polymer.github.io/AUTHORS |
6 The complete set of contributors may be found at http://polymer.github.io/CONTRI
BUTORS | 6 The complete set of contributors may be found at http://polymer.github.io/CONTRI
BUTORS |
7 Code distributed by Google as part of the polymer project is also | 7 Code distributed by Google as part of the polymer project is also |
8 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS | 8 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS |
9 --> | 9 --> |
10 | 10 |
11 <link rel="import" href="../polymer/polymer.html"> | 11 <link rel="import" href="../polymer/polymer.html"> |
12 <link rel="import" href="../iron-icon/iron-icon.html"> | 12 <link rel="import" href="../iron-icon/iron-icon.html"> |
13 <link rel="import" href="../iron-flex-layout/iron-flex-layout.html"> | 13 <link rel="import" href="../iron-flex-layout/iron-flex-layout.html"> |
14 <link rel="import" href="../paper-styles/default-theme.html"> | 14 <link rel="import" href="../paper-styles/default-theme.html"> |
15 <link rel="import" href="../paper-behaviors/paper-button-behavior.html"> | 15 <link rel="import" href="../paper-behaviors/paper-button-behavior.html"> |
16 <link rel="import" href="../paper-behaviors/paper-inky-focus-behavior.html"> | 16 <link rel="import" href="../paper-behaviors/paper-inky-focus-behavior.html"> |
17 <link rel="import" href="../paper-ripple/paper-ripple.html"> | 17 <link rel="import" href="../paper-ripple/paper-ripple.html"> |
18 | 18 |
19 <!-- | 19 <!-- |
20 Material Design: <a href="http://www.google.com/design/spec/components/buttons.h
tml">Buttons</a> | 20 Material design: [Icon toggles](https://www.google.com/design/spec/components/bu
ttons.html#buttons-toggle-buttons) |
21 | 21 |
22 `paper-icon-button` is a button with an image placed at the center. When the use
r touches | 22 `paper-icon-button` is a button with an image placed at the center. When the use
r touches |
23 the button, a ripple effect emanates from the center of the button. | 23 the button, a ripple effect emanates from the center of the button. |
24 | 24 |
25 `paper-icon-button` includes a default icon set. Use `icon` to specify which ic
on | 25 `paper-icon-button` includes a default icon set. Use `icon` to specify which ic
on |
26 from the icon set to use. | 26 from the icon set to use. |
27 | 27 |
28 <paper-icon-button icon="menu"></paper-icon-button> | 28 <paper-icon-button icon="menu"></paper-icon-button> |
29 | 29 |
30 See [`iron-iconset`](#iron-iconset) for more information about | 30 See [`iron-iconset`](#iron-iconset) for more information about |
31 how to use a custom icon set. | 31 how to use a custom icon set. |
32 | 32 |
33 Example: | 33 Example: |
34 | 34 |
35 <link href="path/to/iron-icons/iron-icons.html" rel="import"> | 35 <link href="path/to/iron-icons/iron-icons.html" rel="import"> |
36 | 36 |
37 <paper-icon-button icon="favorite"></paper-icon-button> | 37 <paper-icon-button icon="favorite"></paper-icon-button> |
38 <paper-icon-button src="star.png"></paper-icon-button> | 38 <paper-icon-button src="star.png"></paper-icon-button> |
39 | 39 |
40 ###Styling | 40 ### Styling |
41 | 41 |
42 Style the button with CSS as you would a normal DOM element. If you are using th
e icons | 42 Style the button with CSS as you would a normal DOM element. If you are using th
e icons |
43 provided by `iron-icons`, they will inherit the foreground color of the button. | 43 provided by `iron-icons`, they will inherit the foreground color of the button. |
44 | 44 |
45 /* make a red "favorite" button */ | 45 /* make a red "favorite" button */ |
46 <paper-icon-button icon="favorite" style="color: red;"></paper-icon-button> | 46 <paper-icon-button icon="favorite" style="color: red;"></paper-icon-button> |
47 | 47 |
48 By default, the ripple is the same color as the foreground at 25% opacity. You m
ay | 48 By default, the ripple is the same color as the foreground at 25% opacity. You m
ay |
49 customize the color using this selector: | 49 customize the color using the `--paper-icon-button-ink-color` custom property. |
50 | |
51 /* make #my-button use a blue ripple instead of foreground color */ | |
52 #my-button::shadow #ripple { | |
53 color: blue; | |
54 } | |
55 | |
56 The opacity of the ripple is not customizable via CSS. | |
57 | 50 |
58 The following custom properties and mixins are available for styling: | 51 The following custom properties and mixins are available for styling: |
59 | 52 |
60 Custom property | Description | Default | 53 Custom property | Description | Default |
61 ----------------|-------------|---------- | 54 ----------------|-------------|---------- |
62 `--paper-icon-button-disabled-text` | The color of the disabled button | `--prim
ary-text-color` | 55 `--paper-icon-button-disabled-text` | The color of the disabled button | `--disa
bled-text-color` |
63 `--paper-icon-button-ink-color` | Selected/focus ripple color | `--default-prima
ry-color` | 56 `--paper-icon-button-ink-color` | Selected/focus ripple color | `--primary-text-
color` |
64 `--paper-icon-button` | Mixin for a button | `{}` | 57 `--paper-icon-button` | Mixin for a button | `{}` |
65 `--paper-icon-button-disabled` | Mixin for a disabled button | `{}` | 58 `--paper-icon-button-disabled` | Mixin for a disabled button | `{}` |
66 | 59 |
67 @group Paper Elements | 60 @group Paper Elements |
68 @element paper-icon-button | 61 @element paper-icon-button |
69 @demo demo/index.html | 62 @demo demo/index.html |
70 --> | 63 --> |
71 | 64 |
72 <dom-module id="paper-icon-button"> | 65 <dom-module id="paper-icon-button"> |
73 <style> | 66 <template strip-whitespace> |
| 67 <style> |
| 68 :host { |
| 69 display: inline-block; |
| 70 position: relative; |
| 71 padding: 8px; |
| 72 outline: none; |
| 73 -webkit-tap-highlight-color: rgba(0,0,0,0); |
| 74 -webkit-user-select: none; |
| 75 -moz-user-select: none; |
| 76 -ms-user-select: none; |
| 77 user-select: none; |
| 78 cursor: pointer; |
| 79 z-index: 0; |
| 80 line-height: 1; |
| 81 |
| 82 width: 40px; |
| 83 height: 40px; |
74 | 84 |
75 :host { | 85 /* Because of polymer/2558, this style has lower specificity than * */ |
76 display: inline-block; | 86 box-sizing: border-box !important; |
77 position: relative; | 87 @apply(--paper-icon-button); |
78 padding: 8px; | 88 } |
79 outline: none; | |
80 -webkit-tap-highlight-color: rgba(0,0,0,0); | |
81 -webkit-user-select: none; | |
82 -moz-user-select: none; | |
83 -ms-user-select: none; | |
84 user-select: none; | |
85 cursor: pointer; | |
86 z-index: 0; | |
87 | 89 |
88 @apply(--paper-icon-button); | 90 :host #ink { |
89 } | 91 color: var(--paper-icon-button-ink-color, --primary-text-color); |
| 92 opacity: 0.6; |
| 93 } |
90 | 94 |
91 :host #ink { | 95 :host([disabled]) { |
92 color: var(--paper-icon-button-ink-color, --primary-text-color); | 96 color: var(--paper-icon-button-disabled-text, --disabled-text-color); |
93 opacity: 0.6; | 97 pointer-events: none; |
94 } | 98 cursor: auto; |
| 99 @apply(--paper-icon-button-disabled); |
| 100 } |
95 | 101 |
96 :host([disabled]) { | 102 iron-icon { |
97 color: var(--paper-icon-button-disabled-text, --disabled-text-color); | 103 --iron-icon-width: 100%; |
98 pointer-events: none; | 104 --iron-icon-height: 100%; |
99 cursor: auto; | 105 } |
100 @apply(--paper-icon-button-disabled); | 106 </style> |
101 } | |
102 </style> | |
103 <template> | |
104 <paper-ripple id="ink" class="circle" center></paper-ripple> | |
105 <iron-icon id="icon" src="[[src]]" icon="[[icon]]" alt$="[[alt]]"></iron-ico
n> | 107 <iron-icon id="icon" src="[[src]]" icon="[[icon]]" alt$="[[alt]]"></iron-ico
n> |
106 </template> | 108 </template> |
107 </dom-module> | |
108 <script> | |
109 Polymer({ | |
110 is: 'paper-icon-button', | |
111 | 109 |
112 hostAttributes: { | 110 <script> |
113 role: 'button', | 111 Polymer({ |
114 tabindex: '0' | 112 is: 'paper-icon-button', |
115 }, | |
116 | 113 |
117 behaviors: [ | 114 hostAttributes: { |
118 Polymer.PaperInkyFocusBehavior | 115 role: 'button', |
119 ], | 116 tabindex: '0' |
120 | |
121 properties: { | |
122 /** | |
123 * The URL of an image for the icon. If the src property is specified, | |
124 * the icon property should not be. | |
125 */ | |
126 src: { | |
127 type: String | |
128 }, | 117 }, |
129 | 118 |
130 /** | 119 behaviors: [ |
131 * Specifies the icon name or index in the set of icons available in | 120 Polymer.PaperInkyFocusBehavior |
132 * the icon's icon set. If the icon property is specified, | 121 ], |
133 * the src property should not be. | 122 |
134 */ | 123 properties: { |
135 icon: { | 124 /** |
136 type: String | 125 * The URL of an image for the icon. If the src property is specified, |
| 126 * the icon property should not be. |
| 127 */ |
| 128 src: { |
| 129 type: String |
| 130 }, |
| 131 |
| 132 /** |
| 133 * Specifies the icon name or index in the set of icons available in |
| 134 * the icon's icon set. If the icon property is specified, |
| 135 * the src property should not be. |
| 136 */ |
| 137 icon: { |
| 138 type: String |
| 139 }, |
| 140 |
| 141 /** |
| 142 * Specifies the alternate text for the button, for accessibility. |
| 143 */ |
| 144 alt: { |
| 145 type: String, |
| 146 observer: "_altChanged" |
| 147 } |
137 }, | 148 }, |
138 | 149 |
139 /** | 150 _altChanged: function(newValue, oldValue) { |
140 * Specifies the alternate text for the button, for accessibility. | 151 var label = this.getAttribute('aria-label'); |
141 */ | 152 |
142 alt: { | 153 // Don't stomp over a user-set aria-label. |
143 type: String, | 154 if (!label || oldValue == label) { |
144 observer: "_altChanged" | 155 this.setAttribute('aria-label', newValue); |
| 156 } |
145 } | 157 } |
146 }, | 158 }); |
147 | 159 </script> |
148 _altChanged: function(newValue, oldValue) { | 160 </dom-module> |
149 var label = this.getAttribute('aria-label'); | |
150 | |
151 // Don't stomp over a user-set aria-label. | |
152 if (!label || oldValue == label) { | |
153 this.setAttribute('aria-label', newValue); | |
154 } | |
155 } | |
156 }); | |
157 </script> | |
OLD | NEW |