Browse Source

Merge in custom config.

mscherer 3 years ago
parent
commit
96522fd2d2
2 changed files with 38 additions and 8 deletions
  1. 35 7
      docs/Helper/Icon.md
  2. 3 1
      src/View/Icon/IconCollection.php

+ 35 - 7
docs/Helper/Icon.md

@@ -30,6 +30,23 @@ E.g.
 ],
 ```
 
+For some Icon classes, there is additional configuration available:
+- `namespace`: Some fonts offer different traits (light, bold, round, ...)
+
+E.g.
+```php
+'Icon' => [
+    'config' => [
+        'material' => [
+            'namespace' => 'material-symbols-round',
+        ],
+        ...
+    ],
+],
+```
+Make sure to use the same keys here as for the `sets` definition, otherwise the collector won't find your
+file configuration here.
+
 ## Usage
 
 ### render()
@@ -68,20 +85,30 @@ This way you can also rename icons (and map them in any custom way).
 ### names()
 You can get a nested list of all configured and available icons.
 
-For this make sure to set up the paths to the icon files as per each collector.
-E.g.
+For this make sure to set up the path config to the icon meta files as per each collector.
+E.g.:
 ```php
     'Icon' => [
         // For being able to parse the available icons
-        'paths' => [
-            'fa' => '/path/to/font-awesome/less/variables.less',
-            'bs' => '/path/to/bootstrap-icons/font/bootstrap-icons.json',
-            'feather' => '/path/to/feather-icons/dist/icons.json',
-            'material' => '/path/to/material-symbols/index.d.ts',
+        'config' => [
+            'fa' => [
+                'path' => '/path/to/font-awesome/less/variables.less',
+            ],
+            'bs' => [
+                'path' => '/path/to/bootstrap-icons/font/bootstrap-icons.json',
+            ],
+            'feather' => [
+                'path' => '/path/to/feather-icons/dist/icons.json',
+            ],
+            'material' => [
+                'path' => '/path/to/material-symbols/index.d.ts',
+            ],
             ...
         ],
     ],
 ```
+Make sure to use the same keys here as for the `sets` definition, otherwise the collector won't find your
+file configuration here.
 
 You can then use this to iterate over all of them for display:
 ```php
@@ -93,6 +120,7 @@ foreach ($icons as $iconSet => $list) {
 }
 ```
 
+
 ## Tips
 
 Check out [animations](https://fontawesome.com/docs/web/style/animate) and

+ 3 - 1
src/View/Icon/IconCollection.php

@@ -34,7 +34,9 @@ class IconCollection {
 		unset($config['sets']);
 
 		foreach ($sets as $set => $className) {
-			$this->iconSets[$set] = new $className($config);
+			$iconConfig = $config['config'][$set] ?? [];
+			$iconConfig += $config;
+			$this->iconSets[$set] = new $className($iconConfig);
 		}
 
 		$key = array_key_first($sets);