Inputs

Star Rating

A star rating without JS: the stars are reversed in the markup and flipped back by flex, so one selector drives the highlight.

  • rating
  • stars
  • radio
  • no-js

Preview

1440pxHost theme

Use it with AI

  1. 1. Copy the link.
  2. 2. Write to your agent in your own words and drop the link into the sentence.
  3. 3. The agent opens the link and installs the component from the registry.

put this in the header: https://vibeui.ru/c/rating-001?lang=en

Rate this component

Плохо

Так себе

Нормально

Хорошо

Отлично

Show the full instructions

What the link says, spelled out. Use it when your agent cannot open links — paste this text instead.

# Install and place "rating-001" (Star Rating) from VibeUI

## 1. Install first — do not skip, do not recreate
Run this exact command before writing any code:
npx shadcn@latest add https://vibeui.ru/r/rating-001.json

Registry item: https://vibeui.ru/r/rating-001.json
Installs to: components/vibeui/rating-001.tsx (the exact path follows this project's components.json aliases).
npm dependencies: none.
Registry dependencies: none.

Install it from the registry. Do not recreate it from the description,
do not substitute a similar component from another library, and do not
rewrite it to match the project's existing style.

## 2. What it is
A star rating without JS: the stars are reversed in the markup and flipped back by flex, so one selector drives the highlight.

A star rating: hovering previews the choice and the caption changes without JS. Zero dependencies, one file, no client JS.

## 3. How to use it
import { Rating001 } from "@/components/vibeui/rating-001"

<Rating001 legend="Rate this component" max={5} defaultValue={4} />

Read the installed file for the full prop list.

## 4. Where to place it
This is a small inline component. Put it exactly where the user asked,
inside the existing markup. Do not create a new page, section or
wrapper for it. If a similar control already sits in that spot,
replace it instead of adding a second one.

Placement: ___
(The user fills this line in. If it is still blank, ask where to put it
instead of guessing.)

## 5. Keep exactly as installed
- the local --vibeui-rating-001-* palette — do not swap it for your theme tokens
- the reversed star order with row-reverse: without it ~ paints the wrong side
- the radio buttons: selection, keyboard and form submission come from the browser
- an aria-label on every star — "★" does not read as a score
- previewing the prospective choice on hover instead of a frozen value
- the worded caption: a bare number clarifies nothing

## 6. You may change
- legend, max and defaultValue
- the hints array — the score captions
- the accent through the accent prop
- the star size

## 7. Rules
- Caption rules cover ten scores: a longer scale needs more CSS lines.
- A unique name is mandatory: two scales sharing one become a single group.
- Half stars are unsupported: they need a slider or your own JS.
- Do not lift the CSS variables into globals.css: the component has to stay a single file.

## 8. Verify
- it renders with no console errors;
- it looks like the preview on the VibeUI page you copied this from;
- if it does not, you changed something listed in section 5 — put it back.

For developers

npx shadcn@latest add https://vibeui.ru/r/rating-001.json
https://vibeui.ru/r/rating-001.json

Компонент самодостаточен: один файл, без зависимостей, собственная палитра в локальных переменных --vibeui-rating-001-*. Серверный: хуков нет, состояние держат радиокнопки. Порядок звёзд в разметке обратный, а flex-direction: row-reverse возвращает их на место — только так соседний селектор ~ красит звёзды левее. Подпись оценки тоже выбирается CSS: видна строка, чей value отмечен.

Component source

The same file your agent installs. Here in case you would rather copy it by hand.

import type { ComponentPropsWithoutRef, CSSProperties } from "react"

export type Rating001Props = Omit<
  ComponentPropsWithoutRef<"fieldset">,
  "children" | "defaultValue"
> & {
  legend?: string
  name?: string
  max?: number
  defaultValue?: number
  hints?: string[]
  accent?: string
}

// Идея компонента: оценка звёздами без JS. Каждая звезда — радиокнопка, поэтому
// выбор, клавиатура и отправка формы работают сами. Звёзды идут в разметке в
// обратном порядке и разворачиваются flex-direction: только так соседний
// селектор ~ закрашивает все звёзды левее наведённой без единой строки кода.
const STYLES = `
:where([data-vibeui-block="rating-001"]){
--vibeui-rating-001-bg:oklch(1 0 0);
--vibeui-rating-001-fg:oklch(0.24 0.014 265);
--vibeui-rating-001-muted:oklch(0.58 0.014 265);
--vibeui-rating-001-border:oklch(0.9 0.006 265);
--vibeui-rating-001-empty:oklch(0.88 0.008 265);
--vibeui-rating-001-accent:oklch(0.72 0.16 75);
--vibeui-rating-001-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="rating-001"]{
display:flex;flex-direction:column;gap:0.375rem;
width:100%;max-width:18rem;box-sizing:border-box;margin:0;padding:0.875rem;
background:var(--vibeui-rating-001-bg);
border:1px solid var(--vibeui-rating-001-border);border-radius:0.875rem;
font-family:var(--vibeui-rating-001-font);color:var(--vibeui-rating-001-fg);
}
[data-vibeui-block="rating-001"] legend{float:left;width:100%;padding:0;margin-bottom:0.375rem;font-size:0.875rem;font-weight:650}
/* Обратный порядок в разметке: тогда ~ закрашивает звёзды левее наведённой. */
[data-vibeui-block="rating-001"] [data-part="stars"]{
display:flex;flex-direction:row-reverse;justify-content:flex-end;gap:0.125rem;
}
[data-vibeui-block="rating-001"] input{position:absolute;opacity:0;pointer-events:none}
[data-vibeui-block="rating-001"] [data-part="star"]{
cursor:pointer;font-size:1.5rem;line-height:1;color:var(--vibeui-rating-001-empty);
padding:0 0.0625rem;border-radius:0.25rem;
}
/* Отмеченная звезда и все левее неё: соседи по ~ идут в обратном порядке. */
[data-vibeui-block="rating-001"] label:has(input:checked) [data-part="star"],
[data-vibeui-block="rating-001"] label:has(input:checked) ~ label [data-part="star"]{color:var(--vibeui-rating-001-accent)}
/* Пока курсор в группе, показываем не выбор, а то, что будет выбрано. */
[data-vibeui-block="rating-001"] [data-part="stars"]:hover [data-part="star"]{color:var(--vibeui-rating-001-empty)}
[data-vibeui-block="rating-001"] [data-part="stars"]:hover label:hover [data-part="star"],
[data-vibeui-block="rating-001"] [data-part="stars"]:hover label:hover ~ label [data-part="star"]{color:var(--vibeui-rating-001-accent)}
[data-vibeui-block="rating-001"] input:focus-visible + [data-part="star"]{outline:2px solid var(--vibeui-rating-001-accent);outline-offset:1px}
/* Подпись оценки тоже без JS: видна та строка, чей value отмечен. */
[data-vibeui-block="rating-001"] [data-part="hint"]{display:none;margin:0;font-size:0.75rem;color:var(--vibeui-rating-001-muted)}
[data-vibeui-block="rating-001"] [data-part="hints"]{min-height:1rem}
[data-vibeui-block="rating-001"]:has(input[value="1"]:checked) [data-part="hint"][data-value="1"]{display:block}
[data-vibeui-block="rating-001"]:has(input[value="2"]:checked) [data-part="hint"][data-value="2"]{display:block}
[data-vibeui-block="rating-001"]:has(input[value="3"]:checked) [data-part="hint"][data-value="3"]{display:block}
[data-vibeui-block="rating-001"]:has(input[value="4"]:checked) [data-part="hint"][data-value="4"]{display:block}
[data-vibeui-block="rating-001"]:has(input[value="5"]:checked) [data-part="hint"][data-value="5"]{display:block}
[data-vibeui-block="rating-001"]:has(input[value="6"]:checked) [data-part="hint"][data-value="6"]{display:block}
[data-vibeui-block="rating-001"]:has(input[value="7"]:checked) [data-part="hint"][data-value="7"]{display:block}
[data-vibeui-block="rating-001"]:has(input[value="8"]:checked) [data-part="hint"][data-value="8"]{display:block}
[data-vibeui-block="rating-001"]:has(input[value="9"]:checked) [data-part="hint"][data-value="9"]{display:block}
[data-vibeui-block="rating-001"]:has(input[value="10"]:checked) [data-part="hint"][data-value="10"]{display:block}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="rating-001"] *{animation:none!important;transition:none!important}}
`

const DEFAULT_HINTS = ["Плохо", "Так себе", "Нормально", "Хорошо", "Отлично"]

/**
 * Оценка звёздами на радиокнопках: выбор и клавиатура без JS.
 * Один файл, ноль зависимостей, собственная палитра.
 */
export function Rating001({
  legend = "Оцените компонент",
  name = "vibeui-rating-001",
  max = 5,
  defaultValue = 4,
  hints = DEFAULT_HINTS,
  accent,
  className,
  style,
  ...props
}: Rating001Props) {
  const stars = Array.from({ length: max }, (_, index) => max - index)

  const palette = {
    ...(accent ? { "--vibeui-rating-001-accent": accent } : null),
    ...style,
  } as CSSProperties

  return (
    <>
      <style href="vibeui-rating-001" precedence="medium">
        {STYLES}
      </style>
      <fieldset
        {...props}
        data-vibeui-block="rating-001"
        className={className}
        style={palette}
      >
        <legend>{legend}</legend>
        <div data-part="stars">
          {stars.map((value) => (
            <label key={value} aria-label={`${value} из ${max}`}>
              <input
                type="radio"
                name={name}
                value={value}
                defaultChecked={value === defaultValue}
              />
              <span data-part="star" aria-hidden="true">
                ★
              </span>
            </label>
          ))}
        </div>
        <div data-part="hints" aria-live="polite">
          {hints.map((hint, index) => (
            <p key={hint} data-part="hint" data-value={index + 1}>
              {hint}
            </p>
          ))}
        </div>
      </fieldset>
    </>
  )
}