Get hover colours added

This commit is contained in:
Brabli
2022-08-29 20:08:27 +01:00
parent 5e3756773e
commit 78a321137e
2 changed files with 16 additions and 7 deletions

View File

@@ -81,18 +81,18 @@ final class IconExtension extends AbstractExtension
$mainPallete = $this->getPallete($options['colour']); $mainPallete = $this->getPallete($options['colour']);
$xml = new \SimpleXMLElement($cleanSvgMarkup);
$xml = $this->addAttributeToXmlElement($xml, 'class', $mainPallete['stroke'] . ' ' . $mainPallete['fill']); $colourClasses = "{$mainPallete['stroke']} {$mainPallete['fill']}";
$cleanSvgMarkup = $this->removeXMLDeclaration($xml->saveXML());
if (null !== $options['hover']) { if (null !== $options['hover']) {
$hoverPallete = $this->getPallete($options['hover']); $hoverPallete = $this->getPallete($options['hover']);
$xml = new \SimpleXMLElement($cleanSvgMarkup); $colourClasses .= " hover:{$hoverPallete['stroke']} hover:{$hoverPallete['fill']}";
$xml = $this->addAttributeToXmlElement($xml, 'class', 'hover:' . $hoverPallete['stroke'] . ' ' . 'hover:' . $hoverPallete['fill']);
$cleanSvgMarkup = $this->removeXMLDeclaration($xml->saveXML());
} }
$markup = $cleanSvgMarkup; $xml = new \SimpleXMLElement($cleanSvgMarkup);
$xml = $this->addAttributeToXmlElement($xml, 'class', $colourClasses);
$markup = $this->removeXMLDeclaration($xml->saveXML());
if ($this->isNonEmptyString($options['title'])) if ($this->isNonEmptyString($options['title']))
$markup = $this->addTitleToMarkup($markup, $options['title']); $markup = $this->addTitleToMarkup($markup, $options['title']);

View File

@@ -253,5 +253,14 @@ class IconExtensionTest extends TestCase
$this->assertMatchesRegularExpression('/<svg.+class=".*hover:stroke-white.*".*>/', $contents); $this->assertMatchesRegularExpression('/<svg.+class=".*hover:stroke-white.*".*>/', $contents);
} }
public function testSvgClassContainsHoverAndColourPalleteClasses(): void
{
$contents = $this->icon->renderIcon(['icon' => self::ICON, 'hover' => 'white', 'colour' => 'primary']);
$this->assertMatchesRegularExpression('/<svg.+class=".*fill-primary.*".*>/', $contents);
$this->assertMatchesRegularExpression('/<svg.+class=".*stroke-primary.*".*>/', $contents);
$this->assertMatchesRegularExpression('/<svg.+class=".*hover:fill-white.*".*>/', $contents);
$this->assertMatchesRegularExpression('/<svg.+class=".*hover:stroke-white.*".*>/', $contents);
}
} }