组件

复选框卡片

一组交互式卡片,可以同时选择多个选项。

<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>

API 参考

此组件基于 div 元素,并支持通用的 margin 属性

根元素

属性类型默认值
asChild
boolean
无默认值
size
Responsive<"1" | "2" | "3">
"2"
variant
"surface" | "classic"
"surface"
color
enum
无默认值
highContrast
boolean
无默认值
columns
Responsive<enum | string>
"repeat(auto-fit, minmax(200px, 1fr))"
gap
Responsive<enum | string>
"4"

Item

组中可以被选中的一个条目。

示例

尺寸

使用 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>
上一个复选框组