pavlosgi / forms

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Forms

Install

yarn

Build

yarn build

Watch

yarn dev

View example page here http://localhost:3000/

Examples

Form

const Form = F.create()
  .require<{ client: 'client' }>()
  .expect<{ surname: [string, string] }>()
  .add(
    'name',
    F.dyn(o =>
      F.text(
        F.dyn(me => `Name ${me || ''} ${o.partial.surname || ''}`),
        v => v.required().andThen(v => right({ tag: 'name', value: v }))
      )
    )
  )
  .add(
    'surname',
    F.text(
      F.dyn(v => `Surname ${v || ''}`),
      F.dyn(
        dyn => val =>
          val
            .required()
            .andThen(v =>
              v.length > 2 ? right(v) : left(`Min length 3, current length ${dyn?.length || 0}`)
            )
      )
    )
  )

Render

const EditForm = Form.interpret(ReactEditRecordInputBlock);
return (
  <EditForm
    onChange={s => console.info(s)}
    client="client"
    value={{
      name: 'a'
    }}
    onSubmit={v => {
      return Promise.resolve(right(console.info(JSON.stringify(v))));
    }}
  />
)

About

License:MIT License


Languages

Language:TypeScript 100.0%