@gmana/form
TypeScript icon, indicating that this package has built-in type declarations

0.0.19 • Public • Published

@gmana/form

A Quick description of the component

This is an internal utility, not intended for public usage.

Installation

bun add @gmana/form zod @hookform/resolvers react-hook-form

Usage

'use client'

import { zodResolver } from '@hookform/resolvers/zod'
import { useForm } from 'react-hook-form'
import * as z from 'zod'

import { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage } from '@gmana/form'
import { Button, Input } from '@gmana/react'

const signInSchema = z.object({
  email: z.string().min(1, 'Email is required').email('Email is invalid'),
  password: z.string().min(1, 'Password is required').min(8, 'Password must be more than 8 characters').max(32, 'Password must be less than 32 characters'),
})

type ISignIn = z.infer<typeof signInSchema>

export function SignIn() {
  const form = useForm<ISignIn>({
    resolver: zodResolver(signInSchema),
    defaultValues: {
      email: '',
      password: '',
    },
  })

  function onSubmit(values: ISignIn) {
    console.log(values)
  }

  return (
    <Form {...form}>
      <form onSubmit={form.handleSubmit(onSubmit)} className="space-y-2">
        <FormField
          control={form.control}
          name="email"
          render={({ field }) => (
            <FormItem>
              <FormLabel>Email</FormLabel>
              <FormControl>
                <Input placeholder="Email" {...field} />
              </FormControl>
              <FormDescription>Please provider your email here</FormDescription>
              <FormMessage />
            </FormItem>
          )}
        />
        <FormField
          control={form.control}
          name="password"
          render={({ field }) => (
            <FormItem>
              <FormLabel>Password</FormLabel>
              <FormControl>
                <Input type="password" placeholder="Password" {...field} />
              </FormControl>
              <FormMessage />
            </FormItem>
          )}
        />
        <Button type="submit">Submit</Button>
      </form>
    </Form>
  )
}

Readme

Keywords

Package Sidebar

Install

npm i @gmana/form

Weekly Downloads

0

Version

0.0.19

License

MIT

Unpacked Size

27.8 kB

Total Files

20

Last publish

Collaborators

  • sunsreng