import { Component, inject, signal } from '@angular/core'; import { RouterLink } from '@angular/router'; import { ButtonComponent, ConfirmService, DrawerService, ModalService, } from '@africanies/africanies-ui'; import { DemoSectionComponent } from '../shared/demo-section.component'; import { PageHeaderComponent } from '../shared/page-header.component'; import { OVERLAY_CONFIRM, OVERLAY_DRAWER, OVERLAY_MODAL, } from '../snippets'; import { DemoDrawerPanel, DemoModalPanel, } from './overlay-demos'; /** * Playground demos for ModalService, DrawerService, and ConfirmService. * Requires provideAfricaniesUiOverlays() (already in playground app.config). */ @Component({ selector: 'app-overlay-page', standalone: true, imports: [ ButtonComponent, PageHeaderComponent, DemoSectionComponent, RouterLink, ], template: `

Service-driven dialogs for focused tasks: modal (forms), drawer (filters/side panels), and confirm (yes/no). Built on CDK Overlay. Closed only by their actions unless you pass dismissible: true for backdrop / Escape.

Last result: {{ modalResult() ?? '—' }}

Last result: {{ drawerResult() ?? '—' }}

Last choice: {{ confirmResult() ?? '—' }}

`, }) export class OverlayPage { private readonly modal = inject(ModalService); private readonly drawer = inject(DrawerService); private readonly confirm = inject(ConfirmService); protected readonly modalResult = signal(null); protected readonly drawerResult = signal(null); protected readonly confirmResult = signal(null); protected readonly modalCode = OVERLAY_MODAL; protected readonly drawerCode = OVERLAY_DRAWER; protected readonly confirmCode = OVERLAY_CONFIRM; protected openModal(dismissible: boolean): void { this.modal .open< { shipmentRef: string }, { saved: boolean; note: string } >(DemoModalPanel, { data: { shipmentRef: 'SFN-1042' }, dismissible, }) .afterClosed() .subscribe((result) => { this.modalResult.set( result?.saved ? `Saved — “${result.note}”` : dismissible ? 'Dismissed (backdrop / Escape / Cancel)' : 'Closed via Cancel', ); }); } protected openWideModal(): void { this.modal .open< { shipmentRef: string }, { saved: boolean; note: string } >(DemoModalPanel, { data: { shipmentRef: 'SFN-1042' }, size: 'lg', dismissible: true, }) .afterClosed() .subscribe((result) => { this.modalResult.set( result?.saved ? `Saved (lg) — “${result.note}”` : 'Dismissed wide modal', ); }); } protected openDrawer(dismissible: boolean): void { this.drawer .open<{ facet: string }, { applied: boolean }>(DemoDrawerPanel, { data: { facet: 'Status' }, dismissible, }) .afterClosed() .subscribe((result) => { this.drawerResult.set( result?.applied ? 'Filters applied' : dismissible ? 'Dismissed (backdrop / Escape / Cancel)' : 'Closed via Cancel', ); }); } protected openConfirm(danger: boolean, dismissible = false): void { this.confirm .confirm({ title: danger ? 'Delete shipment?' : 'Mark as delivered?', message: danger ? 'This cannot be undone. Related documents stay in archive.' : 'The consignee will be notified that the shipment is complete.', confirmLabel: danger ? 'Delete' : 'Mark delivered', cancelLabel: 'Cancel', danger, dismissible, }) .subscribe((ok) => { this.confirmResult.set(ok ? 'Confirmed' : 'Cancelled'); }); } }