Skip to content

feat(Rating): new component #4253

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

Draft
wants to merge 1 commit into
base: v3
Choose a base branch
from

Conversation

J-Michalek
Copy link
Collaborator

πŸ”— Linked issue

Resolves: #505

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

I've added a new component for rating.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@J-Michalek
Copy link
Collaborator Author

@benjamincanac I'm wondering if this component shouldn't be implemented in RekaUI first as it needs a11y support and I'm not sure we want to manage it ourselves in NuxtUI, what are your thoughts?

Copy link
Member

benjamincanac commented May 30, 2025

Yes I agree, this is why I was holding back on this 😬

@J-Michalek
Copy link
Collaborator Author

Alright, I will bring it upstream: unovue/reka-ui#1966 could you please add the reka-ui label to the issue?

@dan-hale
Copy link
Contributor

dan-hale commented Jun 3, 2025

Here is some code I am using currently to do this. There is possibly no need to build it into reka as the RadioGroup component seems to do the job. @J-Michalek

<script setup lang=ts>
import type { ButtonGroupProps } from '@nuxt/ui/components/ButtonGroup.vue'

withDefaults(defineProps<{ length?: number, readonly?: boolean, size?: ButtonGroupProps['size'] }>(), { length: 5 })
const model = defineModel<number>({ default: undefined })

const hoverIndex = ref<number>()
</script>

<template>
  <radio-group-root v-model="model" :disabled="readonly" as-child @mouseleave="hoverIndex = undefined">
    <u-button-group :size>
      <radio-group-item v-for="i in length" :key="i" :value="i" as-child @mouseenter="hoverIndex = i">
        <u-button :disabled="readonly" variant="ghost" class="p-[0.25em] transform-origin-c transition-all transition-ease-in-out hover:scale-120" :icon="(hoverIndex === undefined ? (i <= model) : (!readonly && i <= hoverIndex)) ? 'material-symbols:star-rounded' : 'material-symbols:star-outline-rounded'" :color="(i <= model) || (hoverIndex && !readonly && i <= hoverIndex) ? 'primary' : 'neutral'" />
      </radio-group-item>
    </u-button-group>
  </radio-group-root>
</template>

@J-Michalek
Copy link
Collaborator Author

J-Michalek commented Jun 3, 2025

I kinda like the idea, but I still think that we should bring it upstream. There will be some specific logic such as the precision of the rating i.e. 1.5, 2.5, 4.75, which I think we don't really want to mantain in NuxtUI, also bringing it upstream will make it accessible to more developers as it won't be locked in NuxtUI.

So far I was implementing it from scratch but using the radio group component seems like a good idea as all the a11y is already handled.

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.

[Feature Request] Rating
4 participants