adrema/app/View/Enums/Variant.php

78 lines
2.3 KiB
PHP
Raw Normal View History

2024-10-17 00:25:58 +02:00
<?php
namespace App\View\Enums;
2024-10-19 21:27:03 +02:00
use Illuminate\Support\Collection;
use InvalidArgumentException;
2024-10-17 00:25:58 +02:00
enum Variant: string
{
case PRIMARY = 'primary';
case SECONDARY = 'secondary';
case PRIMARYLIGHT = 'primary-light';
case WARNING = 'warning';
case INFO = 'info';
case DANGER = 'danger';
public function foreground(): string
{
return match ($this) {
self::PRIMARY => 'text-primary-300',
self::SECONDARY => 'text-primary-400',
self::PRIMARYLIGHT => 'text-primary-200',
self::WARNING => 'text-yellow-300',
self::INFO => 'text-blue-300',
self::DANGER => 'text-red-100',
};
}
public function background(): string
{
return match ($this) {
self::PRIMARY => 'bg-primary-700',
self::SECONDARY => 'bg-primary-800',
self::PRIMARYLIGHT => 'bg-primary-600',
self::WARNING => 'bg-yellow-700',
self::INFO => 'bg-blue-700',
self::DANGER => 'bg-red-400',
};
}
public function hoverForeground(): string
{
return match ($this) {
self::PRIMARY => 'hover:text-primary-100',
self::SECONDARY => 'hover:text-primary-200',
self::PRIMARYLIGHT => 'hover:text-primary-100',
self::WARNING => 'hover:text-yellow-100',
self::INFO => 'hover:text-blue-100',
self::DANGER => 'hover:text-red-100',
};
}
public function hoverBackground(): string
{
return match ($this) {
self::PRIMARY => 'hover:bg-primary-500',
self::SECONDARY => 'hover:bg-primary-600',
self::PRIMARYLIGHT => 'hover:bg-primary-500',
self::WARNING => 'hover:bg-yellow-500',
self::INFO => 'hover:bg-blue-500',
self::DANGER => 'hover:bg-red-500',
};
}
public static function fromString(string $input): self
{
return collect(static::cases())
2024-10-19 21:27:03 +02:00
->first(fn ($variant) => $variant->value === $input)
?: throw new InvalidArgumentException("Unknown variant: {$input} - Available Variants: " . self::values()->implode(', '));
}
public static function values(): Collection
{
return collect(static::cases())->map(fn ($variant) => $variant->value);
2024-10-17 00:25:58 +02:00
}
}