跳转到内容

复选框 ​

基于 zw-checkbox 基础组件构建的样式化复选框。

@zeus-web/checkbox数据录入zweb add checkbox自动生成

交互演示 ​

源码 ​

请选择与你的应用框架匹配的入口。

html
<script type="module">
  import '@zeus-web/checkbox/wc/auto'
</script>

<zw-checkbox default-checked>Enable notifications</zw-checkbox>
tsx
import { Checkbox } from '@zeus-web/checkbox/react'

export function CheckboxExample() {
  return <Checkbox defaultChecked>Enable notifications</Checkbox>
}
vue
<script setup lang="ts">
import { Checkbox } from '@zeus-web/checkbox/vue'
</script>

<template>
  <Checkbox default-checked>Enable notifications</Checkbox>
</template>

添加 ​

bash
zweb add checkbox

导入 ​

样式化 Registry 组件:

tsx
import { Checkbox } from '@/components/ui/checkbox'

基础组件 React 包装器:

tsx
import { Checkbox } from '@zeus-web/checkbox/react'

Web Component 入口:

ts
import '@zeus-web/checkbox/wc/auto'

属性 ​

属性类型默认值说明
checkedboolean-受控选中状态。
defaultCheckedboolean-初始选中状态。
indeterminateboolean-混合状态。
sizeCheckboxSize
可选值: sm, md, lg
md复选框尺寸。
requiredboolean-将复选框标记为必填。
ariaLabelstring-无可见标签复选框的无障碍标签。
ariaDescribedbystring-额外无障碍说明的 ID 引用。

事件 ​

事件React 属性详情说明
checked-changeonCheckedChangechecked: boolean, nativeEvent: Event选中状态变化时触发。
focus-changeonFocusChangefocused: boolean, nativeEvent: FocusEvent焦点状态变化时触发。

插槽 ​

插槽说明
default标签内容。
indicator自定义指示器内容。

样式 ​

使用 Tailwind: 是

主题变量:

  • bg-primary
  • text-primary-foreground
  • ring-ring

内部选择器:

  • [&_[data-slot=checkbox-control]]
  • [&_[data-slot=checkbox-indicator]]

Registry ​

Registry 源码:可用。

添加命令: zweb add checkbox

类型: component

依赖:

  • @zeus-web/checkbox
  • class-variance-authority

Registry 依赖:

  • cn
  • globals

文件:

  • templates/react/checkbox.tsx → components/ui/checkbox.tsx
  • templates/vue/checkbox.ts → components/ui/checkbox.ts

AI 使用规则 ​

建议:

  • 布尔表单选项使用 Checkbox。
  • 混合状态使用 indeterminate。

避免:

  • 不要在 Checkbox 旁额外渲染原生 input。
  • 使用基础组件属性时不要手动管理 aria-checked。

示例 ​

React 样式化用法 ​

tsx
import { Checkbox } from '@/components/ui/checkbox'

export function Example() {
  return <Checkbox>Accept terms</Checkbox>
}

基于 MIT 许可证发布。