跳转到内容
Page

Checkbox

可带标签和说明的二元选择。

import { Checkbox } from "@pelagornis/page/components";

上方预览渲染的就是这个文件。把它复制到 src/components/ 即可开始使用。

src/components/CheckboxExample.tsx
import { useState } from "react";
import { Checkbox, Stack } from "@pelagornis/page/components";
export default function CheckboxDemo() {
const [notify, setNotify] = useState(true);
return (
<Stack gap="sizeSmall">
<Checkbox label="Accept terms and conditions" />
<Checkbox
label="Enable notifications"
description="Receive updates about releases"
checked={notify}
onChange={(event) => setNotify(event.target.checked)}
/>
<Checkbox variant="circular" label="Circular" defaultChecked />
<Checkbox label="Disabled" disabled />
</Stack>
);
}

Checkbox 可以直接写在 .mdx 页面中。在 frontmatter 下方导入即可。它在服务器端渲染,不需要 client 指令。

src/content/docs/example.mdx
---
title: Example
---
import { Checkbox } from "@pelagornis/page/components";
<Checkbox label="Accept terms" description="Required to continue" />

pageMarkdoc() 会为这个组件注册 checkbox 标签。在 markdoc.config.mjs 中添加一次预设(见在 Markdoc 中使用),就能在任意 .mdoc 页面中使用该标签。

src/content/docs/example.mdoc
{% checkbox label="Accept terms" description="Required to continue" /%}

属性的名称和取值与 React props 相同。

每个 variant prop 可接受的取值。

Prop取值
variantdefault circular

组件的组成部分,以及每个部分渲染的 data-refineui 角色。

部件角色
rootcheckbox

组件获得焦点时处理的按键。

按键动作
Spaceactivate