Convert Figma logo to code with AI

vform666 logovariant-form

A powerful form designer for Vue.

1,752
307
1,752
18

Top Related Projects

4,272

Vue Forms ⚡️ Supercharged

4,460

Performance-focused API for React forms 🚀

📋 React Hooks for form state management and validation (Web + React Native)

33,863

Build forms in React, without the tears 😭

🏁 Framework agnostic, high performance, subscription-based form state management

Quick Overview

The variant-form project is a React library that provides a flexible and extensible way to create dynamic forms with support for complex validation and conditional rendering. It aims to simplify the process of building forms in React applications by abstracting away the boilerplate and providing a declarative API.

Pros

  • Flexible and Extensible: The library allows for the creation of complex forms with dynamic fields, conditional rendering, and advanced validation rules.
  • Declarative API: The library uses a declarative API, making it easier to reason about and maintain the form structure.
  • Validation Support: The library provides a robust validation system that supports both synchronous and asynchronous validation.
  • Customizable: The library allows for the customization of form components, validation messages, and other aspects of the form.

Cons

  • Learning Curve: The library has a relatively steep learning curve, especially for developers who are not familiar with the concept of "variant forms".
  • Performance: The library may have some performance overhead due to the complexity of the form management and validation logic.
  • Limited Documentation: The project's documentation could be more comprehensive, making it harder for new users to get started.
  • Dependency on React: The library is tightly coupled with React, which may be a limitation for developers who are not using React in their projects.

Code Examples

Here are a few code examples demonstrating the usage of the variant-form library:

import { VariantForm, VariantField } from 'variant-form';

const MyForm = () => {
  return (
    <VariantForm>
      <VariantField name="name" label="Name" required />
      <VariantField name="email" label="Email" type="email" required />
      <VariantField name="password" label="Password" type="password" required />
    </VariantForm>
  );
};

This example demonstrates a basic form with three fields: name, email, and password. The VariantForm and VariantField components are used to define the form structure.

import { VariantForm, VariantField, VariantCondition } from 'variant-form';

const MyForm = () => {
  return (
    <VariantForm>
      <VariantField name="hasAccount" label="Do you have an account?" type="checkbox" />
      <VariantCondition field="hasAccount" value={true}>
        <VariantField name="email" label="Email" type="email" required />
        <VariantField name="password" label="Password" type="password" required />
      </VariantCondition>
    </VariantForm>
  );
};

This example demonstrates the use of a conditional field. The VariantCondition component is used to render the "email" and "password" fields only when the "hasAccount" field is checked.

import { VariantForm, VariantField, VariantValidator } from 'variant-form';

const MyForm = () => {
  return (
    <VariantForm>
      <VariantField
        name="username"
        label="Username"
        required
        validator={VariantValidator.custom((value) => {
          if (value.length < 3) {
            return 'Username must be at least 3 characters long';
          }
          return true;
        })}
      />
    </VariantForm>
  );
};

This example demonstrates the use of a custom validator. The VariantValidator.custom function is used to define a validation rule that checks if the username is at least 3 characters long.

Getting Started

To get started with the variant-form library, follow these steps:

  1. Install the library using npm or yarn:
npm install variant-form
  1. Import the necessary components and functions from the library:
import { VariantForm, VariantField, VariantCondition, VariantValidator } from 'variant-form';
  1. Create a form using the VariantForm and VariantField components:
const MyForm = () => {
  return (
    <Vari

Competitor Comparisons

4,272

Vue Forms ⚡️ Supercharged

Pros of FormKit

  • FormKit provides a comprehensive set of form-related components and utilities, making it a feature-rich solution for building complex forms.
  • The library has a strong focus on accessibility, ensuring that forms created with FormKit are accessible to users with disabilities.
  • FormKit offers a flexible and extensible architecture, allowing developers to customize and extend the library to fit their specific needs.

Cons of FormKit

  • The learning curve for FormKit may be steeper compared to Variant Form, as it has a more extensive set of features and configuration options.
  • The library's size and complexity may be overkill for simpler form-related tasks, where a more lightweight solution like Variant Form might be more appropriate.
  • The documentation for FormKit, while comprehensive, may not be as beginner-friendly as some developers might prefer.

Code Comparison

Variant Form:

const form = useForm({
  initialValues: {
    name: '',
    email: '',
  },
  onSubmit: (values) => {
    console.log(values);
  },
});

FormKit:

<FormKit
  type="form"
  actions={{
    submit: 'Submit',
  }}
  submit-label="Submit"
  @submit="onSubmit"
>
  <FormKit type="text" name="name" label="Name" />
  <FormKit type="email" name="email" label="Email" />
</FormKit>
4,460

Performance-focused API for React forms 🚀

Pros of Unform

  • Unform provides a more comprehensive set of features, including support for nested forms, validation, and error handling.
  • The library has a larger community and more active development, with more contributors and a more extensive documentation.
  • Unform's API is more intuitive and easier to use, with a more consistent and well-designed interface.

Cons of Unform

  • Unform may have a steeper learning curve, especially for developers who are new to form management in React.
  • The library's dependency on React Context API may make it less suitable for certain use cases, such as server-side rendering.
  • Unform's focus on feature-richness may result in a larger bundle size and potential performance implications, depending on the project's requirements.

Code Comparison

Unform:

import { useForm } from 'unform';

const MyForm = () => {
  const { handleSubmit, errors } = useForm();

  const onSubmit = (data) => {
    // Handle form submission
  };

  return (
    <form onSubmit={handleSubmit(onSubmit)}>
      {/* Form fields */}
    </form>
  );
};

Variant Form:

import { useVariantForm } from 'variant-form';

const MyForm = () => {
  const { handleSubmit, errors } = useVariantForm();

  const onSubmit = (data) => {
    // Handle form submission
  };

  return (
    <form onSubmit={handleSubmit(onSubmit)}>
      {/* Form fields */}
    </form>
  );
};

📋 React Hooks for form state management and validation (Web + React Native)

Pros of react-hook-form/react-hook-form

  • Simplicity: react-hook-form provides a straightforward and minimalistic API, making it easy to integrate into existing projects.
  • Performance: The library is designed to be highly performant, with a focus on reducing unnecessary re-renders and optimizing the form state management.
  • Flexibility: react-hook-form supports a wide range of form validation scenarios and can be easily extended with custom validation rules.

Cons of react-hook-form/react-hook-form

  • Lack of Variant Support: Unlike Variant Form, react-hook-form does not provide built-in support for form variants, which can be useful for complex form structures.
  • Limited UI Integration: react-hook-form is primarily focused on the form logic and does not provide any UI components, requiring developers to integrate it with their own UI library.

Code Comparison

Variant Form (vform666/variant-form):

<VariantForm>
  <VariantField name="name" label="Name" />
  <VariantField name="email" label="Email" type="email" />
  <VariantField name="password" label="Password" type="password" />
  <VariantSubmit>Submit</VariantSubmit>
</VariantForm>

react-hook-form (react-hook-form/react-hook-form):

const { register, handleSubmit } = useForm();
const onSubmit = (data) => console.log(data);

return (
  <form onSubmit={handleSubmit(onSubmit)}>
    <input {...register('name')} />
    <input {...register('email')} type="email" />
    <input {...register('password')} type="password" />
    <button type="submit">Submit</button>
  </form>
);
33,863

Build forms in React, without the tears 😭

Pros of Formik

  • Formik provides a comprehensive set of features and utilities for managing form state, validation, and submission, making it a robust and feature-rich solution.
  • Formik has a large and active community, with extensive documentation and a wealth of online resources, making it easier to get started and find solutions to common problems.
  • Formik is highly customizable, allowing developers to tailor the form experience to their specific needs.

Cons of Formik

  • Formik's API can be more complex and verbose compared to Variant Form, which may have a steeper learning curve for some developers.
  • Formik's focus on comprehensive features may result in a larger bundle size, which could be a concern for performance-sensitive applications.

Code Comparison

Formik:

<Formik
  initialValues={{ name: '', email: '' }}
  onSubmit={(values) => console.log(values)}
  validationSchema={Yup.object({
    name: Yup.string().required('Name is required'),
    email: Yup.string().email('Invalid email address').required('Email is required'),
  })}
>
  {(formik) => (
    <form onSubmit={formik.handleSubmit}>
      <input type="text" {...formik.getFieldProps('name')} />
      <input type="email" {...formik.getFieldProps('email')} />
      <button type="submit">Submit</button>
    </form>
  )}
</Formik>

Variant Form:

<VariantForm
  initialValues={{ name: '', email: '' }}
  onSubmit={(values) => console.log(values)}
  validations={{
    name: { required: true },
    email: { required: true, email: true },
  }}
>
  {(form) => (
    <form onSubmit={form.handleSubmit}>
      <input type="text" {...form.getFieldProps('name')} />
      <input type="email" {...form.getFieldProps('email')} />
      <button type="submit">Submit</button>
    </form>
  )}
</VariantForm>

🏁 Framework agnostic, high performance, subscription-based form state management

Pros of Final-Form

  • Larger Community: Final-Form has a larger and more active community, with more contributors and a more extensive ecosystem of plugins and integrations.
  • Comprehensive Documentation: The Final-Form documentation is more comprehensive and provides more detailed guidance on usage and configuration.
  • Wider Adoption: Final-Form is more widely adopted and used in production environments, which can provide more confidence in its stability and reliability.

Cons of Final-Form

  • Steeper Learning Curve: Final-Form has a more complex API and may have a steeper learning curve for developers new to the library.
  • Larger Bundle Size: Final-Form has a larger bundle size compared to Variant-Form, which can impact performance in some cases.

Code Comparison

Variant-Form:

const form = useForm({
  initialValues: {
    name: '',
    email: '',
  },
  onSubmit: (values) => {
    console.log(values);
  },
});

Final-Form:

const { form, handleSubmit } = useForm({
  onSubmit: (values) => {
    console.log(values);
  },
});

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Variant Form

一款高效的Vue低代码表单,可视化设计,一键生成源码,享受更多摸鱼时间。

image


立即体验

在线Demo

🎉🎉基于VForm的全栈低代码平台已发布🎉🎉

美乐低代码——立即进入 (私有部署、开箱即用️,已开源✌✌)️

立即体验VForm Pro高级版(提供商业支持)

Pro Demo

视频教程集合:

B站观看

Vue 3正式版已发布

立即进入

🎉🎉基于Vant组件库的Mobile版本已发布🎉🎉

立即进入

友情链接

Fantastic-admin —— 一款开箱即用的 Vue 中后台管理系统框架(支持Vue2/Vue3)


功能一览

> 拖拽式可视化表单设计;
> 支持PC、Pad、H5三种布局;
> 支持运行时动态加载表单;
> 支持表单复杂交互控制;
> 支持自定义CSS样式;
> 支持自定义校验逻辑;
> 支持国际化多语言;
> 兼容IE 11浏览器;
> 可导出Vue组件、HTML源码;
> 可导出Vue的SFC单文件组件;
> 支持开发自定义组件;
> 支持响应式自适应布局;
> 支持VS Code插件;
> 更多功能等你探究...;

安装依赖

npm install --registry=https://registry.npmmirror.com

开发调试

npm run serve

生产打包

npm run build

表单设计器 + 表单渲染器打包

npm run lib

表单渲染器打包

npm run lib-render

浏览器兼容性

Chrome(及同内核的浏览器如QQ浏览器、360浏览器等等),Edge, Firefox,Safari,IE 11


跟Vue项目集成


1. 安装包

npm i vform-builds

或

yarn add vform-builds

2. 引入并全局注册VForm组件

import Vue from 'vue'
import App from './App.vue'

import ElementUI from 'element-ui'  //引入element-ui库
import VForm from 'vform-builds'  //引入VForm库

import 'element-ui/lib/theme-chalk/index.css'  //引入element-ui样式
import 'vform-builds/dist/VFormDesigner.css'  //引入VForm样式

Vue.config.productionTip = false

Vue.use(ElementUI)  //全局注册element-ui
Vue.use(VForm)  //全局注册VForm(同时注册了v-form-designer和v-form-render组件)

new Vue({
  render: h => h(App),
}).$mount('#app')

3. 在Vue模板中使用表单设计器组件

<template>
  <v-form-designer></v-form-designer>
</template>

<script>
  export default {
    data() {
      return {
      }
    }
  }
</script>

<style lang="scss">
body {
  margin: 0;  /* 如果页面出现垂直滚动条,则加入此行CSS以消除之 */
}
</style>

4. 在Vue模板中使用表单渲染器组件

<template>
  <div>
    <v-form-render :form-json="formJson" :form-data="formData" :option-data="optionData" ref="vFormRef">
    </v-form-render>
    <el-button type="primary" @click="submitForm">Submit</el-button>
  </div>
</template>
<script>
  export default {
    data() {
      return {
        formJson: {"widgetList":[],"formConfig":{"labelWidth":80,"labelPosition":"left","size":"","labelAlign":"label-left-align","cssCode":"","customClass":"","functions":"","layoutType":"PC","onFormCreated":"","onFormMounted":"","onFormDataChange":""}},
        formData: {},
        optionData: {}
      }
    },
    methods: {
      submitForm() {
        this.$refs.vFormRef.getFormData().then(formData => {
          // Form Validation OK
          alert( JSON.stringify(formData) )
        }).catch(error => {
          // Form Validation failed
          this.$message.error(error)
        })
      }
    }
  }
</script>

资源链接


文档官网:https://www.vform666.com/

在线演示:http://120.92.142.115/

Gitee仓库:https://gitee.com/vdpadmin/variant-form

Github仓库:https://github.com/vform666/variant-form

VS Code插件:https://www.vform666.com/plugin/

更新日志:https://www.vform666.com/changelog.html

订阅Pro版:https://www.vform666.com/pro/

技术交流群:扫如下二维码加群

image

NPM DownloadsLast 30 Days