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
- Host: GitHub
- URL: https://github.com/pentiminax/ux-sweet-alert
- Owner: pentiminax
- License: mit
- Created: 2025-04-26T11:22:00.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2026-02-11T15:06:25.000Z (5 months ago)
- Last Synced: 2026-02-11T23:16:02.165Z (5 months ago)
- Topics: javascript, sweetalert2, symfony-bundle, symfony-ux, ux
- Language: PHP
- Homepage: https://pentiminax.github.io/ux-sweet-alert/
- Size: 244 KB
- Stars: 24
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Agents: AGENTS.md
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/)