Skip to content

Rate ​

A rating component built on Lucide Star vector icons. Active stars feature high-saturation HSL-themed golden fills, heavy black borders, and springy hover-scaling micro-interactions.

Preview ​

Preview

基础评分

当前分值: 3

关联外部标签

商品评分

允许半星

当前分值: 2.5

自定义最大值 (10颗星)

当前分值: 6

只读模式

只读分值: 4

自定义图腾图标 (icon)

heart:
lightning:
star-8:

不同的尺寸

小 (sm):
中 (md):
大 (lg):

Installation ​

pnpm dlx brutx-vue@latest add rate

Usage ​

Basic Usage ​

vue
<script setup>
import { ref } from 'vue'
import { Rate } from 'brutx-ui-vue'

const value = ref(3)
</script>

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

Rate uses the current locale for its default accessible name. Use aria-label to provide a custom name, or aria-labelledby to reference visible page text. When aria-labelledby is present, the external label takes precedence.

vue
<template>
    <span id="product-rating-label">Product rating</span>
    <Rate v-model="value" aria-labelledby="product-rating-label" />
</template>

Half Star Support ​

Allow decimal ratings (half stars) using the allow-half property.

vue
<script setup>
import { ref } from 'vue'
import { Rate } from 'brutx-ui-vue'

const value = ref(3.5)
</script>

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

Max Stars Count ​

Change the upper limit of the rating scale (default is 5) using the max property.

vue
<template>
    <Rate v-model="value" :max="10" />
</template>

Readonly Mode ​

Add readonly to display a rating while preventing hover previews, pointer selection, and keyboard changes.

vue
<template>
    <Rate v-model="value" readonly allow-half />
</template>

Sizes ​

SizeDescription
smSmall icons with compact spacing
mdDefault icons and spacing
lgLarge icons with wider spacing

API Reference ​

Rate — Props
NameTypeDefaultDescription
modelValue
number | undefined
0
The current rating, bound with v-model. Hovering temporarily previews a rating; leaving restores the bound value.
Details

Declared type

number | undefined

Default value details

Resolved value
0

Source

Rate.vue:11

packages/ui/src/components/rate/Rate.vue

max
number | undefined
5
The maximum rating, number of rendered icons, and value selected by the End key. Supply a positive integer.
Details

Declared type

number | undefined

Default value details

Resolved value
5

Source

Rate.vue:12

packages/ui/src/components/rate/Rate.vue

allowHalf
boolean | undefined
false
Enables half-point selection and half-filled icons. The left half of each icon selects a half point, and arrow keys move in half-point steps.
Details

Declared type

boolean | undefined

Literal values

  • false
  • true

Default value details

Resolved value
false

Source

Rate.vue:13

packages/ui/src/components/rate/Rate.vue

readonly
boolean | undefined
false
Displays the rating while preventing hover previews, pointer selection, and keyboard changes, and removes the component from the Tab order.
Details

Declared type

boolean | undefined

Literal values

  • false
  • true

Default value details

Resolved value
false

Source

Rate.vue:14

packages/ui/src/components/rate/Rate.vue

size
"lg" | "sm" | "md" | undefined
"md"
Controls the rating icon dimensions and spacing between icons.
Details

Declared type

"lg" | "sm" | "md" | undefined

Literal values

  • "lg"
  • "md"
  • "sm"

Default value details

Resolved value
"md"

Source

Rate.vue:15

packages/ui/src/components/rate/Rate.vue

icon
string | undefined
undefined

Runtime fallback:When omitted, empty, or not recognized by the shape library, the component uses the Lucide Star icon.

The BrutalShape name used for rating icons, such as heart, lightning, or star-5.
Details

Declared type

string | undefined

Default value details

Declaration
undefined

Source: packages/ui/src/components/rate/Rate.vue

Resolved value
undefined
Runtime fallback
When omitted, empty, or not recognized by the shape library, the component uses the Lucide Star icon.

Applied by the component under the documented runtime conditions.

Source

Rate.vue:17

packages/ui/src/components/rate/Rate.vue

ariaLabel
string | undefined
undefined
The custom accessible name for the rating control. It is used when aria-labelledby is omitted; when both are omitted, the current locale supplies the default name.
Details

Declared type

string | undefined

Default value details

Declaration
undefined

Source: packages/ui/src/components/rate/Rate.vue

Resolved value
undefined

Source

Rate.vue:19

packages/ui/src/components/rate/Rate.vue

ariaLabelledby
string | undefined
undefined
The ID of an external label element. When provided, it names the rating control and takes precedence over ariaLabel.
Details

Declared type

string | undefined

Default value details

Declaration
undefined

Source: packages/ui/src/components/rate/Rate.vue

Resolved value
undefined

Source

Rate.vue:21

packages/ui/src/components/rate/Rate.vue

Rate — Events
NameSignature or typeDescription
@update:modelValue
[value: number]
Emitted when pointer or keyboard selection chooses a rating different from the current value, updating v-model. Hover previews do not emit it.
Details

Declared type

[value: number]

Source

Rate.vue

packages/ui/src/components/rate/Rate.vue

@change
[value: number]
Emitted after update:modelValue when the user selects a different rating, with the same new rating as its payload.
Details

Declared type

[value: number]

Source

Rate.vue

packages/ui/src/components/rate/Rate.vue

Accessibility ​

  • Keyboard Interaction: Right or Up increases the rating; Left or Down decreases it. Home selects zero and End selects the maximum. With allowHalf, arrow keys use half-point steps. Read-only mode prevents keyboard changes and removes the component from the Tab order
  • ARIA Attributes: The root element has role="slider", aria-valuenow representing the current rating score, aria-valuemin="0", aria-valuemax mapped to max, and aria-readonly indicating readonly state
  • Accessible Name: The default name comes from the current locale. aria-labelledby references a visible external label and takes precedence over aria-label; use aria-label when no external label is available
  • Reduced Motion: The stamp animation after icon selection reads prefers-reduced-motion and does not play when reduced motion is requested

Brute force builds.