AdvancedRating Component
Set up
Let's import all necessary components in the script tag. We import a thumb-up icon but you can use any icons as you like.
<script>
import { Rating, AdvancedRating } from 'flowbite-svelte';
import { ThumbUp } from 'svelte-heros';
</script>
AdvancedRating component
Set the `total`, rating`, and `ratings` prop for AdvancedRation component. Use the `rating` slot for Rating component with the `total` and `rating` props. Use the `globalText` slot for additional information.
3.21 out of 5
1,745 global ratings
5 star
70%
4 star
17%
3 star
8%
2 star
4%
1 star
1%
<AdvancedRating
total="5"
rating="3.21"
ratings={[
{ label: '5 star', rating: 70 },
{ label: '4 star', rating: 17 },
{ label: '3 star', rating: 8 },
{ label: '2 star', rating: 4 },
{ label: '1 star', rating: 1 }
]}
>
<span slot="rating">
<Rating total="5" rating="3.21">
<p slot="text" class="ml-2 text-sm font-medium text-gray-500 dark:text-gray-400">3.21 out of 5</p>
</Rating>
</span>
<p slot="globalText" class="ml-2 text-sm font-medium text-gray-500 dark:text-gray-400">1,745 global ratings</p>
</AdvancedRating>
Different icon
As we describe in the Rating component, you can change an icon in the `ratingUp` and `ratingDown` in the Rating component.
3.21 out of 5
1,745 global ratings
5 star
70%
4 star
17%
3 star
8%
2 star
4%
1 star
1%
<AdvancedRating
total="5"
rating="3.21"
ratings={[
{ label: '5 star', rating: 70 },
{ label: '4 star', rating: 17 },
{ label: '3 star', rating: 8 },
{ label: '2 star', rating: 4 },
{ label: '1 star', rating: 1 }
]}
>
<span slot="rating">
<Rating total="5" rating="3.21" ceil>
<span slot="ratingUp">
<ThumbUp class="text-yellow-300 dark:text-yellow-200" />
</span>
<span slot="ratingDown">
<ThumbUp class="text-gray-300 dark:text-gray-500" />
</span>
<p slot="text" class="ml-2 text-sm font-medium text-gray-500 dark:text-gray-400">3.21 out of 5</p>
</Rating>
</span>
<p slot="globalText" class="ml-2 text-sm font-medium text-gray-500 dark:text-gray-400">1,745 global ratings</p>
</AdvancedRating>
Props
The component has the following props, type, and default values. See types page for type information.
Name | Type | Default |
---|---|---|
ratings | { label: string | |
divClass | string | 'flex items-center mt-4' |
labelClass | string | 'text-sm font-medium text-blue-600 dark:text-blue-500' |
ratingDivClass | string | 'mx-4 w-2/4 h-5 bg-gray-200 rounded dark:bg-gray-700' |
ratingClass | string | 'h-5 bg-yellow-400 rounded' |
rightLabelClass | string | 'text-sm font-medium text-blue-600 dark:text-blue-500' |
unit | string | '%' |