انتقل إلى المحتوى
TopClass UI

التقييم

نجوم القراءة فقط هي HTML من الخادم ولا تشحن أي سكربت. وحده التقييم القابل للتعديل يترطّب، كمجموعة أزرار راديو أصلية.

split - الحجم لم يُقَس بعد

التقييم

split - الحجم لم يُقَس بعد

نجوم القراءة فقط هي HTML من الخادم ولا تشحن أي سكربت. وحده التقييم القابل للتعديل يترطّب، كمجموعة أزرار راديو أصلية.

تثبيت

جرّبه

value
max
size
readOnly
defaultValue
disabled

الشيفرة

rating.tsx
import { Rating } from 'topclassui/rating'
import type { RatingDesignProps } from 'topclassui/rating'

/** The site's Try it stage: each schema prop arrives from a control, and an absent one keeps its default. */
export default function Demo(props: RatingDesignProps = {}) {
  const { readOnly, defaultValue, disabled, ...shown } = props
  if (readOnly === false) {
    return <Rating defaultValue={defaultValue ?? 3} disabled={disabled} {...shown} readOnly={false} aria-label="Rate this course" />
  }
  return <Rating value={3.5} {...shown} />
}

value وحده يعرض النجوم على الخادم؛ ووحده readOnly={false} يشحن نصف العميل.

كل الحالات، بدون تمرير الفأرة

6 حالات

أو استورده من الحزمة

topclassui/rating
import { Rating } from 'topclassui/rating'

ثبّت مرة واحدة:npm i topclassui@beta zod

أمثلة

  • القراءة فقط هي الافتراضية: value محصور بين 0 وmax ويُرسم إلى أقرب نصف نجمة.
  • readOnly={false} يعرض أزرار راديو أصلية، زر لكل نجمة، مسمّاة من «نجمة واحدة» إلى «5 نجوم».
  • مع name تُرسل الخطوة المحددة، من 1 إلى max، قبل تشغيل أي سكربت. وإعادة ضبط النموذج تعيد الخطوة التي أرسلها الخادم وتستدعي onValueChange.
  • value مع onValueChange يحتاجان ملفًا فيه 'use client': صفحة الخادم لا تستطيع تمرير دالة. أما defaultValue فيعمل من صفحة الخادم.
  • max من 1 إلى 10، والافتراضي 5. عشر نجوم بحجم xl عرضها 436px، فيلتف الصف على الهاتف بدل أن تتمرر الصفحة.
read-only

128 reviews

editable

Rate this course

in-form

How was your stay?

controlled

Chosen: 2 of 5

disabled
sizes
max-ten
بالعربية، من اليمين إلى اليسار

قيّم هذه الدورة

الخصائص

خصائص Rating
الخاصيةالنوعالافتراضيالحدودالوصف
aria-labelstring--
aria-labelledbystring--
defaultValuenumber, min 0, max 100min 0, max 10Editing only: the step checked at first when value is not passed, rounded to a whole star. 0 checks none.
disabledbooleanfalse-Editing only: every radio is disabled, so it takes no key, no click and is not submitted.
labelsLabels--The built-in strings: labels.rating.value names a read-only rating, labels.rating.stars each step. Defaults to English.
localestring--The BCP 47 tag the numbers in those names are formatted in. Defaults to en.
maxinteger, min 1, max 105min 1, max 10How many stars, rounded and clamped to 1-10.
namestring--The field name in a form. Each radio submits its step, "1" to max. Without one the rating is in no form: not submitted, not reset.
readOnlybooleantrue-true renders stars on the server and ships no script. false renders a radio group, which hydrates.
sizexs | sm | md | lg | xl | custom"md"-The star, from the icon scale: 16, 20, 24, 32 or 40 px. custom draws it at 1em, so it follows your font size.
valuenumber, min 0, max 100min 0, max 10The rating shown, clamped to 0 and max. Read-only, it is drawn to the nearest half; editing, it is the checked step, and passing it makes the rating controlled.

لوحة المفاتيح وإمكانية الوصول

لوحة مفاتيح Rating
المفاتيحما يفعله
Tabيدخل التقييم القابل للتعديل على النجمة المحددة، أو على الأولى إن لم تُحدد أي نجمة؛ والضغطة التالية تغادره.
ArrowRightArrowLeftArrowUpArrowDownتنقل بين النجوم وتحدد النجمة التي تصل إليها.
Spaceيحدد النجمة التي عليها التركيز.
  • في وضع القراءة فقط هو صورة واحدة مسمّاة «4.5 من 5»؛ مرّر aria-label لتقول أكثر، مثل «4.3 من 128 مراجعة».
  • في وضع التعديل تحتاج المجموعة إلى aria-label أو aria-labelledby. ولا تقل مساحة ضغط النجمة عن 24px، و44px تحت مؤشر لمس.
  • النجمة الممتلئة بلون warning-on-soft، بتباين 3:1 أو أكثر على كل سطح؛ وفي وضع الألوان القسرية تبقى الممتلئة مصمتة والفارغة محدّدة الإطار.

من اليمين إلى اليسار

النجمة الأولى على اليمين، ونصف النجمة يملأ نصفها الأيمن. مرّر labels وlocale العربيين لأسماء عربية.

الخادم والمتصفح

يُعرض على الخادم، والجزء التفاعلي مكوّن متصفح لا يُرسل إلا عند استخدامه.

الملفات: index.tsx, client.tsx.

على الشارة: split - الحجم لم يُقَس بعد.