1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace JeroenNoten\LaravelAdminLte\Components\Layout; |
4
|
|
|
|
5
|
|
|
use Illuminate\View\Component; |
6
|
|
|
use JeroenNoten\LaravelAdminLte\Http\Controllers\DarkModeController; |
7
|
|
|
|
8
|
|
|
class NavbarDarkmodeWidget extends Component |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* The Font Awesome icon to use when dark mode is disabled. |
12
|
|
|
* |
13
|
|
|
* @var string |
14
|
|
|
*/ |
15
|
|
|
public $iconDisabled = 'far fa-moon'; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* The Font Awesome icon to use when dark mode is enabled. |
19
|
|
|
* |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
public $iconEnabled = 'fas fa-moon'; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* The AdminLTE color to use for the icon when dark mode is disabled. |
26
|
|
|
* |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
public $colorDisabled; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* The AdminLTE color to use for the icon when dark mode is enabled. |
33
|
|
|
* |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
public $colorEnabled; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Create a new component instance. |
40
|
|
|
* |
41
|
|
|
* @return void |
42
|
|
|
*/ |
43
|
2 |
|
public function __construct( |
44
|
|
|
$iconDisabled = null, $iconEnabled = null, |
45
|
|
|
$colorDisabled = null, $colorEnabled = null |
46
|
|
|
) { |
47
|
|
|
// Setup the icon to use when dark mode is disabled. |
48
|
|
|
|
49
|
2 |
|
if (! empty($iconDisabled)) { |
50
|
1 |
|
$this->iconDisabled = $iconDisabled; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
// Setup the icon to use when dark mode is enabled. |
54
|
|
|
|
55
|
2 |
|
if (! empty($iconEnabled)) { |
56
|
1 |
|
$this->iconEnabled = $iconEnabled; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
// Setup the icon colors. |
60
|
|
|
|
61
|
2 |
|
$this->colorDisabled = $colorDisabled; |
62
|
2 |
|
$this->colorEnabled = $colorEnabled; |
63
|
2 |
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Make the class attribute for the dark mode widget icon. |
67
|
|
|
* |
68
|
|
|
* @return string |
69
|
|
|
*/ |
70
|
1 |
|
public function makeIconClass() |
71
|
|
|
{ |
72
|
|
|
// Use the controller to check if dark mode is enabled. |
73
|
|
|
|
74
|
1 |
|
if ((new DarkModeController())->isEnabled()) { |
75
|
1 |
|
$classes = $this->makeIconEnabledClass(); |
76
|
|
|
} else { |
77
|
1 |
|
$classes = $this->makeIconDisabledClass(); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
// Return the icon classes. |
81
|
|
|
|
82
|
1 |
|
return implode(' ', $classes); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Make the class attribute for the icon when dark mode is disabled. |
87
|
|
|
* |
88
|
|
|
* @return array |
89
|
|
|
*/ |
90
|
1 |
|
public function makeIconDisabledClass() |
91
|
|
|
{ |
92
|
1 |
|
$classes = explode(' ', $this->iconDisabled); |
93
|
|
|
|
94
|
1 |
|
if (! empty($this->colorDisabled)) { |
95
|
1 |
|
$classes[] = "text-{$this->colorDisabled}"; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
// Return the icon classes. |
99
|
|
|
|
100
|
1 |
|
return $classes; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Make the class attribute for the icon when dark mode is enabled. |
105
|
|
|
* |
106
|
|
|
* @return array |
107
|
|
|
*/ |
108
|
1 |
|
public function makeIconEnabledClass() |
109
|
|
|
{ |
110
|
1 |
|
$classes = explode(' ', $this->iconEnabled); |
111
|
|
|
|
112
|
1 |
|
if (! empty($this->colorEnabled)) { |
113
|
1 |
|
$classes[] = "text-{$this->colorEnabled}"; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
// Return the icon classes. |
117
|
|
|
|
118
|
1 |
|
return $classes; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Get the view / contents that represent the component. |
123
|
|
|
* |
124
|
|
|
* @return \Illuminate\View\View|string |
125
|
|
|
*/ |
126
|
1 |
|
public function render() |
127
|
|
|
{ |
128
|
1 |
|
return view('adminlte::components.layout.navbar-darkmode-widget'); |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|