alert

Displays a callout for user attention.

PreviousNext
Success! Your changes have been saved
This is an alert with icon, title and description.
Unable to process your payment
Please verify your billing information and try again.
import { ChangeDetectionStrategy, Component } from '@angular/core';

import { provideIcons } from '@ng-icons/core';
import { lucideCircleCheck } from '@ng-icons/lucide';

import { ZardAlertComponent } from '@/shared/components/alert/alert.component';

@Component({
  selector: 'z-demo-alert-preview',
  imports: [ZardAlertComponent],
  template: `
    <div class="grid w-full max-w-md items-start gap-4">
      <z-alert
        zIcon="lucideCircleCheck"
        zTitle="Success! Your changes have been saved"
        zDescription="This is an alert with icon, title and description."
      />

      <z-alert
        zType="destructive"
        zTitle="Unable to process your payment"
        zDescription="Please verify your billing information and try again."
      />
    </div>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
  viewProviders: [provideIcons({ lucideCircleCheck })],
})
export class ZardDemoAlertPreviewComponent {}

Installation

Copy
npx zard-cli@latest add alert

Usage

import { ZardAlertComponent } from '@/shared/components/alert/alert.component';
Copy
<z-alert zTitle="Heads up!" zDescription="You can add components to your app using the cli."></z-alert>
Copy

Examples

basic

Use zIcon, zTitle, and zDescription on z-alert to render a callout with an icon, title, and description.
Payment successful
Your payment of $29.99 has been processed. A receipt has been sent to your email address.
New feature available
We've added dark mode support. You can enable it in your account settings.
import { ChangeDetectionStrategy, Component } from '@angular/core';

import { provideIcons } from '@ng-icons/core';
import { lucideCircleCheck, lucideInfo } from '@ng-icons/lucide';

import { ZardAlertComponent } from '@/shared/components/alert/alert.component';

@Component({
  selector: 'z-demo-alert-basic',
  imports: [ZardAlertComponent],
  template: `
    <div class="grid w-full max-w-md items-start gap-4">
      <z-alert
        zIcon="lucideCircleCheck"
        zTitle="Payment successful"
        zDescription="Your payment of $29.99 has been processed. A receipt has been sent to your email address."
      />

      <z-alert
        zIcon="lucideInfo"
        zTitle="New feature available"
        zDescription="We've added dark mode support. You can enable it in your account settings."
      />
    </div>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
  viewProviders: [provideIcons({ lucideCircleCheck, lucideInfo })],
})
export class ZardDemoAlertBasicComponent {}

destructive

Set zType="destructive" on z-alert to flag a critical message. When zIcon is not set, it defaults to lucideCircleAlert.
Payment failed
Your payment could not be processed. Please check your payment method and try again.
import { ChangeDetectionStrategy, Component } from '@angular/core';

import { ZardAlertComponent } from '@/shared/components/alert/alert.component';

@Component({
  selector: 'z-demo-alert-destructive',
  imports: [ZardAlertComponent],
  template: `
    <div class="grid w-full max-w-md items-start gap-4">
      <z-alert
        zType="destructive"
        zTitle="Payment failed"
        zDescription="Your payment could not be processed. Please check your payment method and try again."
      />
    </div>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ZardDemoAlertDestructiveComponent {}

action

Pass a TemplateRef to zAction to render a z-button inside the alert.
Dark mode is now available
Enable it under your profile settings to get started.
import { ChangeDetectionStrategy, Component } from '@angular/core';

import { ZardAlertComponent } from '@/shared/components/alert/alert.component';
import { ZardButtonComponent } from '@/shared/components/button';

@Component({
  selector: 'z-demo-alert-action',
  imports: [ZardAlertComponent, ZardButtonComponent],
  template: `
    <ng-template #actionTpl>
      <button type="button" z-button zSize="xs">Enable</button>
    </ng-template>

    <div class="grid w-full max-w-md items-start gap-4">
      <z-alert
        class="w-md"
        zTitle="Dark mode is now available"
        zDescription="Enable it under your profile settings to get started."
        [zAction]="actionTpl"
      />
    </div>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ZardDemoAlertActionComponent {}

custom colors

Override the class input on z-alert to customize its border, background, and text colors.
Your subscription will expire in 3 days
Renew now to avoid service interruption or upgrade to a paid plan to continue using the service.
import { ChangeDetectionStrategy, Component } from '@angular/core';

import { provideIcons } from '@ng-icons/core';
import { lucideAlertTriangle } from '@ng-icons/lucide';

import { ZardAlertComponent } from '@/shared/components/alert/alert.component';

@Component({
  selector: 'z-demo-alert-custom-colors',
  imports: [ZardAlertComponent],
  template: `
    <div class="grid w-full max-w-md items-start gap-4">
      <z-alert
        class="max-w-md border-amber-200 bg-amber-50 text-amber-900 dark:border-amber-900 dark:bg-amber-950 dark:text-amber-50"
        zDescription="Renew now to avoid service interruption or upgrade to a paid plan to continue using the service."
        zIcon="lucideAlertTriangle"
        zTitle="Your subscription will expire in 3 days"
      />
    </div>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
  viewProviders: [provideIcons({ lucideAlertTriangle })],
})
export class ZardDemoAlertCustomColorsComponent {}

API Reference

z-alertComponent

Displays a callout for user attention.

PropertyDescriptionTypeDefault
[class] Custom CSS classes ClassValue ''
[zAction] Alert action TemplateRef<void> -
[zDescription] Alert description string | TemplateRef<void> -
[zIcon] Alert icon (an ng-icons name or a TemplateRef). When unset, defaults to 'lucideCircleAlert' for the 'destructive' zType; otherwise no icon renders. TemplateRef<void> | string -
[zRole] Overrides the ARIA role. Defaults to 'status' when [zAction] is set, otherwise 'alert'. 'alert' | 'status' -
[zTitle] Alert title string | TemplateRef<void> -
[zType] Alert variant 'default' | 'destructive' 'default'
github iconwhatsapp icondiscord iconX icon

Made with ❤ in Brazil. Open source and available on GitHub .