1e41f4b71Sopenharmony_ci# badge
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci
4e41f4b71Sopenharmony_ciThe **\<badge>** component is used to mark new events that require user attention in your application.
5e41f4b71Sopenharmony_ci
6e41f4b71Sopenharmony_ci>  **NOTE**
7e41f4b71Sopenharmony_ci>
8e41f4b71Sopenharmony_ci> The APIs of this module are supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version.
9e41f4b71Sopenharmony_ci
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci## Child Components
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ciThis component supports only one child component.
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci
16e41f4b71Sopenharmony_ci## attributes
17e41f4b71Sopenharmony_ci
18e41f4b71Sopenharmony_ciIn addition to the [universal attributes](js-service-widget-common-attributes.md), the following attributes are supported.
19e41f4b71Sopenharmony_ci
20e41f4b71Sopenharmony_ci| Name| Type| Default Value| Mandatory| Description|
21e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- |
22e41f4b71Sopenharmony_ci| placement | string | rightTop | No| Position of a number or dot badge. Available values are as follows:<br>**right**: on the right border of the component.<br>- **rightTop**: in the upper right corner of the component border.<br>- **left**: on the left border of the component.|
23e41f4b71Sopenharmony_ci| count | number | 0 | No| Number of notifications displayed via the badge. The default value is **0**. If the number of notifications is greater than 0, the badge changes from a dot to the number. If this attribute is not set or the value is less than or equal to 0, the badge is a dot.<br>When the **count** value is greater than the **maxcount** value, *maxcount***+** is displayed. The largest integer value supported for **count** is **2147483647**.|
24e41f4b71Sopenharmony_ci| visible | boolean | false | No| Whether to display the badge. The value **true** means that the badge shows up when a new notification is received. To use a number badge, set the **count** attribute.|
25e41f4b71Sopenharmony_ci| maxcount | number | 99 | No| Maximum number of notifications. When the number of new notifications exceeds the value of this attribute, *maxcount***+** is displayed, for example, **99+**.<br>Note: The maximum integer value is 2147483647.|
26e41f4b71Sopenharmony_ci| config | BadgeConfig | - | No| Configuration of the badge.|
27e41f4b71Sopenharmony_ci| label | string | - | No| Text of the new notification displayed via the badge.<br>When this attribute is set, attributes **count** and **maxcount** do not take effect.|
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci### BadgeConfig
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ci| Name| Type| Default Value| Mandatory| Description|
32e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- |
33e41f4b71Sopenharmony_ci| badgeColor | &lt;color&gt; | 	#fa2a2d | No| Background color of the badge.|
34e41f4b71Sopenharmony_ci| textColor | &lt;color&gt; | #ffffff | No| Text color of the number badge.|
35e41f4b71Sopenharmony_ci| textSize | &lt;length&gt; | 10px | No| Text size of the number badge.|
36e41f4b71Sopenharmony_ci| badgeSize | &lt;length&gt; | 6px | No| Size of the dot badge.|
37e41f4b71Sopenharmony_ci
38e41f4b71Sopenharmony_ci
39e41f4b71Sopenharmony_ci## Styles
40e41f4b71Sopenharmony_ci
41e41f4b71Sopenharmony_ciThe [universal styles](js-service-widget-common-styles.md) are supported.
42e41f4b71Sopenharmony_ci
43e41f4b71Sopenharmony_ci
44e41f4b71Sopenharmony_ci## Events
45e41f4b71Sopenharmony_ci
46e41f4b71Sopenharmony_ciThe [universal events](js-service-widget-common-events.md) are supported.
47e41f4b71Sopenharmony_ci
48e41f4b71Sopenharmony_ci
49e41f4b71Sopenharmony_ci## Example
50e41f4b71Sopenharmony_ci
51e41f4b71Sopenharmony_ci   ```html
52e41f4b71Sopenharmony_ci    <!-- xxx.hml -->
53e41f4b71Sopenharmony_ci    <div class="container">
54e41f4b71Sopenharmony_ci      <badge class="badge" config="{{badgeconfig}}" visible="true" count="100" maxcount="99">
55e41f4b71Sopenharmony_ci        <text class="text1">example</text>
56e41f4b71Sopenharmony_ci      </badge>
57e41f4b71Sopenharmony_ci      <badge class="badge" visible="true" count="1">
58e41f4b71Sopenharmony_ci        <text class="text2">example</text>
59e41f4b71Sopenharmony_ci      </badge>
60e41f4b71Sopenharmony_ci    </div>
61e41f4b71Sopenharmony_ci   ```
62e41f4b71Sopenharmony_ci
63e41f4b71Sopenharmony_ci   ```css
64e41f4b71Sopenharmony_ci    /* xxx.css */
65e41f4b71Sopenharmony_ci    .container {
66e41f4b71Sopenharmony_ci      flex-direction: column;
67e41f4b71Sopenharmony_ci      width: 100%;
68e41f4b71Sopenharmony_ci      align-items: center;
69e41f4b71Sopenharmony_ci    }
70e41f4b71Sopenharmony_ci
71e41f4b71Sopenharmony_ci    .badge {
72e41f4b71Sopenharmony_ci      width: 80px;
73e41f4b71Sopenharmony_ci      height: 60px;
74e41f4b71Sopenharmony_ci      margin-top: 30px;
75e41f4b71Sopenharmony_ci    }
76e41f4b71Sopenharmony_ci
77e41f4b71Sopenharmony_ci    .text1 {
78e41f4b71Sopenharmony_ci      background-color: #f9a01e;
79e41f4b71Sopenharmony_ci      font-size: 19fp;
80e41f4b71Sopenharmony_ci    }
81e41f4b71Sopenharmony_ci
82e41f4b71Sopenharmony_ci    .text2 {
83e41f4b71Sopenharmony_ci      background-color: #46b1e3;
84e41f4b71Sopenharmony_ci      font-size: 19fp;
85e41f4b71Sopenharmony_ci    }
86e41f4b71Sopenharmony_ci   ```
87e41f4b71Sopenharmony_ci
88e41f4b71Sopenharmony_ci   ```json
89e41f4b71Sopenharmony_ci    {
90e41f4b71Sopenharmony_ci      "data":{
91e41f4b71Sopenharmony_ci        "badgeconfig":{
92e41f4b71Sopenharmony_ci          "badgeColor":"#0a59f7",
93e41f4b71Sopenharmony_ci          "textColor":"#ffffff",
94e41f4b71Sopenharmony_ci          "textSize":"9px",
95e41f4b71Sopenharmony_ci          "badgeSize": "14px"
96e41f4b71Sopenharmony_ci        }
97e41f4b71Sopenharmony_ci      }
98e41f4b71Sopenharmony_ci    }
99e41f4b71Sopenharmony_ci   ```
100e41f4b71Sopenharmony_ci
101e41f4b71Sopenharmony_ci![badgeSample](figures/badgeSample.png)
102