SignatureField
Canvas-based signature capture with image export.
Preview
"use client";
import { zodResolver } from "@hookform/resolvers/zod";
import { useForm, FormProvider } from "react-hook-form";
import { z } from "zod";
import SignatureField from "@/components/ui/SignatureField";
export const schema = z.object({
signature: z.string().min(1, { message: "Please sign before submitting." }),
});
export function SignatureFieldBasicExample() {
const methods = useForm<z.infer<typeof schema>>({
resolver: zodResolver(schema),
defaultValues: { signature: "" },
});
const onSubmit = (data: z.infer<typeof schema>) => {
console.log("Form data:", data);
alert("Signature saved as data URL. Check the console!");
};
return (
<FormProvider {...methods}>
<form onSubmit={methods.handleSubmit(onSubmit)} className="space-y-4 w-[26rem]">
<SignatureField name="signature" label="Signature" />
<button type="submit" className="form-button form-button-primary w-full">Submit</button>
</form>
</FormProvider>
);
}
Props
| Name | Type | Default | Description |
|---|---|---|---|
| name* | string | - | Form field name. |
| label* | string | - | Label displayed above the canvas. |
| width | number | 320 | Canvas width. |
| height | number | 160 | Canvas height. |
| className | string | - | Additional CSS classes. |