Компоненты

Системный компонент TopBar

Создание

Системный компонент TopBar используется для создания верхней панели навигации в MoonShine.

Вы можете создать TopBar, используя статический метод make() класса TopBar.

make(array $components = [])
make(array $components = [])

В качестве параметра метод make() принимает массив с компонентами.

namespace App\MoonShine;
 
use MoonShine\Components\Layout\LayoutBlock;
use MoonShine\Components\Layout\LayoutBuilder;
use MoonShine\Components\Layout\Menu;
use MoonShine\Components\Layout\Profile;
use MoonShine\Components\Layout\TopBar;
use MoonShine\Contracts\MoonShineLayoutContract;
 
final class MoonShineLayout implements MoonShineLayoutContract
{
public static function build(): LayoutBuilder
{
return LayoutBuilder::make([
TopBar::make([
Menu::make()->top()
]),
 
//...
]);
}
}
namespace App\MoonShine;
 
use MoonShine\Components\Layout\LayoutBlock;
use MoonShine\Components\Layout\LayoutBuilder;
use MoonShine\Components\Layout\Menu;
use MoonShine\Components\Layout\Profile;
use MoonShine\Components\Layout\TopBar;
use MoonShine\Contracts\MoonShineLayoutContract;
 
final class MoonShineLayout implements MoonShineLayoutContract
{
public static function build(): LayoutBuilder
{
return LayoutBuilder::make([
TopBar::make([
Menu::make()->top()
]),
 
//...
]);
}
}

topbar topbar_dark

Действия

Метод actions() компонента TopBar позволяет добавлять дополнительные элементы в области actions. Метод принимает массив компонентов в качестве параметра.

namespace App\MoonShine;
 
use MoonShine\Components\Layout\LayoutBlock;
use MoonShine\Components\Layout\LayoutBuilder;
use MoonShine\Components\Layout\Menu;
use MoonShine\Components\Layout\Profile;
use MoonShine\Components\Layout\TopBar;
use MoonShine\Contracts\MoonShineLayoutContract;
 
final class MoonShineLayout implements MoonShineLayoutContract
{
public static function build(): LayoutBuilder
{
return LayoutBuilder::make([
TopBar::make([
Menu::make()->top(),
])
->actions([
When::make(
static fn() => config('moonshine.auth.enable', true),
static fn() => [Profile::make()]
)
]),
 
//...
]);
}
}
namespace App\MoonShine;
 
use MoonShine\Components\Layout\LayoutBlock;
use MoonShine\Components\Layout\LayoutBuilder;
use MoonShine\Components\Layout\Menu;
use MoonShine\Components\Layout\Profile;
use MoonShine\Components\Layout\TopBar;
use MoonShine\Contracts\MoonShineLayoutContract;
 
final class MoonShineLayout implements MoonShineLayoutContract
{
public static function build(): LayoutBuilder
{
return LayoutBuilder::make([
TopBar::make([
Menu::make()->top(),
])
->actions([
When::make(
static fn() => config('moonshine.auth.enable', true),
static fn() => [Profile::make()]
)
]),
 
//...
]);
}
}

topbar_actions topbar_actions_dark

Скрытие логотипа

Метод hideLogo() позволяет скрыть логотип.

hideLogo()
hideLogo()
namespace App\MoonShine;
 
use MoonShine\Components\Layout\LayoutBlock;
use MoonShine\Components\Layout\LayoutBuilder;
use MoonShine\Components\Layout\Menu;
use MoonShine\Components\Layout\Profile;
use MoonShine\Components\Layout\TopBar;
use MoonShine\Contracts\MoonShineLayoutContract;
 
final class MoonShineLayout implements MoonShineLayoutContract
{
public static function build(): LayoutBuilder
{
return LayoutBuilder::make([
TopBar::make([
Menu::make()->top(),
])
->hideLogo(),
 
//...
]);
}
}
namespace App\MoonShine;
 
use MoonShine\Components\Layout\LayoutBlock;
use MoonShine\Components\Layout\LayoutBuilder;
use MoonShine\Components\Layout\Menu;
use MoonShine\Components\Layout\Profile;
use MoonShine\Components\Layout\TopBar;
use MoonShine\Contracts\MoonShineLayoutContract;
 
final class MoonShineLayout implements MoonShineLayoutContract
{
public static function build(): LayoutBuilder
{
return LayoutBuilder::make([
TopBar::make([
Menu::make()->top(),
])
->hideLogo(),
 
//...
]);
}
}

Скрытие переключателя темы

Метод hideSwitcher() позволяет скрыть переключатель темы.

hideSwitcher()
hideSwitcher()
namespace App\MoonShine;
 
use MoonShine\Components\Layout\LayoutBlock;
use MoonShine\Components\Layout\LayoutBuilder;
use MoonShine\Components\Layout\Menu;
use MoonShine\Components\Layout\Profile;
use MoonShine\Components\Layout\TopBar;
use MoonShine\Contracts\MoonShineLayoutContract;
 
final class MoonShineLayout implements MoonShineLayoutContract
{
public static function build(): LayoutBuilder
{
return LayoutBuilder::make([
TopBar::make([
Menu::make()->top(),
])
->hideSwitcher(),
 
//...
]);
}
}
namespace App\MoonShine;
 
use MoonShine\Components\Layout\LayoutBlock;
use MoonShine\Components\Layout\LayoutBuilder;
use MoonShine\Components\Layout\Menu;
use MoonShine\Components\Layout\Profile;
use MoonShine\Components\Layout\TopBar;
use MoonShine\Contracts\MoonShineLayoutContract;
 
final class MoonShineLayout implements MoonShineLayoutContract
{
public static function build(): LayoutBuilder
{
return LayoutBuilder::make([
TopBar::make([
Menu::make()->top(),
])
->hideSwitcher(),
 
//...
]);
}
}