Rating
نمای کلیimport { Rating, RatingAlignment, RatingBar, RatingBarArea, RatingBarLabels, RatingBarType } from '@nili/ui';این همان صفحهی نمای کلیِ خود کتابخانه است که زنده رندر میشود. زبان یا تم را از هدر عوض کنید، همراهش میآید.
تعاملی
زیر آیکونها مجموعهای از رادیوهاست، پس کلیدهای جهت کار میکنند و مقدار همراه فرم ارسال میشود. name آن را به ارسال بومی گره میزند.
import { Rating } from "@nili/ui"
export function Example() {
const [score, setScore] = useState(4)
return (
<Rating
value={score}
onValueChange={setScore}
name="score"
labels={{
root: "Rate this article",
item: (score) => `${score} stars`,
}}
/>
)
}فقطخواندنی
فقط برای نمایش — یک میانگین، یک امتیاز نقد. بهجای مجموعهای از رادیوها یک نقش تصویر میسازد و مقدار اعشاری میپذیرد، پس ۴٫۵ نیمستاره میکشد.
import { Rating } from "@nili/ui"
export function Example() {
return (
<>
<Rating readOnly value={4.5} showValue />
<Rating
readOnly
value={4.5}
valueLabel={t('reviews')}
labels={{ summary: (value, max) => `${value} out of ${max}` }}
/>
</>
)
}آیکون و حالت خالی
type بین ستاره و قلب انتخاب میکند و رنگ را هم تعیین میکند. empty بین طرح خالی و یک آیکون خاکستریِ پرشده انتخاب میکند — دومی روی سطح شلوغ بهتر خوانده میشود.
import { Rating } from "@nili/ui"
export function Example() {
return (
<>
<Rating type="star" defaultValue={3} />
<Rating type="heart" defaultValue={3} />
<Rating type="star" empty="filled" defaultValue={3} />
<Rating max={10} defaultValue={7} />
</>
)
}امتیاز و نقد
alignment همان بلوک Rating & Review فیگماست: ratings ردیف خالی است، vertical توضیح را زیرش میگذارد و horizontal کنارش.
import { Rating, LinkButton } from "@nili/ui"
export function Example() {
return (
<>
<Rating
readOnly
value={4.5}
alignment="vertical"
showValue
description="Based on 128 reviews from verified buyers."
linkButton={<LinkButton href="#" size="sm">Read reviews</LinkButton>}
/>
<Rating
readOnly
value={4.5}
alignment="horizontal"
description="128 reviews"
/>
</>
)
}نوار امتیاز
یک مقیاس رضایت پنجنقطهای — کنترل نظرسنجی، نه ردیف ستاره. چهار نوع، و ارقام از لوکال پیروی میکنند.
import { RatingBar } from "@nili/ui"
export function Example() {
return (
<>
<RatingBar type="emoji" labels={{ root: "How was it?" }} />
<RatingBar type="number" labels={{ root: "How was it?" }} />
<RatingBar type="star" labels={{ root: "How was it?" }} />
<RatingBar type="heart" labels={{ root: "How was it?" }} />
</>
)
}نوار امتیاز با نظر
کل بلوک نظرسنجی: مقیاس بهعلاوهٔ یک فیلد متن آزاد. وقتی نظر نشان داده میشود commentLabel الزامی است — یک textarea خالی چیزی برای نامگرفتن ندارد.
import { RatingBarArea } from "@nili/ui"
export function Example() {
return (
<RatingBarArea
type="emoji"
labels={{ root: "How was your experience?" }}
commentLabel="Tell us more"
commentPlaceholder="Tell us why!"
/>
)
}Rating
extends Omit< ComponentPropsWithoutRef<'div'>, 'onChange' | 'defaultValue' | 'color' >
بقیهی پراپها
| پراپ | نوع | پیشفرض | توضیح |
|---|---|---|---|
| children | ReactNode | — | |
| aria-label | string | — | |
| value | number | — | Current score. Controlled. |
| defaultValue | number | 0 | |
| onValueChange | (value: number) => void | — | |
| max | number | 5 | Number of items. |
| type | star | heart | star | Figma's Type. Drives the glyph and its colour. |
| empty | filled | line | line | Which empty glyph to draw. Figma's `Empty Line` / `Empty Filled`. |
| readOnly | boolean | false | Display only — an average, a review score. Renders a single `role="img"` instead of a set of radios, and accepts fractional values. |
| disabled | boolean | false | |
| icon | ReactNode | — | Replaces the glyph the `type` would pick. |
| emptyIcon | ReactNode | — | Empty-state glyph, when it is not simply the outline of `icon`. |
| showValue | boolean | false | Shows the numeric score beside the items. |
| valueLabel | ReactNode | — | Replaces the readout — `'4.5 (128 reviews)'`, a count, anything. |
| name | string | — | `name` for the underlying radios, when the form is submitted natively. |
| locale | string | — | BCP-47 tag driving the digits (`'fa'` → Persian). Defaults to the ambient locale from `NiliProvider`. |
| labels | RatingLabels | — | |
| alignment | horizontal | vertical | ratings | ratings | Figma's `Rating & Review` → Alignment. `ratings` is the bare row; `vertical` and `horizontal` place `description` below it or beside it. |
| description | ReactNode | — | Supporting copy. Figma's "Description". |
| linkButton | ReactNode | — | Action under the score. Figma's "Link Button". |
RatingBar
بقیهی پراپها
| پراپ | نوع | پیشفرض | توضیح |
|---|---|---|---|
| type | number | emoji | star | heart | star | Figma `🧩 Type`. |
| count | number | 5 | How many options. Figma draws five; the count is yours. |
| value | number | null | — | |
| defaultValue | number | null | — | |
| onValueChange | (value: number) => void | — | |
| disabled | boolean | false | |
| emojis | readonly ReactNode[] | — | Overrides the emoji set. Must be at least `count` long. |
| locale | string | — | Digits follow the locale, so `4` renders in Persian digits under `fa`. |
| labels | RatingBarLabels | — | |
| name | string | — | |
| id | string | — | |
| className | string | — |
RatingBarArea
extends RatingBarProps
بقیهی پراپها
| پراپ | نوع | پیشفرض | توضیح |
|---|---|---|---|
| commentPlaceholder | string | — | The comment field's placeholder — Figma's "Tell us why!". |
| commentLabel | string | — | Accessible name for the comment field. Required if the comment is shown. |
| comment | string | — | |
| defaultComment | string | ||
| onCommentChange | (comment: string) => void | — | |
| showComment | boolean | true | Hides the comment box, leaving a bordered scale. |
| rows | number | 4 | |
| footer | ReactNode | — | |
| rootClassName | string | — | |
| type | number | emoji | star | heart | — | Figma `🧩 Type`. |
| count | number | — | How many options. Figma draws five; the count is yours. |
| value | number | null | — | |
| defaultValue | number | null | — | |
| onValueChange | (value: number) => void | — | |
| disabled | boolean | — | |
| emojis | readonly ReactNode[] | — | Overrides the emoji set. Must be at least `count` long. |
| locale | string | — | Digits follow the locale, so `4` renders in Persian digits under `fa`. |
| labels | RatingBarLabels | — | |
| name | string | — | |
| id | string | — | |
| className | string | — |
RatingFill
داخلیمحورهای واریانت — از تعریف cva کامپوننت
| پراپ | نوع | پیشفرض | توضیح |
|---|---|---|---|
| type | star | heart | star |
RatingGlyph
داخلیRatingInput
داخلیRatingItem
داخلیمحورهای واریانت — از تعریف cva کامپوننت
| پراپ | نوع | پیشفرض | توضیح |
|---|---|---|---|
| interactive | 'true' | 'false' | false | |
| disabled | 'true' | 'false' | false | |
| empty | line | filled | line |
RatingReview
داخلیمحورهای واریانت — از تعریف cva کامپوننت
| پراپ | نوع | پیشفرض | توضیح |
|---|---|---|---|
| alignment | ratings | vertical | horizontal | ratings |