独立的单选按钮,可用于任何布局。
<Flex align="start" direction="column" gap="1">
<Flex asChild gap="2">
<Text as="label" size="2">
<Radio name="example" value="1" defaultChecked />
Default
</Text>
</Flex>
<Flex asChild gap="2">
<Text as="label" size="2">
<Radio name="example" value="2" />
Comfortable
</Text>
</Flex>
<Flex asChild gap="2">
<Text as="label" size="2">
<Radio name="example" value="3" />
Compact
</Text>
</Flex>
</Flex>
此组件继承自 Radio Group 基元 的属性,并支持通用的 margin 属性。
包含单选组的所有部件。
属性 | 类型 | 默认 |
---|---|---|
asChild | boolean | 无默认值 |
size | Responsive<"1" | "2" | "3"> | "2" |
variant | "classic" | "surface" | "soft" | "surface" |
color | enum | 无默认值 |
highContrast | boolean | 无默认值 |
组中可以被选中的一项。
使用 size
属性来控制单选按钮的大小。
<Flex align="center" gap="4">
<Flex gap="2">
<Radio size="1" name="size-1" value="1" defaultChecked />
<Radio size="1" name="size-1" value="2" />
</Flex>
<Flex gap="2">
<Radio size="2" name="size-2" value="1" defaultChecked />
<Radio size="2" name="size-2" value="2" />
</Flex>
<Flex gap="2">
<Radio size="3" name="size-3" value="1" defaultChecked />
<Radio size="3" name="size-3" value="2" />
</Flex>
</Flex>
使用 variant
属性来控制单选按钮的视觉样式。
<Flex align="center" gap="4">
<Flex gap="2">
<Radio variant="surface" name="surface" value="1" defaultChecked />
<Radio variant="surface" name="surface" value="2" />
</Flex>
<Flex gap="2">
<Radio variant="classic" name="classic" value="1" defaultChecked />
<Radio variant="classic" name="classic" value="2" />
</Flex>
<Flex gap="2">
<Radio variant="soft" name="soft" value="1" defaultChecked />
<Radio variant="soft" name="soft" value="2" />
</Flex>
</Flex>
使用 color
属性来指定特定的颜色。
<Flex as="span" gap="2">
<Radio color="indigo" defaultChecked />
<Radio color="cyan" defaultChecked />
<Radio color="orange" defaultChecked />
<Radio color="crimson" defaultChecked />
</Flex>
使用 highContrast
属性来增加与背景的颜色对比度。
<Grid columns="5" display="inline-grid" gap="2">
<Radio color="indigo" defaultChecked />
<Radio color="cyan" defaultChecked />
<Radio color="orange" defaultChecked />
<Radio color="crimson" defaultChecked />
<Radio color="gray" defaultChecked />
<Radio color="indigo" defaultChecked highContrast />
<Radio color="cyan" defaultChecked highContrast />
<Radio color="orange" defaultChecked highContrast />
<Radio color="crimson" defaultChecked highContrast />
<Radio color="gray" defaultChecked highContrast />
</Grid>
在 Text
中组合 Radio
会自动将其与文本的第一行居中对齐。它也自动与多行文本良好对齐。
<Flex direction="column" gap="3">
<Flex align="start" direction="column" gap="1">
<Flex asChild gap="2">
<Text as="label" size="2">
<Radio size="1" name="alignment-1" value="1" defaultChecked />
Default
</Text>
</Flex>
<Flex asChild gap="2">
<Text as="label" size="2">
<Radio size="1" name="alignment-1" value="2" />
Compact
</Text>
</Flex>
</Flex>
<Flex align="start" direction="column" gap="1">
<Flex asChild gap="2">
<Text as="label" size="3">
<Radio size="2" name="alignment-2" value="1" defaultChecked />
Default
</Text>
</Flex>
<Flex asChild gap="2">
<Text as="label" size="3">
<Radio size="2" name="alignment-2" value="2" />
Compact
</Text>
</Flex>
</Flex>
<Flex align="start" direction="column" gap="1">
<Flex asChild gap="2">
<Text as="label" size="4">
<Radio size="3" name="alignment-3" value="1" defaultChecked />
Default
</Text>
</Flex>
<Flex asChild gap="2">
<Text as="label" size="4">
<Radio size="3" name="alignment-3" value="2" />
Compact
</Text>
</Flex>
</Flex>
</Flex>
使用原生 disabled
属性来创建一个禁用的单选按钮。
<Flex direction="column" gap="3">
<Flex align="start" direction="column" gap="1">
<Flex asChild gap="2">
<Text as="label" size="2">
<Radio name="enabled" value="1" defaultChecked />
On
</Text>
</Flex>
<Flex asChild gap="2">
<Text as="label" size="2">
<Radio name="enabled" value="2" />
Off
</Text>
</Flex>
</Flex>
<Flex align="start" direction="column" gap="1">
<Flex asChild gap="2">
<Text as="label" size="2" color="gray">
<Radio disabled name="disabled" value="1" defaultChecked />
On
</Text>
</Flex>
<Flex asChild gap="2">
<Text as="label" size="2" color="gray">
<Radio disabled name="disabled" value="2" />
Off
</Text>
</Flex>
</Flex>
</Flex>