Copybara bot | be50d49 | 2023-11-30 00:16:42 +0100 | [diff] [blame^] | 1 | |
| 2 | |
| 3 | |
| 4 | <h2 id="introduction">Introduction</h2> |
| 5 | <p>The Material Design Lite (MDL) <strong>badge</strong> component is an onscreen notification element. A badge consists of a small circle, typically containing a number or other characters, that appears in proximity to another object. A badge can be both a notifier that there are additional items associated with an object and an indicator of how many items there are.</p> |
| 6 | <p>You can use a badge to unobtrusively draw the user's attention to items they might not otherwise notice, or to emphasize that items may need their attention. For example:</p> |
| 7 | <ul> |
| 8 | <li>A "New messages" notification might be followed by a badge containing the number of unread messages.</li> |
| 9 | <li>A "You have unpurchased items in your shopping cart" reminder might include a badge showing the number of items in the cart.</li> |
| 10 | <li>A "Join the discussion!" button might have an accompanying badge indicating the number of users currently participating in the discussion.</li> |
| 11 | </ul> |
| 12 | <p>A badge is almost always positioned near a link so that the user has a convenient way to access the additional information indicated by the badge. However, depending on the intent, the badge itself may or may not be part of the link.</p> |
| 13 | <p>Badges are a new feature in user interfaces, and provide users with a visual clue to help them discover additional relevant content. Their design and use is therefore an important factor in the overall user experience.</p> |
| 14 | <h3 id="to-include-an-mdl-badge-component-">To include an MDL <strong>badge</strong> component:</h3> |
| 15 | <p> 1. Code an <code><a></code> (anchor/link) or a <code><span></code> element. Include any desired attributes and content.</p> |
| 16 | <pre><code class="lang-html"><a href="#">This link has a badge.</a> |
| 17 | </code></pre> |
| 18 | <p> 2. Add one or more MDL classes, separated by spaces, to the element using the <code>class</code> attribute.</p> |
| 19 | <pre><code class="lang-html"><a href="#" class="mdl-badge">This link has a badge.</a> |
| 20 | </code></pre> |
| 21 | <p> 3. Add a <code>data-badge</code> attribute and quoted string value for the badge.</p> |
| 22 | <pre><code class="lang-html"><a href="#" class="mdl-badge" data-badge="5">This link has a badge.</a> |
| 23 | </code></pre> |
| 24 | <p>The badge component is ready for use.</p> |
| 25 | <blockquote> |
| 26 | <p><strong>Note:</strong> Because of the badge component's small size, the <code>data-badge</code> value should typically contain one to three characters. More than three characters will not cause an error, but some characters may fall outside the badge and thus be difficult or impossible to see. The value of the <code>data-badge</code> attribute is centered in the badge.</p> |
| 27 | </blockquote> |
| 28 | <h4 id="examples">Examples</h4> |
| 29 | <p>A badge inside a link.</p> |
| 30 | <pre><code class="lang-html"><a href="#" class="mdl-badge" data-badge="7">This link contains a badge.</a> |
| 31 | </code></pre> |
| 32 | <p>A badge near, but not included in, a link.</p> |
| 33 | <pre><code class="lang-html"><a href="#">This link is followed by a badge.</a> |
| 34 | <span class="mdl-badge" data-badge="12"></span> |
| 35 | </code></pre> |
| 36 | <p>A badge inside a link with too many characters to fit inside the badge.</p> |
| 37 | <pre><code class="lang-html"><a href="#" class="mdl-badge" data-badge="123456789"> |
| 38 | This badge has too many characters.</a> |
| 39 | </code></pre> |
| 40 | <p>A badge inside a link with no badge background color.</p> |
| 41 | <pre><code class="lang-html"><a href="#" class="mdl-badge mdl-badge--no-background" data-badge="123"> |
| 42 | This badge has no background color.</a> |
| 43 | </code></pre> |
| 44 | <h2 id="configuration-options">Configuration options</h2> |
| 45 | <p>The MDL CSS classes apply various predefined visual enhancements to the badge. The table below lists the available classes and their effects.</p> |
| 46 | <table> |
| 47 | <thead> |
| 48 | <tr> |
| 49 | <th>MDL class</th> |
| 50 | <th>Effect</th> |
| 51 | <th>Remarks</th> |
| 52 | </tr> |
| 53 | </thead> |
| 54 | <tbody> |
| 55 | <tr> |
| 56 | <td><code>mdl-badge</code></td> |
| 57 | <td>Defines badge as an MDL component</td> |
| 58 | <td>Required on span or link</td> |
| 59 | </tr> |
| 60 | <tr> |
| 61 | <td><code>mdl-badge--no-background</code></td> |
| 62 | <td>Applies open-circle effect to badge</td> |
| 63 | <td>Optional</td> |
| 64 | </tr> |
| 65 | <tr> |
| 66 | <td><code>mdl-badge--overlap</code></td> |
| 67 | <td>Make the badge overlap with its container</td> |
| 68 | <td>Optional</td> |
| 69 | </tr> |
| 70 | <tr> |
| 71 | <td><code>data-badge="value"</code></td> |
| 72 | <td>Assigns string value to badge</td> |
| 73 | <td>Not a class, but a separate attribute; required on span or link</td> |
| 74 | </tr> |
| 75 | </tbody> |
| 76 | </table> |
| 77 | |
| 78 | |