### Install PHP dependencies Source: https://github.com/pentiminax/ux-sweet-alert/blob/main/AGENTS.md Command to install project dependencies via Composer. ```bash composer install ``` -------------------------------- ### Verify installation with a controller action Source: https://github.com/pentiminax/ux-sweet-alert/blob/main/docs/src/content/docs/getting-started/installation.mdx Queue a success alert in a controller to verify that the bundle is correctly configured and rendering. ```php use Pentiminax\UX\SweetAlert\AlertManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; final class DashboardController extends AbstractController { #[Route('/dashboard', name: 'app_dashboard')] public function __invoke(AlertManagerInterface $alertManager): Response { $alertManager->success( title: 'Installed', text: 'UX SweetAlert is ready to render.' ); return $this->render('dashboard/index.html.twig'); } } ``` -------------------------------- ### Install the bundle via Composer Source: https://github.com/pentiminax/ux-sweet-alert/blob/main/docs/src/content/docs/getting-started/installation.mdx Run this command to add the package to your Symfony project. ```bash composer require pentiminax/ux-sweet-alert ``` -------------------------------- ### Install Webpack Encore dependencies Source: https://github.com/pentiminax/ux-sweet-alert/blob/main/docs/src/content/docs/getting-started/installation.mdx Use these commands to install JavaScript dependencies and rebuild assets when using Webpack Encore. ```bash npm install --force npm run watch ``` -------------------------------- ### Controller Alert Integration Source: https://github.com/pentiminax/ux-sweet-alert/blob/main/docs/src/content/docs/integrations/turbo.mdx Example of using AlertManagerInterface within a controller to trigger alerts in JSON responses. ```php use Pentiminax\UX\SweetAlert\AlertManagerInterface; use Symfony\Component\HttpFoundation\JsonResponse; public function __invoke(AlertManagerInterface $alertManager): JsonResponse { $alertManager->info( title: 'Background sync finished', text: 'Your cache is fresh again.' ); return $this->json(['status' => 'ok']); } ``` -------------------------------- ### Automatic HTMX Trigger Header Source: https://github.com/pentiminax/ux-sweet-alert/blob/main/docs/src/content/docs/integrations/htmx.mdx This header is automatically dispatched by the response listener when Turbo is not installed. It contains the first queued alert serialized under the `ux-sweet-alert:alert:added` event name. ```http HX-Trigger: {"ux-sweet-alert:alert:added":{"alert":{"title":"Saved","icon":"success"}}} ``` -------------------------------- ### Run the test suite Source: https://github.com/pentiminax/ux-sweet-alert/blob/main/AGENTS.md Command to execute the PHPUnit test suite. ```bash ./vendor/bin/phpunit ``` -------------------------------- ### Run static analysis Source: https://github.com/pentiminax/ux-sweet-alert/blob/main/AGENTS.md Command to perform static analysis on source and test files using PHPStan. ```bash ./vendor/bin/phpstan analyse src tests ``` -------------------------------- ### Manual Alert Creation Source: https://github.com/pentiminax/ux-sweet-alert/blob/main/docs/src/content/docs/reference/alert-manager-and-alert-object.mdx How to manually create an Alert object. ```APIDOC ## Manual Alert Creation ### Description Methods for creating standalone `Alert` objects. ### Methods - **Alert::new()**: Creates a standalone alert with an optional icon, position, and custom class array. - **Alert::withDefaults()**: Used internally by the manager to apply bundle defaults. ``` -------------------------------- ### Create and Customize a Warning Alert Source: https://github.com/pentiminax/ux-sweet-alert/blob/main/docs/src/content/docs/guide/alerts.mdx Use the `warning()` helper to create an alert and fluently chain customization methods like adding cancel and deny buttons. ```php $alert = $alertManager->warning( title: 'Danger zone', text: 'This action cannot be undone.' ); $alert ->withCancelButton() ->withDenyButton() ->denyOutsideClick() ->denyEscapeKey(); ``` -------------------------------- ### Create a Custom Alert Instance Source: https://github.com/pentiminax/ux-sweet-alert/blob/main/docs/src/content/docs/guide/alerts.mdx Manually create an `Alert` instance using `Alert::new()` for direct control over its lifecycle. This method allows specifying icon, position, and rich content. ```php use Pentiminax\UX\SweetAlert\Enum\Icon; use Pentiminax\UX\SweetAlert\Enum\Position; use Pentiminax\UX\SweetAlert\Model\Alert; $alert = Alert::new( title: 'Custom alert', text: 'Created manually.', icon: Icon::INFO, position: Position::TOP ) ->html('Rich content') ->setFooter('Need help? Contact support.'); $alertManager->addAlert($alert); ``` -------------------------------- ### Create an Input Dialog with Select Field Source: https://context7.com/pentiminax/ux-sweet-alert/llms.txt The `input` method with `Select` allows users to choose from a predefined list of options. Define the options, label, and default value. ```php input( inputType: new Select( options: [ 'admin' => 'Administrator', 'editor' => 'Editor', 'viewer' => 'Viewer', ], label: 'Role', value: 'viewer' ), title: 'Invite Team Member', text: 'Select the role for the new member.', callback: $this->generateUrl( 'app_team_invite_save', referenceType: UrlGeneratorInterface::ABSOLUTE_URL ) ); return $this->render('team/invite.html.twig'); } } ``` -------------------------------- ### Create Info Alert Source: https://context7.com/pentiminax/ux-sweet-alert/llms.txt Displays an informational alert with a blue info icon. ```php info( title: 'Background Sync Finished', text: 'Your cache is fresh again.' ); return $this->json(['status' => 'ok']); } } ``` -------------------------------- ### Create a Question Alert Source: https://context7.com/pentiminax/ux-sweet-alert/llms.txt Use the `question` method to create a confirmation dialog with custom button texts. This is suitable for actions that require user confirmation. ```php question( title: 'Archive Conversation?', text: 'This action cannot be undone.' ) ->withCancelButton() ->withDenyButton() ->confirmButtonText('Archive') ->cancelButtonText('Keep it') ->setDenyButtonText('Delete instead'); return $this->render('conversation/archive.html.twig', ['id' => $id]); } } ``` -------------------------------- ### Create Textarea Input Dialog Source: https://context7.com/pentiminax/ux-sweet-alert/llms.txt Use this to create a dialog for multi-line text input. Specify label, placeholder, and input attributes like rows. ```php input( inputType: new Textarea( label: 'Your Feedback', placeholder: 'Tell us what you think...', inputAttributes: ['rows' => '5'] ), title: 'Submit Feedback', text: 'We appreciate your input.' ) ->withCancelButton() ->confirmButtonText('Submit'); return $this->render('feedback/index.html.twig'); } } ``` -------------------------------- ### AlertManagerInterface::question() Source: https://context7.com/pentiminax/ux-sweet-alert/llms.txt Creates a confirmation dialog with a blue question mark icon. ```APIDOC ## AlertManagerInterface::question() ### Description Creates a question alert with a blue question mark icon, typically used for confirmation dialogs. ### Parameters - **title** (string) - Required - The title of the alert. - **text** (string) - Required - The body text of the alert. ``` -------------------------------- ### Create Range Input Dialog Source: https://context7.com/pentiminax/ux-sweet-alert/llms.txt Use this to create a dialog with a numeric slider for value selection within a defined range. Configure label, default value, min, max, and step. ```php input( inputType: new Range( label: 'Volume Level', value: '50', min: 0, max: 100, step: 5 ), title: 'Adjust Volume' ); return $this->render('settings/volume.html.twig'); } } ``` -------------------------------- ### Create Input Dialogs Source: https://github.com/pentiminax/ux-sweet-alert/blob/main/README.md Use the input method with specific input type classes to collect user data. ```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'); } ``` -------------------------------- ### Applying Theme to Toast Source: https://github.com/pentiminax/ux-sweet-alert/blob/main/docs/src/content/docs/guide/toasts.mdx Customize the appearance of a toast notification by applying a theme. Ensure the Theme enum is imported. ```php use Pentiminax\UX\SweetAlert\Enum\Theme; $toast = $alertManager->toast(title: 'Saved'); $toast->theme(Theme::MaterialUILight); ``` -------------------------------- ### Create an Input Dialog with Text Field Source: https://context7.com/pentiminax/ux-sweet-alert/llms.txt Use the `input` method with `Text` to prompt the user for text input. Configure labels, placeholders, and validation messages. ```php input( inputType: new Text( label: 'Display Name', value: 'Tanguy', placeholder: 'Enter your public display name', inputAttributes: ['maxlength' => '40'] ), title: 'Update Profile', text: 'This change is visible to other users.', callback: $this->generateUrl( 'app_display_name_save', referenceType: UrlGeneratorInterface::ABSOLUTE_URL ) ) ->validationMessage('A display name is required.') ->withCancelButton(); return $this->render('profile/display_name.html.twig'); } } ``` -------------------------------- ### Create File Upload Dialog Source: https://context7.com/pentiminax/ux-sweet-alert/llms.txt Use this to create a dialog for file uploads. Specify the label and accepted file types. ```php input( inputType: new File( label: 'Choose an image', accept: 'image/png,image/jpeg,image/gif' ), title: 'Upload Avatar', text: 'Select an image file (PNG, JPG, or GIF).' ) ->withCancelButton(); return $this->render('profile/avatar.html.twig'); } } ``` -------------------------------- ### AlertManagerInterface::input() Source: https://context7.com/pentiminax/ux-sweet-alert/llms.txt Creates an input dialog for collecting user data via text or select inputs. ```APIDOC ## AlertManagerInterface::input() ### Description Creates an input dialog with a field (Text or Select) for collecting user input. ### Parameters - **inputType** (Object) - Required - The input type instance (Text or Select). - **title** (string) - Required - The title of the dialog. - **text** (string) - Required - The body text of the dialog. - **callback** (string) - Required - The URL to handle the submitted input. ``` -------------------------------- ### Configure a generic HTML input Source: https://github.com/pentiminax/ux-sweet-alert/blob/main/docs/src/content/docs/reference/input-types.mdx Use HtmlInputType for native HTML input types like email, password, or number that do not require specialized class logic. ```php use Pentiminax\UX\SweetAlert\Enum\InputType; use Pentiminax\UX\SweetAlert\InputType\HtmlInputType; $alertManager->input( inputType: new HtmlInputType( type: InputType::Email, label: 'Work email', placeholder: 'name@company.com' ), title: 'Invite a colleague' ); ``` -------------------------------- ### Create Radio Input Dialog Source: https://context7.com/pentiminax/ux-sweet-alert/llms.txt Use this to create a dialog for single-choice selection with radio buttons. Configure options, label, and default value. ```php input( inputType: new Radio( options: [ 'low' => 'Low Priority', 'medium' => 'Medium Priority', 'high' => 'High Priority', 'critical' => 'Critical', ], label: 'Priority Level', value: 'medium' ), title: 'Set Task Priority' ) ->withCancelButton(); return $this->render('task/priority.html.twig', ['id' => $id]); } } ``` -------------------------------- ### Apply a Bootstrap 5 Dark Theme Source: https://github.com/pentiminax/ux-sweet-alert/blob/main/docs/src/content/docs/guide/themes-and-styling.mdx Use the Theme enum to apply a specific framework theme to your alert. Ensure the matching SweetAlert2 CSS is imported by your asset pipeline. ```php use Pentiminax\UX\SweetAlert\Enum\Theme; $alertManager ->success('Saved') ->theme(Theme::Bootstrap5Dark); ``` -------------------------------- ### Create Success Alert Source: https://context7.com/pentiminax/ux-sweet-alert/llms.txt Displays a success alert with a green checkmark icon. ```php success( title: 'Settings Saved', text: 'Your preferences have been updated successfully.' ); return $this->redirectToRoute('app_dashboard'); } } ``` -------------------------------- ### Implement InputModal component Source: https://github.com/pentiminax/ux-sweet-alert/blob/main/docs/src/content/docs/integrations/live-components.mdx Displays an input modal with specific input options and configuration. ```twig ``` -------------------------------- ### AlertManager::input() with HtmlInputType Source: https://github.com/pentiminax/ux-sweet-alert/blob/main/docs/src/content/docs/reference/input-types.mdx Demonstrates how to use the generic HtmlInputType class to create native HTML inputs like email, password, or number fields. ```APIDOC ## AlertManager::input() ### Description Configures an Alert instance for SweetAlert2 input mode using a specific input type class. ### Parameters #### Request Body - **inputType** (Object) - Required - An instance of an InputType class (e.g., HtmlInputType, Text, Select). - **title** (String) - Optional - The title of the SweetAlert modal. ### Request Example ```php use Pentiminax\UX\SweetAlert\Enum\InputType; use Pentiminax\UX\SweetAlert\InputType\HtmlInputType; $alertManager->input( inputType: new HtmlInputType( type: InputType::Email, label: 'Work email', placeholder: 'name@company.com' ), title: 'Invite a colleague' ); ``` ``` -------------------------------- ### Manual HTMX Alert Dispatch with HxTriggerHelper Source: https://github.com/pentiminax/ux-sweet-alert/blob/main/docs/src/content/docs/integrations/htmx.mdx Use `HxTriggerHelper::withAlert()` when you need full control over the HTTP response object. This method allows you to attach a SweetAlert to a custom response. ```php use Pentiminax\UX\SweetAlert\AlertManagerInterface; use Pentiminax\UX\SweetAlert\Htmx\HxTriggerHelper; use Symfony\Component\HttpFoundation\Response; public function save(AlertManagerInterface $alertManager): Response { $alert = $alertManager->success( title: 'Saved', text: 'Your changes are now persisted.' ); return HxTriggerHelper::withAlert(new Response('OK'), $alert); } ``` -------------------------------- ### Render the Twig helper Source: https://github.com/pentiminax/ux-sweet-alert/blob/main/docs/src/content/docs/getting-started/installation.mdx Include the helper in your base layout to enable alert and toast rendering. ```twig {{ ux_sweet_alert_scripts() }} ``` -------------------------------- ### Extend InputModal for Server-Side Handling Source: https://context7.com/pentiminax/ux-sweet-alert/llms.txt Create custom components by extending InputModal to process results on the server. ```php isConfirmed && $result->value) { // Create project with the provided name $projectName = $result->value; // Your project creation logic here... } } } ``` ```twig {# templates/project/create.html.twig #} New Project ``` -------------------------------- ### Customize Button Colors and Apply Dark Theme Source: https://github.com/pentiminax/ux-sweet-alert/blob/main/docs/src/content/docs/guide/themes-and-styling.mdx Control individual button colors and apply a general theme. This allows for fine-grained styling beyond the default theme. ```php $alertManager ->question('Archive item?') ->confirmButtonColor('#ff6b4f') ->cancelButtonColor('#2f4858') ->denyButtonColor('#f4b400') ->theme(Theme::Dark); ``` -------------------------------- ### Create a Toast Notification Source: https://context7.com/pentiminax/ux-sweet-alert/llms.txt The `toast` method creates a non-blocking, auto-dismissing notification. Configure its appearance, position, and timer for user feedback. ```php toast( title: 'Profile Updated', text: 'Changes have been saved.', icon: Icon::SUCCESS, position: Position::TOP_END, timer: 3500, timerProgressBar: true ); return $this->render('profile/index.html.twig'); } } ``` -------------------------------- ### Configure alerts using the fluent API Source: https://context7.com/pentiminax/ux-sweet-alert/llms.txt The Alert object supports method chaining to customize modal appearance, buttons, and behavior. ```php html('Rich HTML content is supported.') ->setFooter('Need help? Contact support') ->setImageUrl('/images/logo.png') ->setImageHeight(100) ->setImageAlt('Company Logo') ->theme(Theme::Bootstrap5) ->withCancelButton() ->withDenyButton() ->confirmButtonText('Accept') ->cancelButtonText('Decline') ->setDenyButtonText('Maybe Later') ->confirmButtonColor('#28a745') ->cancelButtonColor('#6c757d') ->denyButtonColor('#ffc107') ->reverseButtons() ->denyOutsideClick() ->denyEscapeKey() ->setDraggable(true) ->setFocusConfirm(false); $alertManager->addAlert($alert); return $this->render('custom/alert.html.twig'); } } ``` -------------------------------- ### Ask for input from PHP Source: https://github.com/pentiminax/ux-sweet-alert/blob/main/docs/src/content/docs/getting-started/quick-start.mdx Use the input method with an input type object to prompt the user for data within a dialog. ```php use Pentiminax\UX\SweetAlert\InputType\Text; $alertManager->input( inputType: new Text( label: 'Display name', value: 'Tanguy', placeholder: 'Enter your public name' ), title: 'Update profile', text: 'This value will be shown to other users.' ); ``` -------------------------------- ### Implement ConfirmButton component Source: https://github.com/pentiminax/ux-sweet-alert/blob/main/docs/src/content/docs/integrations/live-components.mdx Displays a confirmation modal using the SweetAlert ConfirmButton component. ```twig ``` -------------------------------- ### AlertManagerInterface::info() Source: https://context7.com/pentiminax/ux-sweet-alert/llms.txt Triggers an informational alert with a blue info icon. ```APIDOC ## AlertManagerInterface::info() ### Description Creates an informational alert with a blue info icon. ### Parameters - **title** (string) - Required - The title of the alert. - **text** (string) - Required - The body text of the alert. ### Request Example $alertManager->info(title: 'Background Sync Finished', text: 'Your cache is fresh again.'); ``` -------------------------------- ### Storage Lifecycle Source: https://github.com/pentiminax/ux-sweet-alert/blob/main/docs/src/content/docs/reference/alert-manager-and-alert-object.mdx How alerts are stored and managed throughout their lifecycle. ```APIDOC ## Storage Lifecycle ### Description Details the session storage mechanism for alerts. ### Storage Mechanism Alerts are stored in the session under the `ux-sweet-alert:alerts` key. `getAlerts()` performs a consume-on-read operation, removing alerts from session storage after they have been retrieved for rendering. ``` -------------------------------- ### AlertManagerInterface::toast() Source: https://context7.com/pentiminax/ux-sweet-alert/llms.txt Creates a lightweight non-blocking toast notification. ```APIDOC ## AlertManagerInterface::toast() ### Description Creates a lightweight non-blocking toast notification that auto-dismisses after a timer. ### Parameters - **title** (string) - Required - The title of the toast. - **text** (string) - Required - The body text of the toast. - **icon** (Enum) - Optional - The icon type (e.g., SUCCESS). - **position** (Enum) - Optional - The screen position of the toast. - **timer** (int) - Optional - Auto-dismiss duration in milliseconds. - **timerProgressBar** (bool) - Optional - Whether to show a progress bar. ``` -------------------------------- ### Create a basic text input alert Source: https://github.com/pentiminax/ux-sweet-alert/blob/main/docs/src/content/docs/guide/input-dialogs.mdx Uses the Text input type to collect a simple string value with a label and placeholder. ```php use Pentiminax\UX\SweetAlert\InputType\Text; $alertManager->input( inputType: new Text( label: 'Display name', value: 'Tanguy', placeholder: 'Enter your public name' ), title: 'Update profile', text: 'This change is visible to other users.' ); ``` -------------------------------- ### Handle browser callback Source: https://github.com/pentiminax/ux-sweet-alert/blob/main/docs/src/content/docs/integrations/live-components.mdx Executes a browser function when a confirmation action is triggered. ```twig Delete ``` -------------------------------- ### AlertManagerInterface::success() Source: https://context7.com/pentiminax/ux-sweet-alert/llms.txt Triggers a success alert with a green checkmark icon. ```APIDOC ## AlertManagerInterface::success() ### Description Creates a success alert with a green checkmark icon. Returns the Alert object for fluent customization. ### Parameters - **title** (string) - Required - The title of the alert. - **text** (string) - Required - The body text of the alert. ### Request Example $alertManager->success(title: 'Settings Saved', text: 'Your preferences have been updated successfully.'); ``` -------------------------------- ### Create Warning Alert Source: https://context7.com/pentiminax/ux-sweet-alert/llms.txt Displays a warning alert with an orange exclamation icon, supporting fluent configuration methods. ```php warning( title: 'Danger Zone', text: 'Only administrators should continue past this point.' ) ->withCancelButton() ->denyOutsideClick() ->denyEscapeKey(); return $this->render('danger_zone/index.html.twig'); } } ``` -------------------------------- ### Typical SweetAlert Configuration Overrides Source: https://github.com/pentiminax/ux-sweet-alert/blob/main/docs/src/content/docs/guide/configuration.mdx Overrides the default SweetAlert configuration to enable flash message conversion and customize button text and visibility. ```yaml sweet_alert: auto_convert_flash_messages: true defaults: position: 'top-end' confirmButtonText: 'Continue' cancelButtonText: 'Go back' showCancelButton: true ``` -------------------------------- ### Alert Manager Methods Source: https://github.com/pentiminax/ux-sweet-alert/blob/main/docs/src/content/docs/reference/alert-manager-and-alert-object.mdx Methods available on the Alert Manager to create and manage alerts. ```APIDOC ## Alert Manager Methods ### Description Methods to create and manage alerts using the Alert Manager. ### Methods - **success(), error(), warning(), info(), question()**: Create modal alerts with a predefined icon. - **toast()**: Create a non-blocking toast notification. - **input()**: Create an alert configured by an input type object. - **addAlert(Alert $alert)**: Push a manually created alert into storage. - **getAlerts()**: Consume queued alerts, optionally converting flash messages. ``` -------------------------------- ### Default SweetAlert Configuration Source: https://github.com/pentiminax/ux-sweet-alert/blob/main/docs/src/content/docs/guide/configuration.mdx Sets the default configuration for SweetAlert, including flash message conversion and various alert display options. ```yaml sweet_alert: auto_convert_flash_messages: false defaults: position: 'center' confirmButtonColor: '#3085d6' cancelButtonColor: '#aaa' denyButtonColor: '#dd6b55' confirmButtonText: 'OK' cancelButtonText: 'Cancel' denyButtonText: 'No' showConfirmButton: true showCancelButton: false showDenyButton: false reverseButtons: false animation: true backdrop: true allowOutsideClick: true allowEscapeKey: true focusConfirm: true draggable: false topLayer: false timer: null timerProgressBar: false theme: 'auto' customClass: [] ``` -------------------------------- ### Queue an alert from a controller Source: https://github.com/pentiminax/ux-sweet-alert/blob/main/docs/src/content/docs/getting-started/quick-start.mdx Inject AlertManagerInterface into a controller method to trigger a success alert before redirecting. ```php use Pentiminax\UX\SweetAlert\AlertManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; final class SettingsController extends AbstractController { #[Route('/settings/save', name: 'app_settings_save')] public function save(AlertManagerInterface $alertManager): Response { $alertManager->success( title: 'Settings saved', text: 'Your preferences have been updated.' ); return $this->redirectToRoute('app_settings_show'); } } ``` -------------------------------- ### Trigger alerts in HTMX responses Source: https://context7.com/pentiminax/ux-sweet-alert/llms.txt Use HxTriggerHelper to inject alerts into the HX-Trigger header when Turbo is not available. ```php success( title: 'Saved', text: 'Your changes are now persisted.' ); // Returns response with header: // HX-Trigger: {"ux-sweet-alert:alert:added":{"alert":{...}}} return HxTriggerHelper::withAlert(new Response('OK'), $alert); } } ``` -------------------------------- ### Create Error Alert Source: https://context7.com/pentiminax/ux-sweet-alert/llms.txt Displays an error alert with a red X icon. ```php error( title: 'Upload Failed', text: 'The file size exceeds the maximum allowed limit of 10MB.' ); return $this->redirectToRoute('app_files'); } } ``` -------------------------------- ### Create select and radio input alerts Source: https://github.com/pentiminax/ux-sweet-alert/blob/main/docs/src/content/docs/guide/input-dialogs.mdx Utilizes Select or Radio input types which require an options array to populate the input choices. ```php use Pentiminax\UX\SweetAlert\InputType\Select; $alertManager->input( inputType: new Select( options: [ 'admin' => 'Admin', 'editor' => 'Editor', ], label: 'Role', value: 'editor' ), title: 'Invite user' ); ``` -------------------------------- ### Create Toast Notifications Source: https://github.com/pentiminax/ux-sweet-alert/blob/main/README.md Use the toast method on the AlertManagerInterface to display non-blocking 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'); } } ``` -------------------------------- ### Basic Toast Notification Source: https://github.com/pentiminax/ux-sweet-alert/blob/main/docs/src/content/docs/guide/toasts.mdx Use this to display a simple toast message with a title, text, position, and timer. Ensure AlertManagerInterface and Position enum are imported. ```php use Pentiminax\UX\SweetAlert\AlertManagerInterface; use Pentiminax\UX\SweetAlert\Enum\Position; $alertManager->toast( title: 'Profile updated', text: 'Changes have been saved.', position: Position::BOTTOM_END, timer: 3500, timerProgressBar: true ); ``` -------------------------------- ### Alert Object Capabilities Source: https://github.com/pentiminax/ux-sweet-alert/blob/main/docs/src/content/docs/reference/alert-manager-and-alert-object.mdx Available methods for customizing the Alert object. ```APIDOC ## Selected `Alert` Capabilities ### Description Methods to customize various aspects of an `Alert` object. ### Categories and Methods #### Buttons - **withCancelButton()** - **withDenyButton()** - **withoutConfirmButton()** - **reverseButtons()** - **confirmButtonText(string $text)** - **cancelButtonText(string $text)** - **setDenyButtonText(string $text)** #### Behavior - **withoutAnimation()** - **withoutBackdrop()** - **denyOutsideClick()** - **denyEscapeKey()** - **setFocusConfirm()** - **setDraggable()** - **setTopLayer()** #### Layout - **position(string $position)** - **theme(string $theme)** - **customClass(array $classes)** (via manager helper arguments) #### Content - **html(string $html)** - **setFooter(string $footerHtml)** - **setImageUrl(string $url)** - **setImageAlt(string $alt)** - **setImageHeight(string $height)** #### Input-related - **input(string $type)** - **inputLabel(string $label)** - **inputPlaceholder(string $placeholder)** - **inputValue(mixed $value)** - **inputAttributes(array $attributes)** - **inputOptions(array $options)** - **validationMessage(string $message)** - **returnInputValueOnDeny()** #### Callbacks - **callbackUrl(string $url)** ``` -------------------------------- ### Alert Serialization Source: https://github.com/pentiminax/ux-sweet-alert/blob/main/docs/src/content/docs/reference/alert-manager-and-alert-object.mdx Details on how the Alert object is serialized to JSON. ```APIDOC ## Serialization ### Description Explains the JSON payload structure when an `Alert` object is serialized. ### JSON Payload Contents The `Alert` object implements `JsonSerializable`. The JSON payload sent to the frontend includes: - Modal settings - When relevant: - `toast`, `timer`, and `timerProgressBar` for toast mode - `backdrop` and `allowOutsideClick` for modal mode - `callbackUrl` when a backend callback was configured. ``` -------------------------------- ### Queue a toast notification Source: https://github.com/pentiminax/ux-sweet-alert/blob/main/docs/src/content/docs/getting-started/quick-start.mdx Use the toast method to display a non-blocking notification with specific positioning and timer settings. ```php use Pentiminax\UX\SweetAlert\Enum\Position; $alertManager->toast( title: 'Profile updated', text: 'Changes were saved successfully.', position: Position::TOP_END, timer: 3000, timerProgressBar: true ); ``` -------------------------------- ### Post input results to a Symfony controller Source: https://github.com/pentiminax/ux-sweet-alert/blob/main/docs/src/content/docs/guide/input-dialogs.mdx Provides a callback URL to handle the SweetAlert result via a POST request. ```php use Pentiminax\UX\SweetAlert\InputType\Text; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; $alertManager->input( inputType: new Text(label: 'Project name'), title: 'Create project', callback: $this->generateUrl('app_project_modal_result', referenceType: UrlGeneratorInterface::ABSOLUTE_URL) ); ``` -------------------------------- ### Render SweetAlert Scripts in Twig Source: https://context7.com/pentiminax/ux-sweet-alert/llms.txt Include the required JavaScript assets in your base template. ```twig {# base.html.twig #} {{ ux_sweet_alert_scripts() }} {% block body %}{% endblock %} ``` -------------------------------- ### Symfony Queue Events Source: https://github.com/pentiminax/ux-sweet-alert/blob/main/docs/src/content/docs/reference/alert-manager-and-alert-object.mdx Information about Symfony events dispatched during the alert queuing process. ```APIDOC ## Symfony Queue Events ### Description Details the Symfony events dispatched by the Alert Manager. ### Events #### `BeforeAlertQueuedEvent` - **When it fires**: Before the alert is stored in session/context. - **Typical use**: Enrich or adjust the mutable `Alert` instance. #### `AlertQueuedEvent` - **When it fires**: After the alert has been stored. - **Typical use**: Observe, log, or trigger side effects. Listeners receive the same `Alert` object that the manager persists. Changes made during `BeforeAlertQueuedEvent` are reflected in storage and rendering. ### Example Listener ```php use Pentiminax\UX\SweetAlert\Event\BeforeAlertQueuedEvent; use Pentiminax\UX\SweetAlert\Enum\Theme; use Symfony\Component\EventDispatcher\Attribute\AsEventListener; #[AsEventListener] final class BrandAlertsListener { public function __invoke(BeforeAlertQueuedEvent $event): void { $event->getAlert() ->theme(Theme::Dark) ->withCancelButton(); } } ``` ``` -------------------------------- ### Toast Notification with Icon Source: https://github.com/pentiminax/ux-sweet-alert/blob/main/docs/src/content/docs/guide/toasts.mdx Add an icon to your toast notification for visual emphasis. Import the Icon enum for this functionality. ```php use Pentiminax\UX\SweetAlert\Enum\Icon; $alertManager->toast( title: 'Heads up', text: 'You are close to your rate limit.', icon: Icon::WARNING, timer: 5000 ); ``` -------------------------------- ### UX SweetAlert Icon Enum Values Source: https://context7.com/pentiminax/ux-sweet-alert/llms.txt Lists the available icons within the Icon enum. Each icon corresponds to a specific visual representation for alerts. ```php Delete Article {# With browser callback #} Archive {# With custom classes #} Confirm ``` -------------------------------- ### Create Alerts with AlertManagerInterface Source: https://github.com/pentiminax/ux-sweet-alert/blob/main/README.md Inject the AlertManagerInterface into your controller to trigger success or other alert types. ```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'); } ``` -------------------------------- ### AlertManagerInterface::warning() Source: https://context7.com/pentiminax/ux-sweet-alert/llms.txt Triggers a warning alert with an orange exclamation icon. ```APIDOC ## AlertManagerInterface::warning() ### Description Creates a warning alert with an orange exclamation icon for cautionary messages. Supports fluent methods like withCancelButton(), denyOutsideClick(), and denyEscapeKey(). ### Parameters - **title** (string) - Required - The title of the alert. - **text** (string) - Required - The body text of the alert. ### Request Example $alertManager->warning(title: 'Danger Zone', text: 'Only administrators should continue past this point.')->withCancelButton(); ``` -------------------------------- ### AlertManagerInterface::error() Source: https://context7.com/pentiminax/ux-sweet-alert/llms.txt Triggers an error alert with a red X icon. ```APIDOC ## AlertManagerInterface::error() ### Description Creates an error alert with a red X icon for displaying failures or validation errors. ### Parameters - **title** (string) - Required - The title of the alert. - **text** (string) - Required - The body text of the alert. ### Request Example $alertManager->error(title: 'Upload Failed', text: 'The file size exceeds the maximum allowed limit of 10MB.'); ``` -------------------------------- ### Implement InputModal Component in Twig Source: https://context7.com/pentiminax/ux-sweet-alert/llms.txt Use the InputModal component to collect user input via text, select, or textarea fields. ```twig {# templates/team/invite.html.twig #} {# Text input #} Create Project {# Select input #} Invite Member {# Textarea input #} Add Note ``` -------------------------------- ### Include SweetAlert Scripts in Twig Source: https://github.com/pentiminax/ux-sweet-alert/blob/main/README.md Add this Twig function to your base layout file to enable SweetAlert functionality. ```twig {{ ux_sweet_alert_scripts() }} ``` -------------------------------- ### Customize Alert Before Queuing Source: https://github.com/pentiminax/ux-sweet-alert/blob/main/docs/src/content/docs/reference/alert-manager-and-alert-object.mdx Use BeforeAlertQueuedEvent to modify an Alert instance before it is stored. This listener applies a dark theme and adds a cancel button to the alert. ```php use Pentiminax\UX\SweetAlert\Event\BeforeAlertQueuedEvent; use Pentiminax\UX\SweetAlert\Enum\Theme; use Symfony\Component\EventDispatcher\Attribute\AsEventListener; #[AsEventListener] final class BrandAlertsListener { public function __invoke(BeforeAlertQueuedEvent $event): void { $event->getAlert() ->theme(Theme::Dark) ->withCancelButton(); } } ``` -------------------------------- ### Access Theme Enum Values Source: https://context7.com/pentiminax/ux-sweet-alert/llms.txt Use the Theme enum to select the visual style of the SweetAlert2 modal. ```php input( inputType: new Text( label: 'Display name', inputAttributes: ['maxlength' => '40'] ), title: 'Update profile' ) ->validationMessage('A display name is required.') ->withCancelButton(); ``` -------------------------------- ### Turbo Stream HTML Fragment Source: https://github.com/pentiminax/ux-sweet-alert/blob/main/docs/src/content/docs/integrations/turbo.mdx The rendered fragment appended to HTML responses when Turbo is enabled. ```html ``` -------------------------------- ### Access Position Enum Values Source: https://context7.com/pentiminax/ux-sweet-alert/llms.txt Use the Position enum to define the placement of modals. ```php