/// <summary> /// Normalizes the arguments you can give to Swal.fire() in an object of type SweetAlertOptions. /// </summary> /// <param name="paramaters">The array of arguments to normalize.</param> /// <exception cref="ArgumentException">Thrown if parameters is not 1, 2, or 3 elements long.</exception> public SweetAlertOptions ArgsToParams(IEnumerable <string> paramaters) { if (paramaters == null) { throw new ArgumentNullException(nameof(paramaters)); } int paramLength = paramaters.Count(); if (paramLength > 3 || paramLength < 1) { throw new ArgumentException("Parameters can only be 1, 2, or 3 elements long."); } var paramEnum = paramaters.GetEnumerator(); paramEnum.MoveNext(); var optionsToReturn = new SweetAlertOptions { Title = paramEnum.Current }; if (paramEnum.MoveNext()) { optionsToReturn.Html = paramEnum.Current; } if (paramEnum.MoveNext()) { optionsToReturn.Icon = paramEnum.Current; } return(optionsToReturn); }
/// <summary> /// Function to display a SweetAlert2 modal, with an object of options, all being optional. /// </summary> /// <param name="settings"></param> public Task <SweetAlertResult> FireAsync(SweetAlertOptions settings) { if (settings == null) { throw new ArgumentNullException(nameof(settings)); } return(this.swal.FireAsync(this.Mix(settings))); }
/// <summary> /// Reuse configuration by creating a Swal instance. /// </summary> /// <param name="settings">The default options to set for this instance.</param> /// <returns></returns> public SweetAlertMixin Mixin(SweetAlertOptions settings) { if (settings == null) { throw new ArgumentNullException(nameof(settings)); } return(new SweetAlertMixin(this.Mix(settings), this.swal)); }
/// <summary> /// Inserts a modal in the queue. /// </summary> /// <param name="step">The step configuration (same object as in the Swal.fire() call).</param> /// <param name="index">The index to insert the step at. By default a modal will be added to the end of a queue.</param> public Task <double> InsertQueueStepAsync(SweetAlertOptions step, double?index = null) { if (step == null) { throw new ArgumentNullException(nameof(step)); } return(this.swal.InsertQueueStepAsync(this.Mix(step), index)); }
/// <summary> /// Function to display a simple SweetAlert2 modal. /// </summary> /// <param name="title"></param> /// <param name="message"></param> /// <param name="icon"></param> /// <returns></returns> public Task <SweetAlertResult> FireAsync(string title = null, string message = null, SweetAlertIcon icon = null) { SweetAlertOptions newSettings = this.Mix(this.storedOptions); newSettings.Title = title; newSettings.Html = message ?? newSettings.Html; newSettings.Icon = icon ?? newSettings.Icon; return(this.swal.FireAsync(newSettings)); }
/// <summary> /// Updates popup options. /// </summary> /// <param name="newSettings"></param> public Task UpdateAsync(SweetAlertOptions newSettings) { if (newSettings == null) { throw new ArgumentNullException(nameof(newSettings)); } return(this.swal.UpdateAsync(this.Mix(newSettings))); }
public async Task InfoAsync(string mensagem) { var alert = new SweetAlertOptions { Title = "Informação", Text = mensagem, Icon = SweetAlertIcon.Success, ShowConfirmButton = false, Timer = 1500 }; await Swal.FireAsync(alert); }
/// <summary> /// Inserts a modal in the queue. /// </summary> /// <param name="step">The step configuration (same object as in the Swal.fire() call).</param> /// <param name="index">The index to insert the step at. By default a modal will be added to the end of a queue.</param> public Task <double> InsertQueueStepAsync(SweetAlertOptions step, double?index = null) { if (step == null) { throw new ArgumentNullException(nameof(step)); } var requestId = Guid.NewGuid(); AddCallbackToDictionaries(step, requestId); return(jSRuntime.InvokeAsync <double>($"{JS_NAMESPACE}.InsertQueueStep", requestId, step.ToPOCO(), index).AsTask()); }
/// <summary> /// Updates popup options. /// </summary> /// <param name="newSettings"></param> public async Task UpdateAsync(SweetAlertOptions newSettings) { if (newSettings == null) { throw new ArgumentNullException(nameof(newSettings)); } Guid requestId = Guid.NewGuid(); AddCallbackToDictionaries(newSettings, requestId); await jSRuntime.InvokeAsync <SweetAlertResult>( $"{JS_NAMESPACE}.Update", requestId, newSettings.ToPOCO()).ConfigureAwait(false); }
private static void AddCallbackToDictionaries(SweetAlertOptions settings, Guid requestId) { if (settings.PreConfirm != null) { PreConfirmCallbacks.Add(requestId, settings.PreConfirm); } if (settings.InputValidator != null) { InputValidatorCallbacks.Add(requestId, settings.InputValidator); } if (settings.OnOpen != null) { OnOpenCallbacks.Add(requestId, settings.OnOpen); } if (settings.OnClose != null) { OnCloseCallbacks.Add(requestId, settings.OnClose); } if (settings.OnRender != null) { OnRenderCallbacks.Add(requestId, settings.OnRender); } if (settings.OnBeforeOpen != null) { OnBeforeOpenCallbacks.Add(requestId, settings.OnBeforeOpen); } if (settings.OnAfterClose != null) { OnAfterCloseCallbacks.Add(requestId, settings.OnAfterClose); } if (settings.OnDestroy != null) { OnDestroyCallbacks.Add(requestId, settings.OnDestroy); } }
/// <summary> /// Function to display a SweetAlert2 modal, with an object of options, all being optional. /// </summary> /// <example> /// <code> /// Swal.FireAsync(new SweetAlertOptions { /// Title = "Auto close alert!", /// Text = "I will close in 2 seconds.", /// Timer = 2000 /// }); /// </code> /// </example> /// <param name="settings"></param> public async Task <SweetAlertResult> FireAsync(SweetAlertOptions settings) { if (settings == null) { throw new ArgumentNullException(nameof(settings)); } var tcs = new TaskCompletionSource <SweetAlertResult>(); Guid requestId = Guid.NewGuid(); PendingFireRequests.Add(requestId, tcs); AddCallbackToDictionaries(settings, requestId); await jSRuntime.InvokeAsync <SweetAlertResult>( $"{JS_NAMESPACE}.FireSettings", requestId, settings.ToPOCO(), (int)theme, colorSchemeThemes).ConfigureAwait(false); return(await tcs.Task.ConfigureAwait(false)); }
/// <summary> /// Reuse configuration by creating a Swal instance. /// </summary> /// <param name="settings">The default options to set for this instance.</param> /// <returns></returns> public SweetAlertMixin Mixin(SweetAlertOptions settings) { return(new SweetAlertMixin(settings, this)); }
private SweetAlertOptions Mix(SweetAlertOptions newSettings) { return(new SweetAlertOptions { Title = newSettings.Title ?? this.storedOptions.Title, TitleText = newSettings.TitleText ?? this.storedOptions.TitleText, Text = newSettings.Text ?? this.storedOptions.Text, Html = newSettings.Html ?? this.storedOptions.Html, Footer = newSettings.Footer ?? this.storedOptions.Footer, Icon = newSettings.Icon ?? this.storedOptions.Icon, IconHtml = newSettings.IconHtml ?? this.storedOptions.IconHtml, Backdrop = newSettings.Backdrop ?? this.storedOptions.Backdrop, Toast = newSettings.Toast ?? this.storedOptions.Toast, Target = newSettings.Target ?? this.storedOptions.Target, Input = newSettings.Input ?? this.storedOptions.Input, Width = newSettings.Width ?? this.storedOptions.Width, Padding = newSettings.Padding ?? this.storedOptions.Padding, Background = newSettings.Background ?? this.storedOptions.Background, Position = newSettings.Position ?? this.storedOptions.Position, Grow = newSettings.Grow ?? this.storedOptions.Grow, ShowClass = newSettings.ShowClass ?? this.storedOptions.ShowClass, HideClass = newSettings.HideClass ?? this.storedOptions.HideClass, CustomClass = newSettings.CustomClass ?? this.storedOptions.CustomClass, Timer = newSettings.Timer ?? this.storedOptions.Timer, TimerProgressBar = newSettings.TimerProgressBar ?? this.storedOptions.TimerProgressBar, HeightAuto = newSettings.HeightAuto ?? this.storedOptions.HeightAuto, AllowOutsideClick = newSettings.AllowOutsideClick ?? this.storedOptions.AllowOutsideClick, AllowEscapeKey = newSettings.AllowEscapeKey ?? this.storedOptions.AllowEscapeKey, AllowEnterKey = newSettings.AllowEnterKey ?? this.storedOptions.AllowEnterKey, StopKeydownPropagation = newSettings.StopKeydownPropagation ?? this.storedOptions.StopKeydownPropagation, KeydownListenerCapture = newSettings.KeydownListenerCapture ?? this.storedOptions.KeydownListenerCapture, ShowConfirmButton = newSettings.ShowConfirmButton ?? this.storedOptions.ShowConfirmButton, ShowCancelButton = newSettings.ShowCancelButton ?? this.storedOptions.ShowCancelButton, ConfirmButtonText = newSettings.ConfirmButtonText ?? this.storedOptions.ConfirmButtonText, CancelButtonText = newSettings.CancelButtonText ?? this.storedOptions.CancelButtonText, ConfirmButtonColor = newSettings.ConfirmButtonColor ?? this.storedOptions.ConfirmButtonColor, CancelButtonColor = newSettings.CancelButtonColor ?? this.storedOptions.CancelButtonColor, ConfirmButtonAriaLabel = newSettings.ConfirmButtonAriaLabel ?? this.storedOptions.ConfirmButtonAriaLabel, CancelButtonAriaLabel = newSettings.CancelButtonAriaLabel ?? this.storedOptions.CancelButtonAriaLabel, ButtonsStyling = newSettings.ButtonsStyling ?? this.storedOptions.ButtonsStyling, ReverseButtons = newSettings.ReverseButtons ?? this.storedOptions.ReverseButtons, FocusConfirm = newSettings.FocusConfirm ?? this.storedOptions.FocusConfirm, FocusCancel = newSettings.FocusCancel ?? this.storedOptions.FocusCancel, ShowCloseButton = newSettings.ShowCloseButton ?? this.storedOptions.ShowCloseButton, CloseButtonHtml = newSettings.CloseButtonHtml ?? this.storedOptions.CloseButtonHtml, CloseButtonAriaLabel = newSettings.CloseButtonAriaLabel ?? this.storedOptions.CloseButtonAriaLabel, ShowLoaderOnConfirm = newSettings.ShowLoaderOnConfirm ?? this.storedOptions.ShowLoaderOnConfirm, PreConfirm = newSettings.PreConfirm ?? this.storedOptions.PreConfirm, ImageUrl = newSettings.ImageUrl ?? this.storedOptions.ImageUrl, ImageWidth = newSettings.ImageWidth ?? this.storedOptions.ImageWidth, ImageHeight = newSettings.ImageHeight ?? this.storedOptions.ImageHeight, ImageAlt = newSettings.ImageAlt ?? this.storedOptions.ImageAlt, InputPlaceholder = newSettings.InputPlaceholder ?? this.storedOptions.InputPlaceholder, InputValue = newSettings.InputValue ?? this.storedOptions.InputValue, InputOptions = newSettings.InputOptions ?? this.storedOptions.InputOptions, InputAutoTrim = newSettings.InputAutoTrim ?? this.storedOptions.InputAutoTrim, InputAttributes = newSettings.InputAttributes ?? this.storedOptions.InputAttributes, InputValidator = newSettings.InputValidator ?? this.storedOptions.InputValidator, ValidationMessage = newSettings.ValidationMessage ?? this.storedOptions.ValidationMessage, ProgressSteps = newSettings.ProgressSteps ?? this.storedOptions.ProgressSteps, CurrentProgressStep = newSettings.CurrentProgressStep ?? this.storedOptions.CurrentProgressStep, ProgressStepsDistance = newSettings.ProgressStepsDistance ?? this.storedOptions.ProgressStepsDistance, OnBeforeOpen = newSettings.OnBeforeOpen ?? this.storedOptions.OnBeforeOpen, OnAfterClose = newSettings.OnAfterClose ?? this.storedOptions.OnAfterClose, OnDestroy = newSettings.OnDestroy ?? this.storedOptions.OnDestroy, OnOpen = newSettings.OnOpen ?? this.storedOptions.OnOpen, OnClose = newSettings.OnClose ?? this.storedOptions.OnClose, OnRender = newSettings.OnRender ?? this.storedOptions.OnRender, ScrollbarPadding = newSettings.ScrollbarPadding ?? this.storedOptions.ScrollbarPadding, }); }
internal SweetAlertMixin(SweetAlertOptions settings, SweetAlertService service) { this.storedOptions = settings; this.swal = service; }