1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10:
11:
12: namespace Chromabits\Nucleus\View\Bootstrap;
13:
14: use Chromabits\Nucleus\Foundation\BaseObject;
15: use Chromabits\Nucleus\Support\Str;
16: use Chromabits\Nucleus\View\Common\Anchor;
17: use Chromabits\Nucleus\View\Common\Div;
18: use Chromabits\Nucleus\View\Common\Italic;
19:
20: 21: 22: 23: 24: 25:
26: class DropdownFactory extends BaseObject
27: {
28: 29: 30:
31: protected $hash;
32:
33: 34: 35:
36: protected $options;
37:
38: 39: 40:
41: protected $right;
42:
43: 44: 45:
46: public function __construct()
47: {
48: parent::__construct();
49:
50: $this->hash = Str::random();
51: $this->options = [];
52: $this->right = false;
53: }
54:
55: 56: 57: 58: 59: 60: 61: 62:
63: public function addOption($url, $content)
64: {
65: $this->options[] = new Anchor(
66: [
67: 'class' => 'dropdown-item',
68: 'href' => $url,
69: ],
70: $content
71: );
72:
73: return $this;
74: }
75:
76: 77: 78:
79: public function fromRight()
80: {
81: $this->right = true;
82:
83: return $this;
84: }
85:
86: 87: 88: 89: 90:
91: public function make()
92: {
93: $menuClasses = ['dropdown-menu'];
94:
95: if ($this->right) {
96: $menuClasses[] = 'dropdown-menu-right';
97: }
98:
99: return new Div(['class' => 'dropdown'], [
100: new Anchor(
101: [
102: 'id' => $this->hash,
103: 'data-toggle' => 'dropdown',
104: 'aria-haspopup' => 'true',
105: 'aria-expanded' => 'false',
106: ],
107: new Italic(['class' => 'fa fa-ellipsis-h'])
108: ),
109: new Div(
110: [
111: 'class' => $menuClasses,
112: 'aria-labelledby' => $this->hash,
113: ],
114: $this->options
115: ),
116: ]);
117: }
118: }
119: