PXD

Rating

Rating component for user feedback

Default

<script setup>
import { ref } from 'vue'

const value = ref(0)
</script>

<template>
  <PRating v-model="value" />
</template>

Sizes

<script setup>
import { ref } from 'vue'

const value = ref(0)
</script>

<template>
  <PStack align="center">
    <PRating v-model="value" size="sm" />
    <PRating v-model="value" />
    <PRating v-model="value" size="lg" />
  </PStack>
</template>

Half Star

Enable allow-half to support half-star ratings.

<script setup>
import { ref } from 'vue'

const value = ref(0)
</script>

<template>
  <PRating v-model="value" allow-half />
</template>

Clearable

Enable clearable to allow clearing the value by clicking the same star.

<script setup>
import { ref } from 'vue'

const value = ref(3)
</script>

<template>
  <PRating v-model="value" clearable />
</template>

Readonly

<template>
  <PRating :model-value="3" readonly />
</template>

Disabled

<template>
  <PRating :model-value="3" disabled />
</template>

Custom Color

<script setup>
import { ref } from 'vue'

const value = ref(0)
</script>

<template>
  <PStack direction="vertical">
    <PRating v-model="value" color="var(--color-amber-600)" />
    <PRating v-model="value" color="var(--color-red-700)" void-color="var(--color-gray-alpha-200)" />
  </PStack>
</template>

Custom Count

<script setup>
import { ref } from 'vue'

const value = ref(0)
</script>

<template>
  <PRating v-model="value" :count="10" />
</template>

Props

NameTypeDefaultDescription
model-valuenumber0Current rating value
countnumber5Number of stars
size'sm' | 'md' | 'lg''md'Star size
colorstring-Active star color
void-colorstring-Inactive star color
allow-halfbooleanfalseAllow half star selection
readonlybooleanfalseReadonly mode
disabledbooleanfalseDisabled mode
clearablebooleanfalseAllow clearing value by clicking the same star

Events

NameTypeDescription
change(value: number) => voidEmitted when the user commits a new rating.
update:modelValue(value: number) => voidEmitted together with change when the user commits a new rating.

Source

Source