Giter Club home page Giter Club logo

sotsera.blazor.toaster's Introduction

Sotsera.Blazor.Toaster

A Blazor port of Toastr.js in pure .Net.

The transitions are implemented using System.Threading.Timer timers so the resource usage should be closely monitored when using the server-side hosting model.

Css inclusion for Blazor Server Apps

While on client-side projects the css file is still loaded automatically, on server side projects the following reference must be added to the _Host.cshtml file:

<link href="_content/Sotsera.Blazor.Toaster/toastr.min.css" rel="stylesheet" />

The client-side sample project has been published here.

Changes

version 0.11.0

  • moved to 3.0.0-preview7.19365.7
  • Breaking changes
    • repackaged as Razor Component Library: on server-side projects the css must be referenced explicitly by the host component
    • option NewestOnTop defaults to false

See the RELEASE-NOTES for the previous versions.

Configuration

Installation

Install-Package Sotsera.Blazor.Toaster

Dependency injection configuration

services.AddToaster(config =>
{
    //example customizations
    config.PositionClass = Defaults.Classes.Position.TopRight;
    config.PreventDuplicates = true;
    config.NewestOnTop = false;
});

Css inclusion

Only for Blazor Server Apps, add the following reference to the toaster css in the _Host.cshtml component

<link href="_content/Sotsera.Blazor.Toaster/toastr.min.css" rel="stylesheet" />

Main toaster component

The toast container must be added to the App.razor component or to another component always loaded in the application like MainLayout.razor. It is important to have exactly one instance of this component rendered in the application tree at any given time.

@using Sotsera.Blazor.Toaster
<ToastContainer />

Usage

In a component

@inject Sotsera.Blazor.Toaster.IToaster Toaster

In a class

[Inject] 
protected Sotsera.Blazor.Toaster.IToaster Toaster { get; set; }

then call one of the display methods:

Toaster.Info("toast body text");
Toaster.Success("toast body text");
Toaster.Warning("toast body text");
Toaster.Error("toast body text");

Each of these methods can accept a title and an action for the toast specific configuration

Toaster.Info("toast body text");
Toaster.Info("toast body text", "toast title");
Toaster.Info("toast body text", "toast title", options =>
{
    options.Clicked += toast => Console.WriteLine($"Toast '{toast.Message}' Clicked!");
});

Credits

This is a simple attempt to port Toastr.js to Blazor.

Currently the css styles used are literally COPIED from Toastr.js.

The logo has been made by Freepik from Flaticon and is licensed by CC 3.0 BY

License

Sotsera.Blazor.Toaster is licensed under MIT license

sotsera.blazor.toaster's People

Contributors

ctrl-alt-d avatar ghidello avatar iambipinpaul avatar peterblazejewicz avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.