🚨 Active Supply Chain Attack:node-ipc Package Compromised.Learn More
Socket
Book a DemoSign in
Socket

astro-rating

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

astro-rating

Astro component that uses stars to display the rating of a product, post, comment, etc.

unpublished
latest
Source
npmnpm
Version
0.2.6
Version published
Maintainers
1
Created
Source

Astro Rating :star: :star: :star: :star: :star:

Astro component that uses stars to display the rating of a product, post, comment, etc.

Uses tailwindcss for custom class based styling and astro-icon to customize the star icons

How to use

Install package:

npm i astro-rating

Inside a .astro component/layout/page:

Single Default Rating

import { Rating } from 'astro-rating';

//Create a rating
<Rating total="90876" rate="2.5" max="5" />

Examples

Default

Rating Component Example

<Rating total="1279643" rate="5" max="5" />
<Rating total="673923" rate="4.5" max="5" />
<Rating total="90876" rate="3.5" max="5" />
<Rating total="8634" rate="3" max="5" />
<Rating total="178" rate="2.5" max="5" />
<Rating total="39" rate="1.5" max="5" />
<Rating total="8" rate="0.5" max="5" />
<Rating total="0" rate="0" max="5" />

Astro-Icon Support

astro-rating uses astro-icon to deliver svgs for displaying stars. If you want to use different star icons read about the Icon name property and how it uses Iconify to fetch any popular icon from a bunch of the most popular icon packs.

Phosphor

Phosphor

const phosphor = {
  rate: "8.5",
  max: "10",
  total: "32769",
  full: "ph:star-fill",
  half: "ph:star-half-fill",
  empty: "ph:star",
  starClass: "text-yellow-500 w-4 h-4"
}

<Rating {...phosphor}/>

Material Design Icons

Material Design

const material_design = {
  rate: "2.5",
  max: "5",
  total: "72",
  full: "mdi:star",
  half: "mdi:star-half-full",
  empty: "mdi:star-outline",
  starClass: "text-yellow-500 w-4 h-4"
}

<Rating {...material_design}/>

Custom Styling

Use tailwindcss and the provided class props to customize the look of your rating

Reversed Column

const col-reverse = {
  rate="9.5" 
  max="10"
  total="872"
  class: "flex flex-col-reverse items-end",
}

<Rating {...col-reverse}/>

Reversed Row

const row-reverse = {
  rate="2.5" 
  max="5"
  total="178"
  class: "flex flex-row-reverse items-center gap-1",
}

<Rating {...row-reverse}/>

Props

PropnameTypeDescriptionDefault
ratenumber|string0# between 0 and max
maxnumber|string5max number of stars
totalnumber|stringtotal # of ratings
fullstringstar-fullastro-icon Icon name prop representing a full star
halfstringstar-halfastro-icon Icon name prop representing a half star
emptystringstar-emptyastro-icon Icon name prop representing a empty star
totalClassstringleading-none text-xs text-gray-300class of the total ratings span element
starsClassstringflex items-centerclass to div that holds all stars
starClassstringh-4 w-4class to div that surrounds the icons svg element
...attrsstring{class:"flex items-center gap-1"}apply any html attribute like 'class', 'id', or 'style' to the rating container

Advanced Rating

If you need more control over your Rating component use a ARating component. ARating allows you to add attributes to any element inside your rating using an object.

Examples

ARating uses all the same props but puts them inside of any object so you can defined any attribute you would like for that element:

ARating

import { ARating } from 'astro-rating';

const my_rating = {
  max: 5,
  rate: 2.5,
  full: "mdi:star",
  half: "mdi:star-half-full",
  empty: "mdi:star-outline",
  total: {
    text: "9876",
    class: "leading-none text-xs text-gray-300",
  },
  stars: {
    class: "flex items-center"
  },
  star: {
    class: "h-4 w-4 text-yellow-300"
  },
  id: "my-rating"
}

<ARating {...my_rating}/>
PropnameTypeDescriptionDefault
ratenumber|string0# between 0 and max
maxnumber|string5max number of stars
fullstringstar-fullastro-icon Icon name prop representing a full star
halfstringstar-halfastro-icon Icon name prop representing a half star
emptystringstar-emptyastro-icon Icon name prop representing a empty star
totalobject{class:"leading-none text-xs text-gray-300"}Total ratings span element
total.textstringTotal rating span text
starsobject{full: "star-full",half: "star-half",empty: "star-empty",class: "flex items-center"}Div with all star svgs
starobject{class:"flex items-center gap-1"}Star icon svg element
...attrsstring{class:"flex items-center gap-1"}apply any html attribute like 'class', 'id', or 'style' to the rating container

Keywords

astro

FAQs

Package last updated on 22 Jun 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts