Skip to content

Commit

Permalink
Icon classes can now be specified via array
Browse files Browse the repository at this point in the history
  • Loading branch information
avvertix committed Dec 5, 2020
1 parent d3cdf0e commit 855db7b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

## [2.1.0] - 2020-12-05

- Allow to specify icon classes as array

## [2.0.1] - 2020-12-05

- Remove fill color defined on some icons in action, av, content, editor and navigation groups
Expand Down
10 changes: 9 additions & 1 deletion src/MaterialIconsBridgeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,20 @@ public function registerIconSets(): self
*
* @param string $set The icon set within Material UI icons (e.g. action)
* @param string $name The icon name (e.g. alarm)
* @param string $class The eventual class tag to be applied. Default nothing
* @param string|array $class The eventual class tag to be applied. Default nothing
* @param array $attrs Other HTML attributes as an associative array
* @return \BladeUI\Icons\Svg the SVG to render the icon
*/
public function materialicon($set, $name, $class = '', $attrs = [])
{
if(is_array($class)){
if(isset($class['class'])){
$attrs = array_merge($attrs, Arr::except($class, 'class') ?? []);
}

$class = $class['class'] ?? implode(' ', $class ?? []);
}

$full_class = implode(" ", [$this->config['class'], $class]);

$prefixed_set = "materialicon_$set";
Expand Down
14 changes: 14 additions & 0 deletions tests/MaterialIconsBridgeHelpersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ public function test_specifying_class_as_attribute_overrides_default_class()
$this->assertEquals($expected, $result);
}

public function test_specifying_class_as_associative_array_is_supported()
{
$result = materialicon('action', 'accessibility', ['class' => 'overridden'])->toHtml();
$expected = '<svg class="icon overridden" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M12 2c1.1 0 2 .9 2 2s-.9 2-2 2-2-.9-2-2 .9-2 2-2zm9 7h-6v13h-2v-6h-2v6H9V9H3V7h18v2z"/></svg>';
$this->assertEquals($expected, $result);
}

public function test_specifying_class_as_array_is_supported()
{
$result = materialicon('action', 'accessibility', ['overridden', 'additional'])->toHtml();
$expected = '<svg class="icon overridden additional" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M12 2c1.1 0 2 .9 2 2s-.9 2-2 2-2-.9-2-2 .9-2 2-2zm9 7h-6v13h-2v-6h-2v6H9V9H3V7h18v2z"/></svg>';
$this->assertEquals($expected, $result);
}

public function test_materialicon_helper()
{
$result = materialicon('action', 'accessibility')->toHtml();
Expand Down

0 comments on commit 855db7b

Please sign in to comment.