Skip to content

Commit d75ea14

Browse files
authored
Merge pull request #8163 from primefaces/v11-rating
New Component: Rating
2 parents 21f6d4d + 7caf397 commit d75ea14

23 files changed

Lines changed: 622 additions & 0 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Rating } from 'primereact/rating';
2+
3+
function BasicDemo() {
4+
return (
5+
<div className="card flex justify-center">
6+
<Rating />
7+
</div>
8+
);
9+
}
10+
11+
export default BasicDemo;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Rating } from 'primereact/rating';
2+
3+
function DisabledDemo() {
4+
return (
5+
<div className="card flex justify-center">
6+
<Rating modelValue={3} disabled />
7+
</div>
8+
);
9+
}
10+
11+
export default DisabledDemo;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Rating } from 'primereact/rating';
2+
3+
function ReadOnlyDemo() {
4+
return (
5+
<div className="card flex justify-center">
6+
<Rating modelValue={3} readOnly />
7+
</div>
8+
);
9+
}
10+
11+
export default ReadOnlyDemo;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Rating } from 'primereact/rating';
2+
3+
function StarsDemo() {
4+
return (
5+
<div className="card flex justify-center">
6+
<Rating stars={10} />
7+
</div>
8+
);
9+
}
10+
11+
export default StarsDemo;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Rating } from 'primereact/rating';
2+
3+
function TemplateDemo() {
4+
return (
5+
<div className="card flex justify-center">
6+
<Rating
7+
modelValue={3}
8+
onIcon={<img src="https://primefaces.org/cdn/primevue/images/rating/custom-onicon.png" height="24" width="24" />}
9+
offIcon={<img src="https://primefaces.org/cdn/primevue/images/rating/custom-officon.png" height="24" width="24" />}
10+
/>
11+
</div>
12+
);
13+
}
14+
15+
export default TemplateDemo;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
title: Rating API
3+
description: API documentation for Rating component
4+
component: rating
5+
---
6+
7+
## Rating
8+
9+
### Props
10+
11+
<DocTable name="Rating" category="api" type="props" />
12+
13+
### State
14+
15+
<DocTable name="Rating" category="api" type="state" />
16+
17+
### Exposes
18+
19+
<DocTable name="Rating" category="api" type="exposes" />
20+
21+
### Interfaces
22+
23+
<DocTable name="Rating" category="api" type="interfaces" />
24+
25+
### Types
26+
27+
<DocTable name="Rating" category="api" type="types" />
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
title: Rating
3+
description: Rating component is a star based selection input.
4+
component: rating
5+
---
6+
7+
## Usage
8+
9+
```tsx
10+
import { Rating } from 'primereact/rating';
11+
```
12+
13+
```tsx
14+
<Rating />
15+
```
16+
17+
## Examples
18+
19+
### Basic
20+
21+
Rating is used with the `modelValue` property.
22+
23+
<DocDemoViewer name="rating:basic-demo" />
24+
25+
### Number of Stars
26+
27+
Number of stars to display is defined with `stars` property.
28+
29+
<DocDemoViewer name="rating:stars-demo" />
30+
31+
### Template
32+
33+
Custom icons are used to override the default icons with `onIcon` and `offIcon` properties.
34+
35+
<DocDemoViewer name="rating:template-demo" />
36+
37+
### ReadOnly
38+
39+
When `readOnly` is present, value cannot be edited.
40+
41+
<DocDemoViewer name="rating:readonly-demo" />
42+
43+
### Disabled
44+
45+
When `disabled` is present, value cannot be edited.
46+
47+
<DocDemoViewer name="rating:disabled-demo" />
48+
49+
## Accessibility
50+
51+
### Screen Reader
52+
53+
Rating component internally uses radio buttons that are only visible to screen readers. The value to read for item is retrieved from the [locale](/docs/configuration#locale) API via `star` and `stars` of the `aria` property.
54+
55+
### Keyboard Support
56+
57+
Keyboard interaction is derived from the native browser handling of radio buttons in a group.
58+
59+
| Key | Function |
60+
| -------------------------- | ---------------------------------------------------------------------------------------------------- |
61+
| `tab` | Moves focus to the star representing the value, if there is none then first star receives the focus. |
62+
| `left arrow` `up arrow` | Moves focus to the previous star, if there is none then last radio button receives the focus. |
63+
| `right arrow` `down arrow` | Moves focus to the next star, if there is none then first star receives the focus. |
64+
| `space` | If the focused star does not represent the value, changes the value to the star value. |
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
title: Rating Pass Through
3+
description: Pass Through documentation for Rating component
4+
component: rating
5+
---
6+
7+
## Viewer
8+
9+
Some sections may not be visible due to the availability of the particular feature.
10+
11+
<DocPTViewer name="rating-pt" components={['Rating']} />
12+
13+
## Rating PT Options
14+
15+
<DocTable name="Rating" category="pt" />
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
title: Rating Theming
3+
description: Theming documentation for Rating component
4+
component: rating
5+
---
6+
7+
## Styled
8+
9+
### CSS Classes
10+
11+
List of class names used in the styled mode.
12+
13+
<DocTable name="Rating" category="style" />
14+
15+
### Design Tokens
16+
17+
List of design tokens.
18+
19+
<DocTable name="Rating" category="token" />
20+
21+
## Unstyled
22+
23+
Theming is implemented with the pass through properties in unstyled mode.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './useRating';
2+
export * from './useRating.props';

0 commit comments

Comments
 (0)