1e41f4b71Sopenharmony_ci# Rating
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciThe **\<Rating>** component provides a rating bar.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci>  **NOTE**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci>  This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci
10e41f4b71Sopenharmony_ci## Child Components
11e41f4b71Sopenharmony_ci
12e41f4b71Sopenharmony_ciNot supported
13e41f4b71Sopenharmony_ci
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci## APIs
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ciRating(options?: { rating: number, indicator?: boolean })
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci**Parameters**
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci| Name   | Type| Mandatory| Description                                                    |
26e41f4b71Sopenharmony_ci| --------- | -------- | ---- | ------------------------------------------------------------ |
27e41f4b71Sopenharmony_ci| rating    | number   | Yes  | Value to rate.<br>Default value: **0**<br>Value range: [0, stars]<br>A value less than 0 evaluates to the value **0**. A value greater than the value of **stars** evaluates to the value of **stars**.<br>Since API version 10, this parameter supports two-way binding through [$$](../../../quick-start/arkts-two-way-sync.md).|
28e41f4b71Sopenharmony_ci| indicator | boolean  | No  | Whether the component is used only as an indicator.<br>Default value: **false**<br>**NOTE**<br>When **indicator** is set to **true**, the default component height is 12.0 vp, and the component width is calculated as follows: Height x Value of **stars**.<br>When **indicator** is set to **false**, the default component height is 28.0 vp, and the component width is calculated as follows: Height x Value of **stars**.|
29e41f4b71Sopenharmony_ci
30e41f4b71Sopenharmony_ci## Attributes
31e41f4b71Sopenharmony_ci
32e41f4b71Sopenharmony_ci### stars
33e41f4b71Sopenharmony_ci
34e41f4b71Sopenharmony_cistars(value: number)
35e41f4b71Sopenharmony_ci
36e41f4b71Sopenharmony_ciTotal number of ratings. A value less than or equal to 0 evaluates to the default value.
37e41f4b71Sopenharmony_ci
38e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
39e41f4b71Sopenharmony_ci
40e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
41e41f4b71Sopenharmony_ci
42e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
43e41f4b71Sopenharmony_ci
44e41f4b71Sopenharmony_ci**Parameters**
45e41f4b71Sopenharmony_ci
46e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                        |
47e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ---------------------------- |
48e41f4b71Sopenharmony_ci| value  | number | Yes  | Total number of ratings.<br>Default value: **5**|
49e41f4b71Sopenharmony_ci
50e41f4b71Sopenharmony_ci### stepSize
51e41f4b71Sopenharmony_ci
52e41f4b71Sopenharmony_cistepSize(value: number)
53e41f4b71Sopenharmony_ci
54e41f4b71Sopenharmony_ciSets the step for rating. A value less than 0.1 evaluates to the default value.
55e41f4b71Sopenharmony_ci
56e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
57e41f4b71Sopenharmony_ci
58e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
59e41f4b71Sopenharmony_ci
60e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
61e41f4b71Sopenharmony_ci
62e41f4b71Sopenharmony_ci**Parameters**
63e41f4b71Sopenharmony_ci
64e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                                                       |
65e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ----------------------------------------------------------- |
66e41f4b71Sopenharmony_ci| value  | number | Yes  | Step for rating.<br>Default value: **0.5**<br>Value range: [0.1, stars]|
67e41f4b71Sopenharmony_ci
68e41f4b71Sopenharmony_ci### starStyle
69e41f4b71Sopenharmony_ci
70e41f4b71Sopenharmony_cistarStyle(value: { backgroundUri: string, foregroundUri: string, secondaryUri?: string })
71e41f4b71Sopenharmony_ci
72e41f4b71Sopenharmony_ciSets the star style. For details about the supported image types, see [Image](ts-basic-components-image.md).
73e41f4b71Sopenharmony_ci
74e41f4b71Sopenharmony_ciLocal and online images are supported, but not **PixelMap** and **Resource** objects.
75e41f4b71Sopenharmony_ci
76e41f4b71Sopenharmony_ciBy default, the image is loaded in asynchronous mode. Synchronous loading is not supported.
77e41f4b71Sopenharmony_ci
78e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
79e41f4b71Sopenharmony_ci
80e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
81e41f4b71Sopenharmony_ci
82e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
83e41f4b71Sopenharmony_ci
84e41f4b71Sopenharmony_ci**Parameters**
85e41f4b71Sopenharmony_ci
86e41f4b71Sopenharmony_ci| Name| Type                                                        | Mandatory| Description                                                        |
87e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
88e41f4b71Sopenharmony_ci| value  | {<br>backgroundUri: string,<br>foregroundUri: string,<br>secondaryUri?: string<br>} | Yes  | Star style.<br>**backgroundUri**: image path for the unselected star. You can use the default system image or a custom image.<br>**foregroundUri**: image path for the selected star. You can use the default system image or a custom image.<br>**secondaryUri**: image path for the partially selected star. You can use the default system image or a custom image.<br>**NOTE**<br>If the path specified for **backgroundUri**, **foregroundUri**, or **secondaryUri** is incorrect, no image is displayed.<br>If **backgroundUri** or **foregroundUri** is set to **undefined** or an empty string, the **\<Rating>** component loads the default star image source.<br>If **secondaryUri** is set to **undefined** or an empty string or is not set, **backgroundUri** is prioritized, which is equivalent to where only **foregroundUri** and **backgroundUri** are set.|
89e41f4b71Sopenharmony_ci
90e41f4b71Sopenharmony_ci>  **NOTE**
91e41f4b71Sopenharmony_ci>
92e41f4b71Sopenharmony_ci>  The drawing area of each rating image is [width/stars, height], wherein **width** and **height** indicate the width and height of the **\<Rating>** component, respectively.
93e41f4b71Sopenharmony_ci>
94e41f4b71Sopenharmony_ci>  To specify the drawing area as a square, you are advised to customize the width and height in this format: [height * stars, height], width = height * stars.
95e41f4b71Sopenharmony_ci
96e41f4b71Sopenharmony_ci### contentModifier<sup>12+</sup>
97e41f4b71Sopenharmony_ci
98e41f4b71Sopenharmony_cicontentModifier(modifier: ContentModifier\<RatingConfiguration>)
99e41f4b71Sopenharmony_ci
100e41f4b71Sopenharmony_ciCreates a content modifier.
101e41f4b71Sopenharmony_ci
102e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
103e41f4b71Sopenharmony_ci
104e41f4b71Sopenharmony_ci**Parameters**
105e41f4b71Sopenharmony_ci
106e41f4b71Sopenharmony_ci| Name| Type                                         | Mandatory| Description                                            |
107e41f4b71Sopenharmony_ci| ------ | --------------------------------------------- | ---- | ------------------------------------------------ |
108e41f4b71Sopenharmony_ci| modifier  | [ContentModifier\<RatingConfiguration>](#ratingconfiguration12) | Yes  | Content modifier to apply to the current component.<br>**modifier**: content modifier. You need a custom class to implement the **ContentModifier** API.|
109e41f4b71Sopenharmony_ci
110e41f4b71Sopenharmony_ci
111e41f4b71Sopenharmony_ci## Events
112e41f4b71Sopenharmony_ci
113e41f4b71Sopenharmony_ci### onChange
114e41f4b71Sopenharmony_ci
115e41f4b71Sopenharmony_cionChange(callback:(value: number) =&gt; void)
116e41f4b71Sopenharmony_ci
117e41f4b71Sopenharmony_ciTriggered when the rating value changes.
118e41f4b71Sopenharmony_ci
119e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
120e41f4b71Sopenharmony_ci
121e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
122e41f4b71Sopenharmony_ci
123e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
124e41f4b71Sopenharmony_ci
125e41f4b71Sopenharmony_ci**Parameters**
126e41f4b71Sopenharmony_ci
127e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description          |
128e41f4b71Sopenharmony_ci| ------ | ------ | ---- | -------------- |
129e41f4b71Sopenharmony_ci| value  | number | Yes  | Rating value.|
130e41f4b71Sopenharmony_ci
131e41f4b71Sopenharmony_ci## Sequential Keyboard Navigation Specifications                                   
132e41f4b71Sopenharmony_ci| Key        | Description                       |
133e41f4b71Sopenharmony_ci|------------|-----------------------------|
134e41f4b71Sopenharmony_ci| Tab        | Switch the focus between components.                   |
135e41f4b71Sopenharmony_ci| Left and right arrow keys  | Increase or decrease the rating on preview at the specified step, without changing the actual rating.|
136e41f4b71Sopenharmony_ci| Home       | Move the focus to the first star, without changing the actual rating.         |
137e41f4b71Sopenharmony_ci| End        | Move the focus to the last star, without changing the actual rating.        |
138e41f4b71Sopenharmony_ci| Space/Enter | Submit the rating result based on the current rating.              |
139e41f4b71Sopenharmony_ci
140e41f4b71Sopenharmony_ci## RatingConfiguration<sup>12+</sup>
141e41f4b71Sopenharmony_ci
142e41f4b71Sopenharmony_ciYou need a custom class to implement the **ContentModifier** API.
143e41f4b71Sopenharmony_ci
144e41f4b71Sopenharmony_ci| Name | Type   |    Default Value     |  Description             |
145e41f4b71Sopenharmony_ci| ------ | ------ | ------ |-------------------------------- |
146e41f4b71Sopenharmony_ci| rating | number | 0 |Value to rate.|
147e41f4b71Sopenharmony_ci| indicator | boolean | false | Whether the component is used only as an indicator.|
148e41f4b71Sopenharmony_ci| stars | number | 5 |Total number of ratings.|
149e41f4b71Sopenharmony_ci| stepSize | number | 0.5 |Step of an operation.|
150e41f4b71Sopenharmony_ci| triggerChange | Callback\<number> | - |Triggered when the rating value changes.|
151e41f4b71Sopenharmony_ci
152e41f4b71Sopenharmony_ci
153e41f4b71Sopenharmony_ci## Example
154e41f4b71Sopenharmony_ci
155e41f4b71Sopenharmony_ci### Example 1
156e41f4b71Sopenharmony_ci
157e41f4b71Sopenharmony_ci```ts
158e41f4b71Sopenharmony_ci// xxx.ets
159e41f4b71Sopenharmony_ci@Entry
160e41f4b71Sopenharmony_ci@Component
161e41f4b71Sopenharmony_cistruct RatingExample {
162e41f4b71Sopenharmony_ci  @State rating: number = 3.5
163e41f4b71Sopenharmony_ci
164e41f4b71Sopenharmony_ci  build() {
165e41f4b71Sopenharmony_ci    Column() {
166e41f4b71Sopenharmony_ci      Column() {
167e41f4b71Sopenharmony_ci        Rating({ rating: this.rating, indicator: false })
168e41f4b71Sopenharmony_ci          .stars(5)
169e41f4b71Sopenharmony_ci          .stepSize(0.5)
170e41f4b71Sopenharmony_ci          .margin({ top: 24 })
171e41f4b71Sopenharmony_ci          .onChange((value: number) => {
172e41f4b71Sopenharmony_ci            this.rating = value
173e41f4b71Sopenharmony_ci          })
174e41f4b71Sopenharmony_ci        Text('current score is ' + this.rating)
175e41f4b71Sopenharmony_ci          .fontSize(16)
176e41f4b71Sopenharmony_ci          .fontColor('rgba(24,36,49,0.60)')
177e41f4b71Sopenharmony_ci          .margin({ top: 16 })
178e41f4b71Sopenharmony_ci      }.width(360).height(113).backgroundColor('#FFFFFF').margin({ top: 68 })
179e41f4b71Sopenharmony_ci
180e41f4b71Sopenharmony_ci      Row() {
181e41f4b71Sopenharmony_ci        Image('common/testImage.jpg')
182e41f4b71Sopenharmony_ci          .width(40)
183e41f4b71Sopenharmony_ci          .height(40)
184e41f4b71Sopenharmony_ci          .borderRadius(20)
185e41f4b71Sopenharmony_ci          .margin({ left: 24 })
186e41f4b71Sopenharmony_ci        Column() {
187e41f4b71Sopenharmony_ci          Text('Yue')
188e41f4b71Sopenharmony_ci            .fontSize(16)
189e41f4b71Sopenharmony_ci            .fontColor('#182431')
190e41f4b71Sopenharmony_ci            .fontWeight(500)
191e41f4b71Sopenharmony_ci          Row() {
192e41f4b71Sopenharmony_ci            Rating({ rating: 3.5, indicator: false }).margin({ top: 1, right: 8 })
193e41f4b71Sopenharmony_ci            Text('2021/06/02')
194e41f4b71Sopenharmony_ci              .fontSize(10)
195e41f4b71Sopenharmony_ci              .fontColor('#182431')
196e41f4b71Sopenharmony_ci          }
197e41f4b71Sopenharmony_ci        }.margin({ left: 12 }).alignItems(HorizontalAlign.Start)
198e41f4b71Sopenharmony_ci
199e41f4b71Sopenharmony_ci        Text('1st Floor')
200e41f4b71Sopenharmony_ci          .fontSize(10)
201e41f4b71Sopenharmony_ci          .fontColor('#182431')
202e41f4b71Sopenharmony_ci          .position({ x: 295, y: 8 })
203e41f4b71Sopenharmony_ci      }.width(360).height(56).backgroundColor('#FFFFFF').margin({ top: 64 })
204e41f4b71Sopenharmony_ci    }.width('100%').height('100%').backgroundColor('#F1F3F5')
205e41f4b71Sopenharmony_ci  }
206e41f4b71Sopenharmony_ci}
207e41f4b71Sopenharmony_ci```
208e41f4b71Sopenharmony_ci
209e41f4b71Sopenharmony_ci![rating](figures/rating.gif)
210e41f4b71Sopenharmony_ci
211e41f4b71Sopenharmony_ci### Example 2
212e41f4b71Sopenharmony_ci
213e41f4b71Sopenharmony_ci```ts
214e41f4b71Sopenharmony_ci// xxx.ets
215e41f4b71Sopenharmony_ci@Entry
216e41f4b71Sopenharmony_ci@Component
217e41f4b71Sopenharmony_cistruct RatingExample {
218e41f4b71Sopenharmony_ci  @State rating: number = 3.5
219e41f4b71Sopenharmony_ci
220e41f4b71Sopenharmony_ci  build() {
221e41f4b71Sopenharmony_ci    Column() {
222e41f4b71Sopenharmony_ci      Rating({ rating: this.rating, indicator: false })
223e41f4b71Sopenharmony_ci        .stars(5)
224e41f4b71Sopenharmony_ci        .stepSize(0.5)
225e41f4b71Sopenharmony_ci        .starStyle({
226e41f4b71Sopenharmony_ci          backgroundUri: '/common/imag1.png', // The common folder is at the same level as pages.
227e41f4b71Sopenharmony_ci          foregroundUri: '/common/imag2.png',
228e41f4b71Sopenharmony_ci          secondaryUri: '/common/imag3.png'
229e41f4b71Sopenharmony_ci        })
230e41f4b71Sopenharmony_ci        .margin({ top: 24 })
231e41f4b71Sopenharmony_ci        .onChange((value: number) => {
232e41f4b71Sopenharmony_ci          this.rating = value
233e41f4b71Sopenharmony_ci        })
234e41f4b71Sopenharmony_ci      Text('current score is ' + this.rating)
235e41f4b71Sopenharmony_ci        .fontSize(16)
236e41f4b71Sopenharmony_ci        .fontColor('rgba(24,36,49,0.60)')
237e41f4b71Sopenharmony_ci        .margin({ top: 16 })
238e41f4b71Sopenharmony_ci    }.width('100%').height('100%').backgroundColor('#F1F3F5')
239e41f4b71Sopenharmony_ci  }
240e41f4b71Sopenharmony_ci}
241e41f4b71Sopenharmony_ci```
242e41f4b71Sopenharmony_ci
243e41f4b71Sopenharmony_ci![rating1](figures/rating1.gif)
244e41f4b71Sopenharmony_ci
245e41f4b71Sopenharmony_ci### Example 3
246e41f4b71Sopenharmony_ciThis example implements a custom rating bar, with each circle representing 0.5 point. If **ratingIndicator** is set to **true**, the rating bar is used only as an indicator, and the rating cannot be changed.
247e41f4b71Sopenharmony_ciif it is set to **false**, the rating can be changed. **ratingStars** sets the rating value. **ratingStepsize** sets the step for rating.
248e41f4b71Sopenharmony_ci
249e41f4b71Sopenharmony_ci```ts
250e41f4b71Sopenharmony_ci// xxx.ets
251e41f4b71Sopenharmony_ciclass MyRatingStyle implements ContentModifier<RatingConfiguration> {
252e41f4b71Sopenharmony_ci  name: string = ""
253e41f4b71Sopenharmony_ci  style: number = 0
254e41f4b71Sopenharmony_ci  constructor(value1: string, value2: number) {
255e41f4b71Sopenharmony_ci    this.name = value1
256e41f4b71Sopenharmony_ci    this.style = value2
257e41f4b71Sopenharmony_ci  }
258e41f4b71Sopenharmony_ci  applyContent() : WrappedBuilder<[RatingConfiguration]> {
259e41f4b71Sopenharmony_ci    return wrapBuilder(buildRating)
260e41f4b71Sopenharmony_ci  }
261e41f4b71Sopenharmony_ci}
262e41f4b71Sopenharmony_ci
263e41f4b71Sopenharmony_ci@Builder function buildRating(config: RatingConfiguration) {
264e41f4b71Sopenharmony_ci  Column() {
265e41f4b71Sopenharmony_ci    Row() {
266e41f4b71Sopenharmony_ci      Circle({ width: 25, height: 25 })
267e41f4b71Sopenharmony_ci        .fill(config.rating >= 0.4 ? Color.Black : Color.Red)
268e41f4b71Sopenharmony_ci        .onClick((event: ClickEvent) => {
269e41f4b71Sopenharmony_ci          if (!config.indicator) {
270e41f4b71Sopenharmony_ci            if (config.stepSize = 0.5) {
271e41f4b71Sopenharmony_ci              config.triggerChange(0.5);
272e41f4b71Sopenharmony_ci              return
273e41f4b71Sopenharmony_ci            }
274e41f4b71Sopenharmony_ci            if (config.stepSize = 1) {
275e41f4b71Sopenharmony_ci              config.triggerChange(1);
276e41f4b71Sopenharmony_ci              return
277e41f4b71Sopenharmony_ci            }
278e41f4b71Sopenharmony_ci          }
279e41f4b71Sopenharmony_ci        }).visibility(config.stars >= 1 ? Visibility.Visible : Visibility.Hidden)
280e41f4b71Sopenharmony_ci      Circle({ width: 25, height: 25 })
281e41f4b71Sopenharmony_ci        .fill(config.rating >= 0.9 ? Color.Black : Color.Red)
282e41f4b71Sopenharmony_ci        .onClick((event: ClickEvent) => {
283e41f4b71Sopenharmony_ci          if (!config.indicator) {
284e41f4b71Sopenharmony_ci            config.triggerChange(1);
285e41f4b71Sopenharmony_ci          }
286e41f4b71Sopenharmony_ci        }).visibility(config.stars >= 1 ? Visibility.Visible : Visibility.Hidden)
287e41f4b71Sopenharmony_ci      Circle({ width: 25, height: 25 })
288e41f4b71Sopenharmony_ci        .fill(config.rating >= 1.4 ? Color.Black : Color.Red)
289e41f4b71Sopenharmony_ci        .onClick((event: ClickEvent) => {
290e41f4b71Sopenharmony_ci          if (!config.indicator) {
291e41f4b71Sopenharmony_ci            if (config.stepSize = 0.5) {
292e41f4b71Sopenharmony_ci              config.triggerChange(1.5);
293e41f4b71Sopenharmony_ci              return
294e41f4b71Sopenharmony_ci            }
295e41f4b71Sopenharmony_ci            if (config.stepSize = 1) {
296e41f4b71Sopenharmony_ci              config.triggerChange(2);
297e41f4b71Sopenharmony_ci              return
298e41f4b71Sopenharmony_ci            }
299e41f4b71Sopenharmony_ci          }
300e41f4b71Sopenharmony_ci        }).visibility(config.stars >= 2 ? Visibility.Visible : Visibility.Hidden).margin({left:10})
301e41f4b71Sopenharmony_ci      Circle({ width: 25, height: 25 })
302e41f4b71Sopenharmony_ci        .fill(config.rating >= 1.9 ? Color.Black : Color.Red)
303e41f4b71Sopenharmony_ci        .onClick((event: ClickEvent) => {
304e41f4b71Sopenharmony_ci          if (!config.indicator) {
305e41f4b71Sopenharmony_ci            config.triggerChange(2);
306e41f4b71Sopenharmony_ci          }
307e41f4b71Sopenharmony_ci        }).visibility(config.stars >= 2 ? Visibility.Visible : Visibility.Hidden)
308e41f4b71Sopenharmony_ci      Circle({ width: 25, height: 25 })
309e41f4b71Sopenharmony_ci        .fill(config.rating >= 2.4 ? Color.Black : Color.Red)
310e41f4b71Sopenharmony_ci        .onClick((event: ClickEvent) => {
311e41f4b71Sopenharmony_ci          if (!config.indicator) {
312e41f4b71Sopenharmony_ci            if (config.stepSize = 0.5) {
313e41f4b71Sopenharmony_ci              config.triggerChange(2.5);
314e41f4b71Sopenharmony_ci              return
315e41f4b71Sopenharmony_ci            }
316e41f4b71Sopenharmony_ci            if (config.stepSize = 1) {
317e41f4b71Sopenharmony_ci              config.triggerChange(3);
318e41f4b71Sopenharmony_ci              return
319e41f4b71Sopenharmony_ci            }
320e41f4b71Sopenharmony_ci          }
321e41f4b71Sopenharmony_ci        }).visibility(config.stars >= 3 ? Visibility.Visible : Visibility.Hidden).margin({left:10})
322e41f4b71Sopenharmony_ci      Circle({ width: 25, height: 25 })
323e41f4b71Sopenharmony_ci        .fill(config.rating >= 2.9 ? Color.Black : Color.Red)
324e41f4b71Sopenharmony_ci        .onClick((event: ClickEvent) => {
325e41f4b71Sopenharmony_ci          if (!config.indicator) {
326e41f4b71Sopenharmony_ci            config.triggerChange(3);
327e41f4b71Sopenharmony_ci          }
328e41f4b71Sopenharmony_ci        }).visibility(config.stars >= 3 ? Visibility.Visible : Visibility.Hidden)
329e41f4b71Sopenharmony_ci      Circle({ width: 25, height: 25 })
330e41f4b71Sopenharmony_ci        .fill(config.rating >= 3.4 ? Color.Black : Color.Red)
331e41f4b71Sopenharmony_ci        .onClick((event: ClickEvent) => {
332e41f4b71Sopenharmony_ci          if (!config.indicator) {
333e41f4b71Sopenharmony_ci            if (config.stepSize = 0.5) {
334e41f4b71Sopenharmony_ci              config.triggerChange(3.5);
335e41f4b71Sopenharmony_ci              return
336e41f4b71Sopenharmony_ci            }
337e41f4b71Sopenharmony_ci            if (config.stepSize = 1) {
338e41f4b71Sopenharmony_ci              config.triggerChange(4);
339e41f4b71Sopenharmony_ci              return
340e41f4b71Sopenharmony_ci            }
341e41f4b71Sopenharmony_ci          }
342e41f4b71Sopenharmony_ci        }).visibility(config.stars >= 4 ? Visibility.Visible : Visibility.Hidden).margin({left:10})
343e41f4b71Sopenharmony_ci      Circle({ width: 25, height: 25 })
344e41f4b71Sopenharmony_ci        .fill(config.rating >= 3.9 ? Color.Black : Color.Red)
345e41f4b71Sopenharmony_ci        .onClick((event: ClickEvent) => {
346e41f4b71Sopenharmony_ci          if (!config.indicator) {
347e41f4b71Sopenharmony_ci            config.triggerChange(4);
348e41f4b71Sopenharmony_ci          }
349e41f4b71Sopenharmony_ci        }).visibility(config.stars >= 4 ? Visibility.Visible : Visibility.Hidden)
350e41f4b71Sopenharmony_ci      Circle({ width: 25, height: 25 })
351e41f4b71Sopenharmony_ci        .fill(config.rating >= 4.4 ? Color.Black : Color.Red)
352e41f4b71Sopenharmony_ci        .onClick((event: ClickEvent) => {
353e41f4b71Sopenharmony_ci          if (!config.indicator) {
354e41f4b71Sopenharmony_ci            if (config.stepSize = 0.5) {
355e41f4b71Sopenharmony_ci              config.triggerChange(4.5);
356e41f4b71Sopenharmony_ci              return
357e41f4b71Sopenharmony_ci            }
358e41f4b71Sopenharmony_ci            if (config.stepSize = 1) {
359e41f4b71Sopenharmony_ci              config.triggerChange(5);
360e41f4b71Sopenharmony_ci              return
361e41f4b71Sopenharmony_ci            }
362e41f4b71Sopenharmony_ci          }
363e41f4b71Sopenharmony_ci        }).visibility(config.stars >= 5 ? Visibility.Visible : Visibility.Hidden).margin({left:10})
364e41f4b71Sopenharmony_ci      Circle({ width: 25, height: 25 })
365e41f4b71Sopenharmony_ci        .fill(config.rating >= 4.9 ? Color.Black : Color.Red)
366e41f4b71Sopenharmony_ci        .onClick((event: ClickEvent) => {
367e41f4b71Sopenharmony_ci          if (!config.indicator) {
368e41f4b71Sopenharmony_ci            config.triggerChange(5);
369e41f4b71Sopenharmony_ci          }
370e41f4b71Sopenharmony_ci        }).visibility(config.stars >= 5 ? Visibility.Visible : Visibility.Hidden)
371e41f4b71Sopenharmony_ci    }
372e41f4b71Sopenharmony_ci    Text ("Rating: "+ config.rating)
373e41f4b71Sopenharmony_ci  }
374e41f4b71Sopenharmony_ci}
375e41f4b71Sopenharmony_ci
376e41f4b71Sopenharmony_ci@Entry
377e41f4b71Sopenharmony_ci@Component
378e41f4b71Sopenharmony_cistruct ratingExample {
379e41f4b71Sopenharmony_ci  @State rating: number = 0;
380e41f4b71Sopenharmony_ci  @State ratingIndicator: boolean = true;
381e41f4b71Sopenharmony_ci  @State ratingStars: number = 0;
382e41f4b71Sopenharmony_ci  @State ratingStepsize: number = 0.5;
383e41f4b71Sopenharmony_ci  @State ratingEnabled: boolean = true;
384e41f4b71Sopenharmony_ci  build() {
385e41f4b71Sopenharmony_ci    Row() {
386e41f4b71Sopenharmony_ci      Column() {
387e41f4b71Sopenharmony_ci        Rating({
388e41f4b71Sopenharmony_ci          rating: 0,
389e41f4b71Sopenharmony_ci          indicator: this.ratingIndicator
390e41f4b71Sopenharmony_ci        })
391e41f4b71Sopenharmony_ci          .stepSize(this.ratingStepsize)
392e41f4b71Sopenharmony_ci          .stars(this.ratingStars)
393e41f4b71Sopenharmony_ci          .backgroundColor(Color.Transparent)
394e41f4b71Sopenharmony_ci          .width('100%')
395e41f4b71Sopenharmony_ci          .height(50)
396e41f4b71Sopenharmony_ci          .onChange((value: number) => {
397e41f4b71Sopenharmony_ci            console.info('Rating change is'+ value);
398e41f4b71Sopenharmony_ci            this.rating = value
399e41f4b71Sopenharmony_ci          })
400e41f4b71Sopenharmony_ci          .contentModifier(new MyRatingStyle("hello", 3))
401e41f4b71Sopenharmony_ci        Button(this.ratingIndicator ? "ratingIndicator : true" : "ratingIndicator : false")
402e41f4b71Sopenharmony_ci          .onClick((event) => {
403e41f4b71Sopenharmony_ci            if (this.ratingIndicator) {
404e41f4b71Sopenharmony_ci              this.ratingIndicator = false
405e41f4b71Sopenharmony_ci            } else {
406e41f4b71Sopenharmony_ci              this.ratingIndicator = true
407e41f4b71Sopenharmony_ci            }
408e41f4b71Sopenharmony_ci          }).margin({top : 5})
409e41f4b71Sopenharmony_ci
410e41f4b71Sopenharmony_ci        Button(this.ratingStars < 5 ? "ratingStars + 1, ratingStars = " + this.ratingStars : "Maximum value of ratingStars: 5")
411e41f4b71Sopenharmony_ci          .onClick((event) => {
412e41f4b71Sopenharmony_ci            if (this.ratingStars < 5) {
413e41f4b71Sopenharmony_ci              this.ratingStars += 1
414e41f4b71Sopenharmony_ci            }
415e41f4b71Sopenharmony_ci          }).margin({top : 5})
416e41f4b71Sopenharmony_ci
417e41f4b71Sopenharmony_ci        Button(this.ratingStars > 0 ? "ratingStars - 1, ratingStars = " + this.ratingStars : "Values less than or equal to 0 are handled as 5")
418e41f4b71Sopenharmony_ci          .onClick((event) => {
419e41f4b71Sopenharmony_ci            if (this.ratingStars > 0) {
420e41f4b71Sopenharmony_ci              this.ratingStars -= 1
421e41f4b71Sopenharmony_ci            }
422e41f4b71Sopenharmony_ci          }).margin({top : 5})
423e41f4b71Sopenharmony_ci
424e41f4b71Sopenharmony_ci        Button(this.ratingStepsize == 0.5 ? "ratingStepsize : 0.5" : "ratingStepsize : 1")
425e41f4b71Sopenharmony_ci          .onClick((event) => {
426e41f4b71Sopenharmony_ci            if (this.ratingStepsize == 0.5) {
427e41f4b71Sopenharmony_ci              this.ratingStepsize = 1
428e41f4b71Sopenharmony_ci            } else {
429e41f4b71Sopenharmony_ci              this.ratingStepsize = 0.5
430e41f4b71Sopenharmony_ci            }
431e41f4b71Sopenharmony_ci          }).margin({top : 5})
432e41f4b71Sopenharmony_ci      }
433e41f4b71Sopenharmony_ci      .width('100%')
434e41f4b71Sopenharmony_ci      .height('100%')
435e41f4b71Sopenharmony_ci      .justifyContent(FlexAlign.Center)
436e41f4b71Sopenharmony_ci    }
437e41f4b71Sopenharmony_ci    .height('100%')
438e41f4b71Sopenharmony_ci  }
439e41f4b71Sopenharmony_ci}
440e41f4b71Sopenharmony_ci```
441e41f4b71Sopenharmony_ci
442e41f4b71Sopenharmony_ci![rating2](figures/rating2.gif)
443