rezaulhreza/flash-toast

A fluent toast manager built with TALL stack.


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Demo Project

FlashToast Demo

Installation

You can install the package via composer:

composer require rezaulhreza/flash-toast

then publish the config file

php artisan vendor:publish --tag="flash-toast-config"

publish the view files

php artisan vendor:publish --tag="flash-toast-views"

Once you publish the file, move the files from resources\views\vendor\flash-toast\components to resources\views\components. now you can place the file anywhere you want such as .

alterantively, just do:

@include('vendor.flash-toast.components.flash-toast')

Usage

Runs with the TALL stack: Laravel, TailwindCSS, Livewire, AlpineJS.

Guide:

Available methods: success- info - warning - danger. title, html, level, duration.

use FlashToast in the component class.

In the component class: Example:

$this->toastInfo('this is a info toast');
$this->toastSuccess('this is a successful toast');

Of course the above are customisable.

To add a html code or title or duration even custom level(level is the type of toast e.g. - success, info etc). Example:

use FlashToast; // don't forget to import it!!!
$this->toastSuccess('This is a string message');

p.s: to showcase the usage in the readme, a space was left intentionally otherwise it would compile the markdown preview with h1. Use actual markup when using within the applciation scenario.

Blade component:

component/toast.blade.php

Styles are inside a blade file, however, you can customize it

An example is given below

<?php
namespace Rezaulhreza\FlashToast\Example;

use Livewire\Component;
use Rezaulhreza\FlashToast\FlashToast;

class FlashToastExample extends Component
{

    public function stringMessage()
    {
        $this->toastSuccess('This is a string message');
    }

    public function text()
    {
        $this->flashToast((new \Rezaulhreza\FlashToast\Manager\ToastManager)->text('Some text'));
    }

    public function html()
    {
        $this->flashToast((new \Rezaulhreza\FlashToast\Manager\ToastManager)->title('My title')->level('warning')->html('<h2 class="text-2xl">Sub title</h2> <b>Warning</b>'));
    }

    public function duration()
    {
        $this->flashToast((new \Rezaulhreza\FlashToast\Manager\ToastManager)->text('Showing for 200 ms')->showForMilliseconds(200));
    }

    public function render()
    {
        return view('flash-toast-example');
    }
}

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email emailrezahere@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.