You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+34-11
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,7 @@
1
1
# css-classes
2
-
Simple library to manage list of CSS classes. It simplifies tasks of constructing list of CSS classes from given information, adding and removing classes from the list.
2
+
Simple library to manage a list of CSS classes.
3
+
4
+
It simplifies tasks of constructing a list of CSS classes from given information, adding and removing classes from the list.
Functionality is exposed via [`\Flying\Util\Css\Classes`](src/Classes.php) class.
16
+
Functionality is exposed via [`Classes`](src/Classes.php) and [`MutableClasses`](src/MutableClasses.php) classes, both implements same [`ClassesInterface`](src/ClassesInterface.php) interface.
17
+
18
+
Further documentation uses immutable `Classes` implementation as an example unless explicitly defined otherwise, but `MutableClasses` have exactly same usage in except of mutability.
15
19
16
20
### Accepted values
17
21
18
-
Any method that is mean to accept CSS classes actually accepts arbitrary amount of arguments of any type (`mixed ...$classes`). Given arguments are processed in this way:
22
+
Any method that is mean to accept CSS classes actually accepts arbitrary number of arguments of any type (`mixed ...$classes`).
23
+
24
+
Given arguments are processed in this way:
19
25
20
26
- Iterables are expanded
21
27
- Nested values are flattened
22
28
- Any values besides non-empty strings are ignored
23
29
24
30
### Immutability
25
31
26
-
Class is immutable by its nature, so all mutation methods of the class returns new instance.
32
+
v1 provides only immutable implementation. Since v2 there are both immutable `Classes` and mutable `MutableClasses` implementations.
These methods can be used to modify list of CSS classes:
72
+
These methods can be used to modify the list of CSS classes:
54
73
55
74
-`with(...$classes)` - Add given CSS classes to the list
56
75
-`without(...$classes)` - Remove given CSS classes from the list
57
76
-`filter(callable $filter)` - Filter CSS classes list using provided filter. `$filter` signature is `(string $class): bool`
58
-
-`clear()` - Remove all CSS classes from the list. Taking [immutability](#immutability)in consideration it is equivalent of `new Classes()`.
77
+
-`clear()` - Remove all CSS classes from the list. For [immutable](#immutability)`Classes` implementation it is equivalent of `new Classes()`.
59
78
60
79
### Classes list exporting
61
80
62
-
Classes list can be exported as a plain array using `toArray()` method. Also class implements `ArrayAggregate` and `Stringable` interfaces, so it is also possible to iterate classes list and cast its value into string.
81
+
Classes list can be exported as a plain array using `toArray()` method.
82
+
83
+
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.
63
84
64
85
### Other methods
65
86
66
-
`Classes` implements`Countable` interface, so amount of available CSS classes can be calculated using `count()` PHP function or by calling `count()` method.
87
+
`ClassesInterface` extends`Countable` interface, so number of available CSS classes can be calculated using `count()` PHP function or by calling `count()` method.
67
88
68
-
It is also possible to check if given class is available in list by using `has(string $class)` method.
89
+
It is also possible to check if given CSS class is available in the list by using `has(string $class)` method.
69
90
70
91
### Standalone `classes()` function
71
92
72
-
For simple cases when it is only need to create CSS classes list as a string from available data it is also possible to use `\Flying\Util\Css\classes()` function.
93
+
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.
73
94
74
95
`classes()` function is available since v1.1.0
75
96
@@ -102,7 +123,9 @@ But it is also possible to use CSS classes list modification methods:
102
123
</ul>
103
124
```
104
125
105
-
Refer to the [Twig documentation](https://twig.symfony.com/doc/3.x/api.html#using-extensions) on how to add extension to the Twig.
126
+
Refer to the [Twig documentation](https://twig.symfony.com/doc/3.x/api.html#using-extensions) on how to add the extension to the Twig.
127
+
128
+
For Symfony, there is a [separate bundle](https://github.com/FlyingDR/css-classes-bundle) to simplify integration.
0 commit comments