# Alert — SvelteKit UI

Package: sveltekit-ui 1.1.94

Page: https://www.sveltekit-ui.com/components/alert

Category: Feedback

Manages display of alerts, including auto-delete and optional callbacks

Public component import: `Alert`

Public manager import: `create_alert_manager`

## Usage

```svelte
<script>
  // Import the shared stylesheet once in your application's root layout.
  import "sveltekit-ui/style.css"
  import { Alert, create_alert_manager, Button, create_button_manager } from "sveltekit-ui"

  const manager = create_alert_manager({ border_radius: 1 })

  const notify_button = create_button_manager({
    text: "Show notification",
    on_click: () => manager.add_alert("Saved", "Your changes are ready.", "check"),
  })
</script>

<Button manager={notify_button} />
<Alert {manager} />
```

## Configuration

### `alerts`

- type: array
- default:
- description: initial list of alerts

### `is_small_screen`

- type: boolean
- default: false
- description: whether the layout adjusts for smaller screens

### `x_color`

- type: string
- default: var(--g7-t)
- description: color for the x dismiss icon

### `border_radius`

- type: number
- default: 1
- description: rem-based border radius for the alert

### `success_icon_color`

- type: string
- default: var(--success-t)
- description: color for the success check icon

### `error_icon_color`

- type: string
- default: var(--error-t)
- description: color for the error x icon

### `on_alert_added`

- type: function
- default: null
- description: callback triggered each time a new alert is created

## Methods

### `add_alert()`

- description: adds a new alert, auto-assigns an id, and starts the auto-delete timer if inactive; the oldest alert is removed every 3.8 seconds
- parameters:
  - header: string
  - message: string
  - icon: string
- returns: void

### `delete_alert()`

- description: removes a specific alert by id; also clears the auto-delete interval if no alerts remain
- parameters:
  - id: string
- returns: void

## Returned state

### `interval`

- type: any
- description: reference to the auto-delete setinterval, or null if inactive

### `alerts`

- type: array
- description: current array of alerts being tracked

### `is_small_screen`

- type: boolean
- description: reflects if the layout is set to small screen mode

### `x_color`

- type: string
- description: color for the x dismiss icon

### `border_radius`

- type: number
- description: rem-based border radius for the alert

### `success_icon_color`

- type: string
- description: color for the success check icon

### `error_icon_color`

- type: string
- description: color for the error x icon
