跳转到内容

标签 ​

基于 zw-label 基础组件构建的样式化标签。

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

交互演示 ​

源码 ​

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

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

<zw-label for="workspace-name">Workspace name</zw-label>
<input id="workspace-name" value="Zeus" />
tsx
import { Label } from '@zeus-web/label/react'

export function LabelExample() {
  return (
    <div>
      <Label for="workspace-name">Workspace name</Label>
      <input id="workspace-name" defaultValue="Zeus" />
    </div>
  )
}
vue
<script setup lang="ts">
import { Label } from '@zeus-web/label/vue'
</script>

<template>
  <div>
    <Label for="workspace-name">Workspace name</Label>
    <input id="workspace-name" value="Zeus" />
  </div>
</template>

添加 ​

bash
zweb add label

导入 ​

样式化 Registry 组件:

tsx
import { Label } from '@/components/ui/label'

基础组件 React 包装器:

tsx
import { Label } from '@zeus-web/label/react'

Web Component 入口:

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

属性 ​

属性类型默认值说明
forstring-关联表单控件的 ID。
requiredboolean-显示必填指示器。
disabledboolean-将标签标记为禁用。
visuallyHiddenboolean-在保持无障碍可访问的同时从视觉上隐藏标签。

事件 ​

暂无公开事件。

插槽 ​

插槽说明
default标签内容。

样式 ​

使用 Tailwind: 是

主题变量:

  • text-foreground
  • text-destructive

内部选择器:

  • [data-slot=label]
  • [data-slot=label-required-indicator]

Registry ​

Registry 源码:可用。

添加命令: zweb add label

类型: component

依赖:

  • @zeus-web/label

Registry 依赖:

  • cn
  • globals

文件:

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

AI 使用规则 ​

建议:

  • 将 Label 与表单控件搭配使用。
  • 使用 for 将标签与控件 ID 关联。

避免:

  • 不要把 Label 当作通用文本容器。

示例 ​

React 样式化用法 ​

tsx
import { Label } from '@/components/ui/label'

export function Example() {
  return <Label for="email">Email</Label>
}

基于 MIT 许可证发布。