基礎呈現
最小的呈現單位:圖示、標題、圖片、標籤與排版容器。
INFO
所有元件都能用共用方法(key、visible、class、attributes、view…)。
Icon
icon svg symbol內建 SVG 圖示。沒有 label 時視為裝飾,螢幕閱讀器會略過。
php
use Cg\ComponentFramework\Component\Icon\Icon;
Icon::make('check')->size('lg')->label('完成');建構:Icon::make(Closure|string $name)
可用選項
size():xs·sm·md·lg·xl
方法一覽 (2)
size(string $size)label(?string $label)
Heading
heading title typography標題文字,語意層級(h1–h6)與視覺大小分開設定。
php
use Cg\ComponentFramework\Component\Heading\Heading;
Heading::make('季度報告')
->level(2)
->size('xl')
->description('2026 Q4 營運摘要');建構:Heading::make(Htmlable|Closure|string $content)
可用選項
size():xs·sm·md·lg·xl·2xl
方法一覽 (3)
level(int $level)size(?string $size)description(?string $description)
Image
image media picture圖片,必須提供替代文字;可設定尺寸、裁切方式與是否立即載入。
php
use Cg\ComponentFramework\Component\Image\Image;
Image::make('/images/cover.jpg', '產品封面')
->dimensions(960, 540)
->fit('cover');建構:Image::make(Closure|string $source, Closure|string $alt = '')
可用選項
fit():contain·cover·fill·none·scale-down
方法一覽 (3)
dimensions(?int $width, ?int $height)fit(string $fit)eager(bool $condition = true)
Badge
badge tag label小型狀態標籤,用來標示分類、狀態或數量。
php
use Cg\ComponentFramework\Component\Badge\Badge;
Badge::make('已上線')->color('success')->icon('check');建構:Badge::make(Htmlable|Closure|string $label)
可用選項
color():neutral·primary·success·warning·danger·infosize():sm·md·lg
方法一覽 (4)
color(string $color)size(string $size)icon(Icon|string|null $icon)rounded(bool $condition = true)
Label
label form表單標籤,可綁定欄位 id、標示必填,或只給螢幕閱讀器看。
php
use Cg\ComponentFramework\Component\Label\Label;
Label::make('電子郵件', 'email')->required();建構:Label::make(Htmlable|Closure|string $content, ?string $for = null)
方法一覽 (3)
for(?string $id)required(bool $condition = true)visuallyHidden(bool $condition = true)
Separator
separator divider分隔線,可加上中間的文字,支援水平與垂直。
php
use Cg\ComponentFramework\Component\Separator\Separator;
Separator::make('或');建構:Separator::make(Closure|string|null $label = null)
可用選項
orientation():horizontal·vertical
方法一覽 (1)
orientation(string $orientation)
Stack
stack layout排版容器,把子元件依方向、間距與對齊排列。
php
use Cg\ComponentFramework\Component\Badge\Badge;
use Cg\ComponentFramework\Component\Stack\Stack;
Stack::make([
Badge::make('PHP'),
Badge::make('Laravel')->color('primary'),
])->direction('row')->gap('sm')->wrap();建構:Stack::make(iterable $components = [])
可用選項
direction():row·columngap():none·xs·sm·md·lg·xlalign():start·center·end·stretch·baselinejustify():start·center·end·between·around·evenly
方法一覽 (7)
components(iterable $components)push(Component $component)direction(string $direction)gap(string $gap)align(string $align)justify(string $justify)wrap(bool $condition = true)
這一頁由 scripts/wiki-components/generate.php 依原始碼產生,範例都經過實際渲染驗證。