Blade Class Directive

Inspired by classnames for react.

Installation

composer require pskordilakis/blade-class-directive

Usage

@class directive accepts a variable number of arguments that can be of type string or array and returns(prints) a class attribute for an HTML element. Any string argument will be added as part of the value of the class attribute. For the array arguments, the entries will be filtered based on the value (truthy/falsy) and the key will be added to the class value

String arguments

@class('btn btn-primary')

Array Arguments

@class([ 'btn' => true, 'btn-primary' => true, 'disabled' => $isDisabled ])

Mixed Arguments

@class('btn btn-primary', [ 'disabled' => $isDisabled ])

On HTML elements

<li @class('page-item', [ 'disabled' => $pagination->onFirstPage() ])></li>