pentiminax / ux-sweet-alert
SweetAlert2 integration for Symfony
Package info
github.com/pentiminax/ux-sweet-alert
Type:symfony-bundle
pkg:composer/pentiminax/ux-sweet-alert
Requires
- php: >=8.3
- symfony/config: ^7.0|^8.0
- symfony/dependency-injection: ^7.0|^8.0
- symfony/event-dispatcher: ^7.0|^8.0
- symfony/http-kernel: ^7.0|^8.0
- symfony/stimulus-bundle: ^2.0 | ^3.0
- symfony/ux-live-component: ^2.0 | ^3.0
- symfony/ux-twig-component: ^2.0 | ^3.0
- twig/twig: ^3.8
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.94
- phpstan/phpstan: ^2.1.12
- phpunit/phpunit: ^12.0
- symfony/browser-kit: ^7.0|^8.0
- symfony/framework-bundle: ^7.0|^8.0
- symfony/phpunit-bridge: ^7.0|^8.0
- symfony/twig-bundle: ^7.0|^8.0
- symfony/validator: ^7.0|^8.0
- symfony/var-dumper: ^7.0|^8.0
Suggests
- symfony/validator: To answer preConfirmUrl() requests from constraint violations with PreConfirmResponse
Provides
None
Conflicts
- symfony/flex: <1.13
Replaces
None
- dev-main
- v0.22.0
- v0.21.0
- v0.20.1
- v0.20.0
- v0.19.0
- v0.18.0
- v0.17.0
- v0.16.0
- v0.15.0
- v0.14.0
- v0.13.0
- v0.12.0
- v0.11.0
- v0.10.0
- v0.9.1
- v0.9.0
- v0.8.0
- v0.7.5
- v0.7.4
- v0.7.3
- v0.7.2
- v0.7.1
- v0.7.0
- v0.6.2
- v0.6.1
- v0.6.0
- v0.5.0
- v0.4.2
- v0.4.1
- v0.4.0
- v0.3.2
- v0.3.1
- v0.3.0
- v0.2.2
- v0.2.1
- v0.2.0
- v0.1.6
- v0.1.5
- v0.1.4
- v0.1.3
- v0.1.2
- v0.1.1
- v0.1.0
- dev-feat/demo-app
- dev-feat/progress-steps
- dev-fix/alert-defaults
- dev-feat/visual-options
- dev-test/functional-coverage
- dev-feat/constraint-validation
- dev-claude/code-quality-audit-a21594
- dev-feat/pre-confirm-url
- dev-refactor/alert-delivery
- dev-refactor/alert-presentation
- dev-chore/update-js-deps
- dev-chore/phpunit-12
- dev-fix/toast-incompatible-params
This package is auto-updated.
Last update: 2026-11-04 03:33:58 UTC
README
UX SweetAlert is a Symfony bundle that integrates the SweetAlert2 library into your Symfony applications. It provides PHP helpers, input-type abstractions, Live Components, and a Stimulus controller to display alerts, input dialogs, and toast notifications.
Requirements
- PHP 8.3 or higher
- Symfony StimulusBundle
- Composer
Installation
Install the library via Composer:
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):
{{ ux_sweet_alert_scripts() }}
Alerts
Inject the AlertManagerInterface and use the helper methods to create alerts:
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:
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'); } }
Input dialogs
Use AlertManagerInterface::input() with one of the provided input type classes when you want to collect user input from PHP:
use Pentiminax\UX\SweetAlert\AlertManagerInterface; use Pentiminax\UX\SweetAlert\InputType\Text; #[Route('/profile', name: 'app_profile')] public function index(AlertManagerInterface $alertManager): Response { $alertManager->input( inputType: new Text( label: 'Display name', value: 'Tanguy', placeholder: 'Enter your display name', ), title: 'Update profile', text: 'This change is visible to other users.' ); return $this->render('profile/index.html.twig'); }
Available helpers include Text, Textarea, Select, Radio, Checkbox, File, Range, and HtmlInputType for other native HTML input types.
Live Components
The bundle also ships SweetAlert:ConfirmButton and SweetAlert:InputModal Live Components. Render {{ ux_sweet_alert_scripts() }} on the page, then use the component that matches your interaction pattern. See the online documentation for full examples.
Run the demo
The demo/ folder is a Symfony 8.1 app (PHP 8.4+) that shows every feature next to the code behind it. It uses the bundle from this checkout, so your changes in src/ show up on reload.
cd demo
composer install
symfony serve
Without the Symfony CLI, run php -S localhost:8000 -t public instead (and php bin/console tailwind:build --watch if you edit the styles).