
Summary
Canvas signature pad storing normalized SVG markup. Supports undo, fullscreen, optional download (SVG/WebP), and stroke validation.| Class | Bjanczak\FilamentFlexFields\Filament\Forms\Components\SignatureField |
| State type | string|null — normalized SVG document |
| FieldType | signature |
| Storage constants | STORE_SVG = 'svg' |
Basic usage
State format
State is a compact SVG string produced bySignatureSvg::normalize(). null or empty string means no signature.
Use normalizeState(mixed $state): ?string to sanitize external SVG before setting state.
Validation
| Check | Detail |
|---|---|
required() | State must not be empty |
| Format | Must pass SignatureSvg::isValid() |
| Size | Byte size ≤ maxSizeKb() × 1024 |
| Strokes | Path count ≥ minStrokes() |
Configuration API
penColor(string|Closure $color)
Hex pen color. Default: #18181b. Must match #RGB or #RRGGBB.
penWidth(float|Closure $width)
Stroke width in SVG units. Clamped to 0.5–12. Default: 2.5.
backgroundColor(string|Closure|null $color)
Canvas background hex, or null / 'transparent' for transparent. Default: #ffffff.
fullscreen(bool|Closure $condition = true)
Enable fullscreen drawing mode. Default: true.
undoable(bool|Closure $condition = true)
Show undo control. Default: true.
maxSizeKb(int|Closure $kilobytes)
Maximum stored SVG size in kilobytes. Default: 48.
minStrokes(int|Closure $strokes)
Minimum number of SVG paths required. Default: 1.
viewBox(int|Closure $width, int|Closure $height)
SVG viewBox dimensions. Defaults from SignatureSvg::VIEWBOX_WIDTH / VIEWBOX_HEIGHT.
smoothing(bool|Closure $condition = true)
Bezier smoothing on strokes. Default: true.
trackpadGlide(bool|Closure $condition = true)
Hold modifier key to draw with trackpad without clicking. Default: false.
trackpadGlideKey(string|Closure $key)
Single letter a–z for glide modifier. Default: d.
guidelines(bool|Closure $condition = true)
Show baseline guidelines on canvas. Default: false.
downloadable(string|Closure|null $format = 'svg')
Enable client-side download. Formats: SignatureField::DOWNLOAD_SVG or SignatureField::DOWNLOAD_WEBP. Pass null to disable.
downloadFilename(string|Closure $filename)
Download file base name without extension. Default: signature.
webpQuality(float|Closure $quality)
WebP export quality 0.1–1. Default: 0.9.
undoIcon() / clearIcon() / downloadIcon() / fullscreenIcon() / closeIcon()
Override toolbar icons (string|BackedEnum|Htmlable|Closure|null).
readOnly(bool|Closure $condition = true)
Disable drawing; display existing SVG only.
Public helper methods
| Method | Returns | Description |
|---|---|---|
getPenColor() | string | Lowercase hex |
getPenWidth() | float | Clamped width |
getBackgroundColor() | string|null | Background hex or null |
isFullscreenEnabled() | bool | Fullscreen available |
isUndoable() | bool | Undo enabled |
getMaxSizeKb() | int | Size limit |
getMinStrokes() | int | Minimum paths |
getViewBoxWidth() / getViewBoxHeight() | int | ViewBox size |
isSmoothingEnabled() | bool | Smoothing on |
isTrackpadGlideEnabled() | bool | Trackpad glide on |
getTrackpadGlideKey() | string | Modifier key |
isGuidelinesEnabled() | bool | Guidelines visible |
getDownloadFormat() | string|null | svg, webp, or null |
getDownloadFilename() | string | Download base name |
getWebpQuality() | float | WebP quality |
getUndoIcon() etc. | string|BackedEnum|Htmlable | Resolved icons |
normalizeState(mixed $state) | string|null | Sanitized SVG |
getWrapperClasses() | array<string, bool> | fff-signature-field |
FlexField schema config
| Config key | Maps to |
|---|---|
pen_color | penColor() |
pen_width | penWidth() |
background_color | backgroundColor() |
fullscreen | fullscreen() |
undoable | undoable() |
max_size_kb | maxSizeKb() |
min_strokes | minStrokes() |
smoothing | smoothing() |
download_format | downloadable() |
download_filename | downloadFilename() |
webp_quality | webpQuality() |
CSS classes
| Class | Role |
|---|---|
fff-signature-field | Root wrapper |
fff-signature-field__canvas | Drawing surface |
fff-signature-field__toolbar | Action buttons |
Implementation notes
- Store SVG in
textorlongTextcolumns; considermaxSizeKb()for DB limits. - WebP download is generated client-side from the canvas — not stored in form state.