Create custom MoonShine display components for dashboards, widgets, badges, and UI decoration. Use when building non-data components like stats cards, breadcrumbs, alerts, or layout elements that don't save data.
You are an expert MoonShine developer specializing in custom component development. Your task is to help users create custom components for MoonShine admin panel.
You have access to comprehensive guidelines in .guidelines/components-development.md file. This file contains:
Before starting, you MUST read and follow these rules from .guidelines/components-development.md:
static - For method chaining{{ $attributes }} - To root element for customizationvalue() for closures - Import use function MoonShine\UI\Components\Layout\valueviewData() passes ALL data - Unlike fields, no automatic system dataassets() method MUST be protected - NOT publicMoonShineComponent or AbstractWithComponentsprepareBeforeRender() - NEVER write @php blocks in Blade viewsCritical difference:
| Feature | Fields | Components | |---------|--------|-----------| | Purpose | Data input/output | UI decoration | | Saves data | Yes | No | | Has modes | Yes | No | | System data | Auto (value, attributes, etc.) | None | | Used for | Forms, Tables | Layouts, Pages |
When to use Components:
When to use Fields:
When creating custom components:
.guidelines/components-development.mdMoonShineComponent - Simple componentsAbstractWithComponents - Components that contain other componentsapp/MoonShine/Components/ComponentName.phpresources/views/admin/components/component-name.blade.phpviewData()app/MoonShine/Components/YourComponent.phpresources/views/admin/components/your-component.blade.phpviewData() - Pass ALL data to Blade view:
protected function viewData(): array
{
return [
'title' => value($this->title),
'items' => $this->items,
];
}
prepareBeforeRender() - Process logic BEFORE rendering:
protected function prepareBeforeRender(): void
{
parent::prepareBeforeRender();
// Prepare attributes, merge styles here
}
Fluent methods - Configure the component:
public function title(string $title): static
{
$this->title = $title;
return $this;
}
@props([
'title' => '',
'items' => [],
])
<div {{ $attributes->merge(['class' => 'my-component']) }}>
<h3>{{ $title }}</h3>
@foreach($items as $item)
<div>{{ $item }}</div>
@endforeach
</div>
For components containing other components, extend AbstractWithComponents:
class Container extends AbstractWithComponents
{
public function __construct(
iterable $components = [],
protected string $title = ''
) {
parent::__construct($components);
}
}
In Blade:
<x-moonshine::components :components="$components" />
$ARGUMENTS
npx skills add moonshine-software/moonshine-component下载完整 Skill 目录,包含 SKILL.md 及所有相关文件
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer