StructCE / our-react-components

our-react-components
0 stars 0 forks source link

feature/FormFactory #3

Closed artistrea closed 1 year ago

artistrea commented 1 year ago

Objetivo:

Criar uma factory de form, para poder facilmente criar qualquer form sem se importar com a estilização ou html, apenas a lógica. Sendo assim:

Leve em conta e melhore o exemplo do README:

import { FormFactory } from "";

const userSchema = {
  name: {
    type: "text", // input type, could be image, etc
    required: true,
  },
  age: {
    type: "number",
    required: true,
  },
  email: {
    type: "email",
    required: true,
  },
  password: {
    type: "password",
    required: true,
    customValidation: (formInfo) => formInfo.password.length > 6,
  },
  passwordConfirmation: {
    type: "password",
    required: true,
    customValidation: (formInfo) =>
      formInfo.password === formInfo.passwordConfirmation,
  },
};

export const UserForm = FormFactory(userSchema);