2017 © Pedro Peláez
 

library blade-class-names

Package for handling html classes output based on conditions

image

tautvydasr/blade-class-names

Package for handling html classes output based on conditions

  • Sunday, June 24, 2018
  • by tautvydasr
  • Repository
  • 1 Watchers
  • 0 Stars
  • 3 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Blade class names

Build Status, (*1)

Simple package which helps to handle conditional html classes in blade templates., (*2)

NOTICE: If Laravel 8 or later is used consider using native @class directive instead., (*3)

Installation

First of all require this package in composer:, (*4)

composer require tautvydasr/blade-class-names

Finally, add service provider to providers array in your config/app.php file for Laravel:, (*5)

'providers' => [
    // ...
    ClassNames\ClassNamesServiceProvider::class,
    // ...
],

or register service provider in bootstrap/app.php if using Lumen:, (*6)

...
$app->register(\ClassNames\ClassNamesServiceProvider::class);
...

Usage

Basically package allows you to simplify conditional classes situations like this, (*7)

<a href="#" class="menu-item{{ $loop->first ? ' first-item' : '' }}{{ request()->routeIs('foo') ? ' active' : '' }}">
    ...
</a>

to this using blade directive @classNames()., (*8)

<a href="#" class="@classNames('menu-item', ['first-item' => $loop->first, 'active' => request()->routeIs('foo')])">
    ...
</a>

For Lumen users it can be accessed via app() helper or facade., (*9)

<a href="#" class="app('classnames')->render('menu-item', ['first-item' => $loop->first, 'active' => request()->routeIs('foo')])">
    ...
</a>

<a href="#" class="\ClassNames\ClassNamesFacade::render('menu-item', ['first-item' => $loop->first, 'active' => request()->routeIs('foo')])">
    ...
</a>

Using facade approach make sure the line $app->withFacades(); is uncommented in bootstrap/app.php file., (*10)

Local setup

Copy example docker compose config file (optional):, (*11)

cp docker-compose.yml.dist docker-compose.yml

Run docker containers (optional):, (*12)

docker-compose up -d

Login to docker container where CONTAINER_ID is your id (optional):, (*13)

docker exec -ti CONTAINER_ID /bin/bash

Install dependencies using composer:, (*14)

composer install

Tests

Run phpunit tests:, (*15)

./vendor/bin/phpunit

License

Package is free to use and is licensed under the MIT license, (*16)

The Versions

24/06 2018

dev-master

9999999-dev

Package for handling html classes output based on conditions

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tautvydas Rasimavicius

laravel blade class-names

24/06 2018

1.0.1

1.0.1.0

Package for handling html classes output based on conditions

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tautvydas Rasimavicius

laravel blade class-names

13/06 2018

1.0.0

1.0.0.0

Package for handling html classes output based on conditions

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tautvydas Rasimavicius

laravel blade class-names