styriabytes/reactive-html-attributes

A library for binding state to html attributes

v1.0.1 2022-02-17 20:36 UTC

This package is auto-updated.

Last update: 2024-05-18 01:36:31 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.