用于切换选项开关的基础输入元素。
<Text as="label" size="2">
<Flex gap="2">
<Checkbox defaultChecked />
Agree to Terms and Conditions
</Flex>
</Text>
此组件继承自 Checkbox primitive 的属性,并支持通用 margin 属性。
属性 | 类型 | 默认值 |
---|---|---|
尺寸 | Responsive<"1" | "2" | "3"> | "2" |
变体 | "classic" | "surface" | "soft" | "surface" |
颜色 | 枚举 | 无默认值 |
高对比度 | 布尔值 | 无默认值 |
使用 size
属性来控制复选框的尺寸。
<Flex align="center" gap="2">
<Checkbox size="1" defaultChecked />
<Checkbox size="2" defaultChecked />
<Checkbox size="3" defaultChecked />
</Flex>
使用 variant
属性来控制复选框的视觉样式。
<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
属性来分配特定的颜色。
<Flex gap="2">
<Checkbox color="indigo" defaultChecked />
<Checkbox color="cyan" defaultChecked />
<Checkbox color="orange" defaultChecked />
<Checkbox color="crimson" defaultChecked />
</Flex>
使用 highContrast
属性来增加与背景的颜色对比度。
<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>
在 Text
中组合 Checkbox
会自动将其与文本的第一行居中对齐。
<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>
它也可以自动与多行文本良好对齐。
<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
属性来创建一个禁用的复选框。
<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"
值来创建一个不确定状态的复选框。
<Flex gap="2">
<Checkbox defaultChecked="indeterminate" />
<Checkbox checked="indeterminate" />
</Flex>