---
name: "Checkbox"
mode: "component"
versionRequirements:
  - { name: "@ray-js/ray", version: "0.5.10" }
title: "Checkbox - 多选项目"
---

## Checkbox

> [VERSION] @ray-js/ray >= 0.5.10

### 描述

多选框，用于在选项列表中开启或关闭单项选择。

### 属性

| 属性 | 类型 | 必填 | 默认值 | 描述 |
| --- | --- | --- | --- | --- |
| `value` | `string` | 否 | - | 选中时触发所属 checkbox-group 的 change 事件，并携带该 value |
| `checked` | `boolean` | 否 | `false` | 当前是否选中，可作默认选中 |
| `disabled` | `boolean` | 否 | `false` | 是否禁用 |
| `color` | `string` | 否 | `"#007AFF"` | 多选框颜色，同 CSS color |

### 示例代码

#### 基础用法

```tsx
import React from 'react';
import { Checkbox, View, Text } from '@ray-js/ray';

export default function () {
  return (
    <View style={{ padding: '20px' }}>
      <Checkbox checked />
    </View>
  );
}
```

#### 不同状态

```tsx
import React from 'react';
import { Checkbox, View, Text } from '@ray-js/ray';

export default function () {
  const [checked, setChecked] = React.useState(false);

  return (
    <View style={{ padding: '20px' }}>
      <View style={{ marginBottom: '10px' }}>
        <Text>默认状态：</Text>
        <Checkbox />
      </View>
      <View style={{ marginBottom: '10px' }}>
        <Text>选中状态：</Text>
        <Checkbox checked />
      </View>
      <View style={{ marginBottom: '10px' }}>
        <Text>禁用状态：</Text>
        <Checkbox disabled />
      </View>
      <View style={{ marginBottom: '10px' }}>
        <Text>自定义颜色：</Text>
        <Checkbox color="#ff0000" checked />
      </View>
    </View>
  );
}
```
