51 lines
2.3 KiB
PHP
51 lines
2.3 KiB
PHP
{{-- Pemilih peran di bilah atas: menampilkan peran aktif; menu hanya berisi daftar peran milik akun (prototipe: peralihan belum aktif). --}}
|
|
@props(['user'])
|
|
|
|
@php
|
|
$roles = \App\Support\Prototype\RoleAccess::for($user);
|
|
$current = $user->role;
|
|
@endphp
|
|
|
|
<div class="role-switch" x-data="{ open: false }" x-on:keydown.escape="open = false" x-on:click.outside="open = false">
|
|
<button
|
|
type="button"
|
|
class="role-switch__trigger"
|
|
aria-haspopup="true" aria-label="Peran aktif: {{ $current->label() }}. Lihat daftar peran"
|
|
aria-controls="role-switch-menu"
|
|
x-bind:aria-expanded="open"
|
|
aria-expanded="false"
|
|
data-no-busy
|
|
x-on:click="open = !open"
|
|
>
|
|
<x-dynamic-component :component="'heroicon-o-'.$current->roleIcon()" class="role-switch__icon" />
|
|
<span class="role-switch__role">{{ $current->label() }}</span>
|
|
</button>
|
|
|
|
<div id="role-switch-menu" class="role-switch__menu" x-bind:class="{ 'is-open': open }" x-bind:inert="!open" inert>
|
|
<ul class="role-switch__list" role="list" aria-label="Peran yang dimiliki">
|
|
@foreach ($roles as $role)
|
|
<li>
|
|
@if ($role === $current)
|
|
<span class="role-switch__item is-current" aria-current="true">
|
|
<x-dynamic-component :component="'heroicon-o-'.$role->roleIcon()" class="role-switch__icon" />
|
|
<span class="role-switch__item-text">{{ $role->label() }}</span>
|
|
<x-heroicon-s-check class="role-switch__check" />
|
|
</span>
|
|
@else
|
|
<button
|
|
type="button"
|
|
class="role-switch__item"
|
|
data-no-busy
|
|
x-on:click="open = false; toast('info', 'Peralihan ke peran {{ $role->label() }} belum aktif pada tampilan prototipe.')"
|
|
>
|
|
<x-dynamic-component :component="'heroicon-o-'.$role->roleIcon()" class="role-switch__icon" />
|
|
<span class="role-switch__item-text">{{ $role->label() }}</span>
|
|
</button>
|
|
@endif
|
|
</li>
|
|
@endforeach
|
|
</ul>
|
|
|
|
</div>
|
|
</div>
|