Skip to content

資料組合 ​

呈現結構化資料:表格、圖表、分頁標籤、摺疊面板、清單與樹狀結構。

INFO

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

Chart ​

chart amcharts graph gantt pie dashboard

圖表(預設 amCharts),支援折線、長條、圓餅、甘特圖等。詳細設定見「進階 → 圖表」。

php
use Cg\ComponentFramework\Component\Chart\Chart;
use Cg\ComponentFramework\Component\Chart\ChartSeries;

Chart::make('monthly-revenue')
    ->column()
    ->title('月營收')
    ->categoryField('month')
    ->series([ChartSeries::make('revenue', '營收')])
    ->data([
        ['month' => '1 月', 'revenue' => 120],
        ['month' => '2 月', 'revenue' => 168],
        ['month' => '3 月', 'revenue' => 142],
    ]);

建構:Chart::make(string $name)

可用選項

  • type():line · area · step · column · bar · scatter · pie · donut · gantt · raw
  • cursor():none · cross · horizontal · vertical · segment · multi
  • theme():animated · dark · responsive · micro · kelly · moonrise · spirited · frozen · dataviz
  • exportable():png · jpg · svg · pdf · csv · json · xlsx · print · html
  • time():1D · 1W · 1M · 3M · 6M · 1Y · YTD · all
方法一覽 (54)
  • type(string $type)
  • line()
  • area()
  • step()
  • column()
  • bar()
  • scatter()
  • pie()
  • donut()
  • label(string $label)
  • height(string $height)
  • categoryField(string $field)
  • dateField(string $field, string $unit = 'day', int $count = 1)
  • series(array $series)
  • data(Traversable|Arrayable|Closure|array $rows)
  • title(string $title, ?string $subtitle = null)
  • emptyText(string $text, ?string $hint = null)
  • numberFormat(string $format)
  • markLine(int|float $value, ?string $label = null, ?string $color = null, int $axis = 1, bool $dashed = true)
  • markBand(int|float $from, int|float $to, ?string $label = null, ?string $color = null, int $axis = 1)
  • markDate(mixed $date, ?string $label = null, ?string $color = null, bool $dashed = true)
  • markPeriod(mixed $from, mixed $to, ?string $label = null, ?string $color = null)
  • axis(int $axis, ?string $title = null, int|float|null $min = null, int|float|null $max = null, ?string $format = null, bool $logarithmic = false)
  • time(array $ranges = ['1M', '3M', '6M', '1Y', 'all'], array $granularity = [])
  • cursor(string $mode)
  • cursorWhenEmpty(bool $show = true)
  • zoomOutButton(bool $show = true)
  • axisTooltips(bool $x = true, bool $y = true)
  • renderer(string $renderer)
  • zoom(bool $x = true, bool $y = false, string $mode = 'select', bool $wheel = false)
  • withoutZoom()
  • syncZoom(string $group, ?string $call = null)
  • scrollbar(bool $x = true, bool $y = false)
  • legend(bool $condition = true)
  • legendValues(bool $show = true)
  • exportable(?array $formats = null, ?string $filename = null)
  • source(string $method, array $args = [])
  • refresh(int $seconds)
  • window(int $points)
  • theme(string $theme)
  • palette(array $colors)
  • style(array $style)
  • font(string $family, ?string $pdfFont = null)
  • driver(string $name)
  • driverOptions(string $driver, array $options)
  • native(array $settings)
  • unsupported()
  • requireSupport()
  • preset(string $name)
  • rawConfig(array $config)
  • amchart(array $settings)
  • hook(string $name)
  • ganttOptions(array $options)
  • tasks(array $tasks)

Accordion ​

accordion

摺疊面板。single() 讓同時只展開一個。

php
use Cg\ComponentFramework\Component\Accordion\Accordion;
use Cg\ComponentFramework\Component\Accordion\AccordionItem;

Accordion::make([
    AccordionItem::make('shipping', '運送方式')
        ->content('下單後 2 個工作天內出貨。')
        ->open(),
    AccordionItem::make('refund', '退貨政策')
        ->content('到貨 7 天內可申請退貨。'),
])->single();

建構:Accordion::make(iterable $items = [])

方法一覽 (4)
  • items(iterable $items)
  • push(AccordionItem $item)
  • single(bool $condition = true)
  • label(?string $label)

ItemList ​

item-list list

項目清單,每列可有說明、附註、圖示與連結。

php
use Cg\ComponentFramework\Component\ItemList\ItemList;
use Cg\ComponentFramework\Component\ItemList\ListItem;

ItemList::make([
    ListItem::make('inbox', '收件匣')->meta('12')->url('/mail/inbox')->current(),
    ListItem::make('sent', '寄件備份')->url('/mail/sent'),
])->divided();

建構:ItemList::make(iterable $items = [])

可用選項

  • spacing():none · sm · md · lg
方法一覽 (6)
  • items(iterable $items)
  • push(ListItem $item)
  • ordered(bool $condition = true, int $start = 1)
  • spacing(string $spacing)
  • divided(bool $condition = true)
  • label(?string $label)

Table ​

table

資料表格(Filament 風格):資料源可直接接 Eloquent、Query Builder、Collection、array 或 Paginator;支援搜尋、篩選、排序、分組、彙總、類 Excel 公式、欄位群組、可切換/可摺疊欄位與窄螢幕堆疊。完整說明見進階:Table 資料表。

php
use Cg\ComponentFramework\Component\Table\Column;
use Cg\ComponentFramework\Component\Table\ColumnGroup;
use Cg\ComponentFramework\Component\Table\Filters\SelectFilter;
use Cg\ComponentFramework\Component\Table\Summaries\Sum;
use Cg\ComponentFramework\Component\Table\Table;

Table::make([
    Column::make('number', '單號')->searchable()->sortable()->copyable(),
    Column::make('customer', '客戶')->searchable(),
    Column::make('status', '狀態')->badge(['paid' => 'success', 'pending' => 'warning']),
    ColumnGroup::make('金額', [
        Column::make('price', '單價')->numeric()->align('end'),
        Column::make('qty', '數量')->align('end'),
        Column::make('subtotal', '小計')->formula('=price * qty')->numeric()->align('end')
            ->summarize(Sum::make()),
    ])->key('amount'),
    Column::make('note', '備註')->collapsible()->placeholder('—'),
])
    ->records([
        ['number' => 'SO-1001', 'customer' => '王小明', 'status' => 'paid', 'price' => 120, 'qty' => 3, 'note' => null],
        ['number' => 'SO-1002', 'customer' => '陳美玲', 'status' => 'pending', 'price' => 980, 'qty' => 1, 'note' => '需要發票'],
    ])
    ->rowKey('number')
    ->filters([
        SelectFilter::make('status', '狀態')->options(['paid' => '已付款', 'pending' => '待付款']),
    ])
    ->paginate(25, [10, 25, 50])
    ->stackOn('md')
    ->striped();

建構:Table::make(iterable $columns = [])

方法一覽 (52)
  • copy()
  • columns(iterable $columns)
  • pushColumn(TableColumnNode $column)
  • records(mixed $records)
  • query(Builder|Relation|Builder|Closure $query)
  • model(string $model)
  • rowKey(Closure|string|null $key)
  • modifyQueryUsing(Closure $callback)
  • afterResolve(Closure $callback)
  • caption(Htmlable|Closure|string|null $caption)
  • label(string $label)
  • emptyState(Htmlable|Closure|string $content)
  • striped(bool $condition = true)
  • hoverable(bool $condition = true)
  • compact(bool $condition = true)
  • stickyHeader(bool $condition = true)
  • stickyFooter(bool $condition = true)
  • maxHeight(?string $height)
  • stackOn(?string $breakpoint = 'md')
  • transpose(bool $condition = true)
  • recordTitle(Closure|string|null $title)
  • detail(?Closure $content, string $label = '詳細資料')
  • summaryLabels(array $labels)
  • filters(iterable $filters)
  • filtersLayout(string $layout)
  • searchPlaceholder(string $placeholder)
  • defaultSort(string $column, string $direction = 'asc')
  • groups(array $groups)
  • groupBy(Group|string $group)
  • defaultGroup(?string $group)
  • paginate(int $perPage = 15, array $options = [])
  • perPageOptions(array $options)
  • paginationMode(string $mode)
  • simplePagination(bool $condition = true)
  • cursorPagination(bool $condition = true)
  • queryStringIdentifier(?string $identifier)
  • state(TableState|Closure|array|null $state)
  • request(?Request $request)
  • eagerLoadRelations(bool $condition = true)
  • reorderableColumns(bool $condition = true)
  • linkerNavigation(?string $method = 'navigate', array $extra = [])
  • reorderable(string $column, string $linkerMethod, array $extra = [])
  • paramName(string ...$segments)
  • urlFor(TableState $state, bool $keepPage = false)
  • pagination(Pagination|Closure|null $pagination)
  • resolve()
  • config(string $name)
  • currentRequest()
  • tableId()
  • foreignQuery(array $without = [])
  • wrapTableQuery(array $tableQuery)
  • activeLeaves(TableColumnNode $node, array $shown, TableState $state)

Tabs ​

tabs

分頁標籤,切換是純前端狀態、不發請求。

php
use Cg\ComponentFramework\Component\Tabs\Tab;
use Cg\ComponentFramework\Component\Tabs\Tabs;

Tabs::make([
    Tab::make('profile', '個人資料')->content('姓名、頭像與自我介紹。'),
    Tab::make('security', '安全性')->content('密碼與兩步驟驗證。'),
])->active('profile');

建構:Tabs::make(iterable $tabs = [])

可用選項

  • orientation():horizontal · vertical
  • activation():automatic · manual
方法一覽 (7)
  • tabs(iterable $tabs)
  • push(Tab $tab)
  • active(?string $key)
  • orientation(string $orientation)
  • activation(string $activation)
  • label(string $label)
  • stateKey(string $key)

TreeView ​

tree-view tree

樹狀結構,支援展開、單選或多選。

php
use Cg\ComponentFramework\Component\TreeView\TreeNode;
use Cg\ComponentFramework\Component\TreeView\TreeView;

TreeView::make([
    TreeNode::make('src', 'src')
        ->children([
            TreeNode::make('app', 'app'),
            TreeNode::make('routes', 'routes'),
        ])
        ->expanded(),
    TreeNode::make('readme', 'README.md'),
])->selection('single');

建構:TreeView::make(iterable $nodes = [])

可用選項

  • selection():none · single · multiple
方法一覽 (7)
  • nodes(iterable $nodes)
  • push(TreeNode $node)
  • label(string $label)
  • selection(string $mode)
  • selected(Closure|array|string|null $keys)
  • expanded(Closure|array|string|null $keys)
  • stateKeys(string $selection, string $expanded)

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