All Projects → Basaingeal → Razor.SweetAlert2

Basaingeal / Razor.SweetAlert2

Licence: MIT License
A Razor class library for interacting with SweetAlert2

Programming Languages

C#
18002 projects
typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Razor.SweetAlert2

Sweetalert2
A beautiful, responsive, highly customizable and accessible (WAI-ARIA) replacement for JavaScript's popup boxes. Zero dependencies.
Stars: ✭ 13,929 (+14113.27%)
Mutual labels:  notifications, alert, sweetalert, sweetalert2, dialog, prompt, popup, toast, confirm, confirmation-dialog
Alertifyjs
A javascript framework for developing pretty browser dialogs and notifications.
Stars: ✭ 1,922 (+1861.22%)
Mutual labels:  notifications, alert, dialog, prompt, confirm
Notie
🔔 a clean and simple notification, input, and selection suite for javascript, with no dependencies
Stars: ✭ 6,170 (+6195.92%)
Mutual labels:  notifications, alert, prompt, toast, confirm
react-st-modal
Simple and flexible modal dialog component for React JS
Stars: ✭ 41 (-58.16%)
Mutual labels:  alert, dialog, prompt, confirm
Jbox
jBox is a jQuery plugin that makes it easy to create customizable tooltips, modal windows, image galleries and more.
Stars: ✭ 1,251 (+1176.53%)
Mutual labels:  alert, dialog, popup, confirm
Jquery Confirm
A multipurpose plugin for alert, confirm & dialog, with extended features.
Stars: ✭ 1,776 (+1712.24%)
Mutual labels:  alert, dialog, popup, confirm
Alerttoast
Create Apple-like alerts & toasts using SwiftUI
Stars: ✭ 151 (+54.08%)
Mutual labels:  alert, dialog, popup, toast
Wc Messagebox
基于 Vue 2.0 开发的 Alert, Toast, Confirm 插件, UI仿照 iOS 原生
Stars: ✭ 203 (+107.14%)
Mutual labels:  alert, dialog, toast, confirm
vue2-dialog
A mobile Vue plugin for VueDialog
Stars: ✭ 21 (-78.57%)
Mutual labels:  alert, dialog, toast, confirm
BalloonPopup
Forget Android Toast! BalloonPopup displays a round or squared popup and attaches it to a View, like a callout. Uses the Builder pattern for maximum ease. The popup can automatically hide and can persist when the value is updated.
Stars: ✭ 32 (-67.35%)
Mutual labels:  alert, dialog, popup, toast
jquery.dialog.js
A lightweight replacement for the browser's default dialog boxes.
Stars: ✭ 17 (-82.65%)
Mutual labels:  alert, dialog, prompt, confirm
php-flasher
🔔 Flasher is a powerful and flexible flash notifications system for PHP, Laravel, Symfony
Stars: ✭ 68 (-30.61%)
Mutual labels:  notifications, sweetalert, sweetalert2, toast
Alertjs
Dialog Builder allows you to create fully customisable dialogs and popups in Dynamics 365.
Stars: ✭ 80 (-18.37%)
Mutual labels:  alert, dialog, prompt, popup
Notiflix
Notiflix is a JavaScript library for client-side non-blocking notifications, popup boxes, loading indicators, and more that makes your web projects much better.
Stars: ✭ 172 (+75.51%)
Mutual labels:  notifications, alert, toast, confirm
React Native Alert Pro
The Pro Version of React Native Alert (Android & iOS)
Stars: ✭ 69 (-29.59%)
Mutual labels:  alert, dialog, popup, confirm
Sweetalert
A beautiful replacement for JavaScript's "alert"
Stars: ✭ 21,871 (+22217.35%)
Mutual labels:  alert, sweetalert, dialog, popup
Sweet Alert
A BEAUTIFUL, RESPONSIVE, CUSTOMIZABLE, ACCESSIBLE (WAI-ARIA) REPLACEMENT FOR JAVASCRIPT'S POPUP BOXES FOR LARAVEL
Stars: ✭ 696 (+610.2%)
Mutual labels:  dialog, prompt, popup, toast
Vuejs Dialog
A lightweight, promise based alert, prompt and confirm dialog
Stars: ✭ 327 (+233.67%)
Mutual labels:  alert, dialog, prompt, confirm
mobile-message
基于移动端的弹窗组件,默认提供info、success、warning、error、alert、confirm、multiple、vertical、bottomSheet、prompt,可自定义弹窗。它可以包含任何Html内容可以自定义弹窗的样式,也可以加入自定以的弹窗动画。
Stars: ✭ 13 (-86.73%)
Mutual labels:  alert, dialog, prompt, confirm
Popmodal
jquery plugin for showing tooltips, titles, modal dialogs and etc
Stars: ✭ 149 (+52.04%)
Mutual labels:  notifications, dialog, popup, confirm

CurrieTechnologies.Razor.SweetAlert2

Blazor

SweetAlert2
A beautiful, responsive, customizable, accessible (WAI-ARIA) replacement for JavaScript's popup boxes.
All wrapped inside a Razor Component Library for use in Blazor Server and WebAssembly applications.
SweetAlert2 in action
See SweetAlert2 in action
Master Develop Version Downloads Mergify
Build Status Build Status Nuget Nuget mergify-status

👉 Upgrading from v3.x to v4.x? Read the release notes!

👉 Upgrading from v4.x to v5.x? Read the release notes!

This package is for both Blazor Server Apps and Blazor WebAssembly Apps. It should be used instead of CurrieTechnologies.Blazor.SweetAlert2 which is now deprecated.

🙌 Includes themes from the Official SweetAlert2 Themes project 🙌

Installation

Install-Package CurrieTechnologies.Razor.SweetAlert2

Or install from the NuGet Package Manager

Usage

Register the service in your Startup file.

// Startup.cs
public void ConfigureServices(IServiceCollection services)
{
...
 services.AddSweetAlert2();
...
}

OR

If you want to use one of the Official SweetAlert2 themes

// Startup.cs
public void ConfigureServices(IServiceCollection services)
{
...
 services.AddSweetAlert2(options => {
   options.Theme = SweetAlertTheme.Dark;
 });
...
}

See Configuration for more information.

Add this script tag in your root html file (Likely _Host.cshtml for Blazor Server or index.html for Blazor WebAssembly), right under the framework script tag. (i.e <script src="_framework/blazor.server.js"></script> for Blazor Server or <script src="_framework/blazor.webassembly.js"></script> for Blazor WebAssembly)

<script src="_content/CurrieTechnologies.Razor.SweetAlert2/sweetAlert2.min.js"></script>

If you need to support IE11, this script tag is different. See IE Compatibility.

Inject the SweetAlertService into any Blazor component.

// Sample.razor
@inject SweetAlertService Swal;
<button class="btn btn-primary"
   @onclick="(async () => await Swal.FireAsync("Any fool can use a computer"))">
 Try me!
</button>

Examples

The most basic message:

await Swal.FireAsync("Hello world!");

A message signaling an error:

await Swal.FireAsync("Oops...", "Something went wrong!", "error");

Handling the result of SweetAlert2 modal:

// async/await
SweetAlertResult result = await Swal.FireAsync(new SweetAlertOptions
 {
   Title = "Are you sure?",
   Text = "You will not be able to recover this imaginary file!",
   Icon = SweetAlertIcon.Warning,
   ShowCancelButton = true,
   ConfirmButtonText = "Yes, delete it!",
   CancelButtonText = "No, keep it"
 });

if (!string.IsNullOrEmpty(result.Value))
{
 await Swal.FireAsync(
   "Deleted",
   "Your imaginary file has been deleted.",
   SweetAlertIcon.Success
   );
}
else if (result.Dismiss == DismissReason.Cancel)
{
 await Swal.FireAsync(
   "Cancelled",
   "Your imaginary file is safe :)",
   SweetAlertIcon.Error
   );
}

// Promise/Task based
Swal.FireAsync(new SweetAlertOptions
 {
   Title = "Are you sure?",
   Text = "You will not be able to recover this imaginary file!",
   Icon = SweetAlertIcon.Warning,
   ShowCancelButton = true,
   ConfirmButtonText = "Yes, delete it!",
   CancelButtonText = "No, keep it"
 }).ContinueWith(swalTask =>
 {
   SweetAlertResult result = swalTask.Result;
   if (!string.IsNullOrEmpty(result.Value))
   {
     Swal.FireAsync(
       "Deleted",
       "Your imaginary file has been deleted.",
       SweetAlertIcon.Success
       );
   }
   else if (result.Dismiss == DismissReason.Cancel)
   {
     Swal.FireAsync(
       "Cancelled",
       "Your imaginary file is safe :)",
       SweetAlertIcon.Error
       );
   }
 });

More examples can be found on the SweetAlert2 project site

Configuration

In Startup.cs you have the opportunity to configure how sweetalert2 will behave in your application.

Theme

With SweetAlertServiceOptions.Theme you can specify one of the official sweetalert2 themes to apply to your modal throughout your application.

SetThemeForColorSchemePreference()

With the SweetAlertServiceOptions.SetThemeForColorSchemePreference() method, you can specify which theme the user uses, based on the result of their prefers-color-scheme CSS media query. Most commonly this can be used to help create a dark version of your application, based on user preference. Browsers that do not support the prefers-color-scheme media query will fall back to the theme specified in SweetAlertServiceOptions.Theme

Theme Examples

If you want the default theme by default, and the dark theme if the user prefers a dark color scheme:

services.AddSweetAlert2(options => {
 options.SetThemeForColorSchemePreference(ColorScheme.Dark, SweetAlertTheme.Dark);
});

A dark theme by default, and a lighter theme if the user prefers a light color scheme:

services.AddSweetAlert2(options => {
 options.Theme = SweetAlertTheme.Dark;
 options.SetThemeForColorSchemePreference(ColorScheme.Light, SweetAlertTheme.Bootstrap4);
});

A minimal theme as a fallback, and a dark/light theme to match user preference:

services.AddSweetAlert2(options => {
 options.Theme = SweetAlertTheme.Minimal;
 options.SetThemeForColorSchemePreference(ColorScheme.Light, SweetAlertTheme.Default);
 options.SetThemeForColorSchemePreference(ColorScheme.Dark, SweetAlertTheme.Dark);
});

See prefers-color-scheme for more information.

Default Settings

If you want some settings globally applied to all of your SweetAlert2 dialogs, configure your default settings in Startup.cs

services.AddSweetAlert2(options => {
 options.DefaultOptions = new SweetAlertOptions {
   HeightAuto = false
 };
});

These can be overriden in individual FireAsync() calls.

NB: This will only apply to FireAsync() calls that take a SweetAlertOptions object as a parameter. The methods that take in primitive types bypass SweetAlertOptions entirely on both the C# and JS libraries.

Notable differences from the JavaScript library

  • No methods that return an HTMLElement are included (e. g. Swal.getHtmlContainer())
  • The value of a SweetAlertResult (result.Value) can only be a string. Numbers and booleans must be converted. Object must be parsed to/from JSON in your code.
  • DidOpenAsync(), WillCloseAsync(), WillOpenAsync(), and DidCloseAsync() can all take asynchronous callbacks. 🎉 (none will return an HTMLElement though.)
  • No support for <optgroup> in the select input type.
  • No async option for InputOptions or InputValue
  • Callbacks must be passed inside of objects specifically designed for the given callback property. e.g. the InputValidator property takes an InputValidatorCallback created like so:
new SweetAlertOptions {
 ...
 InputValidator = new InputValidatorCallback((string input) => input.Length == 0 ? "Please provide a value" : null, this),
 ...
}

this is passed in so that the Blazor EventCallback used behind the scenes can trigger a re-render if the state of the calling component was changed in the callback. If the callback does not require the calling component to re-render, passing in this is optional. These callbacks are necessary because there is currently no way to create an EventCallback in Blazor that isn't a component parameter without using the EventCallbackFactory which is clunky. It also allows the callback to return a value that can be used by the SweetAlert2 library. (e.g. A validation message to show if input validation fails.) Native Blazor EventCallbacks only return generic Tasks.

Browser compatibility

IE11* Edge Chrome Firefox Safari Opera UC Browser

IE Compatibility*

IE Compatibility has been removed in v5 due to sweetalert2@11 dropping their support for it.

If you need to support IE11, use v4 or earlier, and use this script tag instead. (file size is about 35% larger)

<script src="_content/CurrieTechnologies.Razor.SweetAlert2/sweetAlert2.ieCompat.min.js"></script>

You will also likely need to utilize the Blazor.Polyfill library, for general Blazor functionality in IE.

Related projects

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].