Skip to content

Form Fields ​

Form inputs. All share the field methods (label, helper text, errors, required, disabled, client state).

INFO

Every component also has the common methods (key, visible, class, attributes, view…).

Checkbox ​

checkbox

Checkbox with configurable checked and unchecked values.

php
use Cg\ComponentFramework\Component\Checkbox\Checkbox;

Checkbox::make('terms', '我同意服務條款')->required();

Constructor:Checkbox::make(string $name, Htmlable|Closure|string|null $label = null)

All methods (3)
  • value(string|int|float|bool $value)
  • uncheckedValue(string|int|float|bool|null $value)
  • checked(Closure|bool $condition = true)

All shared field methods are also available.

ColorPicker ​

color-picker

Color picker with optional preset swatches.

php
use Cg\ComponentFramework\Component\ColorPicker\ColorPicker;

ColorPicker::make('brand_color', '品牌色')
    ->value('#6366f1')
    ->presets(['#6366f1', '#22d3ee', '#f59e0b']);

Constructor:ColorPicker::make(string $name, Htmlable|Closure|string|null $label = null)

All methods (4)
  • value(Closure|string $value)
  • presets(array $colors)
  • showText(Closure|bool $condition = true)
  • uppercase(bool $condition = true)

All shared field methods are also available.

Combobox ​

combobox

Searchable select, suited to long option lists.

php
use Cg\ComponentFramework\Component\Combobox\Combobox;

Combobox::make('city', '城市')
    ->options(['tpe' => '台北', 'tch' => '台中', 'khh' => '高雄'])
    ->placeholder('輸入搜尋')
    ->clearable();

Constructor:Combobox::make(string $name, Htmlable|Closure|string|null $label = null)

All methods (6)
  • options(Traversable|Closure|array $options)
  • selected(Closure|string|int|float|null $value)
  • placeholder(Closure|string|null $placeholder)
  • emptyMessage(Closure|string $message)
  • clearable(Closure|bool $condition = true, string $label = '清除選取')
  • autocomplete(?string $autocomplete)

All shared field methods are also available.

DateInput ​

date-input

Native browser date/time field (date, datetime-local, time, month, week).

php
use Cg\ComponentFramework\Component\DateInput\DateInput;

DateInput::make('due_at', '截止時間')
    ->mode('datetime-local')
    ->min('2026-01-01T00:00');

Constructor:DateInput::make(string $name, Htmlable|Closure|string|null $label = null)

Options

  • mode():date · datetime-local · time · month · week
All methods (6)
  • mode(string $mode)
  • value(Closure|string|null $value)
  • min(?string $value)
  • max(?string $value)
  • step(string|int|float|null $step)
  • autocomplete(?string $autocomplete)

All shared field methods are also available.

DatePicker ​

date-picker

Custom calendar picker with display format and first day of week.

php
use Cg\ComponentFramework\Component\DatePicker\DatePicker;

DatePicker::make('birthday', '生日')
    ->displayFormat('Y/m/d')
    ->max('2026-12-31')
    ->clearable();

Constructor:DatePicker::make(string $name, Htmlable|Closure|string|null $label = null)

Options

  • displayFormat():Y-m-d · Y/m/d · d/m/Y · m/d/Y
All methods (7)
  • value(Closure|string|null $value)
  • min(?string $value)
  • max(?string $value)
  • placeholder(Closure|string|null $placeholder)
  • displayFormat(string $format)
  • weekStartsOn(int $day)
  • clearable(Closure|bool $condition = true)

All shared field methods are also available.

FileUpload ​

file-upload

File upload field with type, size and count limits. Makes its Form multipart automatically.

php
use Cg\ComponentFramework\Component\FileUpload\FileUpload;

FileUpload::make('avatar', '頭像')
    ->imageOnly()
    ->maxSize(2048);

Constructor:FileUpload::make(string $name, Htmlable|Closure|string|null $label = null)

All methods (6)
  • accept(array|string|null $types)
  • imageOnly()
  • multiple(Closure|bool $condition = true)
  • capture(?string $facingMode = 'environment')
  • maxFiles(?int $count)
  • maxSize(?int $kilobytes)

All shared field methods are also available.

RadioButton ​

radio-button

Radio button. Share one name across the group and give each a different value.

php
use Cg\ComponentFramework\Component\RadioButton\RadioButton;
use Cg\ComponentFramework\Component\Stack\Stack;

Stack::make([
    RadioButton::make('plan', 'free', '免費方案')->checked(),
    RadioButton::make('plan', 'pro', '專業方案'),
])->gap('sm');

Constructor:RadioButton::make(string $name, string|int|float|bool $value, Htmlable|Closure|string|null $label = null)

All methods (1)
  • checked(Closure|bool $condition = true)

All shared field methods are also available.

Rating ​

rating

Star rating field.

php
use Cg\ComponentFramework\Component\Rating\Rating;

Rating::make('score', '評分')
    ->max(5)
    ->value(4)
    ->showValue();

Constructor:Rating::make(string $name, Htmlable|Closure|string|null $label = null)

All methods (4)
  • max(int $max)
  • value(Closure|int|null $value)
  • clearable(Closure|bool $condition = true, string $label = '清除評分')
  • showValue(Closure|bool $condition = true)

All shared field methods are also available.

RichTextEditor ​

rich-text-editor

WYSIWYG editor; submitted HTML is sanitized on the server.

php
use Cg\ComponentFramework\Component\RichTextEditor\RichTextEditor;

RichTextEditor::make('content', '內文')
    ->tools(['bold', 'italic', 'bulletList', 'undo', 'redo'])
    ->height('md')
    ->maxLength(5000);

Constructor:RichTextEditor::make(string $name, Htmlable|Closure|string|null $label = null)

Options

  • tools():bold · italic · underline · strike · heading2 · heading3 · bulletList · orderedList · blockquote · code · undo · redo · clear
  • height():sm · md · lg
All methods (5)
  • value(Closure|string|null $value)
  • placeholder(Closure|string|null $placeholder)
  • tools(array $tools)
  • height(string $height)
  • maxLength(?int $length)

All shared field methods are also available.

SearchInput ​

search-input

Search box with optional clear and submit buttons.

php
use Cg\ComponentFramework\Component\SearchInput\SearchInput;

SearchInput::make('q', '搜尋')
    ->placeholder('輸入關鍵字')
    ->clearable()
    ->submitButton('搜尋');

Constructor:SearchInput::make(string $name, Htmlable|Closure|string|null $label = null)

Options

  • type():text · email · password · url · tel · search · number · date · time · datetime-local · month · week · color · range
All methods (12)
  • type(string $type)
  • clearable(Closure|bool $condition = true, string $label = '清除搜尋內容')
  • submitButton(Htmlable|Closure|string|null $label = '搜尋')
  • value(mixed $value)
  • placeholder(Closure|string|null $placeholder)
  • autocomplete(?string $autocomplete)
  • min(string|int|float|null $value)
  • max(string|int|float|null $value)
  • step(string|int|float|null $value)
  • minLength(?int $length)
  • maxLength(?int $length)
  • inputMode(?string $mode)

All shared field methods are also available.

SegmentedControl ​

segmented-control

Segmented control for a few mutually exclusive options shown side by side.

php
use Cg\ComponentFramework\Component\SegmentedControl\SegmentedControl;

SegmentedControl::make('view', '檢視方式')
    ->options(['list' => '列表', 'grid' => '格狀'])
    ->selected('list');

Constructor:SegmentedControl::make(string $name, Htmlable|Closure|string|null $label = null)

Options

  • size():sm · md · lg
All methods (5)
  • options(Traversable|Closure|array $options)
  • selected(mixed $value)
  • disableOptions(iterable $values)
  • size(string $size)
  • block(bool $condition = true)

All shared field methods are also available.

Select ​

select

Native select. A nested array in the options becomes an option group (optgroup).

php
use Cg\ComponentFramework\Component\Select\Select;

Select::make('country', '國家')
    ->options([
        'tw' => '台灣',
        'jp' => '日本',
        '歐洲' => ['fr' => '法國', 'de' => '德國'],
    ])
    ->placeholder('請選擇');

Constructor:Select::make(string $name, Htmlable|Closure|string|null $label = null)

All methods (4)
  • options(Traversable|Closure|array $options)
  • selected(mixed $value)
  • placeholder(Closure|string|null $placeholder)
  • multiple(Closure|bool $condition = true)

All shared field methods are also available.

Slider ​

slider

Range slider with min/max, step and unit.

php
use Cg\ComponentFramework\Component\Slider\Slider;

Slider::make('volume', '音量')
    ->range(0, 100)
    ->step(5)
    ->value(60)
    ->unit('%');

Constructor:Slider::make(string $name, Htmlable|Closure|string|null $label = null)

All methods (5)
  • range(int|float $min, int|float $max)
  • step(int|float $step)
  • value(Closure|int|float|null $value)
  • showValue(Closure|bool $condition = true)
  • unit(string $suffix, string $prefix = '')

All shared field methods are also available.

TextArea ​

text-area

Multi-line text field.

php
use Cg\ComponentFramework\Component\TextArea\TextArea;

TextArea::make('bio', '自我介紹')
    ->rows(4)
    ->maxLength(500)
    ->placeholder('簡單介紹自己');

Constructor:TextArea::make(string $name, Htmlable|Closure|string|null $label = null)

All methods (5)
  • value(mixed $value)
  • placeholder(Closure|string|null $placeholder)
  • rows(int $rows)
  • minLength(?int $length)
  • maxLength(?int $length)

All shared field methods are also available.

TextInput ​

text-input

Single-line input supporting HTML types such as email, password and number.

php
use Cg\ComponentFramework\Component\TextInput\TextInput;

TextInput::make('email', '電子郵件')
    ->type('email')
    ->autocomplete('email')
    ->required();

Constructor:TextInput::make(string $name, Htmlable|Closure|string|null $label = null)

Options

  • type():text · email · password · url · tel · search · number · date · time · datetime-local · month · week · color · range
All methods (10)
  • type(string $type)
  • value(mixed $value)
  • placeholder(Closure|string|null $placeholder)
  • autocomplete(?string $autocomplete)
  • min(string|int|float|null $value)
  • max(string|int|float|null $value)
  • step(string|int|float|null $value)
  • minLength(?int $length)
  • maxLength(?int $length)
  • inputMode(?string $mode)

All shared field methods are also available.

Toggle ​

toggle

Switch; semantically a checkbox, suited to settings that apply immediately.

php
use Cg\ComponentFramework\Component\Toggle\Toggle;

Toggle::make('notifications', '接收通知')
    ->checked()
    ->color('success');

Constructor:Toggle::make(string $name, Htmlable|Closure|string|null $label = null)

Options

  • color():primary · success · warning · danger
  • size():sm · md · lg
All methods (6)
  • color(string $color)
  • size(string $size)
  • inline(bool $condition = true)
  • value(string|int|float|bool $value)
  • uncheckedValue(string|int|float|bool|null $value)
  • checked(Closure|bool $condition = true)

All shared field methods are also available.


Generated from source by scripts/wiki-components/generate.php; every example is rendered as part of the build.