Add colour classes
This commit is contained in:
@@ -77,10 +77,14 @@ final class IconExtension extends AbstractExtension
|
|||||||
$rawSvgMarkup = $this->getSvgMarkup($iconFilepath);
|
$rawSvgMarkup = $this->getSvgMarkup($iconFilepath);
|
||||||
$cleanSvgMarkup = $this->cleanSvgMarkup($rawSvgMarkup);
|
$cleanSvgMarkup = $this->cleanSvgMarkup($rawSvgMarkup);
|
||||||
|
|
||||||
$mainColour = $this->getMainPallete($options['colour']);
|
$mainPallete = $this->getMainPallete($options['colour']);
|
||||||
|
|
||||||
|
$xml = new \SimpleXMLElement($cleanSvgMarkup);
|
||||||
|
$xml = $this->addAttributeToXmlElement($xml, 'class', $mainPallete['stroke'] . ' ' . $mainPallete['fill']);
|
||||||
|
$markup = $this->removeXMLDeclaration($xml->saveXML());
|
||||||
|
|
||||||
if ($this->isNonEmptyString($options['title']))
|
if ($this->isNonEmptyString($options['title']))
|
||||||
$markup = $this->addTitleToMarkup($cleanSvgMarkup, $options['title']);
|
$markup = $this->addTitleToMarkup($markup, $options['title']);
|
||||||
|
|
||||||
if ($options['size'] < 0)
|
if ($options['size'] < 0)
|
||||||
throw new \InvalidArgumentException('Size must not be negative');
|
throw new \InvalidArgumentException('Size must not be negative');
|
||||||
@@ -175,12 +179,12 @@ final class IconExtension extends AbstractExtension
|
|||||||
|
|
||||||
private function removeBlackStrokeAttributes(string $content): string
|
private function removeBlackStrokeAttributes(string $content): string
|
||||||
{
|
{
|
||||||
return preg_replace('/stroke="\s*(#0{6}|#000)|(rgb\(\s*0,\s*0,\s*0\s*\))|(black)\s*"/', '', $content);
|
return preg_replace('/stroke="\s*(#0{6}|#000|rgb\(\s*0,\s*0,\s*0\s*\)|black)\s*"/', '', $content);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function removeBlackFillAttributes(string $content): string
|
private function removeBlackFillAttributes(string $content): string
|
||||||
{
|
{
|
||||||
return preg_replace('/fill="\s*(#0{6}|#000)|(rgb\(\s*0,\s*0,\s*0\s*\))|(black)\s*"/', '', $content);
|
return preg_replace('/fill="\s*(#0{6}|#000|rgb\(\s*0,\s*0,\s*0\s*\)|black)\s*"/', '', $content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,10 @@ class IconExtensionTest extends TestCase
|
|||||||
'primary' => [
|
'primary' => [
|
||||||
'stroke' => 'stroke-primary',
|
'stroke' => 'stroke-primary',
|
||||||
'fill' => 'fill-primary'
|
'fill' => 'fill-primary'
|
||||||
|
],
|
||||||
|
'white' => [
|
||||||
|
'stroke' => 'stroke-white',
|
||||||
|
'fill' => 'fill-white'
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -211,4 +215,12 @@ class IconExtensionTest extends TestCase
|
|||||||
$this->icon->renderIcon(['icon' => self::ICON, 'colour' => 'red']);
|
$this->icon->renderIcon(['icon' => self::ICON, 'colour' => 'red']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSvgClassContainsPalleteClasses(): void
|
||||||
|
{
|
||||||
|
$contents = $this->icon->renderIcon(['icon' => self::ICON, 'colour' => 'white']);
|
||||||
|
$this->assertMatchesRegularExpression('/<svg.*?class=".*?fill-white.*?>/', $contents);
|
||||||
|
$this->assertMatchesRegularExpression('/<svg.*?class=".*?stroke-white?.*>/', $contents);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user