Skip to content

Alert Dialog

Hộp thoại modal làm gián đoạn người dùng với nội dung quan trọng và mong đợi phản hồi.

Cài đặt

bash
npx @galaxy-stack/nebula-cli@latest add alert-dialog
bash
pnpm dlx @galaxy-stack/nebula-cli@latest add alert-dialog
bash
yarn dlx @galaxy-stack/nebula-cli@latest add alert-dialog
bash
bunx @galaxy-stack/nebula-cli@latest add alert-dialog

Sử dụng

Vue

vue
<script setup lang="ts">
import {
  AlertDialog,
  AlertDialogTrigger,
  AlertDialogContent,
  AlertDialogTitle,
  AlertDialogDescription,
  AlertDialogAction,
  AlertDialogCancel
} from '@/components/ui'
</script>

<template>
  <AlertDialog>
    <AlertDialogTrigger>Xóa Tài Khoản</AlertDialogTrigger>
    <AlertDialogContent>
      <AlertDialogTitle>Bạn có chắc chắn?</AlertDialogTitle>
      <AlertDialogDescription>
        Hành động này không thể hoàn tác.
      </AlertDialogDescription>
      <AlertDialogCancel>Hủy</AlertDialogCancel>
      <AlertDialogAction>Xóa</AlertDialogAction>
    </AlertDialogContent>
  </AlertDialog>
</template>

React

tsx
import {
  AlertDialog,
  AlertDialogTrigger,
  AlertDialogContent,
  AlertDialogTitle,
  AlertDialogDescription,
  AlertDialogAction,
  AlertDialogCancel
} from '@/components/ui'

export default function AlertDialogDemo() {
  return (
    <AlertDialog>
      <AlertDialogTrigger>Xóa Tài Khoản</AlertDialogTrigger>
      <AlertDialogContent>
        <AlertDialogTitle>Bạn có chắc chắn?</AlertDialogTitle>
        <AlertDialogDescription>
          Hành động này không thể hoàn tác.
        </AlertDialogDescription>
        <AlertDialogCancel>Hủy</AlertDialogCancel>
        <AlertDialogAction>Xóa</AlertDialogAction>
      </AlertDialogContent>
    </AlertDialog>
  )
}

Angular

typescript
import { Component } from '@angular/core';
import { AlertDialogComponent } from '@/components/ui/alert-dialog';

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [AlertDialogComponent],
  template: `
    <ui-alert-dialog [open]="isOpen" (openChange)="isOpen = $event">
      <ui-alert-dialog-trigger>
        <button variant="destructive">Xóa Tài Khoản</button>
      </ui-alert-dialog-trigger>
      <ui-alert-dialog-content>
        <ui-alert-dialog-title>Bạn có chắc chắn?</ui-alert-dialog-title>
        <ui-alert-dialog-description>
          Hành động này không thể hoàn tác.
        </ui-alert-dialog-description>
        <button (click)="isOpen = false">Hủy</button>
        <button (click)="handleDelete()">Xóa</button>
      </ui-alert-dialog-content>
    </ui-alert-dialog>
  `
})
export class AppComponent {
  isOpen = false;

  handleDelete() {
    // Xử lý xóa
    this.isOpen = false;
  }
}

React Native

tsx
import {
  AlertDialog,
  AlertDialogTrigger,
  AlertDialogContent,
  AlertDialogTitle,
  AlertDialogDescription,
  AlertDialogAction,
  AlertDialogCancel
} from '@/components/ui/alert-dialog'
import { Button, ButtonText } from '@/components/ui/button'

export default function App() {
  return (
    <AlertDialog>
      <AlertDialogTrigger asChild>
        <Button variant="destructive">
          <ButtonText>Xóa Tài Khoản</ButtonText>
        </Button>
      </AlertDialogTrigger>
      <AlertDialogContent>
        <AlertDialogTitle>Bạn có chắc chắn?</AlertDialogTitle>
        <AlertDialogDescription>
          Hành động này không thể hoàn tác.
        </AlertDialogDescription>
        <AlertDialogCancel>
          <ButtonText>Hủy</ButtonText>
        </AlertDialogCancel>
        <AlertDialogAction>
          <ButtonText>Xóa</ButtonText>
        </AlertDialogAction>
      </AlertDialogContent>
    </AlertDialog>
  )
}

Flutter

dart
import 'package:flutter/material.dart';
import 'package:galaxy_design/galaxy_alert_dialog.dart';

class AlertDialogExample extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return GalaxyButton(
      variant: GalaxyButtonVariant.destructive,
      onPressed: () {
        GalaxyAlertDialog.show(
          context: context,
          title: 'Bạn có chắc chắn?',
          description: 'Hành động này không thể hoàn tác.',
          cancelText: 'Hủy',
          confirmText: 'Xóa',
          onConfirm: () {
            // Xử lý xóa
          },
        );
      },
      child: const Text('Xóa Tài Khoản'),
    );
  }
}

API Reference

Props

PropTypeDefaultDescriptionFrameworks
openboolean-Trạng thái mở được kiểm soátReact, Vue, Angular
defaultOpenbooleanfalseTrạng thái mở ban đầu cho chế độ uncontrolledReact, Vue, Angular
onOpenChange / update:open(open: boolean) => void-Được gọi khi trạng thái mở thay đổiReact (onOpenChange), Vue (update:open), Angular
titlestring-Văn bản tiêu đề tùy chọnFlutter only
descriptionstring-Văn bản mô tả tùy chọnFlutter only
cancelTextstring'Cancel'Văn bản nút hủyFlutter only
confirmTextstring'Confirm'Văn bản nút xác nhậnFlutter only
variant'default' | 'destructive''default'Biến thể kiểu dáng trực quanFlutter only
paddingEdgeInsetsGeometry-Padding bên trong container alertFlutter only

Sub-components

AlertDialogTrigger

PropTypeDefaultDescriptionFrameworks
asChildbooleanfalseRender trigger như một phần tử conReact, Vue
asAsTag | Component'button'Phần tử hoặc component để renderVue only

AlertDialogContent

PropTypeDefaultDescriptionFrameworks
forceMountboolean-Force-mount content ngay cả khi đóngReact, Vue
className / classstring-Tên CSS classReact (className), Vue (class)
onOpenAutoFocus(event: Event) => void-Được gọi khi focus di chuyển vào alert dialog sau khi mởReact only
onCloseAutoFocus(event: Event) => void-Được gọi khi focus trở lại sau khi đóngReact only

Khả năng truy cập

  • Điều hướng bàn phím: [TODO]
  • Đọc màn hình: [TODO]
  • Quản lý focus: [TODO]
  • Tuân thủ WCAG: Tuân thủ WCAG 2.1 cấp độ AA

Tác giả

Bùi Trọng Hiếu (kevinbui)

Giấy phép

MIT © 2025 Bùi Trọng Hiếu (kevinbui)

Phát hành theo Giấy phép MIT.