ui icon indicating copy to clipboard operation
ui copied to clipboard

Feat: add new `Ratings` component and examples

Open jrTilak opened this issue 6 months ago • 18 comments

fixes #1107 , fixes #2235

Added Rating Star Component

image

Why?

The library lacks a rating component, and this addition aims to provide a valuable feature. Addressing community's demand: Two related issues, #1107 and #2235, highlighted the community's interest in having a rating component.

How?

  • Introduced a new component, Ratings, that displays a rating value as a series of stars or other custom icon.
  • Utilized the Lucide React library for star icons.
  • Provided customization options for total stars, size, fill behavior, and different variants.

Feedback is appreciated. 🔥❤️

jrTilak avatar Jan 09 '24 09:01 jrTilak

@jrTilak is attempting to deploy a commit to the shadcn-pro Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar Jan 09 '24 09:01 vercel[bot]

How can this component be edited to be used in a form with maybe ToggleGroupPrimitive?

iansamz avatar Jan 09 '24 18:01 iansamz

How can this component be edited to be used in a form with maybe ToggleGroupPrimitive?

We can do like this :

<Ratings rating={1.5} />
<Ratings rating={2} variant="destructive" Icon={Heart} />
<Ratings rating={2.5} variant="yellow" totalStars={8} />

We can pass the following props and other native props as a html element like onClick, styles etc

Name Type Default Description
rating number (required) - Rating value.
totalStars number 5 Total number of stars.
size number 20 Size of each star.
fill boolean true Whether to fill the stars or not.
Icon React.ComponentType Star Custom icon instead of Star.
variant enum "default" "default", "destructive", and "yellow".

That's it and i don't understand what you mean by ToggleGroupPrimitive 🫠

jrTilak avatar Jan 10 '24 01:01 jrTilak

How can this component be edited to be used in a form with maybe ToggleGroupPrimitive?

We can do like this :

<Ratings rating={1.5} />
<Ratings rating={2} variant="destructive" Icon={Heart} />
<Ratings rating={2.5} variant="yellow" totalStars={8} />

We can pass the following props and other native props as a html element like onClick, styles etc

Name Type Default Description rating number (required) - Rating value. totalStars number 5 Total number of stars. size number 20 Size of each star. fill boolean true Whether to fill the stars or not. Icon React.ComponentType Star Custom icon instead of Star. variant enum "default" "default", "destructive", and "yellow". That's it and i don't understand what you mean by ToggleGroupPrimitive 🫠

👋 awesome but I have a question, wouldn't it be better to use icon={<Heart/>} instead? imo that'd be more flexible in terms of DX?

Edit: by that I mean it'd allow customization of icon easily

twlite avatar Jan 12 '24 10:01 twlite

Yeah, I didn't think about that, Thanks for the suggestion. @twlite

jrTilak avatar Jan 13 '24 16:01 jrTilak

Could this be made to be used in a form via hover states, and callbacks with the selected value?

TomHart avatar Jan 18 '24 00:01 TomHart

@shadcn Need some feedback!! What do you say? ⭐

jrTilak avatar Jan 18 '24 07:01 jrTilak

Just chiming in to say I really would like to see something like this available! Great addition.

karlmacklin avatar Jan 24 '24 20:01 karlmacklin

Component LGTM!

iamshubhamjangle avatar Jan 31 '24 07:01 iamshubhamjangle

Seems good!

thomasbeckford avatar Feb 05 '24 19:02 thomasbeckford

can we please merge this? this looks really good, I was looking for a component like this

lyondeveloper avatar Feb 27 '24 19:02 lyondeveloper

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 6, 2024 2:29am

vercel[bot] avatar Feb 29 '24 05:02 vercel[bot]

Any updates?

c0h1b4 avatar Apr 05 '24 20:04 c0h1b4

@shadcn please merge this 🙏 I will start copying already. good job @jrTilak !

tonnoz avatar Apr 07 '24 09:04 tonnoz