styriabytes / reactive-html-attributes
A library for binding state to html attributes
v1.0.1
2022-02-17 20:36 UTC
Requires
- php: >=7.2
Requires (Dev)
- phpunit/phpunit: 9.5.*
- squizlabs/php_codesniffer: 3.6.*
This package is auto-updated.
Last update: 2024-12-18 02:57:09 UTC
README
The reactive html attributes library provides a clean and modern way to bind reactivity to a html tag attribute.
Installation
Reactive HTML Attributes uses Composer to install and update:
composer require styriabytes/reactive-html-attributes
Usage
Quick Start
The following piece of code...
<?php
use Styriabytes\ReactiveHtmlAttributes\Bind;
$variant = 'success';
$cssClasses = [
'alert',
'alert-success' => $variant === 'success',
'alert-warning' => $variant === 'warning',
'alert-danger' => $variant === 'danger',
'alert-info' => $variant === 'info',
];
?>
<div<?= Bind::class($cssClasses) ?> role="alert">
A simple primary alert—check it out!
</div>
...will render:
<div class="alert alert-success" role="alert">
A simple primary alert—check it out!
</div>
Contribution
Any type of feedback, pull request or issue is welcome.
We use the PHP_CodeSniffer to check for Coding Standard Issues.
Check Coding Standard
composer checkcs
# or
vendor/bin/phpcs --standard=PSR1,PSR2,PSR12 --colors src
Fix Errors Automatically
composer fixcs
# or
vendor/bin/phpcbf --standard=PSR1,PSR2,PSR12 src
Run Tests
composer test
# or
vendor/bin/phpunit
License
The Styriabytes Reactive HTML Attributes library is licensed under the MIT license.