组件 · COMPONENT
复选框 Checkbox
16px 方框、圆角 4。选中是墨底白勾,未选是 1.5px 描边;文字随状态从灰变深。
import { useState } from 'react'
import { Checkbox } from './extracted/Checkbox.jsx'
export default function CheckboxDemo() {
const [a, setA] = useState(true)
const [b, setB] = useState(false)
return (
<div style={{ display: 'flex', gap: 24, flexWrap: 'wrap', alignItems: 'center' }}>
<Checkbox checked={a} onChange={setA} label="已选复选框" />
<Checkbox checked={b} onChange={setB} label="未选" />
</div>
)
}<div style="display: flex; gap: 24px; flex-wrap: wrap; align-items: center">
<button
type="button"
role="checkbox"
aria-checked="true"
class="zzm-check"
style="
display: inline-flex;
align-items: center;
gap: 8px;
padding: 0;
border: 0;
border-radius: 4px;
background: transparent;
font-family: inherit;
cursor: pointer;
"
>
<span
style="
width: 16px;
height: 16px;
border-radius: 4px;
background: #1d1d1b;
display: flex;
align-items: center;
justify-content: center;
flex: none;
"
>
<svg width="10" height="10" viewBox="0 0 12 12" aria-hidden="true">
<path
d="M2 6.2 L4.8 9 L10 3.4"
stroke="#FFFFFF"
stroke-width="1.8"
fill="none"
stroke-linecap="round"
stroke-linejoin="round"
></path>
</svg>
</span>
<span style="font-size: 12.5px; color: #3f3f3b">已选复选框</span>
</button>
<button
type="button"
role="checkbox"
aria-checked="false"
class="zzm-check"
style="
display: inline-flex;
align-items: center;
gap: 8px;
padding: 0;
border: 0;
border-radius: 4px;
background: transparent;
font-family: inherit;
cursor: pointer;
"
>
<span
style="
width: 16px;
height: 16px;
border-radius: 4px;
border: 1.5px solid rgba(0, 0, 0, 0.25);
flex: none;
"
></span>
<span style="font-size: 12.5px; color: #8b8b85">未选</span>
</button>
</div>/* extracted.css */
.zzm-v4 .zzm-switch:focus-visible,
.zzm-v4 .zzm-check:focus-visible,
.zzm-v4 .zzm-tab:focus-visible,
.zzm-v4 .zzm-page:focus-visible,
.zzm-v4 .zzm-sort:focus-visible {
outline: none;
box-shadow: 0 0 0 3px rgba(166, 64, 47, .2);
}import { Checkbox } from './extracted/Checkbox.jsx'
export function States() {
return (
<>
<Checkbox checked label="已选复选框" />
<Checkbox label="未选" />
</>
)
}<button
type="button"
role="checkbox"
aria-checked="true"
class="zzm-check"
style="
display: inline-flex;
align-items: center;
gap: 8px;
padding: 0;
border: 0;
border-radius: 4px;
background: transparent;
font-family: inherit;
cursor: pointer;
"
>
<span
style="
width: 16px;
height: 16px;
border-radius: 4px;
background: #1d1d1b;
display: flex;
align-items: center;
justify-content: center;
flex: none;
"
>
<svg width="10" height="10" viewBox="0 0 12 12" aria-hidden="true">
<path
d="M2 6.2 L4.8 9 L10 3.4"
stroke="#FFFFFF"
stroke-width="1.8"
fill="none"
stroke-linecap="round"
stroke-linejoin="round"
></path>
</svg>
</span>
<span style="font-size: 12.5px; color: #3f3f3b">已选复选框</span>
</button>
<button
type="button"
role="checkbox"
aria-checked="false"
class="zzm-check"
style="
display: inline-flex;
align-items: center;
gap: 8px;
padding: 0;
border: 0;
border-radius: 4px;
background: transparent;
font-family: inherit;
cursor: pointer;
"
>
<span
style="
width: 16px;
height: 16px;
border-radius: 4px;
border: 1.5px solid rgba(0, 0, 0, 0.25);
flex: none;
"
></span>
<span style="font-size: 12.5px; color: #8b8b85">未选</span>
</button>/* extracted.css */
.zzm-v4 .zzm-switch:focus-visible,
.zzm-v4 .zzm-check:focus-visible,
.zzm-v4 .zzm-tab:focus-visible,
.zzm-v4 .zzm-page:focus-visible,
.zzm-v4 .zzm-sort:focus-visible {
outline: none;
box-shadow: 0 0 0 3px rgba(166, 64, 47, .2);
}属性
| 属性 | 取值 | 默认 | 说明 |
|---|---|---|---|
| checked | boolean | false | 是否选中(受控) |
| onChange | (next: boolean) => void | — | 切换回调 |
| label | string | — | 右侧文字;整行都是点击目标 |
| disabled | boolean | false | 禁用 |