yii-extension/alert-flash-tailwind

There is no license information available for the latest version (dev-master) of this package.

Alert Flash Tailwind Widget.

This package's canonical repository appears to be gone and the package has been frozen as a result.


README

68747470733a2f2f6c68332e676f6f676c6575736572636f6e74656e742e636f6d2f65685354506e5871726b6b304d33552d5550436a4330667479394b366c67796b4b32574f5541326e5548703867496b526a65544e387a385341426c6b766376522d39504972626f7849765047756a50675765624c51654848675837794c556f7846536475695a72546f6736576f5a4c694176716354523151545056526d6e733274596a414370703745513d7732343030

Alert Flash Tailwind Widget


Total Downloads build codecov Mutation testing badge static analysis type-coverage

Installation

composer require yii-extension/alert-flash-tailwind

Usage

The widgets do not register any assets, you must register the assets for Tailwind Css Framework

In controller or action:

<?php

declare(strict_types=1);

namespace App\Action;

use Psr\Http\Message\ResponseInterface;
use Yiisoft\Session\Flash\Flash;

final class Action
{
    public function index(Flash $flash): ResponseInterface
    {
        $flash->add(
            'danger', // types: [danger, info, success, warning]
            [
                'body' => '<b>Holy smokes!</b> Something seriously bad happened.' // Its mandatory.
            ],
            true
        );
    }
}

In layout:

<?php

declare(strict_types=1);

use Yii\Extension\Tailwind\AlertFlash;
use Yiisoft\Session\Flash\Flash;

/** @var Flash $flash */
?>

<?= AlertFlash::widget([$flash])
    ->bodyClass('align-middle flex-grow inline-block mr-8')
    ->bodyTag('p')
    ->buttonLabel('&times;')
    ->buttonOnClick('closeAlert()')
    ->iconAttributes(['class' => 'fa-2x pr-2'])
    ->class('flex font-bold items-center px-4 py-3 text-sm text-white')
    ->layoutBody('{icon}{body}{button}')
    ->render();
?>

HtmlOutput:

<div id="w0-alert" class="bg-red-600 flex font-bold items-center px-4 py-3 text-sm text-white" role="alert">
    <div><i class="fa-2x pr-2 far fa-times-circle"></i></div>
    <p class="align-middle flex-grow inline-block mr-8"><b>Holy smokes!</b> Something seriously bad happened.</p>
    <button type="button" class="float-right px-4 py-3" onclick="closeAlert()">&times;</button>
</div>

Note: Tailwind does not provide any Javascript implementation for closing the AlertFlash, so you will need to implement it.

Example JavaScript:

function closeAlert() {
    document.getElementById('w0-alert').style.display = 'none';
}

Unit testing

The package is tested with PHPUnit. To run tests:

./vendor/bin/phpunit

Mutation testing

The package tests are checked with Infection mutation framework. To run it:

./vendor/bin/infection

Static analysis

The code is statically analyzed with Psalm. To run static analysis:

./vendor/bin/psalm

License

The yii-extension/alert-flash-tailwind for Yii Packages is free software.

It is released under the terms of the BSD License. Please see LICENSE for more information.

Maintained by Yii Extension.

Support the project

Open Collective

Powered by Yii Framework

Official website