An open API service indexing awesome lists of open source software.

https://github.com/pentiminax/ux-sweet-alert

SweetAlert2 integration for Symfony
https://github.com/pentiminax/ux-sweet-alert

javascript sweetalert2 symfony-bundle symfony-ux ux

Last synced: 5 months ago
JSON representation

SweetAlert2 integration for Symfony

Awesome Lists containing this project

README

          

# UX SweetAlert

UX SweetAlert is a Symfony bundle that integrates the SweetAlert2 library into your Symfony applications. It provides PHP helpers and a Stimulus controller to easily display alerts and toast notifications.

## Requirements

- PHP 8.2 or higher
- Symfony StimulusBundle
- Composer

## Installation

Install the library via Composer:

```bash
composer require pentiminax/ux-sweet-alert
```

## Basic usage

To automatically display toasts and alerts in your templates, add the following Twig function in your base.html.twig (or the layout file):

```twig
{{ ux_sweet_alert_scripts() }}
```

## Alerts

Inject the AlertManagerInterface and use the helper methods to create alerts:

```php
use Pentiminax\UX\SweetAlert\AlertManagerInterface;

#[Route('/', name: 'app_homepage')]
public function index(AlertManagerInterface $alertManager): Response
{
$alertManager->success(
title: 'Update Successful',
text: 'Your settings have been saved.'
);

return $this->redirectToRoute('dashboard');
}
```

## Toasts

Use the `AlertManagerInterface` service with the `toast()` method to create toast notifications:

```php
use Pentiminax\UX\SweetAlert\AlertManagerInterface;
use Pentiminax\UX\SweetAlert\Enum\Position;

class HomeController extends AbstractController
{
#[Route('/', name: 'app_homepage')]
public function index(AlertManagerInterface $alertManager): Response
{
$alertManager->toast(
title: 'title',
text: 'text',
position: Position::TOP_END,
timer: 3000,
timerProgressBar: true
);

return $this->render('home/index.html.twig');
}
}
```

## Documentation

- [Online documentation](https://pentiminax.github.io/ux-sweet-alert/)