Skip to content
Cynosurev0.5.0
SearchStorybookGitHubnpmColour mode: System. Switch to Light

Components / Controls

SignaturePad

A pad to draw a signature with a mouse, finger or pen.

Drawing astroke

When to useLink to "When to use"

  • Collecting a handwritten signature for a document or a form.

Always offer another way. Drawing needs a pointer and steady hands; it cannot be done from a keyboard or with most assistive technology. Put the pad beside a typed-name option and an upload option (for example as Tabs in a Dialog), and point to them with aria-describedby.

UsageLink to "Usage"

tsx
Copy
import { SignaturePad } from "@arshad-shah/cynosure";

const [strokes, setStrokes] = useState<InkStroke[]>([]);

<SignaturePad label="Draw your signature" value={strokes} onChange={setStrokes} />

onChange is called once per finished stroke with the whole list. Undo and clear are yours: drop the last stroke, or empty the list.

Undo and clear are yours

Pens, fingers and palmsLink to "Pens, fingers and palms"

  • Pens: pressure (through a curve that lifts light writing) and tilt shape the line.
  • Mouse and touch: a steady line, like a ballpoint (speed-based pressure makes lines wobble).
  • One stroke at a time: a second finger, a right-click or a pen's barrel button never starts or replaces a stroke.
  • Palm rejection: touches are ignored for three seconds after a pen was last seen.

Keeping its shapeLink to "Keeping its shape"

Pass space to record strokes in a fixed coordinate space. The signature then keeps its shape and weight whatever size the pad is shown at (a phone, a large screen, a resize while drawing).

Keeps its shape at any size

SavingLink to "Saving"

inkToSvg(strokes, { width, height, ink, weight }) returns a standalone SVG for saving or placing in a PDF. inkPath(stroke, weight) gives one stroke's path data using only M, C and Z, which canvases and PDF writers read alike.

PropsLink to "Props"

Every prop of SignaturePad
PropWhat it doesTypeDefault
labelRequired
Accessible name, e.g. "Draw your signature".string
valueRequired
The strokes so far, in the pad's coordinate space.InkStroke[]
onChangeRequired
Called once per finished stroke with the new list. Undo and clear are yours (slice or empty the list).(strokes: InkStroke[]) => void
ink
Ink colour (any CSS colour). Default: the ink token, so it follows dark mode on screen.stringthe ink token
weight
Nib size. Default medium.InkWeight`medium`
space
The coordinate space strokes are recorded in. Without it strokes are in shown CSS pixels; with it a signature keeps its shape and weight however big the pad is shown (phone width, text size, a resize while drawing).{ width: number; height: number; }
width
Fixed size in CSS pixels. Default: the full width, and the height token.numberthe full width
height
Fixed height in CSS pixels. Default: the height token.numberthe height token
disabled
Stops drawing; the strokes so far stay shown.boolean
aria-describedby
Ids of text that explains the pad (e.g. "Or type your name instead").string
className
Added to the root element, for layout.string
style
Layout only. Restyle through --cy-signature-pad-* tokens.CSSProperties

Generated from the type definitions in @arshad-shah/cynosure 0.5.0.

Behaviour and accessibilityLink to "Behaviour and accessibility"

  • Role: the canvas is an image named by label; describe the other ways to sign with aria-describedby.
  • Touch: gestures on the pad draw instead of scrolling the page, and long-press menus are suppressed while drawing.
  • Colour: without ink, the ink token is used, so the line is dark on light and light on dark. In forced colours it uses the system text colour.
  • Disabled: aria-disabled, nothing draws.

ThemingLink to "Theming"

Tokens: --cy-signature-pad-ink, --cy-signature-pad-background, --cy-signature-pad-height and --cy-signature-pad-guide.

FloatingToolbar · FileDrop · Dialog

These examples run Cynosure 0.5.0 (commit 50ce30b), the version on npm.

Getting started
Theming
Icons
Accessibility
Code editors and highlighters
Using Cynosure without React
Build-tool adapters
Components
Accordion
AppShell
AspectRatio
Breadcrumbs
Calendar
Card
Container
Disclosure
Divider
DocumentViewport
Grid
Inline
PageHeader
PanZoomCanvas
ScrollArea
SideNav
SortableList
SplitPane
Stack
StatusBar
Tabs
TitleBar
Toolbar
Tree
VirtualList
ZoomControls
Announcer
Avatar
Badge
CodeBlock
DescriptionList
EmptyState
ErrorBoundary
Field
Heading
IconTile
Image
Kbd
List
LoadingDots
Notice
ProgressBar
Prose
Skeleton
Stat
Steps
Table
Text
Button
Checkbox
Checklist
ColorField
ColorSwatches
Combobox
CompareSlider
CopyButton
DateField
FileDrop
IconButton
KeyValueEditor
Link
NumberField
Pagination
PathField
RadioGroup
SearchField
SegmentedControl
Select
SelectionFrame
SignaturePad
Slider
Switch
TagInput
TextArea
TextField
ThemeToggle
TimeField
ButtonBase
ChoiceBase
DialogBase
FileInputBase
HiddenValue
Icon
InputBase
LinkBase
LiveRegion
TextAreaBase
ChatMessage
Choice
DataGrid
DeviceFrame
HighlightedText
HotkeyField
ListRow
OptionList
OverlayFrame
QRCode
RowActions
Section
SiteFooter
SiteHeader
SkipLink
SortButton
VisuallyHidden
CommandPalette
ContextMenu
Dialog
FloatingToolbar
HoverCard
Menu
Menubar
Popover
ProgressOverlay
Sheet
Toast
Tooltip
Changelog