Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ✨ new Rating Component #2951

Open
wants to merge 22 commits into
base: main
Choose a base branch
from

Conversation

flixlix
Copy link
Contributor

@flixlix flixlix commented Mar 8, 2024

✨ New Rating Component

Disclaimer: I am aware of other PRs such as #2818 and #2350, but I reviewed both and came to the conclusion that I wanted to sort of combine them. #2818 allows a user to select a new rating but a new rating is set when hovering, which I'm not a fan of. #2350 does not allow for setting a rating, instead just displays the rating that was passed as a prop.

This implementation is based on @radix-ui/react-radio-group, which makes it more accessible, since it is also navigable with a keyboard.

Screen.Recording.2024-03-08.at.14.36.59.mov
image

Custom icon

A custom icon can be passed as an Icon prop. Depending on the style, you should pass a Lucide Icon or a Radix Icon. The Rating components handles all states.

image image

count

A custom amount of ratings can be passed to adjust the granularity of the rating using the ratingSteps prop.

image image

custom label

By default the label will be (${currentValue}/${totalSteps}). This can be overridden by simply passing a customLabel prop as a string.

image image

disabled

To show the user the rating component is disabled, the opacity of the icons is lowered.

image image

readonly

In contrary to the disabled state, the readonly is supposed to be used in cases where the component merely displays the current rating and never expects any input to be entered.
In this case the component looks the same but cursor events as well as keyboard events are turned off.

image image

Copy link

vercel bot commented Mar 8, 2024

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

A member of the Team first needs to authorize it.

@flixlix flixlix changed the title Feat rating component feat: ✨ new *Rating* Component Mar 8, 2024
@flixlix flixlix changed the title feat: ✨ new *Rating* Component feat: ✨ new **Rating** Component Mar 8, 2024
@flixlix flixlix changed the title feat: ✨ new **Rating** Component feat: ✨ new Rating Component Mar 8, 2024
Copy link

vercel bot commented Mar 11, 2024

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 11, 2024 3:46pm

Copy link

@amjed-ali-k amjed-ali-k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@flixlix flixlix force-pushed the feat-rating-component branch from ff4ab58 to 117ee84 Compare April 6, 2024 21:36
@ruymon
Copy link

ruymon commented Apr 15, 2024

LGTM! 🚀

@rayaanr
Copy link

rayaanr commented May 19, 2024

Hey, Is it possible to rate, or display decimal values such as 3.5 , 4.5?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants