standard colours
This commit is contained in:
@@ -6,19 +6,92 @@ namespace Modules\Helpdesk\Support;
|
||||
|
||||
final class Color
|
||||
{
|
||||
/**
|
||||
* Standard approved Helpdesk badge colours.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
public const PALETTE = [
|
||||
'green' => '#16a34a',
|
||||
'red' => '#dc2626',
|
||||
'amber' => '#d97706',
|
||||
'blue' => '#2563eb',
|
||||
'indigo' => '#4f46e5',
|
||||
'purple' => '#7c3aed',
|
||||
'gray' => '#6b7280',
|
||||
];
|
||||
|
||||
/**
|
||||
* Legacy Flux/Tailwind colour aliases normalised into the WMS palette.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
private const ALIASES = [
|
||||
'emerald' => 'green',
|
||||
'lime' => 'green',
|
||||
'rose' => 'red',
|
||||
'yellow' => 'amber',
|
||||
'orange' => 'amber',
|
||||
'sky' => 'blue',
|
||||
'cyan' => 'blue',
|
||||
'violet' => 'purple',
|
||||
'slate' => 'gray',
|
||||
'zinc' => 'gray',
|
||||
'' => 'gray',
|
||||
];
|
||||
|
||||
/**
|
||||
* Resolve a stored colour key or supported hex value into a CSS colour.
|
||||
*/
|
||||
public static function css(?string $color): string
|
||||
{
|
||||
return match ($color) {
|
||||
'red', 'rose' => '#e11d48',
|
||||
'amber', 'yellow' => '#d97706',
|
||||
'emerald', 'green' => '#059669',
|
||||
'blue' => '#2563eb',
|
||||
'sky', 'cyan' => '#0284c7',
|
||||
'indigo' => '#4f46e5',
|
||||
'violet', 'purple' => '#7c3aed',
|
||||
'slate' => '#334155',
|
||||
'zinc', null, '' => '#52525b',
|
||||
default => str_starts_with((string) $color, '#') ? (string) $color : '#52525b',
|
||||
};
|
||||
$resolved = self::normalise($color);
|
||||
|
||||
if (str_starts_with($resolved, '#')) {
|
||||
return $resolved;
|
||||
}
|
||||
|
||||
return self::PALETTE[$resolved] ?? self::PALETTE['gray'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return approved palette options for settings dropdowns.
|
||||
*
|
||||
* @return array<string, array{name: string, hex: string}>
|
||||
*/
|
||||
public static function options(): array
|
||||
{
|
||||
return collect(self::PALETTE)
|
||||
->mapWithKeys(fn (string $hex, string $name): array => [
|
||||
$name => [
|
||||
'name' => str($name)->headline()->toString(),
|
||||
'hex' => $hex,
|
||||
],
|
||||
])
|
||||
->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return approved palette keys for validation rules.
|
||||
*
|
||||
* @return list<string>
|
||||
*/
|
||||
public static function keys(): array
|
||||
{
|
||||
return array_keys(self::PALETTE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalise legacy aliases and supported hex colours.
|
||||
*/
|
||||
public static function normalise(?string $color): string
|
||||
{
|
||||
$value = strtolower(trim((string) $color));
|
||||
|
||||
if (preg_match('/^#[a-f0-9]{6}$/', $value) === 1) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
return self::ALIASES[$value] ?? $value;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user