0.6.0 β€’ Published 7 months ago

antd-custom-form v0.6.0

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

antd-custom-form πŸš€

Say goodbye to the boilerplate blues! Introducing antd-custom-form, your one-stop shop for all things form-related in Ant Design. Create forms that are as easy to set up as they are on the eyes.

Features 🌟

  • πŸ“ Versatile Fields: Text, number, select, date, fileβ€”you name it, we've got it.
  • 🐜 Ant Design BFF: Seamlessly integrates with your favorite UI library.
  • πŸ“ Flexible Layout: Uses Ant Design's grid system to make your forms look like a million bucks.
  • 🎬 Action Button Customization: Place 'em where you want 'em.
  • 🎁 Initial Values: Because sometimes, you just want to give your users a head start.

Installation πŸ› οΈ

# With npm
npm i antd-custom-form

# Or if you're a yarn person
yarn add antd-custom-form

Props πŸ“š

For the Form πŸ“‹

PropRequired?DefaultDescription
fieldGroupsYes 🚨-An array of field groups. It's like Inception but for forms.
onSubmitYes 🚨-What happens in the form, stays in the formβ€”until you submit it.
formControlNo 🀷-Your very own Ant Design form instance.
initialValueNo 🀷-Pre-fill like a pro.
layoutNo 🀷"horizontal"How do you like your forms? Stacked or side-by-side?
actionButtonsPlacementNo 🀷"end"Where the action happens.
submitButtonNo 🀷trueThe button that seals the deal.
resetButtonNo 🀷trueThe button that says, "Let's start over, shall we?"
formPropsNo 🀷-Extra props? Yes, please!

For the Fields 🌱

PropRequired?DefaultDescription
labelYes 🚨-What's in a name? Well, a lot actually.
nameYes 🚨-The key to your field's heart.
typeYes 🚨-The personality of your field.
listConditional πŸ€”-The options that make your select fields happy.
rulesNo 🀷-Keep your fields in check.
hideNo 🀷falseWhether to render.
formItemPropsNo 🀷-The props for each form item.
inputPropsNo 🀷-The custom spices for each input.
spanNo 🀷24How much personal space to give your field?

πŸ€” The list prop is only required for single-select, multi-select and toggle. For other field types, it's a "thanks, but no thanks" situation.


Usage 🎨

Ready to create your first masterpiece? Here's a quick example to get you started:

import React from "react"
import { CustomForm, IFieldGroup } from "antd-custom-form"
import { Typography } from "antd"

interface Fields {
  firstName: string
  age: number
  color: string
  dob: Moment
  hobbies: string[]
  gender?: "male" | "female"
  isEnabled?: boolean
  bio: string
}

function App() {
  const fieldsGroups: IFieldGroup<Fields> = [
    [
      {
        label: "Name",
        name: "firstName",
        type: "text",
        rules: [{ required: true, message: "Please enter a name" }],
        hide: true,
        formItemProps: {
          validateStatus: "success",
          hasFeedback: true,
        },
      },
      {
        label: "Age",
        name: "age",
        type: "number",
      },
    ],
    [
      {
        label: "Favorite Color",
        name: ["color"],
        type: "single-select",
        list: [
          { label: "Red", value: "red" },
          { label: "Blue", value: "blue" },
          { label: "Green", value: "green" },
        ],
      },
      {
        label: "Date of Birth",
        name: "dob",
        type: "date",
      },
    ],
    [
      {
        label: "Hobbies",
        name: "hobbies",
        type: "checkbox",
        list: [
          { label: "Hobby 1", value: "h1" },
          { label: "Hobby 2", value: "h2" },
        ],
      },
      {
        label: "Gender",
        name: "gender",
        type: "radio",
        list: [
          { label: "Male", value: "male" },
          { label: "Female", value: "female" },
        ],
      },
    ],
    [
      {
        label: "Bio",
        name: "bio",
        type: "textarea",
      },
      {
        label: "Is Active?",
        name: "isEnabled",
        type: "toggle",
        list: [
          { label: "Yes", value: true },
          { label: "No", value: false },
        ],
      },
    ],
  ]

  const handleSubmit = (data: Fields) => {
    console.log("Form Data:", data)
  }

  return (
    <div style={{ width: "70vw", marginInline: "auto" }}>
      <Typography.Title>Basic Form</Typography.Title>
      <CustomForm
        fieldGroups={fieldsGroups}
        onSubmit={handleSubmit}
        resetButton={false}
        layout="vertical"
        initialValues={{
          firstName: "Osama",
          age: 27,
          color: "teal",
          dob: moment(),
          hobbies: [],
          bio: "",
        }}
      />
    </div>
  )
}

License πŸ“œ

MIT

0.6.0

7 months ago

0.5.0

7 months ago

0.4.1

7 months ago

0.4.0

7 months ago

0.3.2

7 months ago

0.3.1

7 months ago

0.3.0

7 months ago

0.2.0

7 months ago

0.1.1

7 months ago

0.1.0

9 months ago