组件
评分 Rating Group
RatingGroup:评分组件。一排图标默认低调,点亮后使用 primary 色。部件:Root、Label、Control、Item、HiddenInput(另有 Context 和 ItemContext 渲染辅助)。
#基础用法
<script setup lang="ts">
import { RatingGroup } from "@bysages/vue";
</script>
<template>
<RatingGroup.Root :count="5" :default-value="3">
<RatingGroup.Label>Rate this entry</RatingGroup.Label>
<RatingGroup.Control>
<RatingGroup.Context v-slot="{ items }">
<RatingGroup.Item v-for="item in items" :key="item" :index="item">
<svg viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
<path
d="M12 2.5l2.9 6.1 6.7.9-4.9 4.6 1.2 6.6-5.9-3.2-5.9 3.2 1.2-6.6L2.4 9.5l6.7-.9z"
/>
</svg>
</RatingGroup.Item>
</RatingGroup.Context>
<RatingGroup.HiddenInput />
</RatingGroup.Control>
</RatingGroup.Root>
</template>
#属性
#Control
纯造型的部件——自身没有属性,沿用部件结构的共享样式。
#HiddenInput
纯造型的部件——自身没有属性,沿用部件结构的共享样式。
#ItemContext
纯造型的部件——自身没有属性,沿用部件结构的共享样式。
#Item
| 属性 | 类型 | 默认值 | 描述 |
|---|---|---|---|
index | number | — |
#Label
纯造型的部件——自身没有属性,沿用部件结构的共享样式。
#Root
| 属性 | 类型 | 默认值 | 描述 |
|---|---|---|---|
size | String as PropType<"sm" | "md" | "lg"> | "md" | 评分控件的尺寸档位 |
allowHalf | boolean | 是否允许半星 | |
autoFocus | boolean | 是否自动聚焦评分组件 | |
count | number | 5 | 评分项总数 |
defaultValue | number | 评分渲染时的初始值;不需要控制评分值时使用 | |
disabled | boolean | 评分是否禁用 | |
form | string | 底层 input 元素关联的表单 | |
id | string | 组件内部状态机的唯一标识 | |
ids | Partial<{ root: string; label: string; hiddenInput: string; control: string; item(id: string): string; }> | 评分各元素的 id,适合组合使用 | |
modelValue | number | 评分组的 v-model 值 | |
name | string | 评分元素的 name 属性,用于表单 | |
readOnly | boolean | 评分是否只读 | |
required | boolean | 评分是否必填 | |
translations | ratingGroup.IntlTranslations | 无障碍元素及其状态的本地化文案 |