zicht / classes
PHP utility for conditionally joining CSS classes.
Installs: 24 071
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 4
Forks: 0
Open Issues: 0
Requires
- php: ^7.2 || ^8.0
Requires (Dev)
- phpunit/phpunit: ^8
This package is auto-updated.
Last update: 2024-10-17 14:57:35 UTC
README
Utility function for conditionally joining CSS classes.
Installing
composer require zicht/classes
Purpose
When building a component (or any piece of HTML, really), it's quite common to render or not render certain CSS classes based on certain variables. If you manually concatenate the class names, it quickly becomes a mess of if
/ else
or ternary operators. This function helps to keep it readable.
Usage
HtmlClassHelper::classes('art-vandelay'); ⇒ 'art-vandelay'
HtmlClassHelper::classes(['art-vandelay', 'kramerica']); ⇒ 'art-vandelay kramerica'
HtmlClassHelper::classes(['art-vandelay' => true, 'kramerica' => false]); ⇒ 'art-vandelay'
HtmlClassHelper::classes('art-vandelay', ['kramerica' => false, 'kel-varnsen' => true]); ⇒ 'art-vandelay kel-varnsen'
Credits
This function was created because the JS equivalent classnames was nice to use in React.