v2.15.0

InputRating

Компонент для показа и сбора оценок от пользователей.

Использование

Директива v-model управляет значением оценки InputRating.

<script setup lang="ts">
const value = ref(3)
</script>

<template>
  <B24InputRating v-model="value" />
</template>
<script setup lang="ts">
import { ref } from 'vue'

const value = ref(3)
</script>

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

Пропс default-value задаёт начальное значение, когда управлять состоянием не нужно.

<template>
  <B24InputRating :default-value="3" />
</template>

Шаг

Пропс step задаёт точность каждой звезды. Значение 0.5 разрешает оценки в ползвезды.

<template>
  <B24InputRating :step="0.5" :default-value="3.5" />
</template>

Количество

Пропс length задаёт число звёзд. По умолчанию 5.

<template>
  <B24InputRating :length="10" :step="0.5" :default-value="7.5" />
</template>

Сбрасываемое значение

Пропс clearable позволяет сбросить оценку щелчком по текущему выбранному значению. По умолчанию false.

<template>
  <B24InputRating clearable :default-value="3" />
</template>

Предпросмотр при наведении

Пропс hoverable определяет, показывает ли оценка предпросмотр значения при наведении на звёзды. По умолчанию false.

<template>
  <B24InputRating hoverable :default-value="3" />
</template>

Иконка

Пропс icon меняет иконку звёзд.

<script setup lang="ts">
import RocketIcon from '@bitrix24/b24icons-vue/main/RocketIcon'
</script>

<template>
  <B24InputRating :icon="RocketIcon" :default-value="4" />
</template>

Иконка пустой звезды

Пропс empty-icon меняет иконку пустых звёзд. Если он не задан, используется та же иконка, что и в icon.

<script setup lang="ts">
import RocketIcon from '@bitrix24/b24icons-vue/main/RocketIcon'
</script>

<template>
  <B24InputRating :next-icon="RocketIcon" :default-value="3" />
</template>

Цвет

Пропс color меняет цвет закрашенных звёзд.

<template>
  <B24InputRating color="air-primary-success" :default-value="4" />
</template>

Размер

Пропс size меняет размер звёзд.

<template>
  <B24InputRating size="xl" :default-value="4" />
</template>

Ориентация

Пропс orientation меняет ориентацию оценки. По умолчанию horizontal.

<template>
  <B24InputRating orientation="vertical" :default-value="4" />
</template>

Отключение

Пропс disabled отключает InputRating.

<template>
  <B24InputRating disabled :default-value="3" />
</template>

Только чтение

Пропс readonly показывает оценку без возможности взаимодействия. В отличие от disabled, внешний вид остаётся обычным (полная непрозрачность, курсор по умолчанию). Используйте, когда оценку нельзя менять, но выглядеть она должна как обычно.

<template>
  <B24InputRating readonly :default-value="4.5" />
</template>

API

Пропсы

Prop Default Type
as'div'any

The element or component this component should render as.

id string

The id of the rating.

readonlyfalseboolean

Make the rating readonly (non-interactive).

iconicons.starIconComponent

The icon displayed for each rating value.

emptyIconIconComponent

The icon displayed for empty rating values. Defaults to icon when not provided.

color'air-primary'"air-primary" | "air-primary-success" | "air-primary-alert" | "air-primary-warning" | "air-primary-copilot"
size'md' "xss" | "xs" | "sm" | "md" | "lg" | "xl"
orientation'horizontal' "horizontal" | "vertical"

The orientation of the rating.

step1 1 | 0.5 | 0.25 | 0.1

The granularity each rating item is divided into.

disabledboolean

When true, prevents the user from interacting with radio items.

requiredboolean

When true, indicates that the user must set the value before the owning form can be submitted.

name string

The name of the field. Submitted with its owning form as part of a name/value pair.

defaultValue0 number

The rating value when initially rendered. Use when you do not need to control the state of the rating.

modelValue number

The controlled rating value. Can be bound with v-model.

length5 number

The number of rating items to render.

clearablefalseboolean

When true, clicking the currently selected rating resets the value to 0.

hoverablefalseboolean

When true, the rating previews the value under the pointer on hover.

b24ui { root?: SlotClass; item?: SlotClass; indicator?: SlotClass; icon?: SlotClass; emptyIcon?: SlotClass; }

Слоты

Slot Type
item{ index: number; filled: boolean; }

Rendered for each item. filled is false for the empty background layer and true for the highlighted overlay.

События

Event Type
update:modelValue[payload: number]
change[event: Event]

Тема

https://github.com/bx-shef/b24-ui/tree/main/src/theme/input-rating.ts
export default {
  slots: {
    root: '',
    item: 'relative inline-block cursor-pointer select-none rounded-sm has-focus-visible:outline-3 outline-(--b24ui-border-color) transition',
    indicator: 'absolute inset-0 overflow-hidden outline-none text-transparent w-(--reka-rating-item-step-width) opacity-(--reka-rating-item-step-opacity) z-(--reka-rating-item-step-z-index) data-[state=active]:text-(--b24ui-background)',
    icon: 'block',
    emptyIcon: 'block w-full h-full text-legend pointer-events-none'
  },
  variants: {
    orientation: {
      horizontal: {
        root: 'inline-flex items-center gap-0.5'
      },
      vertical: {
        root: 'inline-flex flex-col items-center gap-0.5'
      }
    },
    size: {
      xss: {
        item: 'size-2',
        icon: 'size-2'
      },
      xs: {
        item: 'size-3',
        icon: 'size-3'
      },
      sm: {
        item: 'size-4',
        icon: 'size-4'
      },
      md: {
        item: 'size-5',
        icon: 'size-5'
      },
      lg: {
        item: 'size-6',
        icon: 'size-6'
      },
      xl: {
        item: 'size-7',
        icon: 'size-7'
      }
    },
    color: {
      'air-primary': {
        root: 'style-filled'
      },
      'air-primary-success': {
        root: 'style-filled-success'
      },
      'air-primary-alert': {
        root: 'style-filled-alert'
      },
      'air-primary-copilot': {
        root: 'style-filled-copilot'
      },
      'air-primary-warning': {
        root: 'style-filled-warning'
      }
    },
    readonly: {
      true: {
        root: 'cursor-default',
        item: 'cursor-default'
      },
      false: {}
    },
    disabled: {
      true: {
        root: 'opacity-30 cursor-not-allowed',
        item: 'cursor-not-allowed pointer-events-none'
      },
      false: {}
    }
  },
  compoundVariants: [
    {
      readonly: false,
      disabled: false,
      class: {
        item: 'hover:scale-110'
      }
    }
  ],
  defaultVariants: {
    color: 'air-primary',
    size: 'md'
  }
}