|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace AbterPhp\PropellerAdmin\Decorator; |
|
6
|
|
|
|
|
7
|
|
|
use AbterPhp\Framework\Decorator\Decorator; |
|
8
|
|
|
use AbterPhp\Framework\Decorator\Rule; |
|
9
|
|
|
use AbterPhp\Framework\Html\Component; |
|
10
|
|
|
use AbterPhp\Framework\Html\Component\Button; |
|
11
|
|
|
|
|
12
|
|
|
class General extends Decorator |
|
13
|
|
|
{ |
|
14
|
|
|
const BUTTON_CLASS = 'btn'; |
|
15
|
|
|
|
|
16
|
|
|
/** @var array */ |
|
17
|
|
|
protected $buttonIntentMap = [ |
|
18
|
|
|
Button::INTENT_PRIMARY => ['btn-primary'], |
|
19
|
|
|
Button::INTENT_SECONDARY => ['btn-secondary'], |
|
20
|
|
|
Button::INTENT_DANGER => ['btn-danger'], |
|
21
|
|
|
Button::INTENT_SUCCESS => ['btn-success'], |
|
22
|
|
|
Button::INTENT_INFO => ['btn-info'], |
|
23
|
|
|
Button::INTENT_WARNING => ['btn-warning'], |
|
24
|
|
|
Button::INTENT_LINK => ['btn-link'], |
|
25
|
|
|
Button::INTENT_DEFAULT => ['btn-default'], |
|
26
|
|
|
|
|
27
|
|
|
Button::INTENT_SMALL => ['btn-sm'], |
|
28
|
|
|
Button::INTENT_LARGE => ['btn-lg'], |
|
29
|
|
|
|
|
30
|
|
|
Button::INTENT_FAB => ['pmd-btn-fab'], |
|
31
|
|
|
Button::INTENT_FLAT => ['pmd-btn-flat'], |
|
32
|
|
|
Button::INTENT_RAISED => ['pmd-btn-raised'], |
|
33
|
|
|
Button::INTENT_OUTLINE => ['pmd-btn-outline'], |
|
34
|
|
|
Button::INTENT_RIPPLE => ['pmd-ripple-effect '], |
|
35
|
|
|
]; |
|
36
|
|
|
|
|
37
|
|
|
/** @var array */ |
|
38
|
|
|
protected $componentMap = [ |
|
39
|
|
|
Component::INTENT_HIDDEN => [Component::CLASS_HIDDEN], |
|
40
|
|
|
Component::INTENT_ICON => ['material-icons'], |
|
41
|
|
|
Component::INTENT_SMALL => ['pmd-sm'], |
|
42
|
|
|
Component::INTENT_LARGE => ['pmd-lg'], |
|
43
|
|
|
]; |
|
44
|
|
|
|
|
45
|
|
|
protected $initialized = false; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @return Decorator |
|
49
|
|
|
*/ |
|
50
|
|
|
public function init(): Decorator |
|
51
|
|
|
{ |
|
52
|
|
|
if ($this->initialized) { |
|
53
|
|
|
return $this; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
$this->initialized = true; |
|
57
|
|
|
|
|
58
|
|
|
// Add the appropriate class to components |
|
59
|
|
|
$this->rules[] = new Rule([], null, [], $this->componentMap); |
|
60
|
|
|
|
|
61
|
|
|
// Add the appropriate class to buttons |
|
62
|
|
|
$this->rules[] = new Rule([], Button::class, [static::BUTTON_CLASS], $this->buttonIntentMap); |
|
63
|
|
|
|
|
64
|
|
|
return $this; |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|