73 lines
2.5 KiB
PHP
73 lines
2.5 KiB
PHP
{{--
|
|
Tombol pemicu + dialog konfirmasi. Dirender sebagai <form> (atribut tambahan ke form).
|
|
Tanpa JS pemicu adalah tombol kirim biasa: formulir langsung terkirim (progressive enhancement).
|
|
Jangan taruh di dalam <form> lain.
|
|
--}}
|
|
@props([
|
|
'action',
|
|
'method' => 'POST',
|
|
'title',
|
|
'message' => null,
|
|
'confirmLabel' => 'Ya, lanjutkan',
|
|
'cancelLabel' => 'Batal',
|
|
'tone' => 'primary',
|
|
'icon' => null,
|
|
'iconOnly' => false,
|
|
'triggerLabel' => null,
|
|
'label' => null,
|
|
'variant' => 'ghost',
|
|
])
|
|
|
|
@php
|
|
$method = strtoupper($method);
|
|
$method = in_array($method, ['POST', 'PUT', 'PATCH', 'DELETE'], true) ? $method : 'POST';
|
|
$tone = $tone === 'danger' ? 'danger' : 'primary';
|
|
$variant = $variant === 'secondary' ? 'secondary' : 'ghost';
|
|
$uid = 'confirm-'.\Illuminate\Support\Str::random(8);
|
|
@endphp
|
|
|
|
<form
|
|
method="POST"
|
|
action="{{ $action }}"
|
|
x-data="confirmDialog"
|
|
{{ $attributes->class('confirm') }}
|
|
>
|
|
@csrf
|
|
@if ($method !== 'POST') @method($method) @endif
|
|
|
|
<x-ui.button
|
|
type="submit"
|
|
:variant="$variant"
|
|
:icon="$icon"
|
|
:icon-only="$iconOnly"
|
|
:class="$tone === 'danger' ? 'confirm__trigger--danger' : ''"
|
|
:aria-label="$iconOnly ? ($label ?? $title) : null"
|
|
x-ref="trigger"
|
|
x-on:click.prevent="show()"
|
|
>{{ $triggerLabel ?? $title }}</x-ui.button>
|
|
|
|
<dialog
|
|
x-ref="dialog"
|
|
@class(['dialog', 'dialog--danger' => $tone === 'danger'])
|
|
aria-labelledby="{{ $uid }}-title"
|
|
@if ($message) aria-describedby="{{ $uid }}-message" @endif
|
|
x-on:click="backdrop($event)"
|
|
x-on:close="restore()"
|
|
>
|
|
<div class="dialog__body">
|
|
<div class="dialog__head">
|
|
<span class="dialog__icon" aria-hidden="true">
|
|
@if ($tone === 'danger') <x-heroicon-o-exclamation-triangle /> @else <x-heroicon-o-question-mark-circle /> @endif
|
|
</span>
|
|
<p id="{{ $uid }}-title" class="dialog__title">{{ $title }}</p>
|
|
<x-ui.dialog-close />
|
|
</div>
|
|
@if ($message) <p id="{{ $uid }}-message" class="dialog__message">{{ $message }}</p> @endif
|
|
<div class="dialog__actions">
|
|
<x-ui.button type="submit" :variant="$tone === 'danger' ? 'danger' : 'primary'">{{ $confirmLabel }}</x-ui.button>
|
|
<x-ui.button variant="secondary" x-ref="cancel" x-on:click="close()">{{ $cancelLabel }}</x-ui.button>
|
|
</div>
|
|
</div>
|
|
</dialog>
|
|
</form>
|