coxmichael / classlist
helper utility to concat a list of class names
Installs: 12
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/coxmichael/classlist
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