Skip to content

輸入欄位 ​

表單輸入。全部共用「欄位元件」的方法(標籤、說明、錯誤、必填、停用、綁定前端狀態)。

INFO

所有元件都能用共用方法(key、visible、class、attributes、view…)。

Checkbox ​

checkbox

核取方塊,可設定勾選與未勾選時送出的值。

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

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

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

方法一覽 (3)
  • value(string|int|float|bool $value)
  • uncheckedValue(string|int|float|bool|null $value)
  • checked(Closure|bool $condition = true)

另外可用所有欄位元件共用方法。

ColorPicker ​

color-picker

顏色選擇器,可提供預設色票。

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

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

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

方法一覽 (4)
  • value(Closure|string $value)
  • presets(array $colors)
  • showText(Closure|bool $condition = true)
  • uppercase(bool $condition = true)

另外可用所有欄位元件共用方法。

Combobox ​

combobox

可輸入搜尋的下拉選單,適合選項很多的情況。

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

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

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

方法一覽 (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)

另外可用所有欄位元件共用方法。

DateInput ​

date-input

瀏覽器原生的日期/時間欄位(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');

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

可用選項

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

另外可用所有欄位元件共用方法。

DatePicker ​

date-picker

自訂樣式的日曆選擇器,可設定顯示格式與週起始日。

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

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

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

可用選項

  • displayFormat():Y-m-d · Y/m/d · d/m/Y · m/d/Y
方法一覽 (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)

另外可用所有欄位元件共用方法。

FileUpload ​

file-upload

檔案上傳欄位,可限制類型、大小與數量。放進 Form 會自動改成 multipart。

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

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

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

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

另外可用所有欄位元件共用方法。

RadioButton ​

radio-button

單選按鈕。同一組使用相同的 name,各自給不同的 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');

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

方法一覽 (1)
  • checked(Closure|bool $condition = true)

另外可用所有欄位元件共用方法。

Rating ​

rating

星等評分欄位。

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

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

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

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

另外可用所有欄位元件共用方法。

RichTextEditor ​

rich-text-editor

所見即所得編輯器,送出的 HTML 會在伺服器端過濾。

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

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

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

可用選項

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

另外可用所有欄位元件共用方法。

SearchInput ​

search-input

搜尋框,可附清除按鈕與送出按鈕。

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

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

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

可用選項

  • type():text · email · password · url · tel · search · number · date · time · datetime-local · month · week · color · range
方法一覽 (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)

另外可用所有欄位元件共用方法。

SegmentedControl ​

segmented-control

分段切換,少量互斥選項並排顯示。

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

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

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

可用選項

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

另外可用所有欄位元件共用方法。

Select ​

select

原生下拉選單。選項陣列的值若是陣列,會變成選項群組(optgroup)。

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

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

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

方法一覽 (4)
  • options(Traversable|Closure|array $options)
  • selected(mixed $value)
  • placeholder(Closure|string|null $placeholder)
  • multiple(Closure|bool $condition = true)

另外可用所有欄位元件共用方法。

Slider ​

slider

滑桿,設定範圍、間隔與單位。

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

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

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

方法一覽 (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 = '')

另外可用所有欄位元件共用方法。

TextArea ​

text-area

多行文字欄位。

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

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

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

方法一覽 (5)
  • value(mixed $value)
  • placeholder(Closure|string|null $placeholder)
  • rows(int $rows)
  • minLength(?int $length)
  • maxLength(?int $length)

另外可用所有欄位元件共用方法。

TextInput ​

text-input

單行輸入欄位,支援 email、password、number 等 HTML 類型。

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

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

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

可用選項

  • type():text · email · password · url · tel · search · number · date · time · datetime-local · month · week · color · range
方法一覽 (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)

另外可用所有欄位元件共用方法。

Toggle ​

toggle

開關,語意上是核取方塊,適合「立即生效」的設定。

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

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

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

可用選項

  • color():primary · success · warning · danger
  • size():sm · md · lg
方法一覽 (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)

另外可用所有欄位元件共用方法。


這一頁由 scripts/wiki-components/generate.php 依原始碼產生,範例都經過實際渲染驗證。