Download the PHP package flying/css-classes without Composer
On this page you can find all versions of the php package flying/css-classes. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download flying/css-classes
More information about flying/css-classes
Files in flying/css-classes
Package css-classes
Short Description CSS classes list manipulation library
License MIT
Informations about the package css-classes
css-classes
Simple library to manage a list of CSS classes.
It simplifies tasks of constructing a list of CSS classes from given information, adding and removing classes from the list.
Installation
Simply install it using Composer:
Standalone usage
Functionality is exposed via ClassesInterface
interface.
Further documentation uses immutable Classes
implementation as an example unless explicitly defined otherwise, but MutableClasses
have exactly same usage in except of mutability.
Accepted values
Any method that is mean to accept CSS classes actually accepts arbitrary number of arguments of any type (mixed ...$classes
).
Given arguments are processed in this way:
- Iterables are expanded
- Nested values are flattened
- Any values besides non-empty strings are ignored
Immutability
v1 provides only immutable implementation. Since v2 there are both immutable Classes
and mutable MutableClasses
implementations.
List creation
Classes list can be constructed using either by creating new Classes
instance or by using Classes::from()
static method. Both methods are accepted variable amount arguments of any type.
Example:
Fluent interface is also possible to use:
Classes list modification
These methods can be used to modify the list of CSS classes:
with(...$classes)
- Add given CSS classes to the listwithout(...$classes)
- Remove given CSS classes from the listfilter(callable $filter)
- Filter CSS classes list using provided filter.$filter
signature is(string $class): bool
clear()
- Remove all CSS classes from the list. For immutableClasses
implementation it is equivalent ofnew Classes()
.
Classes list exporting
Classes list can be exported as a plain array using toArray()
method.
Also, ClassesInterface
interface extends ArrayAggregate
and Stringable
interfaces, so it is also possible to iterate over the list of CSS classes and cast its value into string.
Other methods
ClassesInterface
extends Countable
interface, so number of available CSS classes can be calculated using count()
PHP function or by calling count()
method.
It is also possible to check if given CSS class is available in the list by using has(string $class)
method.
Standalone classes()
function
For simple cases when it is only needs to create CSS classes list as a string from available data it is also possible to use \Flying\Util\Css\classes()
function.
classes()
function is available since v1.1.0
Usage in Twig
Library includes \Flying\Util\Css\Twig\ClassesExtension
Twig extension that exposes classes
function that provides same functionality as a main class.
It can be used as a simple construction of the classes list:
But it is also possible to use CSS classes list modification methods:
Refer to the Twig documentation on how to add the extension to the Twig.
For Symfony, there is a separate bundle to simplify integration.
License
Library is licensed under MIT license.