一组交互式卡片,允许同时选择多个选项。
<Box maxWidth="600px">
<CheckboxCards.Root defaultValue={['1']} columns={{ initial: '1', sm: '3' }}>
<CheckboxCards.Item value="1">
<Flex direction="column" width="100%">
<Text weight="bold">A1 Keyboard</Text>
<Text>US Layout</Text>
</Flex>
</CheckboxCards.Item>
<CheckboxCards.Item value="2">
<Flex direction="column" width="100%">
<Text weight="bold">Pro Mouse</Text>
<Text>Zero-lag wireless</Text>
</Flex>
</CheckboxCards.Item>
<CheckboxCards.Item value="3">
<Flex direction="column" width="100%">
<Text weight="bold">Lightning Mat</Text>
<Text>Wireless charging</Text>
</Flex>
</CheckboxCards.Item>
</CheckboxCards.Root>
</Box>
此组件基于 div
元素并支持 常用边距属性。
属性 | 类型 | 默认值 |
---|---|---|
asChild | 布尔值 | 无默认值 |
size | 响应式<"1" | "2" | "3"> | "2" |
variant | "surface" | "classic" | "surface" |
color | 枚举 | 无默认值 |
highContrast | 布尔值 | 无默认值 |
columns | 响应式<枚举 | 字符串> | "repeat(auto-fit, minmax(200px, 1fr))" |
gap | 响应式<枚举 | 字符串> | "4" |
组中可以被选中的项目。
使用 size
属性控制尺寸。
<Flex align="center" gap="3">
<CheckboxCards.Root defaultValue={['1']} size="1">
<CheckboxCards.Item value="1">Agree to Terms</CheckboxCards.Item>
</CheckboxCards.Root>
<CheckboxCards.Root defaultValue={['1']} size="2">
<CheckboxCards.Item value="1">Agree to Terms</CheckboxCards.Item>
</CheckboxCards.Root>
<CheckboxCards.Root defaultValue={['1']} size="3">
<CheckboxCards.Item value="1">Agree to Terms</CheckboxCards.Item>
</CheckboxCards.Root>
</Flex>
使用 variant
属性控制视觉样式。
<Flex direction="column" gap="3" maxWidth="200px">
<CheckboxCards.Root defaultValue={['1']} variant="surface">
<CheckboxCards.Item value="1">Agree to Terms</CheckboxCards.Item>
</CheckboxCards.Root>
<CheckboxCards.Root defaultValue={['1']} variant="classic">
<CheckboxCards.Item value="1">Agree to Terms</CheckboxCards.Item>
</CheckboxCards.Root>
</Flex>
使用 color
属性分配特定的 颜色。
<Flex direction="column" gap="3" maxWidth="200px">
<CheckboxCards.Root defaultValue={['1']} color="indigo">
<CheckboxCards.Item value="1">Agree to Terms</CheckboxCards.Item>
</CheckboxCards.Root>
<CheckboxCards.Root defaultValue={['1']} color="cyan">
<CheckboxCards.Item value="1">Agree to Terms</CheckboxCards.Item>
</CheckboxCards.Root>
<CheckboxCards.Root defaultValue={['1']} color="orange">
<CheckboxCards.Item value="1">Agree to Terms</CheckboxCards.Item>
</CheckboxCards.Root>
<CheckboxCards.Root defaultValue={['1']} color="crimson">
<CheckboxCards.Item value="1">Agree to Terms</CheckboxCards.Item>
</CheckboxCards.Root>
</Flex>
使用 highContrast
属性增加与背景的颜色对比度。
<Grid columns="2" gap="3" display="inline-grid">
<CheckboxCards.Root defaultValue={['1']} color="indigo">
<CheckboxCards.Item value="1">Agree to Terms</CheckboxCards.Item>
</CheckboxCards.Root>
<CheckboxCards.Root defaultValue={['1']} color="indigo" highContrast>
<CheckboxCards.Item value="1">Agree to Terms</CheckboxCards.Item>
</CheckboxCards.Root>
<CheckboxCards.Root defaultValue={['1']} color="cyan">
<CheckboxCards.Item value="1">Agree to Terms</CheckboxCards.Item>
</CheckboxCards.Root>
<CheckboxCards.Root defaultValue={['1']} color="cyan" highContrast>
<CheckboxCards.Item value="1">Agree to Terms</CheckboxCards.Item>
</CheckboxCards.Root>
<CheckboxCards.Root defaultValue={['1']} color="orange">
<CheckboxCards.Item value="1">Agree to Terms</CheckboxCards.Item>
</CheckboxCards.Root>
<CheckboxCards.Root defaultValue={['1']} color="orange" highContrast>
<CheckboxCards.Item value="1">Agree to Terms</CheckboxCards.Item>
</CheckboxCards.Root>
<CheckboxCards.Root defaultValue={['1']} color="crimson">
<CheckboxCards.Item value="1">Agree to Terms</CheckboxCards.Item>
</CheckboxCards.Root>
<CheckboxCards.Root defaultValue={['1']} color="crimson" highContrast>
<CheckboxCards.Item value="1">Agree to Terms</CheckboxCards.Item>
</CheckboxCards.Root>
</Grid>
<Flex direction="column" gap="4" maxWidth="450px">
<CheckboxCards.Root columns="2" defaultValue="2">
<CheckboxCards.Item value="1">Off</CheckboxCards.Item>
<CheckboxCards.Item value="2">On</CheckboxCards.Item>
</CheckboxCards.Root>
<CheckboxCards.Root columns="2" defaultValue="2">
<CheckboxCards.Item value="1" disabled>
Off
</CheckboxCards.Item>
<CheckboxCards.Item value="2" disabled>
On
</CheckboxCards.Item>
</CheckboxCards.Root>
</Flex>