1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Formularium\Frontend\Vuetify\Element; |
4
|
|
|
|
5
|
|
|
use Formularium\Element as Element; |
6
|
|
|
use Formularium\Exception\Exception; |
7
|
|
|
use Formularium\HTMLNode; |
8
|
|
|
|
9
|
|
|
abstract class VuetifyElement extends Element |
10
|
|
|
{ |
11
|
|
|
const COLOR = 'color'; |
12
|
|
|
const COLOR_PRIMARY = 'primary'; |
13
|
|
|
const COLOR_LINK = 'link'; |
14
|
|
|
const COLOR_INFO = 'info'; |
15
|
|
|
const COLOR_SUCCESS = 'success'; |
16
|
|
|
const COLOR_WARNING = 'warning'; |
17
|
|
|
const COLOR_ERROR = 'error'; |
18
|
|
|
|
19
|
|
|
public function color(array $parameters, HTMLNode $node): HTMLNode |
20
|
|
|
{ |
21
|
|
|
$color = $parameters[self::COLOR] ?? ''; |
22
|
|
|
if (!$color) { |
23
|
|
|
return $node; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
$colorMap = [ |
27
|
|
|
self::COLOR_PRIMARY => 'primary', |
28
|
|
|
self::COLOR_LINK => 'anchor', |
29
|
|
|
self::COLOR_INFO => 'info', |
30
|
|
|
self::COLOR_SUCCESS => 'success', |
31
|
|
|
self::COLOR_WARNING => 'warning', |
32
|
|
|
self::COLOR_ERROR => 'error', |
33
|
|
|
]; |
34
|
|
|
|
35
|
|
|
if (array_key_exists($color, $colorMap)) { |
36
|
|
|
$color = $parameters[self::COLOR]; |
37
|
|
|
} else { |
38
|
|
|
$colors = [ |
39
|
|
|
'primary', |
40
|
|
|
'secondary', |
41
|
|
|
'helper', |
42
|
|
|
'accent', |
43
|
|
|
'anchor', |
44
|
|
|
'error', |
45
|
|
|
'info', |
46
|
|
|
'success', |
47
|
|
|
'warning', |
48
|
|
|
]; |
49
|
|
|
if (!in_array($color, $colors)) { |
50
|
|
|
throw new Exception('Invalid button color: ' . $color); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
if ($color) { |
54
|
|
|
$node->addAttribute('color', $color); |
55
|
|
|
} |
56
|
|
|
return $node; |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|