Replace 'palletes' with 'colours' which is a bit more intuitive and is also spelt correctly.
This commit is contained in:
@@ -19,7 +19,7 @@ class Configuration implements ConfigurationInterface
|
||||
->arrayNode('directories')
|
||||
->scalarPrototype()->end()
|
||||
->end()
|
||||
->arrayNode('palletes') // Akshewally it is defined
|
||||
->arrayNode('colours') // Akshewally it is defined
|
||||
->variablePrototype()->end()
|
||||
->end()
|
||||
->end()
|
||||
|
||||
@@ -26,6 +26,6 @@ class PcmIconExtension extends Extension
|
||||
$definition = $container->getDefinition('pcm_icon.icon_extension');
|
||||
|
||||
$definition->addArgument($config['directories']);
|
||||
$definition->addArgument($config['palletes']);
|
||||
$definition->addArgument($config['colours']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,29 +20,29 @@ final class IconExtension extends AbstractExtension
|
||||
'classes' => [],
|
||||
];
|
||||
|
||||
public function __construct(private array $directories, private array $palletes)
|
||||
public function __construct(private array $directories, private array $colours)
|
||||
{
|
||||
if (empty($this->palletes)) {
|
||||
throw new \InvalidArgumentException('Palletes array must contain at least one pallet!');
|
||||
if (empty($this->colours)) {
|
||||
throw new \InvalidArgumentException('Colours array must contain at least one colour!');
|
||||
}
|
||||
|
||||
$palletesContainNonarray = array_reduce($this->palletes,
|
||||
$coloursContainsNonArray = array_reduce($this->colours,
|
||||
fn($notArray, $path) => $notArray || !is_array($path));
|
||||
|
||||
if ($palletesContainNonarray) {
|
||||
throw new \TypeError('Palletes array must only contain arrays!');
|
||||
if ($coloursContainsNonArray) {
|
||||
throw new \TypeError('Colours array must only contain arrays!');
|
||||
}
|
||||
|
||||
foreach ($this->palletes as $pallete) {
|
||||
foreach ($this->colours as $colour) {
|
||||
if (!(
|
||||
array_key_exists('stroke', $pallete) &&
|
||||
array_key_exists('fill', $pallete) &&
|
||||
array_key_exists('fill-hover', $pallete) &&
|
||||
array_key_exists('stroke-hover', $pallete) &&
|
||||
array_key_exists('fill-group-hover', $pallete) &&
|
||||
array_key_exists('stroke-group-hover', $pallete))
|
||||
array_key_exists('stroke', $colour) &&
|
||||
array_key_exists('fill', $colour) &&
|
||||
array_key_exists('fill-hover', $colour) &&
|
||||
array_key_exists('stroke-hover', $colour) &&
|
||||
array_key_exists('fill-group-hover', $colour) &&
|
||||
array_key_exists('stroke-group-hover', $colour))
|
||||
) {
|
||||
throw new \Exception('Palletes must contain a "stroke" and "fill" key!');
|
||||
throw new \Exception('Colours must contain a "stroke" and "fill" key!');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -66,8 +66,8 @@ final class IconExtension extends AbstractExtension
|
||||
* 'icon' => (string) REQUIRED Which icon to use
|
||||
* 'title' => (?string) Text to appear on mouse hover
|
||||
* 'size' => (int) Height and width in px
|
||||
* 'colour' => (string) Main colour pallete
|
||||
* 'hover' => (?string) Hover colour pallete
|
||||
* 'colour' => (string) Main colour
|
||||
* 'hover' => (?string) Hover colour
|
||||
* 'classes' => (array) Additional classes to add to the icon.
|
||||
* Use with caution as this can potentially
|
||||
* cause Tailwind class conflicts!
|
||||
@@ -159,24 +159,24 @@ final class IconExtension extends AbstractExtension
|
||||
|
||||
private function getColourClasses(string $primaryColour, ?string $hoverColour): string
|
||||
{
|
||||
$mainPallete = $this->getPallete($primaryColour);
|
||||
$colourClasses = "{$mainPallete['stroke']} {$mainPallete['fill']}";
|
||||
$mainColour = $this->getColour($primaryColour);
|
||||
$colourClasses = "{$mainColour['stroke']} {$mainColour['fill']}";
|
||||
|
||||
if (null !== $hoverColour) {
|
||||
$hoverPallete = $this->getPallete($hoverColour);
|
||||
$colourClasses .= " cursor-pointer {$hoverPallete['stroke-hover']} {$hoverPallete['fill-hover']} {$hoverPallete['stroke-group-hover']} {$hoverPallete['fill-group-hover']}";
|
||||
$hoverColour = $this->getColour($hoverColour);
|
||||
$colourClasses .= " cursor-pointer {$hoverColour['stroke-hover']} {$hoverColour['fill-hover']} {$hoverColour['stroke-group-hover']} {$hoverColour['fill-group-hover']}";
|
||||
}
|
||||
|
||||
return $colourClasses;
|
||||
}
|
||||
|
||||
private function getPallete(string $palleteName): array
|
||||
private function getColour(string $colourName): array
|
||||
{
|
||||
if (array_key_exists($palleteName, $this->palletes)) {
|
||||
return $this->palletes[$palleteName];
|
||||
if (array_key_exists($colourName, $this->colours)) {
|
||||
return $this->colours[$colourName];
|
||||
}
|
||||
|
||||
throw new PalleteNotFound("The pallete '$palleteName' was not found!");
|
||||
throw new ColourNotFound("The colour \"$colourName\" was not found!");
|
||||
}
|
||||
|
||||
private function addClassesToSvg(string $svg, string $classes): string
|
||||
@@ -239,4 +239,4 @@ final class IconExtension extends AbstractExtension
|
||||
|
||||
class IconNotFound extends \Exception {};
|
||||
|
||||
class PalleteNotFound extends \Exception {};
|
||||
class ColourNotFound extends \Exception {};
|
||||
|
||||
Reference in New Issue
Block a user