This is a migrated thread and some comments may be shown as answers.

Why such a bad implementation?

2 Answers 325 Views
Notification
This is a migrated thread and some comments may be shown as answers.
Martin
Top achievements
Rank 1
Veteran
Martin asked on 22 Apr 2021, 07:51 AM

Please take a look at https://github.com/Blazored/Toast this is how a toast should be implemented with default methods for ShowInfo
ShowSuccess,,ShowWarning and ShowError

Radzen and many other also have a similar implementation. Please be inspired and give us similar functionality in a upcoming release

2 Answers, 1 is accepted

Sort by
0
Martin
Top achievements
Rank 1
Veteran
answered on 22 Apr 2021, 09:16 AM

I created some extension methods to make live easier

using Telerik.Blazor;
 
namespace EmployeeTrading.Client.Pages
{
    using Telerik.Blazor.Components;
 
    namespace OneNotificationPerApp.Shared
    {
        public class Notification
        {
 
            // set by blazor at runtime @ref component
            public TelerikNotification Instance { get; set; }
             
            public void Info(string msg)
            {
                var m = new NotificationModel
                {
                    Text = msg,
                    ThemeColor = ThemeColors.Info,
                    Icon = "info-circle",
                    CloseAfter = 5000
                };
                Instance.Show(m);
            }
     
            public void Success(string msg)
            {
                var m = new NotificationModel
                {
                    Text = msg,
                    ThemeColor = ThemeColors.Success,
                    Icon = "check-outline",
                    CloseAfter = 5000
                };
                Instance.Show(m);
            }
     
            public void Warning(string msg)
            {
                var m = new NotificationModel
                {
                    Text = msg,
                    ThemeColor = ThemeColors.Warning,
                    Icon = "exclamation-circle",
                    CloseAfter = 5000
                };
                Instance.Show(m);
            }
     
            public void Error(string msg)
            {
                var m = new NotificationModel
                {
                    Text = msg,
                    ThemeColor = ThemeColors.Error,
                    Icon = "x-outline",
                    CloseAfter = 0
                };
                Instance.Show(m);
            }
        }
    }
}
/*** Notification ***/
.bi-notification .k-icon {
    width: 2em;
    height: 2em;
    font-size: 32px;
}
 
.bi-notification .k-notification-content {
    font-size: large;
    align-self: center;
}

 

How to use

if (string.IsNullOrEmpty(filename))
           {
               Notification.Error("Failed to upload the attachment");
           }
           else
           {
               Notification.Success("Attachment uploaded");
           }
0
Hristian Stefanov
Telerik team
answered on 26 Apr 2021, 05:21 PM

Hello Martin,

Great suggestions from you. Your feedback helped us a lot to improve our documentation. We now have examples there for implementing these common notification types. 

We have made changes to the Notification documentation, and you can follow them to see the difference here.

Also, you can see the live preview of the page here: https://github.com/telerik/blazor-docs/blob/master/components/notification/overview.md#success-info-warning-error-notifications. It will be live with our next upload.

We have chosen not to add explicit .Error(), .Info(), .Success() and .Warning() methods because our notifications have several additional settings, and combining all of them would make the API cumbersome. Nevertheless, making a facade like you have done is a perfectly valid approach for your project.

If you have any other questions or cases, feel free to give us feedback again.

Regards,
Hristian Stefanov
Progress Telerik

Тhe web is about to get a bit better! 

The Progress Hack-For-Good Challenge has started. Learn how to enter and make the web a worthier place: https://progress-worthyweb.devpost.com.

Tags
Notification
Asked by
Martin
Top achievements
Rank 1
Veteran
Answers by
Martin
Top achievements
Rank 1
Veteran
Hristian Stefanov
Telerik team
Share this question
or