OLD | NEW |
1 <!-- | 1 <!-- |
2 Copyright (c) 2014 The Polymer Project Authors. All rights reserved. | 2 Copyright (c) 2014 The Polymer Project Authors. All rights reserved. |
3 This code may only be used under the BSD style license found at http://polymer.g
ithub.io/LICENSE.txt | 3 This code may only be used under the BSD style license found at http://polymer.g
ithub.io/LICENSE.txt |
4 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt | 4 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt |
5 The complete set of contributors may be found at http://polymer.github.io/CONTRI
BUTORS.txt | 5 The complete set of contributors may be found at http://polymer.github.io/CONTRI
BUTORS.txt |
6 Code distributed by Google as part of the polymer project is also | 6 Code distributed by Google as part of the polymer project is also |
7 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS.txt | 7 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS.txt |
8 --> | 8 --> |
9 | 9 |
10 <!-- | 10 <!-- |
(...skipping 12 matching lines...) Expand all Loading... |
23 <paper-button noink>No ripple effect</paper-button> | 23 <paper-button noink>No ripple effect</paper-button> |
24 | 24 |
25 You may use custom DOM in the button body to create a variety of buttons. For ex
ample, to | 25 You may use custom DOM in the button body to create a variety of buttons. For ex
ample, to |
26 create a button with an icon and some text: | 26 create a button with an icon and some text: |
27 | 27 |
28 <paper-button> | 28 <paper-button> |
29 <core-icon icon="favorite"></core-icon> | 29 <core-icon icon="favorite"></core-icon> |
30 custom button content | 30 custom button content |
31 </paper-button> | 31 </paper-button> |
32 | 32 |
33 Styling | 33 ## Styling |
34 ------- | |
35 | 34 |
36 Style the button with CSS as you would a normal DOM element. | 35 Style the button with CSS as you would a normal DOM element. |
37 | 36 |
38 /* make #my-button green with yellow text */ | 37 /* make #my-button green with yellow text */ |
39 #my-button { | 38 #my-button { |
40 background: green; | 39 background: green; |
41 color: yellow; | 40 color: yellow; |
42 } | 41 } |
43 | 42 |
44 By default, the ripple is the same color as the foreground at 25% opacity. You m
ay | 43 By default, the ripple is the same color as the foreground at 25% opacity. You m
ay |
45 customize the color using this selector: | 44 customize the color using this selector: |
46 | 45 |
47 /* make #my-button use a blue ripple instead of foreground color */ | 46 /* make #my-button use a blue ripple instead of foreground color */ |
48 #my-button::shadow #ripple { | 47 #my-button::shadow #ripple { |
49 color: blue; | 48 color: blue; |
50 } | 49 } |
51 | 50 |
52 The opacity of the ripple is not customizable via CSS. | 51 The opacity of the ripple is not customizable via CSS. |
53 | 52 |
54 @element paper-button | 53 @element paper-button |
55 @extends paper-button-base | 54 @extends paper-button-base |
56 @status unstable | 55 @status unstable |
57 --> | 56 --> |
58 | 57 |
59 <link href="../polymer/polymer.html" rel="import"> | 58 <link href="../polymer/polymer.html" rel="import"> |
60 <link href="../paper-shadow/paper-shadow.html" rel="import"> | 59 <link href="../paper-shadow/paper-shadow.html" rel="import"> |
| 60 <link href="../core-a11y-keys/core-a11y-keys.html" rel="import"> |
61 | 61 |
62 <link href="paper-button-base.html" rel="import"> | 62 <link href="paper-button-base.html" rel="import"> |
63 | 63 |
64 <polymer-element name="paper-button" extends="paper-button-base" attributes="rai
sed recenteringTouch fill" | 64 <polymer-element name="paper-button" extends="paper-button-base" attributes="rai
sed recenteringTouch fill" |
65 role="button"> | 65 role="button"> |
66 | 66 |
67 <template> | 67 <template> |
68 | 68 |
69 <style> | 69 <style> |
70 | 70 |
(...skipping 21 matching lines...) Expand all Loading... |
92 background: #eaeaea; | 92 background: #eaeaea; |
93 color: #a8a8a8; | 93 color: #a8a8a8; |
94 cursor: auto; | 94 cursor: auto; |
95 pointer-events: none; | 95 pointer-events: none; |
96 } | 96 } |
97 | 97 |
98 ::content * { | 98 ::content * { |
99 text-transform: inherit; | 99 text-transform: inherit; |
100 } | 100 } |
101 | 101 |
102 #shadow { | 102 #bg, #shadow { |
103 border-radius: inherit; | 103 border-radius: inherit; |
104 } | 104 } |
105 | 105 |
106 #ripple { | 106 #ripple { |
107 pointer-events: none; | 107 pointer-events: none; |
108 z-index: -1; | 108 z-index: -1; |
109 } | 109 } |
110 | 110 |
111 .button-content { | 111 .button-content { |
112 padding: 0.7em 0.57em | 112 padding: 0.7em 0.57em |
113 } | 113 } |
114 | 114 |
115 polyfill-next-selector { content: '.button-content > a'; } | 115 polyfill-next-selector { content: '.button-content > a'; } |
116 ::content > a { | 116 ::content > a { |
117 height: 100%; | 117 height: 100%; |
118 padding: 0.7em 0.57em; | 118 padding: 0.7em 0.57em; |
| 119 margin: -0.7em -0.57em; |
119 /* flex */ | 120 /* flex */ |
120 -ms-flex: 1 1 0.000000001px; | 121 -ms-flex: 1 1 0.000000001px; |
121 -webkit-flex: 1; | 122 -webkit-flex: 1; |
122 flex: 1; | 123 flex: 1; |
123 -webkit-flex-basis: 0.000000001px; | 124 -webkit-flex-basis: 0.000000001px; |
124 flex-basis: 0.000000001px; | 125 flex-basis: 0.000000001px; |
125 } | 126 } |
126 | 127 |
127 </style> | 128 </style> |
128 | 129 |
129 <template if="{{raised}}"> | 130 <template if="{{raised}}"> |
130 <paper-shadow id="shadow" fit animated></paper-shadow> | 131 <paper-shadow id="shadow" fit animated></paper-shadow> |
131 </template> | 132 </template> |
132 | 133 |
133 <!-- this div is needed to position the ripple behind text content --> | 134 <!-- this div is needed to position the ripple behind text content --> |
134 <div class="button-content" relative layout horizontal center-center> | 135 <div class="button-content" relative layout horizontal center-center> |
135 <content></content> | 136 <content></content> |
136 </div> | 137 </div> |
137 | 138 |
| 139 <core-a11y-keys keys="space enter" target="{{}}" on-keys-pressed="{{_activat
e}}"></core-a11y-keys> |
| 140 |
138 </template> | 141 </template> |
139 | 142 |
140 <script> | 143 <script> |
141 Polymer({ | 144 Polymer({ |
142 | 145 |
143 publish: { | 146 publish: { |
144 | 147 |
145 /** | 148 /** |
146 * If true, the button will be styled with a shadow. | 149 * If true, the button will be styled with a shadow. |
147 * | 150 * |
(...skipping 16 matching lines...) Expand all Loading... |
164 /** | 167 /** |
165 * By default the ripple expands to fill the button. Set this to true to | 168 * By default the ripple expands to fill the button. Set this to true to |
166 * constrain the ripple to a circle within the button. | 169 * constrain the ripple to a circle within the button. |
167 * | 170 * |
168 * @attribute fill | 171 * @attribute fill |
169 * @type boolean | 172 * @type boolean |
170 * @default true | 173 * @default true |
171 */ | 174 */ |
172 fill: true | 175 fill: true |
173 | 176 |
| 177 }, |
| 178 |
| 179 _activate: function() { |
| 180 this.click(); |
| 181 this.fire('tap'); |
| 182 if (!this.pressed) { |
| 183 var bcr = this.getBoundingClientRect(); |
| 184 var x = bcr.left + (bcr.width / 2); |
| 185 var y = bcr.top + (bcr.height / 2); |
| 186 this.downAction({x: x, y: y}); |
| 187 var fn = function fn() { |
| 188 this.upAction(); |
| 189 this.removeEventListener('keyup', fn); |
| 190 }.bind(this); |
| 191 this.addEventListener('keyup', fn); |
| 192 } |
174 } | 193 } |
175 | 194 |
176 }); | 195 }); |
177 </script> | 196 </script> |
178 </polymer-element> | 197 </polymer-element> |
OLD | NEW |