A brick is a class extending Awcodes\Mason\Brick. It defines how the brick is identified, how it appears in the sidebar, how it is configured via a form, and how it renders to HTML.
Core Methods
| Method | Purpose |
|---|
getId() | Required. The unique identifier stored in the JSON. Changing this will orphan existing content. |
getLabel() | The label shown in the sidebar. Defaults to the class name if not overridden. |
getIcon() | The sidebar icon. Accepts a Heroicon case, an icon name string, or an Htmlable (for inline SVGs). |
getTags() | An array of search terms used to improve discoverability in the sidebar search. |
toHtml(array $config, ?array $data = null) | Renders the brick's HTML using the saved $config and optional $data provided by the renderer. |
configureBrickAction(Action $action) | Configures the Filament Action that builds the form used for inserting or editing the brick. |
Example Brick Implementation
use Awcodes\Mason\Brick;
use Filament\Actions\Action;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\Radio;
use Filament\Forms\Components\RichEditor;
use Filament\Support\Icons\Heroicon;
use Illuminate\Contracts\Support\Htmlable;
class Section extends Brick
{
public static function getId(): string
{
return 'section';
}
public static function getIcon(): string | Heroicon | Htmlable | null
{
return Heroicon::OutlinedSquares2x2;
}
public static function getTags(): array
{
return ['section', 'content', 'layout'];
}
public static function toHtml(array $config, ?array $data = null): ?string
{
return view('mason.section', [
'background_color' => $config['background_color'] ?? 'white',
'image' => $config['image'] ?? null,
'text' => $config['text'] ?? null,
])->render();
}
public static function configureBrickAction(Action $action): Action
{
return $action
->slideOver()
->schema([
Radio::make('background_color'),
FileUpload::make('image'),
RichEditor::make('text'),
]);
}
}