Skip to content

Rate

Used for quick evaluation or displaying rating results.

Component Types

Basic Usage

Set v-model to bind the current score, num is used to set the total score, default is 5.

html
<wd-rate v-model="value" @change="handleChange" />
ts
const value = ref(5)

function handleChange({ value }: { value: number }) {
  console.log(value)
}

Component States

Read-only

Set the readonly property.

html
<wd-rate v-model="value" readonly />

Disabled

Set the disabled property.

html
<wd-rate v-model="value" disabled />

Component Styles

Modify Selected Color

You can modify the selected icon color through active-color, and also support passing in a two-color array to achieve segmented colors.

html
<wd-rate v-model="value" active-color="linear-gradient(180deg, rgba(255, 238, 0, 1) 0%, rgba(250, 176, 21, 1) 100%)" />
<wd-rate
  v-model="value"
  :active-color="[
    'linear-gradient(180deg, rgba(255, 238, 0, 1) 0%, rgba(250, 176, 21, 1) 100%)',
    'linear-gradient(315deg, rgba(245, 34, 34, 1) 0%, rgba(255, 117, 102, 1) 100%)'
  ]"
/>

Modify Icon and Color

You can set unselected and selected icons through icon and active-icon respectively, and customize the visual style in combination with active-color.

html
<wd-rate v-model="value" block icon="Fire" active-icon="Fire" active-color="var(--wot-red-6)" />
<wd-rate v-model="value" block icon="thumb-down-fill" active-icon="thumb-up-fill" active-color="var(--wot-green-6)" />

Modify Size and Spacing

Modify icon size through size, and icon spacing through space.

html
<wd-rate v-model="value" size="36" space="12px" />

Special Styles

Allow Half Selection

Set the allow-half property.

html
<wd-rate v-model="value" allow-half />

Allow Clearing Rating

After setting the clearable property, clicking the current minimum score again can clear the rating. When combined with allow-half, half-star ratings can be cleared.

html
<wd-rate v-model="value" clearable />
<wd-rate v-model="value" clearable allow-half />

Attributes

ParameterDescriptionTypeDefault Value
v-modelCurrent scorenumber | nullnull
numMaximum rating valuenumber5
readonlyWhether read-onlybooleanfalse
sizeIcon sizestring-
spaceIcon spacingstring | number-
colorUnselected icon colorstring-
active-colorSelected icon color, supports string or string[]string | string[]-
iconUnselected icon class namestring'star-fill'
active-iconSelected icon class namestring'star-fill'
disabledWhether disabledbooleanfalse
allow-halfWhether to allow half selectionbooleanfalse
clearableWhether to allow clearing after clicking againbooleanfalse
blockWhether to display as blockbooleanfalse
custom-classRoot node custom class namestring''
custom-styleRoot node custom stylestring''

Events

Event NameDescriptionParameters
changeTriggered when clicking the icon to modify the score{ value }

主题定制

CSS 变量

组件提供了下列 CSS 变量,可用于自定义样式,使用方法请参考 ConfigProvider 全局配置

名称默认值描述
--wot-rate-color$filled-extra-strong未激活图标颜色
--wot-rate-active-color$classifyapplication-yellow-content激活图标颜色
--wot-rate-size$n-24图标尺寸
--wot-rate-disabled-opacity$opacity-disabled禁用态透明度
--wot-rate-item-space$spacing-extra-tight图标间距

Source Code

Documentation
Component

Released under the MIT License.

Released under the MIT License.