Skip to content

Commit 2751ee7

Browse files
committed
Documentation is updated to reflect new functionality
1 parent f02dd64 commit 2751ee7

File tree

1 file changed

+34
-11
lines changed

1 file changed

+34
-11
lines changed

README.md

+34-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# 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.
35

46
## Installation
57

@@ -11,19 +13,23 @@ composer require flying/css-classes
1113

1214
## Standalone usage
1315

14-
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.
1519

1620
### Accepted values
1721

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:
1925

2026
- Iterables are expanded
2127
- Nested values are flattened
2228
- Any values besides non-empty strings are ignored
2329

2430
### Immutability
2531

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.
2733

2834
### List creation
2935

@@ -48,28 +54,43 @@ echo $classes;
4854
echo count($classes);
4955
```
5056

57+
Fluent interface is also possible to use:
58+
59+
```php
60+
$classes = Classes::from('foo', 'bar baz', ['a', 'b', 'c'])
61+
->without('baz')
62+
->filter(fn(string $class): bool => strlen($class) > 1)
63+
->with('x', null, true, false, 42, 1.2345, ['y', ['z']]);
64+
// Outputs: foo bar x y z
65+
echo $classes;
66+
// Outputs: 5
67+
echo count($classes);
68+
```
69+
5170
### Classes list modification
5271

53-
These methods can be used to modify list of CSS classes:
72+
These methods can be used to modify the list of CSS classes:
5473

5574
- `with(...$classes)` - Add given CSS classes to the list
5675
- `without(...$classes)` - Remove given CSS classes from the list
5776
- `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()`.
5978

6079
### Classes list exporting
6180

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.
6384

6485
### Other methods
6586

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.
6788

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.
6990

7091
### Standalone `classes()` function
7192

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.
7394

7495
`classes()` function is available since v1.1.0
7596

@@ -102,7 +123,9 @@ But it is also possible to use CSS classes list modification methods:
102123
</ul>
103124
```
104125

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.
106129

107130
## License
108131

0 commit comments

Comments
 (0)