Components

复选框

用于切换选项开关的基本输入元素。

<Text as="label" size="2">
<Flex gap="2">
<Checkbox defaultChecked />
Agree to Terms and Conditions
</Flex>
</Text>

API 参考

¥API Reference

此组件继承了 复选框基础组件 的属性并支持 常用边距属性

¥This component inherits props from the Checkbox primitive and supports common margin props.

PropTypeDefault
size
Responsive<"1" | "2" | "3">
"2"
variant
"classic" | "surface" | "soft"
"surface"
color
enum
No default value
highContrast
boolean
No default value

示例

¥Examples

尺寸

¥Size

使用 size 属性控制复选框的大小。

¥Use the size prop to control the size of the checkbox.

<Flex align="center" gap="2">
<Checkbox size="1" defaultChecked />
<Checkbox size="2" defaultChecked />
<Checkbox size="3" defaultChecked />
</Flex>

变体

¥Variant

使用 variant 属性控制复选框的视觉样式。

¥Use the variant prop to control the visual style of the checkbox.

<Flex align="center" gap="4">
<Flex gap="2">
<Checkbox variant="surface" defaultChecked />
<Checkbox variant="surface" />
</Flex>
<Flex gap="2">
<Checkbox variant="classic" defaultChecked />
<Checkbox variant="classic" />
</Flex>
<Flex gap="2">
<Checkbox variant="soft" defaultChecked />
<Checkbox variant="soft" />
</Flex>
</Flex>

颜色

¥Color

使用 color 属性指定特定的 color

¥Use the color prop to assign a specific color.

<Flex gap="2">
<Checkbox color="indigo" defaultChecked />
<Checkbox color="cyan" defaultChecked />
<Checkbox color="orange" defaultChecked />
<Checkbox color="crimson" defaultChecked />
</Flex>

高对比度

¥High-contrast

使用 highContrast 属性增加与背景的颜色对比度。

¥Use the highContrast prop to increase color contrast with the background.

<Grid columns="5" display="inline-grid" gap="2">
<Checkbox color="indigo" defaultChecked />
<Checkbox color="cyan" defaultChecked />
<Checkbox color="orange" defaultChecked />
<Checkbox color="crimson" defaultChecked />
<Checkbox color="gray" defaultChecked />
<Checkbox color="indigo" defaultChecked highContrast />
<Checkbox color="cyan" defaultChecked highContrast />
<Checkbox color="orange" defaultChecked highContrast />
<Checkbox color="crimson" defaultChecked highContrast />
<Checkbox color="gray" defaultChecked highContrast />
</Grid>

对齐方式

¥Alignment

Text 中组合 Checkbox,会自动将其与第一行文本居中。

¥Composing Checkbox within Text automatically centers it with the first line of text.

<Flex direction="column" gap="3">
<Text as="label" size="2">
<Flex as="span" gap="2">
<Checkbox size="1" defaultChecked /> Agree to Terms and Conditions
</Flex>
</Text>
<Text as="label" size="3">
<Flex as="span" gap="2">
<Checkbox size="2" defaultChecked /> Agree to Terms and Conditions
</Flex>
</Text>
<Text as="label" size="4">
<Flex as="span" gap="2">
<Checkbox size="3" defaultChecked /> Agree to Terms and Conditions
</Flex>
</Text>
</Flex>

它还能自动与多行文本对齐。

¥It is automatically well-aligned with multi-line text too.

<Box maxWidth="300px">
<Text as="label" size="3">
<Flex as="span" gap="2">
<Checkbox defaultChecked /> I understand that these documents are
confidential and cannot be shared with a third party.
</Flex>
</Text>
</Box>

已禁用

¥Disabled

使用原生 disabled 属性创建禁用的复选框。

¥Use the native disabled attribute to create a disabled checkbox.

<Flex direction="column" gap="2">
<Text as="label" size="2">
<Flex as="span" gap="2">
<Checkbox />
Not checked
</Flex>
</Text>
<Text as="label" size="2">
<Flex as="span" gap="2">
<Checkbox defaultChecked />
Checked
</Flex>
</Text>
<Text as="label" size="2" color="gray">
<Flex as="span" gap="2">
<Checkbox disabled />
Not checked
</Flex>
</Text>
<Text as="label" size="2" color="gray">
<Flex as="span" gap="2">
<Checkbox disabled defaultChecked />
Checked
</Flex>
</Text>
</Flex>

不确定

¥Indeterminate

使用 "indeterminate" 值创建不确定的复选框。

¥Use the "indeterminate" value to create an indeterminate checkbox.

<Flex gap="2">
<Checkbox defaultChecked="indeterminate" />
<Checkbox checked="indeterminate" />
</Flex>
Previous卡片