yii-extension / alert-flash-tailwind
Alert Flash Tailwind Widget.
This package's canonical repository appears to be gone and the package has been frozen as a result.
Installs: 1 163
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 6
Requires
- php: ^7.4|^8.0
- yii-extension/asset-tailwind: ^1.0.0
- yii-extension/widgets: ^1.0.0
- yiisoft/session: ^1.0
Requires (Dev)
- nyholm/psr7: ^1.4.0
- phpunit/phpunit: ^9.5
- roave/infection-static-analysis-plugin: ^1.8
- vimeo/psalm: ^4.8
- yiisoft/var-dumper: ^1.1.0
- dev-master / 1.0.x-dev
- dev-dependabot/composer/vimeo/psalm-tw-5.8
- dev-dependabot/github_actions/actions/cache-3.3.0
- dev-dependabot/composer/yiisoft/session-tw-2.0
- dev-dependabot/github_actions/shivammathur/setup-php-2.24.0
- dev-dependabot/github_actions/actions/checkout-3.3.0
- dev-dependabot/github_actions/codecov/codecov-action-3.1.1
This package is auto-updated.
Last update: 2024-01-10 06:44:22 UTC
README
Alert Flash Tailwind Widget
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('×') ->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()">×</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.