coxmichael / classlist
helper utility to concat a list of class names
v1.0.1
2021-04-07 11:27 UTC
Requires (Dev)
- pestphp/pest: ^1.0
README
A simple utility for conditionally concatenating a list of class names.
classlist('one', 'two') // 'one two' classlist(['conditional' => true]) // 'conditional' classlist(['conditional' => false]) // '' classlist(['sub', 'array'], (object) ['conditional' => true]) // 'sub array conditional'
Install
composer require coxmichael/classlist
Usage
<div class="<?php echo classlist(...args) ?>"></div>
Or retrieve the array of class names with a tokenlist:
$tokens = tokenlist('in-results', [ 'not-in-results' => false ]) // ['in-results']
Miscellaneous
- All falsy values are ignored:
false
,0
,null
,""
,[]
- Arrays are flattened
- An object or array's string key will be used if its value is truthy
- Arguments are html attribute escaped