Skip to content

Rate

Used for rating things.

Basic Usage

The component uses a five-point rating scale by default, and colors can be used to customize the active icon color.

Default:
Custom colors:
Basic Usage

Different Sizes

Use the size prop to switch between large, default, and small.

Different Sizes

Allow Half Selection

Set allow-half to enable half-step ratings.

Allow Half Selection

Auxiliary Text

Use show-text to display helper text or show-score to render the numeric value.

Fair
3.7 pts
Auxiliary Text

Clearable

Use clearable to reset the value to 0 when clicking the current score again.

Clearable

Read-only

Set disabled to enable read-only display mode.

3.7
Read-only

Custom Icon

Use the icon slot to replace the built-in rating icon.

Custom Icon

Use in Nuxt

YhRate works in Nuxt 3/4 after registering @yh-ui/nuxt.

Average Score:
4.5
Use in Nuxt

API

Props

PropDescriptionTypeDefault
model-value / v-modelBinding valuenumber0
maxMaximum valuenumber5
disabledWhether it is read-onlybooleanfalse
allow-halfWhether half-selection is allowedbooleanfalse
iconCustom selected iconstring | Component''
void-iconCustom unselected iconstring | Component''
disabled-void-iconCustom unselected icon when disabledstring | Component''
colorsActive rating colorsstring | string[] | Record<number, string>'#F7BA2A'
void-colorColor for unselected statusstring'#C6D1DE'
disabled-void-colorUnselected color when disabledstring'#EFF2F7'
show-scoreWhether to display the current scorebooleanfalse
show-textWhether to display auxiliary textbooleanfalse
text-colorAuxiliary text colorstring'#1f2d3d'
textsArray of auxiliary textsstring[][]
score-templateDisplay template for scoresstring'{value}'
sizeSize of rating icons'large' | 'default' | 'small''default'
clearableWhether clicking the current value resets the ratingbooleanfalse
theme-overridesComponent-level theme variable overridesComponentThemeVarsundefined

Events

Event NameDescriptionCallback Parameters
update:modelValueTriggered when the bound value changes(value: number) => void
changeTriggered when the value changes(value: number) => void

Slots

Slot NameDescriptionParameters
iconCustom icon{ index: number, width: string, activeColor: string, voidColor: string }

Expose

This component does not expose public instance methods or properties.

Theme Variables

VariableDescriptionDefault
--yh-rate-void-colorUnselected color#c6d1de
--yh-rate-fill-colorSelected color#f7ba2a
--yh-rate-disabled-void-colorUnselected color when disabled#eff2f7
--yh-rate-text-colorAuxiliary text color#1f2d3d
--yh-rate-font-sizeAuxiliary text size14px
--yh-rate-icon-marginIcon spacing6px

Type Exports

NameDescription
YhRatePropsComponent props type
YhRateEmitsComponent emits type
YhRateSlotsComponent slots type
YhRateSizeSize union type
YhRateInstanceComponent instance type

Released under the MIT License.