Lewati ke konten
MarkasUI
Ketik untuk mencari

    Panduan

    MarkasUI

    Form

    Feedback

    Overlay

    Navigasi

    Data

    Section

    Animasi

    Latar

    Tombol

    Template

    Halaman

    Alert Dialog

    Konfirmasi modal berbasis elemen dialog native. Wajib memilih batal atau aksi, tidak tertutup saat backdrop diklik.

    Publish this post?

    Your post will be visible to everyone who follows your blog.

    Publish this post?

    Your post will be visible to everyone who follows your blog.

    Publish this post?

    Your post will be visible to everyone who follows your blog.

    Publish this post?

    Your post will be visible to everyone who follows your blog.

    Publish this post?

    Your post will be visible to everyone who follows your blog.
    <x-markas.alert-dialog title="Publish this post?">
        <x-slot:trigger>
            <x-markas.button>Publish post</x-markas.button>
        </x-slot:trigger>
    
        Your post will be visible to everyone who follows your blog.
    </x-markas.alert-dialog>
    import { AlertDialog } from "@/components/markas/AlertDialog";
    import { Button } from "@/components/markas/Button";
    
    export default function AlertDialogExample() {
      return (
        <AlertDialog
          title="Publish this post?"
          trigger={<Button>Publish post</Button>}
        >
          Your post will be visible to everyone who follows your blog.
        </AlertDialog>
      );
    }
    <script setup lang="ts">
    import AlertDialog from "@/components/markas/AlertDialog.vue";
    import Button from "@/components/markas/Button.vue";
    </script>
    
    <template>
      <AlertDialog title="Publish this post?">
        <template #trigger>
          <Button>Publish post</Button>
        </template>
    
        Your post will be visible to everyone who follows your blog.
      </AlertDialog>
    </template>
    <script lang="ts">
      import AlertDialog from "$lib/components/markas/AlertDialog.svelte";
      import Button from "$lib/components/markas/Button.svelte";
    </script>
    
    <AlertDialog title="Publish this post?">
      {#snippet trigger()}
        <Button>Publish post</Button>
      {/snippet}
      Your post will be visible to everyone who follows your blog.
    </AlertDialog>
    ---
    import AlertDialog from "@/components/markas/AlertDialog.astro";
    import Button from "@/components/markas/Button.astro";
    ---
    
    <AlertDialog title="Publish this post?">
      <Button slot="trigger">Publish post</Button>
      Your post will be visible to everyone who follows your blog.
    </AlertDialog>
    import { Component } from "@angular/core";
    import { AlertDialog } from "./markas/alert-dialog.component";
    import { Button } from "./markas/button.component";
    
    @Component({
      selector: "markas-example",
      imports: [AlertDialog, Button],
      template: `
        <markas-alert-dialog title="Publish this post?">
          <button markas-button trigger>Publish post</button>
          Your post will be visible to everyone who follows your blog.
        </markas-alert-dialog>
      `,
    })
    export default class AlertDialogExample {}

    Contoh

    Aksi berbahaya

    Delete your account?

    All of your projects, invoices, and team members will be removed. You cannot undo this action.

    Delete your account?

    All of your projects, invoices, and team members will be removed. You cannot undo this action.

    Delete your account?

    All of your projects, invoices, and team members will be removed. You cannot undo this action.

    Delete your account?

    All of your projects, invoices, and team members will be removed. You cannot undo this action.

    Delete your account?

    All of your projects, invoices, and team members will be removed. You cannot undo this action.

    Buang perubahan

    Draft: Q3 product update

    3 unsaved changes

    Discard unsaved changes?

    Your edits since the last save will be lost.

    Draft: Q3 product update

    3 unsaved changes

    Discard unsaved changes?

    Your edits since the last save will be lost.

    Draft: Q3 product update

    3 unsaved changes

    Discard unsaved changes?

    Your edits since the last save will be lost.

    Draft: Q3 product update

    3 unsaved changes

    Discard unsaved changes?

    Your edits since the last save will be lost.

    Draft: Q3 product update

    3 unsaved changes

    Discard unsaved changes?

    Your edits since the last save will be lost.

    Pemicu dengan ikon

    Sign out of all devices?

    You will need to sign in again on your phone, tablet, and other browsers.

    Sign out of all devices?

    You will need to sign in again on your phone, tablet, and other browsers.

    Sign out of all devices?

    You will need to sign in again on your phone, tablet, and other browsers.

    Sign out of all devices?

    You will need to sign in again on your phone, tablet, and other browsers.

    Sign out of all devices?

    You will need to sign in again on your phone, tablet, and other browsers.

    Instalasi

    npx markasui@latest add alert-dialog

    Pemakaian

    <x-markas.alert-dialog title="Hapus akun Anda?" variant="danger" cancel-label="Batal" action-label="Hapus akun" x-on:markas-action="hapusAkun()">
        <x-slot:trigger>
            <x-markas.button variant="danger">Hapus akun</x-markas.button>
        </x-slot:trigger>
    
        Semua proyek dan invoice akan dihapus. Aksi ini tidak bisa dibatalkan.
    </x-markas.alert-dialog>

    Butuh Alpine.js. Livewire 3 dan 4 sudah membawa Alpine, jadi tidak perlu dipasang lagi.

    Livewire

    <x-markas.alert-dialog title="Delete project?" wire:model="confirming" wire:markas-action="delete">
        This cannot be undone.
    </x-markas.alert-dialog>

    wire:model terhubung ke status terbuka. wire:markas-action menjalankan action Livewire saat tombol aksi ditekan; wire:markas-cancel untuk penutupan lainnya.

    import { AlertDialog } from "@/components/markas/AlertDialog";
    import { Button } from "@/components/markas/Button";
    
    <AlertDialog
      title="Hapus akun Anda?"
      variant="danger"
      cancelLabel="Batal"
      actionLabel="Hapus akun"
      trigger={<Button variant="danger">Hapus akun</Button>}
      onAction={() => hapusAkun()}
      onCancel={() => console.log("batal")}
    >
      Semua proyek dan invoice akan dihapus. Aksi ini tidak bisa dibatalkan.
    </AlertDialog>;
    <template>
      <AlertDialog
        title="Hapus akun Anda?"
        variant="danger"
        cancel-label="Batal"
        action-label="Hapus akun"
        @action="hapusAkun"
      >
        <template #trigger>
          <Button variant="danger">Hapus akun</Button>
        </template>
    
        Semua proyek dan invoice akan dihapus. Aksi ini tidak bisa dibatalkan.
      </AlertDialog>
    </template>
    <script lang="ts">
      import AlertDialog from "$lib/components/markas/AlertDialog.svelte";
      import Button from "$lib/components/markas/Button.svelte";
    </script>
    
    <AlertDialog
      title="Hapus akun Anda?"
      variant="danger"
      cancelLabel="Batal"
      actionLabel="Hapus akun"
      onaction={hapusAkun}
    >
      {#snippet trigger()}
        <Button variant="danger">Hapus akun</Button>
      {/snippet}
    
      Semua proyek dan invoice akan dihapus. Aksi ini tidak bisa dibatalkan.
    </AlertDialog>
    ---
    import AlertDialog from "@/components/markas/AlertDialog.astro";
    import Button from "@/components/markas/Button.astro";
    ---
    
    <AlertDialog
      title="Hapus akun Anda?"
      variant="danger"
      cancelLabel="Batal"
      actionLabel="Hapus akun"
    >
      <Button slot="trigger" variant="danger">Hapus akun</Button>
    
      Semua proyek dan invoice akan dihapus. Aksi ini tidak bisa dibatalkan.
    </AlertDialog>

    Satu script kecil yang dibundel Astro membuka semua alert dialog di halaman dan memancarkan event markas-action atau markas-cancel (bubbling) dari dialog saat tertutup.

    import { Component } from "@angular/core";
    import { AlertDialog } from "./markas/alert-dialog.component";
    import { Button } from "./markas/button.component";
    
    @Component({
      selector: "app-hapus-akun",
      imports: [AlertDialog, Button],
      template: `
        <markas-alert-dialog
          title="Hapus akun Anda?"
          variant="danger"
          cancelLabel="Batal"
          actionLabel="Hapus akun"
          (action)="hapusAkun()"
        >
          <button markas-button trigger variant="danger">Hapus akun</button>
    
          Semua proyek dan invoice akan dihapus. Aksi ini tidak bisa dibatalkan.
        </markas-alert-dialog>
      `,
    })
    export class HapusAkun {
      hapusAkun() {}
    }
    • Berbeda dengan Modal, klik backdrop tidak menutup dialog. User wajib memilih batal atau aksi; Escape dihitung sebagai batal.
    • Fokus awal ada di tombol batal.
    • dialog.returnValue berisi action atau cancel saat event close.
    • Teks tombol default dalam bahasa Inggris (“Cancel” dan “Continue”). Isi cancelLabel dan actionLabel (Blade: cancel-label, action-label) untuk situs berbahasa Indonesia.

    Props

    NamaTipeDefaultKeterangan
    titlestring-Judul dialog, dipakai sebagai aria-labelledby.
    children / slotslot / ReactNode / snippet-Penjelasan singkat akibat aksi, dipakai sebagai aria-describedby.
    triggerslot / ReactNode / snippet-Elemen yang membuka dialog saat diklik. Angular: elemen dengan atribut trigger.
    variantdefault | dangerdefaultWarna tombol aksi. Pakai danger untuk aksi yang merusak atau tidak bisa dibatalkan.
    cancelLabelstringCancelTeks tombol batal. Isi "Batal" untuk situs berbahasa Indonesia.
    actionLabelstringContinueTeks tombol aksi. Isi "Lanjutkan" atau nama aksinya untuk situs berbahasa Indonesia.
    onAction / @action / markas-action() => void-Dipanggil saat tombol aksi dipilih. Svelte: onaction. Blade dan Astro memancarkan event markas-action.
    onCancel / @cancel / markas-cancel() => void-Dipanggil saat dialog ditutup lewat tombol batal atau Escape. Svelte: oncancel. Blade dan Astro memancarkan event markas-cancel.
    idstringautoId dialog. Bisa dipakai untuk membuka dialog dari luar lewat showModal().
    actionoutput<void>-Khusus Angular. Dipancarkan saat tombol aksi dipilih.
    cancelledoutput<void>-Khusus Angular. Dipancarkan saat dialog ditutup lewat tombol batal atau Escape.

    Aksesibilitas

    • Memakai dialog dengan role=alertdialog dan showModal(), jadi fokus terkunci di dalam dan halaman di belakangnya inert.
    • Judul terhubung lewat aria-labelledby dan penjelasan lewat aria-describedby.
    • Fokus awal ada di tombol batal, jadi Enter yang tidak sengaja tidak menjalankan aksi.
    • Escape menutup dialog dan dihitung sebagai batal. Klik backdrop tidak melakukan apa pun.

    Komponen terkait

    Komponen overlay lain dengan class yang sama di setiap framework.