Skip to main content
SignatureField ← Back to Table of Contents

Summary

Canvas signature pad storing normalized SVG markup. Supports undo, fullscreen, optional download (SVG/WebP), and stroke validation.
ClassBjanczak\FilamentFlexFields\Filament\Forms\Components\SignatureField
State typestring|null — normalized SVG document
FieldTypesignature
Storage constantsSTORE_SVG = 'svg'

Basic usage

use Bjanczak\FilamentFlexFields\Filament\Forms\Components\SignatureField;

SignatureField::make('signature')
    ->label('Sign here')
    ->penColor('#18181b')
    ->backgroundColor('#ffffff')
    ->required();

SignatureField::make('approval_signature')
    ->fullscreen()
    ->undoable()
    ->downloadable(SignatureField::DOWNLOAD_WEBP)
    ->downloadFilename('approval')
    ->maxSizeKb(64)
    ->minStrokes(2);
Read-only preview of an existing signature:
SignatureField::make('signed_at')
    ->default($record->signature_svg)
    ->readOnly();

State format

State is a compact SVG string produced by SignatureSvg::normalize(). null or empty string means no signature. Use normalizeState(mixed $state): ?string to sanitize external SVG before setting state.

Validation

CheckDetail
required()State must not be empty
FormatMust pass SignatureSvg::isValid()
SizeByte size ≤ maxSizeKb() × 1024
StrokesPath count ≥ minStrokes()

Configuration API

penColor(string|Closure $color)

Hex pen color. Default: #18181b. Must match #RGB or #RRGGBB.
SignatureField::make('field_name')
    ->penColor('#000000');

penWidth(float|Closure $width)

Stroke width in SVG units. Clamped to 0.512. Default: 2.5.
SignatureField::make('field_name')
    ->penWidth(2.5);

backgroundColor(string|Closure|null $color)

Canvas background hex, or null / 'transparent' for transparent. Default: #ffffff.
SignatureField::make('field_name')
    ->backgroundColor('#ffffff');

fullscreen(bool|Closure $condition = true)

Enable fullscreen drawing mode. Default: true.
SignatureField::make('field_name')
    ->fullscreen(true);

undoable(bool|Closure $condition = true)

Show undo control. Default: true.
SignatureField::make('field_name')
    ->undoable(true);

maxSizeKb(int|Closure $kilobytes)

Maximum stored SVG size in kilobytes. Default: 48.
SignatureField::make('field_name')
    ->maxSizeKb(1024);

minStrokes(int|Closure $strokes)

Minimum number of SVG paths required. Default: 1.
SignatureField::make('field_name')
    ->minStrokes(3);

viewBox(int|Closure $width, int|Closure $height)

SVG viewBox dimensions. Defaults from SignatureSvg::VIEWBOX_WIDTH / VIEWBOX_HEIGHT.
SignatureField::make('field_name')
    ->viewBox(400, 200);

smoothing(bool|Closure $condition = true)

Bezier smoothing on strokes. Default: true.
SignatureField::make('field_name')
    ->smoothing(true);

trackpadGlide(bool|Closure $condition = true)

Hold modifier key to draw with trackpad without clicking. Default: false.
SignatureField::make('field_name')
    ->trackpadGlide(true);

trackpadGlideKey(string|Closure $key)

Single letter az for glide modifier. Default: d.
SignatureField::make('field_name')
    ->trackpadGlideKey('shift');

guidelines(bool|Closure $condition = true)

Show baseline guidelines on canvas. Default: false.
SignatureField::make('field_name')
    ->guidelines(true);

downloadable(string|Closure|null $format = 'svg')

Enable client-side download. Formats: SignatureField::DOWNLOAD_SVG or SignatureField::DOWNLOAD_WEBP. Pass null to disable.
SignatureField::make('field_name')
    ->downloadable('svg');

downloadFilename(string|Closure $filename)

Download file base name without extension. Default: signature.
SignatureField::make('field_name')
    ->downloadFilename('signature.svg');

webpQuality(float|Closure $quality)

WebP export quality 0.11. Default: 0.9.
SignatureField::make('field_name')
    ->webpQuality(0.8);

undoIcon() / clearIcon() / downloadIcon() / fullscreenIcon() / closeIcon()

Override toolbar icons (string|BackedEnum|Htmlable|Closure|null).
SignatureField::make('field_name')
    ->undoIcon('heroicon-o-arrow-path')
    ->clearIcon('heroicon-o-trash')
    ->downloadIcon('heroicon-o-arrow-down-tray')
    ->fullscreenIcon('heroicon-o-arrows-pointing-out')
    ->closeIcon('heroicon-o-x-mark');

readOnly(bool|Closure $condition = true)

Disable drawing; display existing SVG only.
SignatureField::make('field_name')
    ->readOnly(true);

Public helper methods

MethodReturnsDescription
getPenColor()stringLowercase hex
getPenWidth()floatClamped width
getBackgroundColor()string|nullBackground hex or null
isFullscreenEnabled()boolFullscreen available
isUndoable()boolUndo enabled
getMaxSizeKb()intSize limit
getMinStrokes()intMinimum paths
getViewBoxWidth() / getViewBoxHeight()intViewBox size
isSmoothingEnabled()boolSmoothing on
isTrackpadGlideEnabled()boolTrackpad glide on
getTrackpadGlideKey()stringModifier key
isGuidelinesEnabled()boolGuidelines visible
getDownloadFormat()string|nullsvg, webp, or null
getDownloadFilename()stringDownload base name
getWebpQuality()floatWebP quality
getUndoIcon() etc.string|BackedEnum|HtmlableResolved icons
normalizeState(mixed $state)string|nullSanitized SVG
getWrapperClasses()array<string, bool>fff-signature-field

FlexField schema config

Config keyMaps to
pen_colorpenColor()
pen_widthpenWidth()
background_colorbackgroundColor()
fullscreenfullscreen()
undoableundoable()
max_size_kbmaxSizeKb()
min_strokesminStrokes()
smoothingsmoothing()
download_formatdownloadable()
download_filenamedownloadFilename()
webp_qualitywebpQuality()

CSS classes

ClassRole
fff-signature-fieldRoot wrapper
fff-signature-field__canvasDrawing surface
fff-signature-field__toolbarAction buttons

Implementation notes

  • Store SVG in text or longText columns; consider maxSizeKb() for DB limits.
  • WebP download is generated client-side from the canvas — not stored in form state.