← All libraries

CandyForms

🍬 CandyForms

Foundation lib for form and input primitives

foundation forms inputs leaf-package

Foundation lib for form and input primitives — the raw component implementations that sugar-bits and sugar-prompt re-export. Extracted out of those two leaf libs so the form/prompt engine can ship as a single standalone dependency.

Install

composer require sugarcraft/candy-forms

Quickstart

use SugarCraft\Forms\Field\Input;
use SugarCraft\Forms\Form;
use SugarCraft\Forms\Validator\Required;

$form = Form::new(
    Input::new('name')
        ->withTitle('What is your name?')
        ->withValidator(new Required())
);

echo $form->view();

What's in the box

Input primitivesTextInput, TextArea, ItemList, Viewport, FilePicker, Cursor, Scrollbar, Spinner.
Form engineField interface + Field{Input, Text, Confirm, Select, MultiSelect, Note, FilePicker}, Form, Group, KeyMap, Theme.
ValidatorsRequired, Email, MinLength, MaxLength, Pattern — pluggable validator interface.
Fuzzy matchingFuzzy\FuzzyMatcher with Smith-Waterman algorithm for filter-as-you-type in Select/MultiSelect.

Use it for

Source & demos

Try the quickstart →

API

ClassMethodDescription
Formnew(Field[])Create a new form with fields
Field\Inputnew(string)Create a text input field
Field\Confirmnew(string)Create a confirmation field
Field\Selectnew(string, Options)Create a select field
Validator\Requiredvalidate(mixed)Check value is not empty
Validator\Emailvalidate(mixed)Check valid email format
Spinner\Spinnernew(Style)Create a spinner with style

Demos.

VHS-recorded GIFs of every example shipped with the library. Regenerated automatically on every push that touches the source.

CandyForms demo

Form primitives

TextInput, TextArea, Select and more — the foundation components.