Exemple #1
0
 private async Task Modal_OnUpdate(ConfirmOptions props)
 {
     if (props.Visible)
     {
         await InvokeAsync(StateHasChanged);
     }
 }
Exemple #2
0
        private async Task OnRemove(ConfirmOptions obj)
        {
            await Task.Delay(250);

            confirms.Remove(obj);
            await InvokeAsync(StateHasChanged);
        }
Exemple #3
0
        private DialogOptions BuildDialogOptions(ConfirmOptions confirmOptions)
        {
            DialogOptions config = new DialogOptions()
            {
                Title             = confirmOptions.Title,
                OkButtonProps     = confirmOptions.OkButtonProps,
                CancelButtonProps = confirmOptions.CancelButtonProps,
                Width             = confirmOptions.Width,
                Centered          = confirmOptions.Centered,
                Mask               = confirmOptions.Mask,
                MaskClosable       = confirmOptions.MaskClosable,
                MaskStyle          = confirmOptions.MaskStyle,
                OkText             = confirmOptions.OkText,
                OkType             = confirmOptions.OkType,
                CancelText         = confirmOptions.CancelText,
                CloseIcon          = confirmOptions.Icon,
                ZIndex             = confirmOptions.ZIndex,
                Keyboard           = confirmOptions.Keyboard,
                GetContainer       = confirmOptions.GetContainer,
                Footer             = null,
                TransitionName     = confirmOptions.TransitionName,
                MaskTransitionName = confirmOptions.MaskTransitionName,

                ClassName = confirmOptions.ClassName,
            };

            config.ClassName      = "ant-modal-confirm ant-modal-confirm-" + confirmOptions.ConfirmType;
            config.DestroyOnClose = true;
            config.Width          = 416;
            config.Title          = null;
            config.CloseIcon      = null;
            config.OnClosed       = new EventCallback(this, new Func <Task>(Close));
            config.OnCancel       = new EventCallback <MouseEventArgs>(this, new Func <MouseEventArgs, Task>(HandleCancel));
            return(config);
        }
        public async Task <ModalRef> Confirm(ConfirmOptions props)
        {
            ModalRef modalRef = new ModalRef(props, this);
            await OnOpenEvent?.Invoke(modalRef);

            return(modalRef);
        }
Exemple #5
0
        private DialogOptions BuildDialogOptions(ConfirmOptions confirmOptions)
        {
            DialogOptions config = new DialogOptions()
            {
                Title             = confirmOptions.Title,
                TitleTemplate     = confirmOptions.TitleTemplate,
                OkButtonProps     = confirmOptions.OkButtonProps,
                CancelButtonProps = confirmOptions.CancelButtonProps,
                Width             = confirmOptions.Width,
                Centered          = confirmOptions.Centered,
                Mask         = confirmOptions.Mask,
                MaskClosable = confirmOptions.MaskClosable,
                MaskStyle    = confirmOptions.MaskStyle,
                OkText       = confirmOptions.OkText,
                OkType       = confirmOptions.OkType,
                CancelText   = confirmOptions.CancelText,
                CloseIcon    = confirmOptions.Icon,
                ZIndex       = confirmOptions.ZIndex,
                Keyboard     = confirmOptions.Keyboard,
                GetContainer = confirmOptions.GetContainer,
                Footer       = null,

                ClassName = confirmOptions.ClassName,
            };

            config.ClassName = "ant-modal-confirm ant-modal-confirm-" + confirmOptions.ConfirmType;
            config.Title     = null;
            config.CloseIcon = null;
            config.OnClosed  = Close;
            config.OnCancel  = ConfirmRef.IsCreateByModalService ? HandleCancel : new Func <MouseEventArgs, Task>(async(e) => await Close());
            return(config);
        }
Exemple #6
0
 private static void CheckIsNull(ConfirmOptions options)
 {
     if (options == null)
     {
         throw new ArgumentNullException(nameof(options));
     }
 }
Exemple #7
0
        /// <summary>
        /// show a confirm dialog like MessageBox of Windows
        /// </summary>
        /// <param name="content">the content of dialog</param>
        /// <param name="title">the title of dialog</param>
        /// <param name="confirmButtons">the buttons of dialog</param>
        /// <param name="confirmIcon">the icon of dialog</param>
        /// <param name="options">the configuration options for dialog</param>
        /// <param name="autoFocusButton">the autofocus button</param>
        /// <returns></returns>
        public async Task <ConfirmResult> Show(
            OneOf <string, RenderFragment> content,
            OneOf <string, RenderFragment> title,
            ConfirmButtons confirmButtons,
            ConfirmIcon confirmIcon,
            ConfirmButtonOptions options,
            ConfirmAutoFocusButton?autoFocusButton = ConfirmAutoFocusButton.Ok)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
            ConfirmOptions confirmOptions = new ConfirmOptions()
            {
                Content        = content,
                ConfirmButtons = confirmButtons,
                ConfirmIcon    = confirmIcon,
            };

            if (autoFocusButton != null)
            {
                confirmOptions.AutoFocusButton = (ConfirmAutoFocusButton)autoFocusButton;
            }

            if (title.IsT0)
            {
                confirmOptions.Title = title.AsT0;
            }
            else
            {
                confirmOptions.TitleTemplate = title.AsT1;
            }

            #region config button default properties

            if (options.Button1Props != null)
            {
                confirmOptions.Button1Props = options.Button1Props;
            }
            if (options.Button2Props != null)
            {
                confirmOptions.Button2Props = options.Button2Props;
            }
            if (options.Button3Props != null)
            {
                confirmOptions.Button3Props = options.Button3Props;
            }

            #endregion

            var confirmRef = new ConfirmRef(confirmOptions)
            {
                TaskCompletionSource = new TaskCompletionSource <ConfirmResult>()
            };
            if (OnOpenEvent != null)
            {
                await OnOpenEvent.Invoke(confirmRef);
            }
            return(await confirmRef.TaskCompletionSource.Task);
        }
        public ConfirmRef Confirm(ConfirmOptions props)
        {
            ConfirmRef confirmRef = new ConfirmRef(props, this);

            confirmRef.TaskCompletionSource = new TaskCompletionSource <ConfirmResult>();
            OnOpenEvent?.Invoke(confirmRef);
            return(confirmRef);
        }
        /// <summary>
        /// Create and open a Moal
        /// </summary>
        /// <param name="config">Options</param>
        /// <returns></returns>
        public Task <ConfirmRef> CreateAsync(ConfirmOptions config)
        {
            CheckIsNull(config);
            ConfirmRef confirmRef = new ConfirmRef(config, this);

            OnOpenEvent?.Invoke(confirmRef);
            return(Task.FromResult(confirmRef));
        }
Exemple #10
0
        public ModalRef Confirm(ConfirmOptions props)
        {
            ModalRef modalRef = new ModalRef(props, this);

            modalRef.TaskCompletionSource = new TaskCompletionSource <ConfirmResult>();
            OnOpenEvent?.Invoke(modalRef);
            return(modalRef);
        }
Exemple #11
0
        /// <summary>
        /// 创建并打开一个简单窗口
        /// </summary>
        /// <param name="config">抽屉参数</param>
        /// <returns></returns>
        public async Task <ModalRef> CreateAsync(ConfirmOptions config)
        {
            CheckIsNull(config);
            ModalRef modalRef = new ModalRef(config, this);

            OnOpenEvent.Invoke(modalRef);
            return(modalRef);
        }
Exemple #12
0
 /// <summary>
 /// create and open a OK-Cancel Confirm dialog with error icon
 /// </summary>
 /// <param name="options"></param>
 /// <returns></returns>
 public ConfirmRef Error(ConfirmOptions options)
 {
     if (options == null)
     {
         throw new ArgumentNullException(nameof(options));
     }
     options.ConfirmIcon = ConfirmIcon.Error;
     options.OkCancel    = false;
     return(Confirm(options));
 }
Exemple #13
0
 public ModalRef Warning(ConfirmOptions options)
 {
     if (options == null)
     {
         throw new ArgumentNullException(nameof(options));
     }
     options.ConfirmIcon = ConfirmIcon.Warning;
     options.OkCancel    = false;
     return(Confirm(options));
 }
Exemple #14
0
 public Task <bool> SuccessAsync(ConfirmOptions options)
 {
     if (options == null)
     {
         throw new ArgumentNullException(nameof(options));
     }
     options.ConfirmIcon = ConfirmIcon.Success;
     options.OkCancel    = false;
     return(ConfirmAsync(options));
 }
Exemple #15
0
        public async Task <bool> ConfirmAsync(ConfirmOptions props)
        {
            ModalRef modalRef = new ModalRef(props, this);

            modalRef.TaskCompletionSource = new TaskCompletionSource <ConfirmResult>();
            await OnOpenEvent?.Invoke(modalRef);

            return(await modalRef.TaskCompletionSource.Task
                   .ContinueWith(t =>
            {
                return t.Result == ConfirmResult.OK;
            }, TaskScheduler.Default));
        }
Exemple #16
0
        /// <summary>
        /// create and open a OK-Cancel Confirm dialog,
        /// and return a bool value which indicates whether the OK button has been clicked
        /// </summary>
        /// <param name="props"></param>
        /// <returns></returns>
        public async Task <bool> ConfirmAsync(ConfirmOptions props)
        {
            ConfirmRef confirmRef = new ConfirmRef(props, this);

            confirmRef.TaskCompletionSource = new TaskCompletionSource <ConfirmResult>();
            if (OnConfirmOpenEvent != null)
            {
                await OnConfirmOpenEvent.Invoke(confirmRef);
            }

            return(await confirmRef.TaskCompletionSource.Task
                   .ContinueWith(t => t.Result == ConfirmResult.OK, TaskScheduler.Default));
        }
Exemple #17
0
        /// <summary>
        /// show a confirm dialog like MessageBox of Windows
        /// </summary>
        /// <param name="content">the content of dialog</param>
        /// <param name="title">the title of dialog</param>
        /// <param name="confirmButtons">the buttons of dialog</param>
        /// <param name="confirmIcon">the icon of dialog</param>
        /// <param name="options">the configuration options for dialog</param>
        /// <returns></returns>
        public async Task <ConfirmResult> Show(
            OneOf <string, RenderFragment> content,
            OneOf <string, RenderFragment> title,
            ConfirmButtons confirmButtons,
            ConfirmIcon confirmIcon,
            ConfirmButtonOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
            ConfirmOptions confirmOptions = new ConfirmOptions()
            {
                Title          = title,
                Content        = content,
                ConfirmButtons = confirmButtons,
                ConfirmIcon    = confirmIcon,
            };

            #region config button default properties

            if (options.Button1Props != null)
            {
                confirmOptions.Button1Props = options.Button1Props;
            }
            if (options.Button2Props != null)
            {
                confirmOptions.Button2Props = options.Button2Props;
            }
            if (options.Button3Props != null)
            {
                confirmOptions.Button3Props = options.Button3Props;
            }

            #endregion

            var modalRef = new ConfirmRef(confirmOptions)
            {
                TaskCompletionSource = new TaskCompletionSource <ConfirmResult>()
            };
            if (OnOpenEvent != null)
            {
                await OnOpenEvent.Invoke(modalRef);
            }
            return(await modalRef.TaskCompletionSource.Task);
        }
 public async Task <ModalRef> Warning(ConfirmOptions options)
 {
     if (options == null)
     {
         throw new ArgumentNullException(nameof(options));
     }
     options.Icon = (builder) =>
     {
         builder.OpenComponent <Icon>(0);
         builder.AddAttribute(1, "Type", "exclamation-circle");
         builder.AddAttribute(2, "Theme", "outline");
         builder.CloseComponent();
     };
     options.OkCancel    = false;
     options.ConfirmType = "warning";
     return(await Confirm(options));
 }
Exemple #19
0
 public void Warning(ConfirmOptions options)
 {
     if (options == null)
     {
         throw new ArgumentNullException(nameof(options));
     }
     options.Icon = (builder) =>
     {
         builder.OpenComponent <AntIcon>(0);
         builder.AddAttribute(1, "Type", "exclamation-circle");
         builder.AddAttribute(2, "Theme", "outline");
         builder.CloseComponent();
     };
     options.OkCancel    = false;
     options.OkText      = "OK";
     options.ConfirmType = "warning";
     Confirm(options);
 }
Exemple #20
0
 public Task Error(ConfirmOptions options)
 {
     if (options == null)
     {
         throw new ArgumentNullException(nameof(options));
     }
     options.Icon = (builder) =>
     {
         builder.OpenComponent <Icon>(0);
         builder.AddAttribute(1, "Type", "close-circle");
         builder.AddAttribute(2, "Theme", "outline");
         builder.CloseComponent();
     };
     options.OkCancel    = false;
     options.OkText      = "OK";
     options.ConfirmType = "error";
     return(Confirm(options));
 }
 internal ConfirmRef(ConfirmOptions config)
 {
     Config = config;
 }
Exemple #22
0
 private async Task Modal_OnDestroy(ConfirmOptions props)
 {
     props.Visible = false;
     await InvokeAsync(StateHasChanged);
 }
Exemple #23
0
 private async Task Modal_OnOpenConfirm(ConfirmOptions obj)
 {
     confirms.Add(obj);
     obj.Visible = true;
     await InvokeAsync(StateHasChanged);
 }
Exemple #24
0
        /// <summary>
        /// 创建并打开一个模板窗口
        /// </summary>
        /// <typeparam name="TComponent"></typeparam>
        /// <typeparam name="TContentParams"></typeparam>
        /// <typeparam name="TResult"></typeparam>
        /// <param name="config"></param>
        /// <param name="contentParams"></param>
        /// <returns></returns>
        public async Task <ModalRef <TResult> > CreateAsync <TComponent, TContentParams, TResult>(ConfirmOptions config, TContentParams contentParams) where TComponent : ModalTemplate <TContentParams, TResult>
        {
            CheckIsNull(config);

            ModalRef <TResult> modalRef = new ModalRef <TResult>(config, this);

            OnOpenEvent.Invoke(modalRef);

            RenderFragment child = (builder) =>
            {
                builder.OpenComponent <TComponent>(0);
                builder.AddAttribute(1, "ModalRef", modalRef);
                builder.AddAttribute(2, "Config", contentParams);
                builder.CloseComponent();
            };

            config.Content = child;

            return(modalRef);
        }
Exemple #25
0
 internal ModalRef(ConfirmOptions config, ModalService service) : base(config, service)
 {
 }
Exemple #26
0
        /// <summary>
        /// Create and open template Confirm dialog
        /// </summary>
        /// <typeparam name="TComponent"></typeparam>
        /// <typeparam name="TComponentOptions"></typeparam>
        /// <typeparam name="TResult"></typeparam>
        /// <param name="config"></param>
        /// <param name="componentOptions"></param>
        /// <returns></returns>
        public Task <ConfirmRef <TResult> > CreateConfirmAsync <TComponent, TComponentOptions, TResult>(ConfirmOptions config, TComponentOptions componentOptions) where TComponent : ConfirmTemplate <TComponentOptions, TResult>
        {
            CheckConfirmOptionsIsNull(config);

            ConfirmRef <TResult> confirmRef = new ConfirmRef <TResult>(config, this);

            OnConfirmOpenEvent?.Invoke(confirmRef);

            RenderFragment child = (builder) =>
            {
                builder.OpenComponent <TComponent>(0);
                builder.AddAttribute(1, "ConfirmRef", confirmRef);
                builder.AddAttribute(2, "Options", componentOptions);
                builder.CloseComponent();
            };

            config.Content = child;

            return(Task.FromResult(confirmRef));
        }
 internal ConfirmRef(ConfirmOptions config, ModalService service)
 {
     Config  = config;
     Service = service;
 }
Exemple #28
0
        /// <summary>
        /// Create and open a OK-Cancel Confirm asynchronous
        /// </summary>
        /// <param name="config">Options</param>
        /// <returns></returns>
        public Task <ConfirmRef> CreateConfirmAsync(ConfirmOptions config)
        {
            var confirmRef = Confirm(config);

            return(Task.FromResult(confirmRef));
        }
 /// <summary>
 /// update Confirm dialog config with a new ConfirmOptions
 /// </summary>
 /// <param name="config"></param>
 /// <returns></returns>
 public async Task UpdateConfigAsync(ConfirmOptions config)
 {
     Config = config;
     await UpdateConfigAsync();
 }
Exemple #30
0
 public Task <ConfirmRef <TResult> > CreateAsync <TComponent, TComponentOptions, TResult>
     (ConfirmOptions config, TComponentOptions componentOptions) where TComponent : ConfirmTemplate <TComponentOptions, TResult>
 {
     return(CreateConfirmAsync <TComponent, TComponentOptions, TResult>(config, componentOptions));
 }