Convert Figma logo to code with AI

alibaba logox-render

🚴‍♀️ 阿里 - 很易用的中后台「表单 / 表格 / 图表」解决方案

7,027
994
7,027
22

Top Related Projects

🏆 Use Ant Design like a Pro!

11,356

📱🚀 🧩 Cross Device & High Performance Normal Form/Dynamic(JSON Schema) Form/Form Builder -- Support React/React Native/Vue 2/Vue 3

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

33,863

Build forms in React, without the tears 😭

25,069

🤖 Headless UI for building powerful tables & datagrids for TS/JS - React-Table, Vue-Table, Solid-Table, Svelte-Table

Quick Overview

X-Render is a powerful and flexible form rendering engine developed by Alibaba. It allows developers to create complex forms and user interfaces using JSON schemas, providing a declarative approach to form building and management.

Pros

  • Highly customizable and extensible
  • Supports a wide range of form components and layouts
  • Integrates well with popular React-based frameworks
  • Offers excellent performance for large and complex forms

Cons

  • Steep learning curve for beginners
  • Documentation is primarily in Chinese, which may be challenging for non-Chinese speakers
  • Limited community support compared to more established form libraries
  • May be overkill for simple form requirements

Code Examples

  1. Basic form rendering:
import FormRender from 'form-render';

const schema = {
  type: 'object',
  properties: {
    name: {
      title: 'Name',
      type: 'string',
    },
    age: {
      title: 'Age',
      type: 'number',
    },
  },
};

const Demo = () => <FormRender schema={schema} />;
  1. Custom form validation:
import FormRender from 'form-render';

const schema = {
  type: 'object',
  properties: {
    email: {
      title: 'Email',
      type: 'string',
      format: 'email',
    },
  },
};

const customValidate = (formData) => {
  const errors = {};
  if (!formData.email.includes('@')) {
    errors.email = 'Invalid email format';
  }
  return errors;
};

const Demo = () => <FormRender schema={schema} customValidate={customValidate} />;
  1. Dynamic form fields:
import FormRender, { useForm } from 'form-render';

const schema = {
  type: 'object',
  properties: {
    type: {
      title: 'Type',
      type: 'string',
      enum: ['personal', 'business'],
    },
    // Other fields will be added dynamically
  },
};

const Demo = () => {
  const form = useForm();

  const onTypeChange = (value) => {
    if (value === 'personal') {
      form.setSchema({
        ...schema,
        properties: {
          ...schema.properties,
          ssn: { title: 'SSN', type: 'string' },
        },
      });
    } else {
      form.setSchema({
        ...schema,
        properties: {
          ...schema.properties,
          taxId: { title: 'Tax ID', type: 'string' },
        },
      });
    }
  };

  return <FormRender form={form} schema={schema} onFieldChange={onTypeChange} />;
};

Getting Started

  1. Install the package:

    npm install form-render
    
  2. Import and use in your React component:

    import FormRender from 'form-render';
    
    const schema = {
      type: 'object',
      properties: {
        name: { title: 'Name', type: 'string' },
        email: { title: 'Email', type: 'string', format: 'email' },
      },
    };
    
    const MyForm = () => {
      const onFinish = (formData) => console.log(formData);
      return <FormRender schema={schema} onFinish={onFinish} />;
    };
    
  3. Customize as needed, adding validation, dynamic fields, and custom components.

Competitor Comparisons

🏆 Use Ant Design like a Pro!

Pros of pro-components

  • More comprehensive set of pre-built components for enterprise applications
  • Tighter integration with Ant Design ecosystem
  • Better documentation and examples for complex scenarios

Cons of pro-components

  • Steeper learning curve due to more complex API
  • Potentially heavier bundle size for smaller projects
  • Less flexibility for custom form layouts compared to x-render

Code Comparison

x-render:

<FormRender
  schema={{
    type: 'object',
    properties: {
      name: { type: 'string', title: 'Name' },
      age: { type: 'number', title: 'Age' }
    }
  }}
  onFinish={handleSubmit}
/>

pro-components:

<ProForm
  onFinish={handleSubmit}
>
  <ProFormText name="name" label="Name" />
  <ProFormDigit name="age" label="Age" />
</ProForm>

Summary

x-render focuses on schema-driven form generation, offering a more declarative approach. It's lightweight and flexible but may require more custom work for complex scenarios.

pro-components provides a rich set of pre-built components tailored for enterprise applications. It offers more out-of-the-box functionality but comes with a steeper learning curve and potentially larger bundle size.

Choose x-render for simpler, schema-based forms with high customization needs. Opt for pro-components when building complex enterprise applications within the Ant Design ecosystem.

11,356

📱🚀 🧩 Cross Device & High Performance Normal Form/Dynamic(JSON Schema) Form/Form Builder -- Support React/React Native/Vue 2/Vue 3

Pros of Formily

  • More comprehensive and feature-rich form solution
  • Better support for complex form scenarios and large-scale applications
  • Stronger TypeScript integration and type inference

Cons of Formily

  • Steeper learning curve due to its complexity
  • Heavier bundle size compared to x-render
  • May be overkill for simple form use cases

Code Comparison

Formily:

import { createForm } from '@formily/core'
import { FormProvider, Field } from '@formily/react'

const form = createForm()

<FormProvider form={form}>
  <Field name="username" component="Input" />
</FormProvider>

x-render:

import { FormRender, useForm } from 'form-render'

const form = useForm()

<FormRender
  form={form}
  schema={{
    type: 'object',
    properties: {
      username: { type: 'string', title: 'Username' }
    }
  }}
/>

Key Differences

  • Formily uses a more programmatic approach, while x-render relies on JSON schema
  • Formily offers more granular control over form fields and behaviors
  • x-render provides a simpler API for basic form rendering scenarios
  • Formily has a larger ecosystem with additional packages for specific use cases
  • x-render focuses on schema-driven form generation, making it easier for non-developers to create forms

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

Pros of react-hook-form

  • Lightweight and performant, with minimal re-renders
  • Extensive validation options out-of-the-box
  • Seamless integration with TypeScript for type safety

Cons of react-hook-form

  • Less opinionated, requiring more setup for complex forms
  • Limited built-in UI components compared to x-render
  • Steeper learning curve for advanced features

Code Comparison

react-hook-form:

import { useForm } from "react-hook-form";

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

<form onSubmit={handleSubmit(onSubmit)}>
  <input {...register("firstName")} />
  <input type="submit" />
</form>

x-render:

import { FormRender } from "x-render";

const schema = {
  type: "object",
  properties: {
    firstName: { type: "string", title: "First Name" }
  }
};

<FormRender schema={schema} onFinish={onSubmit} />

react-hook-form focuses on providing a flexible API for form handling, while x-render emphasizes declarative form generation using JSON schemas. react-hook-form offers more granular control over form elements and validation, whereas x-render provides a higher-level abstraction for rapid form development. The choice between the two depends on the specific requirements of the project and the developer's preference for control versus convenience.

33,863

Build forms in React, without the tears 😭

Pros of Formik

  • Lightweight and focused specifically on form handling
  • Extensive documentation and large community support
  • Seamless integration with Yup for schema validation

Cons of Formik

  • Limited to form-specific functionality
  • Requires more manual setup for complex form scenarios
  • Less opinionated, which may lead to inconsistent implementations across projects

Code Comparison

Formik:

import { Formik, Form, Field } from 'formik';

<Formik initialValues={{ name: '' }} onSubmit={handleSubmit}>
  <Form>
    <Field name="name" />
    <button type="submit">Submit</button>
  </Form>
</Formik>

X-Render:

import { FormRender } from '@alib/form-render';

<FormRender
  schema={{
    type: 'object',
    properties: {
      name: { type: 'string', title: 'Name' }
    }
  }}
  onSubmit={handleSubmit}
/>

Key Differences

  • Formik provides a more flexible API for custom form implementations
  • X-Render offers a schema-driven approach, simplifying complex form creation
  • Formik has a steeper learning curve but offers more control
  • X-Render provides built-in UI components and layouts
  • Formik is better suited for smaller, focused form needs
  • X-Render excels in rapidly building complex, data-driven forms

Both libraries have their strengths, and the choice depends on project requirements, team expertise, and desired level of control over form implementation.

25,069

🤖 Headless UI for building powerful tables & datagrids for TS/JS - React-Table, Vue-Table, Solid-Table, Svelte-Table

Pros of Table

  • More flexible and customizable for complex table scenarios
  • Better performance for large datasets due to virtualization
  • Stronger TypeScript support and type safety

Cons of Table

  • Steeper learning curve for beginners
  • Less out-of-the-box functionality for form rendering
  • Requires more manual configuration for basic use cases

Code Comparison

x-render (FormRender):

<FormRender
  schema={{
    type: 'object',
    properties: {
      name: { type: 'string', title: 'Name' },
      age: { type: 'number', title: 'Age' }
    }
  }}
  onFinish={handleSubmit}
/>

Table:

const table = useReactTable({
  data,
  columns,
  getCoreRowModel: getCoreRowModel(),
})

return (
  <table>
    <tbody>
      {table.getRowModel().rows.map(row => (
        <tr key={row.id}>{row.getVisibleCells().map(cell => <td key={cell.id}>{cell.renderCell()}</td>)}</tr>
      ))}
    </tbody>
  </table>
)

x-render focuses on simplifying form rendering with a schema-based approach, while Table provides a more granular control over table rendering and functionality. x-render is easier to set up for basic forms, but Table offers more flexibility for complex table scenarios and better performance for large datasets.

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

logo

XRender

npm GitHub last commit GitHub repo size GitHub closed issues NPM downloads NPM all downloads PRs Welcome

中后台「表单 / 表格 / 图表」开箱即用解决方案

优势

  • FormRender:像写一个 input 一样写表单
  • TableRender:协议生成 & 高度灵活的搜索列表
  • ChartRender:傻瓜式的图表绘制库
  • FormGenerator:中后台表单可视化搭建生成利器

谁在使用?

更多可见使用场景,也很欢迎提交~

支持

  • 如果你觉得 XRender 还不错,可以通过 Star 来表示你的喜欢
  • 在公司或个人项目中使用 XRender,并帮忙推广给伙伴使用

贡献

想贡献代码、解 BUG 或者提高文档可读性?非常欢迎一起参与进来,在提交 PR 前阅读一下 Contributing Guide。

Alt

感谢给 XRender 贡献代码的你们:


https://user-images.githubusercontent.com/8736212/123383626-ff187a80-d5c5-11eb-803f-296762fe72d0.mp4

协议

  • 遵循 MIT 协议
  • 请自由地享受和参与开源

互助答疑群

Star 趋势

Star History Chart

NPM DownloadsLast 30 Days