---
title: Rating
description: "`Rating`は、ユーザーが評価を行うために使用させるコンポーネントです。"
links:
- source: https://github.com/yamada-ui/yamada-ui/tree/main/packages/react/src/components/rating
- storybook: https://yamada-ui.github.io/yamada-ui?path=/story/components-rating--basic
---
```tsx
```
## 使い方
```tsx
import { Rating } from "@yamada-ui/react"
```
```tsx
import { Rating } from "@/components/ui"
```
```tsx
import { Rating } from "@workspaces/ui"
```
```tsx
```
### サイズを変更する
```tsx
{(size) => }
```
### カラースキームを変更する
```tsx
{(colorScheme) => (
)}
```
### デフォルトの値を設定する
デフォルトの値を設定する場合は、`defaultValue`に数値を設定します。
```tsx
```
### 個数を変更する
個数を変更する場合は、`count`に数値を設定します。
```tsx
{(count) => }
```
### 小数点を設定する
小数点を設定する場合は、`fractions`に数値を設定します。
例えば、`0.25`を設定する場合は、`4`を設定します。
```tsx
{({ fractions, defaultValue }) => (
)}
```
### ハイライトする
ハイライトする場合は、`highlightSelectedOnly`を`true`に設定します。
```tsx
```
### 色を変更する
色を変更する場合は、`color`に文字列または関数を設定します。
```tsx
const getColor = useCallback((value: number) => {
switch (value) {
case 1:
return "red.500"
case 2:
return "orange.500"
case 3:
return "yellow.500"
case 4:
return "green.500"
case 5:
return "blue.500"
default:
return undefined
}
}, [])
return (
)
```
### 無効にする
無効にする場合は、`disabled`を`true`に設定します。
```tsx
```
### 読み取り専用にする
読み取り専用にする場合は、`readOnly`を`true`に設定します。
```tsx
```
### アイコンをカスタマイズする
アイコンをカスタマイズする場合は、`emptyIcon`と`filledIcon`に`ReactNode`または関数を設定します。
```tsx
const getColor = useCallback((value: number) => {
switch (value) {
case 1:
return "red.500"
case 2:
return "orange.500"
case 3:
return "yellow.500"
case 4:
return "green.500"
case 5:
return "blue.500"
default:
return undefined
}
}, [])
const getIcon = useCallback((value: number) => {
switch (value) {
case 1:
return
case 2:
return
case 3:
return
case 4:
return
case 5:
return
default:
return null
}
}, [])
return (
}
filledIcon={}
/>
)
```
### 制御する
```tsx
const [value, onChange] = useState(3)
return
```
## Props
| Prop | Default | Type | Description |
| ----------------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------- |
| `as` | - | `As` | The HTML element to render. |
| `asChild` | - | `boolean` | Merges its props onto its immediate child. |
| `css` | - | `CSSObject \| CSSObject[]` | The CSS object. |
| `colorScheme` | - | `"amber" \| "black" \| "blackAlpha" \| "blue" \| "cyan" \| "danger" \| "emerald" \| "error" \| "flashy" \| "fuchsia" ...` | Set color scheme variables. |
| `size` | `"md"` | `"lg" \| "md" \| "sm" \| "xl" \| "xs"` | The size of the component. |
| `color` | - | `"-moz-initial" \| "ActiveBorder" \| "ActiveCaption" \| "aliceblue" \| "amber.100" \| "amber.200" \| "amber.300" \| "amber.400" \| "amber.50" \| "amber.500" ...` | The color of the filled icons. |
| `count` | `5` | `number` | Number of controls that should be rendered. |
| `defaultValue` | `0` | `number` | The initial value of the rating. |
| `disabled` | `false` | `boolean` | If `true`, the field will be disabled. |
| `emptyIcon` | - | `ReactNodeOrFunction` | The empty icon for the rating. |
| `filledIcon` | - | `ReactNodeOrFunction` | The filled icon for the rating. |
| `fractions` | `1` | `number` | Number of fractions each item can be divided into, |
| `groupProps` | - | `FunctionOrValue` | Props for the rating group. |
| `highlightSelectedOnly` | `false` | `boolean` | If `true`, only the selected icons will be filled. |
| `iconProps` | - | `FunctionOrValue` | Props for the rating item. |
| `id` | - | `string` | The top-level id string that will be applied to the rating. The index of the rating item will be appended to this top-level id. |
| `inputProps` | - | `FunctionOrValue>` | Props for the input element. |
| `invalid` | `false` | `boolean` | If `true`, the field will be invalid. |
| `itemProps` | - | `FunctionOrValue` | Props for the rating item. |
| `name` | - | `string` | The name of the input element. |
| `onChange` | - | `(value: number) => void` | The callback invoked when value state changes. |
| `onHover` | - | `(value: number) => void` | The callback invoked when hovering over the rating. |
| `readOnly` | `false` | `boolean` | If `true`, the field will be readonly. |
| `required` | `false` | `boolean` | If `true`, the field will be required. |
| `value` | - | `number` | The value of the rating. |
## アクセシビリティ
現在、v2の移行に伴い、このセクションは更新中です。