Overrides

Form (TanStack)

Extended Features

  • Form wraps TanStack’s useForm instance in a native <form> and handles form.handleSubmit() for you.
  • useFormContext exposes the generic form instance.

Install

Configure your registry in components.json:

{
  "registries": {
    "@uxio": "https://ui.uxio.dev/r/styles/{style}/{name}.json"
  }
}

Then run:

npx shadcn@latest add @uxio/form

This installs @tanstack/react-form and zod as well.

Usage

import { useForm } from "@tanstack/react-form"
import { z } from "zod"

import { Form } from "@/components/ui/form"

const loginSchema = z.object({
  email: z.string(),
  password: z.string(),
})

export function LoginForm() {
  const form = useForm({
    defaultValues: {
      email: "",
      password: "",
    } as z.infer<typeof loginSchema>,
    validators: {
      onSubmit: loginSchema,
    },
    onSubmit: async ({ value }) => {
      // login
    },
  })

  return (
    <Form form={form}>
      <form.Field
        name="email"
        children={(field) => {
          //
        }}
      />
    </Form>
  )
}
import { useStore } from "@tanstack/react-form"
import { z } from "zod"

import { Button } from "@/components/ui/button"
import { useFormContext } from "@/components/ui/form"

const loginSchema = z.object({
  email: z.string(),
  password: z.string(),
})

function FormSubmit() {
  const form = useFormContext<typeof loginSchema>()
  const isSubmitting = useStore(form.store, (state) => state.isSubmitting)

  return (
    <Button loading={isSubmitting} type="submit">
      Login
    </Button>
  )
}

Registration example

Shown on your public profile.

00000000
0000

Minutes and seconds (e.g. 15m 00s).

00

Example: 2/5 for two remote days out of five.