Top Related Projects
Vue Forms ⚡️ Supercharged
Performance-focused API for React forms 🚀
📋 React Hooks for form state management and validation (Web + React Native)
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:
- Install the library using npm or yarn:
npm install variant-form
- Import the necessary components and functions from the library:
import { VariantForm, VariantField, VariantCondition, VariantValidator } from 'variant-form';
- Create a form using the
VariantForm
andVariantField
components:
const MyForm = () => {
return (
<Vari
Competitor Comparisons
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>
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>
);
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 designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Variant Form
ä¸æ¬¾é«æçVueä½ä»£ç 表åï¼å¯è§å设计ï¼ä¸é®çææºç ï¼äº«åæ´å¤æ¸é±¼æ¶é´ã
ç«å³ä½éª
ððåºäºVFormçå ¨æ ä½ä»£ç å¹³å°å·²åå¸ðð
ç¾ä¹ä½ä»£ç ââç«å³è¿å ¥ ï¼ç§æé¨ç½²ãå¼ç®±å³ç¨ï¸ï¼å·²å¼æºââï¼ï¸
ç«å³ä½éªVForm Proé«çº§çï¼æä¾åä¸æ¯æï¼
è§é¢æç¨éåï¼
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/
ææ¯äº¤æµç¾¤ï¼æ«å¦ä¸äºç»´ç å 群
Top Related Projects
Vue Forms ⚡️ Supercharged
Performance-focused API for React forms 🚀
📋 React Hooks for form state management and validation (Web + React Native)
Build forms in React, without the tears 😭
🏁 Framework agnostic, high performance, subscription-based form state management
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot