Documentation menu
Getting Started
Components
Primitives
- Agent Thinking
- Alert
- Alert Dialog
- Avatar
- Badge
- Breadcrumb
- Button
- Button Group
- Calendar
- Card
- Checkbox
- Command
- Command Palette
- Context Menu
- Data Table
- Dialog
- Dropdown Menu
- Empty
- Field
- Glow Cloud
- Input
- Label
- Medication Schedule
- Period Tabs
- Popover
- Rainbow Button
- Scroll Area
- Select
- Selectable Card
- Separator
- Sheet
- Sidebar
- Skeleton
- Slider
- Sonner
- Spinner
- Switch
- Table
- Tabs
- Tag
- Textarea
- Timeline
- Tooltip
- Use Count Up
Charts and metrics
Patterns
- Confirm Button
- Date Picker
- Embedded
- Empty State
- Entity Drawer
- Error Boundary
- Field Row
- File Dropzone
- Form Dialog
- Kv
- List Editor
- List Page
- Live Time
- Mini Table
- Money
- Note Field
- Note Text
- Page Card
- Page Header
- Page Tabs
- Page Toolbar
- Person Cell
- Picture Field
- Print Card
- Range Switcher
- Row Actions
- Search Input
- Search Select
- Selected Box
- Signature Pad
- Status Badge
- Sub Nav Layout
- Suggest Input
- Tab Icons
- Table Footer
- Theme Accent Picker
- Time Picker
- View All Link
Dashboard cards
Advanced
Device frames
Website widgets
Website screens
Website panels
Patterns
Signature Pad
Draw a signature, exported as a PNG.
import { useState } from "react"
import { SignaturePad } from "@/registry/vcare/ui/signature-pad"
export default function SignaturePadDemo() {
const [sig, setSig] = useState<string | undefined>()
return (
<div className="w-full max-w-md">
<SignaturePad value={sig} onChange={setSig} label="Patient signature" clearLabel="Clear" />
</div>
)
}Installation
npx shadcn@latest add @vcare/signature-padOr install directly from the URL: https://ui.vcarehms.com/r/signature-pad.json
- Install the dependencies:
npm i lucide-react - Add the registry items it uses: button.
- Copy this file into your project and change the
@/registry/vcare/…imports to your own paths.
components/ui/signature-pad.tsx
import { useEffect, useRef } from 'react';
import { Eraser } from 'lucide-react';
import { Button } from '@/registry/vcare/ui/button';
/** Pointer-drawn signature exported as a printable PNG data URL. */
export function SignaturePad({
value,
onChange,
readOnly = false,
label = 'Signature',
clearLabel = 'Clear signature',
}: {
value?: string;
onChange: (value: string | undefined) => void;
readOnly?: boolean;
label?: string;
clearLabel?: string;
}) {
const ref = useRef<HTMLCanvasElement>(null);
const drawing = useRef(false);
const blank = () => {
const canvas = ref.current;
if (!canvas) return;
const context = canvas.getContext('2d')!;
context.fillStyle = '#fff';
context.fillRect(0, 0, canvas.width, canvas.height);
};
useEffect(() => {
const canvas = ref.current;
if (!canvas) return;
blank();
if (value) {
const image = new Image();
image.onload = () => canvas.getContext('2d')!.drawImage(image, 0, 0, canvas.width, canvas.height);
image.src = value;
}
}, [value]);
const point = (event: React.PointerEvent) => {
const canvas = ref.current!;
const rect = canvas.getBoundingClientRect();
return { x: ((event.clientX - rect.left) / rect.width) * canvas.width, y: ((event.clientY - rect.top) / rect.height) * canvas.height };
};
const start = (event: React.PointerEvent) => {
if (readOnly) return;
drawing.current = true;
ref.current!.setPointerCapture(event.pointerId);
const context = ref.current!.getContext('2d')!;
const p = point(event);
context.beginPath();
context.moveTo(p.x, p.y);
};
const move = (event: React.PointerEvent) => {
if (!drawing.current) return;
const context = ref.current!.getContext('2d')!;
const p = point(event);
context.lineWidth = 2.5;
context.lineCap = 'round';
context.lineJoin = 'round';
context.strokeStyle = '#111827';
context.lineTo(p.x, p.y);
context.stroke();
};
const end = () => {
if (!drawing.current) return;
drawing.current = false;
onChange(ref.current!.toDataURL('image/png'));
};
return (
<div className="space-y-2">
<canvas
ref={ref}
width={720}
height={210}
aria-label={label}
onPointerDown={start}
onPointerMove={move}
onPointerUp={end}
onPointerCancel={end}
onPointerLeave={end}
className="h-36 w-full touch-none rounded-2xl bg-white text-neutral-950 shadow-border outline outline-1 -outline-offset-1 outline-black/10"
/>
{!readOnly && value && (
<Button type="button" variant="ghost" size="sm" onClick={() => onChange(undefined)}>
<Eraser />
{clearLabel}
</Button>
)}
</div>
);
}Usage
import { SignaturePad } from "@/components/ui/signature-pad"Exports
SignaturePad
Dependencies
lucide-react@^1.80.0(npm)@vcare/button(registry)
Raw item: /r/signature-pad.json