alert

Displays a callout for user attention.

PreviousNext
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 '../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 {}

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

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 '../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

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

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

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-color',
  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
[zAction] Alert action TemplateRef<void> -
[zDescription] Alert description string | TemplateRef<void> -
[zIcon] Alert icon. If not specified, default icon will be lucideCircleAlert 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 .