內容與媒體
內容與媒體:卡片、頭像、輪播、檔案、引言、音訊與影片。
INFO
所有元件都能用共用方法(key、visible、class、attributes、view…)。
Avatar
avatar頭像。沒有圖片時自動顯示名字縮寫,可加上線上狀態。
php
use Cg\ComponentFramework\Component\Avatar\Avatar;
Avatar::make('王小明')
->size('lg')
->status('online');建構:Avatar::make(Closure|string $name, Closure|string|null $source = null)
可用選項
shape():circle·rounded·squaresize():xs·sm·md·lg·xl·2xlstatus():online·offline·away·busy
方法一覽 (7)
source(Closure|string|null $source)initials(Closure|string|null $initials)shape(string $shape)size(string $size)status(?string $status)eager(bool $condition = true)decorative(bool $condition = true)
Card
card卡片,最常用的內容容器;可放標題、說明、內容、動作與圖片。
php
use Cg\ComponentFramework\Component\Badge\Badge;
use Cg\ComponentFramework\Component\Button\Button;
use Cg\ComponentFramework\Component\Card\Card;
Card::make('方案升級')
->description('解鎖進階報表與團隊協作')
->color('primary')
->body(Badge::make('NT$ 299 / 月'))
->actions([
Button::make('立即升級')->color('primary'),
]);建構:Card::make(Htmlable|Closure|string|null $title = null)
可用選項
color():default·primary·success·warning·danger·info
方法一覽 (11)
title(Htmlable|Closure|string|null $title)description(Htmlable|Closure|string|null $description)url(?string $url)image(?string $image)color(string $color)headingLevel(int $level)body(mixed $content)schema(Schema $schema)actions(Actions|Traversable|array $actions)collapsible(bool $condition = true, bool $collapsed = false)serverCollapsible(bool $collapsed = false)
Carousel
carousel輪播,支援自動播放、循環與淡入淡出。
php
use Cg\ComponentFramework\Component\Carousel\Carousel;
use Cg\ComponentFramework\Component\Carousel\CarouselSlide;
use Cg\ComponentFramework\Component\Image\Image;
Carousel::make([
CarouselSlide::make('spring', Image::make('/images/spring.jpg', '春季新品'))
->caption('春季新品'),
CarouselSlide::make('summer', Image::make('/images/summer.jpg', '夏日特賣'))
->caption('夏日特賣'),
])->aspect('video')->autoplay(5)->loop();建構:Carousel::make(iterable $slides = [])
可用選項
aspect():auto·video·square·portraiteffect():slide·fade
方法一覽 (12)
slides(iterable $slides)push(CarouselSlide $slide)label(string $label)active(?string $key)stateKey(string $key)aspect(string $aspect)effect(string $effect)controls(bool $condition = true)indicators(bool $condition = true)loop(bool $condition = true)autoplay(int $seconds = 5)withoutAutoplay()
File
file download檔案下載卡,顯示檔名、大小、類型與修改時間。
php
use Cg\ComponentFramework\Component\File\File;
File::make('2026 年報.pdf', '/files/annual-report.pdf')
->sizeBytes(2_400_000)
->mimeType('application/pdf')
->download();建構:File::make(Htmlable|Closure|string $name, Closure|string $url)
可用選項
target():_self·_blankvariant():default·compact
方法一覽 (9)
description(Htmlable|Closure|string|null $description)sizeBytes(Closure|int|null $bytes)mimeType(Closure|string|null $mimeType)modifiedAt(DateTimeInterface|Closure|null $modifiedAt)icon(Icon|string|null $icon)download(string|bool $filename = true)newTab(bool $condition = true)variant(string $variant)disabled(Closure|bool $condition = true)
Quote
quote引言,可標註作者與出處。
php
use Cg\ComponentFramework\Component\Quote\Quote;
Quote::make('簡單是可靠的先決條件。')
->author('Edsger W. Dijkstra')
->align('center');建構:Quote::make(Htmlable|Closure|string $content)
可用選項
align():start·center·endsize():sm·md·lg
方法一覽 (4)
author(Htmlable|Closure|string|null $author)source(Htmlable|Closure|string|null $title, Closure|string|null $url = null)align(string $alignment)size(string $size)
Sound
sound audio音訊播放器,可加多個來源、字幕軌與逐字稿。
php
use Cg\ComponentFramework\Component\Sound\Sound;
Sound::make('/audio/intro.mp3', '節目片頭')
->preload('metadata');建構:Sound::make(Closure|string|null $source, Closure|string $label = '音訊')
可用選項
preload():none·metadata·autocrossOrigin():anonymous·use-credentials
方法一覽 (11)
source(Closure|string $source, ?string $type = null)sources(iterable $sources)addSource(SoundSource $source)tracks(iterable $tracks)addTrack(SoundTrack $track)transcript(mixed $content, string $label = '顯示逐字稿', bool $open = false)showLabel(bool $condition = true)muted(bool $condition = true)loop(bool $condition = true)preload(string $preload)crossOrigin(?string $crossOrigin)
Video
video media影片播放器,可設定封面、字幕軌與播放選項。
php
use Cg\ComponentFramework\Component\Video\Video;
Video::make('/video/demo.mp4', '產品示範')
->poster('/images/demo-poster.jpg')
->dimensions(1280, 720)
->playsInline();建構:Video::make(Closure|string|null $source, Closure|string $label = '影片')
可用選項
preload():none·metadata·autocrossOrigin():anonymous·use-credentials
方法一覽 (14)
source(Closure|string $source, ?string $type = null)sources(iterable $sources)addSource(VideoSource $source)tracks(iterable $tracks)addTrack(VideoTrack $track)poster(Closure|string|null $poster)controls(bool $condition = true)autoplay(bool $condition = true)muted(bool $condition = true)loop(bool $condition = true)playsInline(bool $condition = true)preload(string $preload)crossOrigin(?string $crossOrigin)dimensions(?int $width, ?int $height)
這一頁由 scripts/wiki-components/generate.php 依原始碼產生,範例都經過實際渲染驗證。