npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

antd-pro-schema-form

v1.7.0

Published

Quickly generate forms through schema based on Antd

Downloads

74

Readme

antd-pro-schema-form

🎉🎉🎉 form item value atomize released!!! See Detail

antd-pro-schema-form based Ant Design, quickly generate interactive forms with Schema configuration.

English | 中文文档

Features

  • Reactive
  • Progressive
  • Schema
  • Group schema
  • Fetch remote data multiple mode
  • Fusion and fission value
  • Test case coverage 99%+

Install

install with npm:

npm install --save-dev antd-pro-schema-form

install with yarn:

yarn add antd-pro-schema-form -dev

install with pnpm:

pnpm add antd-pro-schema-form

Quickstart

normal

import React from 'react';
import { Form, Button } from 'antd';
import SchemaForm, { Schema } from 'antd-pro-schema-form';

export default () => {
  const [formRef] = Form.useForm();

  const schema: Schema = [{
    fieldName: 'title',
    label: 'title',
    type: 'input',
    placeholder: 'please input',
    rules: [{ required: true, message: 'Please input title' }]
  }]
  const onSubmit = () => {
    alert(formRef.current.getFieldsValue());
  };
  return (
    <>
      <SchemaForm form={formRef} schema={schema} />
      <Button onClick={onSubmit}>
        Submit
      </Button>
    </>
  )
}

group schema

import React from 'react';
import { Form, Button } from 'antd';
import SchemaForm, { Schema, SchemaGroups } from 'antd-pro-schema-form';

export default () => {
  const [formInstance] = Form.useForm();

  const schema: Schema = {
    title: {
      fieldName: 'title',
      label: 'title',
      type: 'input',
      placeholder: 'please input',
      rules: [{ required: true, message: 'Please input title' }]
    }
  };
  const schemaGroups: SchemaGroups = [{
    list: [
      'title',
    ]
  }];

  const onSubmit = () => {
    alert(JSON.stringify(formInstance.getFieldsValue()));
  };
  return (
    <>
      <SchemaForm form={formInstance} schema={schema} schemaGroups={schemaGroups} />
      <Button onClick={onSubmit}>
        Submit
      </Button>
    </>
  )
}

Advanced

Convert form item value when initialize or submit

  import React, { useRef, useEffect } from 'react';
  import SchemaForm, { RefCurrent, Schema } from 'antd-pro-schema-form';
  import dayjs from 'dayjs';
  import { Button, Form } from 'antd';

  export default () => {
    const formRef = useRef<RefCurrent>();

    const schema: Schema = [{
      fieldName: 'date',
      label: 'date',
      type: 'datePicker',
      fusion(value) {
        // transform value when setFieldsValue
        return dayjs(value);
      },
      fission(value) {
        // transform value when form submit or getFieldsValue
        return value.format('YYYY-MM-DD HH:mm:ss');
      }
    }];

    useEffect(() => {
      if (!formRef.current) return;
      formRef.current.setFieldsValue({
        date: '2023-08-08',
      })
    }, [formRef]);

    const submit = () => {
      // the same as formInstance.getFieldsValue()
      alert(JSON.stringify(formRef.current.getFieldsValue()));
    };

    return (
      <>
        <SchemaForm enableValueAtomize ref={formRef} schema={schema} />
        <Button type="primary" onClick={submit}>submit</Button>
      </>
    )
  }

Ducumentation

see https://drdevelop.github.io/antd-pro/index.html#/schema-form/readme