A native form element with consolidated error handling.
Installation
npx shadcn@latest add @caprice/formpnpm dlx shadcn@latest add @caprice/formyarn dlx shadcn@latest add @caprice/formbunx shadcn@latest add @caprice/formnpm install @caprice-ui/reactpnpm add @caprice-ui/reactyarn add @caprice-ui/reactbun add @caprice-ui/reactInstall the following dependencies:
npm install @base-ui/react lucide-reactpnpm add @base-ui/react lucide-reactyarn add @base-ui/react lucide-reactbun add @base-ui/react lucide-reactAdd a cn helper
import { defineConfig, getSchema, type VariantProps } from 'cva';
import { twMerge } from 'tailwind-merge';
export const { cva, cx: cn } = defineConfig({
hooks: {
onComplete: (className: string) => twMerge(className),
},
});
export type { VariantProps };
export { getSchema };
Copy and paste the following code into your project.
import { Form as FormPrimitive } from '@base-ui/react/form';
import type * as React from 'react';
import { cn } from '@/lib/utils';
/**
* A native form element with consolidated error handling.
* Renders a `<form>` element.
*
* Documentation: [Caprice UI Form](https://caprice-ui.com/docs/components/form)
*
* API Reference: [Base UI Form](https://base-ui.com/react/components/form)
*/
export namespace Form {
export type State = FormPrimitive.State;
export type Props = React.ComponentProps<typeof FormPrimitive>;
export type SubmitEventDetails = FormPrimitive.SubmitEventDetails;
export type SubmitEventReason = FormPrimitive.SubmitEventReason;
export type ValidationMode = FormPrimitive.ValidationMode;
export type Values = FormPrimitive.Values;
}
export function Form({ className, ...props }: Form.Props) {
return (
<FormPrimitive
className={cn('flex w-full flex-col gap-4', className)}
data-slot="form"
{...props}
/>
);
}
Update the import paths to match your project setup.
Usage
import { Form } from "@/components/caprice-ui/form"import { Form } from "@caprice-ui/react/form"Examples
API Reference
Last updated on