Signature pad
Strokes drawn with a pointer or a pen and its pressure, smoothed, undone and cleared, with a typed name for whoever cannot draw.
Previews are drawn in the theme you made.
Edit itDraw or type #
Signature
import { Bundles, Recipes, SignaturePad, SignaturePadSlots } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
// The strokes and the typed name are the pad's Model, placed by
// `Bundles.SignaturePad`. Draw with a pointer, or type a name in the field
// below for a reader who cannot draw; undo and clear are built in.
export default example({
title: 'Draw or type',
slots: SignaturePadSlots,
recipe: Recipes.SignaturePad,
state: Bundles.SignaturePad.with({ id: 'signature' }),
view: ({ style, model, onMessage, h }) =>
SignaturePad.view({ model, onMessage, label: 'Signature', style }, h),
})In your application: recipe goes to forSlots, state to Bundle.withChild, and the body of view is the call. example is this site’s harness.
Drawn only, on a filled pad #
Initials
import { Bundles, Recipes, SignaturePad, SignaturePadSlots } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
// A filled pad for a pointer alone: `surface: 'muted'` and `fallback: false`,
// which leaves out the typed field. A broader pen is an arg of the Bundle.
export default example({
title: 'Drawn only, on a filled pad',
slots: SignaturePadSlots,
recipe: Recipes.SignaturePad,
pins: { surface: 'muted' },
state: Bundles.SignaturePad.with({ id: 'initials', pen: { size: 6 } }),
view: ({ style, model, onMessage, h }) =>
SignaturePad.view({ model, onMessage, label: 'Initials', fallback: false, style }, h),
})In your application: recipe goes to forSlots, state to Bundle.withChild, and the body of view is the call. example is this site’s harness.
A form field, in your words #
Unterschrift
import { Bundles, Recipes, SignaturePad, SignaturePadSlots } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
// `name` submits the signature with the form around the pad, as the SVG
// `toSvg` writes, in a hidden input that stays empty while nothing is
// signed. The words are the application's: here, the pad's in German.
export default example({
title: 'A form field, in your words',
slots: SignaturePadSlots,
recipe: Recipes.SignaturePad,
state: Bundles.SignaturePad.with({ id: 'consent' }),
view: ({ style, model, onMessage, h }) =>
SignaturePad.view(
{
model,
onMessage,
label: 'Unterschrift',
name: 'signature',
words: {
undo: 'Rückgängig',
clear: 'Löschen',
placeholder: 'Hier unterschreiben',
fallback: 'Oder Namen eingeben',
},
style,
},
h,
),
})In your application: recipe goes to forSlots, state to Bundle.withChild, and the body of view is the call. example is this site’s harness.
Usage
Each example above is a module of its own, shown whole and run as shown, over the theme module Create a theme writes. The page hands it the style picked above.