| 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.txt | 4 This code may only be used under the BSD style license found at http://polymer.g
ithub.io/LICENSE.txt |
| 5 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt | 5 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt |
| 6 The complete set of contributors may be found at http://polymer.github.io/CONTRI
BUTORS.txt | 6 The complete set of contributors may be found at http://polymer.github.io/CONTRI
BUTORS.txt |
| 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.txt | 8 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS.txt |
| 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-flex-layout/iron-flex-layout.html"> |
| 12 <link rel="import" href="../iron-resizable-behavior/iron-resizable-behavior.html
"> | 13 <link rel="import" href="../iron-resizable-behavior/iron-resizable-behavior.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 | 15 |
| 16 <!-- | 16 <!-- |
| 17 `<paper-badge>` is a circular text badge that is displayed on the top right | 17 `<paper-badge>` is a circular text badge that is displayed on the top right |
| 18 corner of an element, representing a status or a notification. It will badge | 18 corner of an element, representing a status or a notification. It will badge |
| 19 the anchor element specified in the `for` attribute, or, if that doesn't exist, | 19 the anchor element specified in the `for` attribute, or, if that doesn't exist, |
| 20 centered to the parent node containing it. | 20 centered to the parent node containing it. |
| 21 | 21 |
| 22 Example: | 22 Example: |
| 23 | 23 |
| 24 <div style="display:inline-block"> | 24 <div style="display:inline-block"> |
| 25 <span>Inbox</span> | 25 <span>Inbox</span> |
| 26 <paper-badge label="3"></paper-badge> | 26 <paper-badge label="3"></paper-badge> |
| 27 </div> | 27 </div> |
| 28 | 28 |
| 29 <div> | 29 <div> |
| 30 <paper-button id="btn">Status</button> | 30 <paper-button id="btn">Status</paper-button> |
| 31 <paper-badge for="btn" label="♥︎">b/paper-badge> | 31 <paper-badge for="btn" label="♥︎"></paper-badge> |
| 32 </div> | 32 </div> |
| 33 | 33 |
| 34 ### Styling | 34 ### Styling |
| 35 | 35 |
| 36 The following custom properties and mixins are available for styling: | 36 The following custom properties and mixins are available for styling: |
| 37 | 37 |
| 38 Custom property | Description | Default | 38 Custom property | Description | Default |
| 39 ----------------|-------------|---------- | 39 ----------------|-------------|---------- |
| 40 `--paper-badge-background` | The background color of the badge | `--accent-color
` | 40 `--paper-badge-background` | The background color of the badge | `--accent-color
` |
| 41 `--paper-badge-opacity` | The opacity of the badge | `1.0` | 41 `--paper-badge-opacity` | The opacity of the badge | `1.0` |
| 42 `--paper-badge-text-color` | The color of the badge text | `white` | 42 `--paper-badge-text-color` | The color of the badge text | `white` |
| 43 `--paper-badge-width` | The width of the badge circle | `22px` | 43 `--paper-badge-width` | The width of the badge circle | `22px` |
| 44 `--paper-badge-height` | The height of the badge circle | `22px` | 44 `--paper-badge-height` | The height of the badge circle | `22px` |
| 45 `--paper-badge-margin-left` | Optional spacing added to the left of the badge. |
`0px` | 45 `--paper-badge-margin-left` | Optional spacing added to the left of the badge. |
`0px` |
| 46 `--paper-badge-margin-bottom` | TOptional spacing added to the bottom of the bad
ge. | `0px` | 46 `--paper-badge-margin-bottom` | TOptional spacing added to the bottom of the bad
ge. | `0px` |
| 47 `--paper-badge` | Mixin applied to the badge | `{}` | 47 `--paper-badge` | Mixin applied to the badge | `{}` |
| 48 | 48 |
| 49 @group Paper Elements | 49 @group Paper Elements |
| 50 @element paper-badge | 50 @element paper-badge |
| 51 @demo demo/index.html | 51 @demo demo/index.html |
| 52 --> | 52 --> |
| 53 | 53 |
| 54 <dom-module id="paper-badge"> | 54 <dom-module id="paper-badge"> |
| 55 <style> | 55 <template> |
| 56 :host { | 56 <style> |
| 57 display: block; | 57 :host { |
| 58 position: absolute; | 58 display: block; |
| 59 outline: none; | 59 position: absolute; |
| 60 } | 60 outline: none; |
| 61 } |
| 61 | 62 |
| 62 #badge { | 63 #badge { |
| 63 @apply(--paper-font-common-base); | 64 @apply(--paper-font-common-base); |
| 64 font-weight: 600; | 65 font-weight: 600; |
| 65 font-size: 12px; | 66 font-size: 12px; |
| 66 border-radius: 50%; | 67 border-radius: 50%; |
| 67 margin-left: var(--paper-badge-margin-left, 0px); | 68 margin-left: var(--paper-badge-margin-left, 0px); |
| 68 margin-bottom: var(--paper-badge-margin-bottom, 0px); | 69 margin-bottom: var(--paper-badge-margin-bottom, 0px); |
| 69 width: var(--paper-badge-width, 22px); | 70 width: var(--paper-badge-width, 22px); |
| 70 height: var(--paper-badge-height, 22px); | 71 height: var(--paper-badge-height, 22px); |
| 71 background-color: var(--paper-badge-background, --accent-color); | 72 background-color: var(--paper-badge-background, --accent-color); |
| 72 opacity: var(--paper-badge-opacity, 1.0); | 73 opacity: var(--paper-badge-opacity, 1.0); |
| 73 color: var(--paper-badge-text-color, white); | 74 color: var(--paper-badge-text-color, white); |
| 74 @apply(--layout); | 75 @apply(--layout); |
| 75 @apply(--layout-center-center); | 76 @apply(--layout-center-center); |
| 76 | 77 |
| 77 @apply(--paper-badge); | 78 @apply(--paper-badge); |
| 78 } | 79 } |
| 79 </style> | 80 </style> |
| 80 <template> | 81 |
| 81 <div id="badge">{{label}}</div> | 82 <div id="badge">{{label}}</div> |
| 82 </template> | 83 </template> |
| 84 |
| 83 <script> | 85 <script> |
| 84 Polymer({ | 86 Polymer({ |
| 85 is: 'paper-badge', | 87 is: 'paper-badge', |
| 86 | 88 |
| 89 hostAttributes: { |
| 90 tabindex: '0', |
| 91 role: 'status' |
| 92 }, |
| 93 |
| 87 behaviors: [ | 94 behaviors: [ |
| 88 Polymer.IronResizableBehavior | 95 Polymer.IronResizableBehavior |
| 89 ], | 96 ], |
| 90 | 97 |
| 91 listeners: { | 98 listeners: { |
| 92 'iron-resize': 'updatePosition' | 99 'iron-resize': 'updatePosition' |
| 93 }, | 100 }, |
| 94 | 101 |
| 95 properties: { | 102 properties: { |
| 96 /** | 103 /** |
| 97 * The id of the element that the badge is anchored to. This element | 104 * The id of the element that the badge is anchored to. This element |
| 98 * must be a sibling of the badge. | 105 * must be a sibling of the badge. |
| 99 */ | 106 */ |
| 100 for: { | 107 for: { |
| 101 type: String, | 108 type: String, |
| 102 observer: '_forChanged' | 109 observer: '_forChanged' |
| 103 }, | 110 }, |
| 104 | 111 |
| 105 /** | 112 /** |
| 106 * The label displayed in the badge. The label is centered, and ideally | 113 * The label displayed in the badge. The label is centered, and ideally |
| 107 * should have very few characters. | 114 * should have very few characters. |
| 108 */ | 115 */ |
| 109 label: { | 116 label: { |
| 110 type: String | 117 type: String, |
| 118 observer: '_labelChanged' |
| 111 } | 119 } |
| 112 }, | 120 }, |
| 113 | 121 |
| 114 attached: function() { | 122 attached: function() { |
| 115 this._updateTarget(); | 123 this._updateTarget(); |
| 116 }, | 124 }, |
| 117 | 125 |
| 118 _forChanged: function() { | 126 _forChanged: function() { |
| 119 // The first time the property is set is before the badge is attached, | 127 // The first time the property is set is before the badge is attached, |
| 120 // which means we're not ready to position it yet. | 128 // which means we're not ready to position it yet. |
| 121 if (!this.isAttached) { | 129 if (!this.isAttached) { |
| 122 return; | 130 return; |
| 123 } | 131 } |
| 124 this._updateTarget(); | 132 this._updateTarget(); |
| 125 }, | 133 }, |
| 126 | 134 |
| 135 _labelChanged: function() { |
| 136 this.setAttribute('aria-label', this.label); |
| 137 }, |
| 138 |
| 127 _updateTarget: function() { | 139 _updateTarget: function() { |
| 128 this._target = this.target; | 140 this._target = this.target; |
| 129 this.async(this.notifyResize, 1); | 141 this.async(this.notifyResize, 1); |
| 130 }, | 142 }, |
| 131 | 143 |
| 132 /** | 144 /** |
| 133 * Returns the target element that this badge is anchored to. It is | 145 * Returns the target element that this badge is anchored to. It is |
| 134 * either the element given by the `for` attribute, or the immediate paren
t | 146 * either the element given by the `for` attribute, or the immediate paren
t |
| 135 * of the badge. | 147 * of the badge. |
| 136 */ | 148 */ |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 var thisRect = this.getBoundingClientRect(); | 184 var thisRect = this.getBoundingClientRect(); |
| 173 | 185 |
| 174 this.style.left = targetRect.left - parentRect.left + | 186 this.style.left = targetRect.left - parentRect.left + |
| 175 (targetRect.width - thisRect.width / 2) + 'px'; | 187 (targetRect.width - thisRect.width / 2) + 'px'; |
| 176 this.style.top = targetRect.top - parentRect.top - | 188 this.style.top = targetRect.top - parentRect.top - |
| 177 (thisRect.height / 2) + 'px'; | 189 (thisRect.height / 2) + 'px'; |
| 178 } | 190 } |
| 179 }) | 191 }) |
| 180 </script> | 192 </script> |
| 181 </dom-module> | 193 </dom-module> |
| OLD | NEW |