跳转到内容

表单字段 ​

基于 form-field 基础组件的样式化表单字段关系组件。

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

交互演示 ​

源码 ​

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

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

<zw-form-field invalid
  ><zw-form-field-label>Email</zw-form-field-label
  ><zw-form-field-control><input type="email" /></zw-form-field-control
  ><zw-form-field-message
    >Enter a valid email.</zw-form-field-message
  ></zw-form-field
>
tsx
import {
  FormField,
  FormFieldControl,
  FormFieldLabel,
  FormFieldMessage,
} from '@zeus-web/form-field/react'

export function FormFieldExample() {
  return (
    <FormField invalid>
      <FormFieldLabel>Email</FormFieldLabel>
      <FormFieldControl>
        <input type="email" />
      </FormFieldControl>
      <FormFieldMessage>Enter a valid email.</FormFieldMessage>
    </FormField>
  )
}
vue
<script setup lang="ts">
import {
  FormField,
  FormFieldControl,
  FormFieldLabel,
  FormFieldMessage,
} from '@zeus-web/form-field/vue'
</script>

<template>
  <FormField invalid
    ><FormFieldLabel>Email</FormFieldLabel
    ><FormFieldControl><input type="email" /></FormFieldControl
    ><FormFieldMessage>Enter a valid email.</FormFieldMessage></FormField
  >
</template>

添加 ​

bash
zweb add form-field

导入 ​

样式化 Registry 组件:

tsx
import { FormField } from '@/components/ui/form-field'

基础组件 React 包装器:

tsx
import { FormField } from '@zeus-web/form-field/react'

Web Component 入口:

ts
import '@zeus-web/form-field/wc/auto'

属性 ​

属性类型默认值说明
idstring-稳定的字段标识符。
invalidboolean-将字段标记为无效。
disabledboolean-禁用关联控件。
requiredboolean-将关联控件标记为必填。

事件 ​

暂无公开事件。

插槽 ​

插槽说明
default标签、描述、控件和校验消息内容。

样式 ​

使用 Tailwind: 是

主题变量:

  • border
  • background
  • foreground
  • ring

内部选择器:

  • [data-slot=form-field]

Registry ​

Registry 源码:可用。

添加命令: zweb add form-field

类型: component

依赖:

  • @zeus-web/form-field

Registry 依赖:

  • cn
  • globals

文件:

  • templates/react/form-field.tsx → components/ui/form-field.tsx
  • templates/vue/form-field.ts → components/ui/form-field.ts

AI 使用规则 ​

建议:

  • 应用界面需要样式时,使用复制到项目中的 Registry 包装器。

避免:

  • 不要假设无样式基础组件提供最终视觉样式。

示例 ​

React 样式化用法 ​

tsx
import {
  FormField,
  FormFieldControl,
  FormFieldLabel,
} from '@/components/ui/form-field'

export function Example() {
  return (
    <FormField required>
      <FormFieldLabel>Work email</FormFieldLabel>
      <FormFieldControl>
        <input type="email" />
      </FormFieldControl>
    </FormField>
  )
}

基于 MIT 许可证发布。