Components

Decoration Collapse

Make

The Collapse decorator allows you to collapse the block contents while maintaining the state.

make(Closure|string|array $labelOrFields = '', array $fields = [])
use MoonShine\Decorations\Collapse;
use MoonShine\Fields\Text;
 
//...
 
public function components(): array
{
return [
Collapse::make('Title/Slug', [
Text::make('Title'),
Text::make('Slug')
])
];
}
 
//...

collapse collapse_dark

Icon

The icon() method allows you to add an icon.

use MoonShine\Decorations\Collapse;
 
//...
 
public function components(): array
{
return [
Collapse::make('Collapse')
->icon('heroicons.outline.users')
];
}
 
//...

For more detailed information, please refer to the section Icons .

collapse_icon collapse_icon_dark

Show

By default, the Collapse decorator is displayed as collapsed.The show() method allows you to override this behavior.

show(bool $show = true)
use MoonShine\Decorations\Collapse;
use MoonShine\Fields\Text;
 
//...
 
public function components(): array
{
return [
Collapse::make('Title/Slug', [
Text::make('Title'),
Text::make('Slug')
])
->show()
];
}
 
//...

Persist

By default, the Collapse remembers the state, but there are times when it is not worth doing this.The persist() method allows you to override this behavior.

persist(Closure|bool|null $condition = null)
use MoonShine\Decorations\Collapse;
use MoonShine\Fields\Text;
 
//...
 
public function components(): array
{
return [
Collapse::make('Title/Slug', [
Text::make('Title'),
Text::make('Slug')
])
->persist(fn () => false)
];
}
 
//…