1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace JeroenNoten\LaravelAdminLte\Helpers; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\View; |
6
|
|
|
|
7
|
|
|
class LayoutHelper |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* Set of tokens related to screen sizes/breakpoints. |
11
|
|
|
* |
12
|
|
|
* @var array |
13
|
|
|
*/ |
14
|
|
|
protected static $screenBreakpoints = ['xs', 'sm', 'md', 'lg', 'xl']; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Check if layout topnav is enabled. |
18
|
|
|
* |
19
|
|
|
* @return bool |
20
|
|
|
*/ |
21
|
|
|
public static function isLayoutTopnavEnabled() |
22
|
|
|
{ |
23
|
|
|
return config('adminlte.layout_topnav') || View::getSection('layout_topnav'); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Check if layout boxed is enabled. |
28
|
12 |
|
* |
29
|
|
|
* @return bool |
30
|
12 |
|
*/ |
31
|
|
|
public static function isLayoutBoxedEnabled() |
32
|
|
|
{ |
33
|
|
|
return config('adminlte.layout_boxed') || View::getSection('layout_boxed'); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Check if layout IFrame is enabled. |
38
|
11 |
|
* |
39
|
|
|
* @return bool |
40
|
11 |
|
*/ |
41
|
|
|
public static function isLayoutIFrameEnabled() |
42
|
|
|
{ |
43
|
|
|
return config('adminlte.layout_iframe.active') || View::getSection('layout_iframe.active'); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Make and return the set of classes related to the body tag. |
48
|
11 |
|
* |
49
|
|
|
* @return string |
50
|
11 |
|
*/ |
51
|
|
|
public static function makeBodyClasses() |
52
|
11 |
|
{ |
53
|
11 |
|
$classes = []; |
54
|
11 |
|
|
55
|
11 |
|
$classes = array_merge($classes, self::makeLayoutClasses()); |
56
|
11 |
|
$classes = array_merge($classes, self::makeSidebarClasses()); |
57
|
|
|
$classes = array_merge($classes, self::makeRightSidebarClasses()); |
58
|
11 |
|
$classes = array_merge($classes, self::makeCustomBodyClasses()); |
59
|
|
|
$classes = array_merge($classes, self::makeDarkModeClasses()); |
60
|
|
|
|
61
|
|
|
return trim(implode(' ', $classes)); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Make and return the set of data attributes related to the body tag. |
66
|
1 |
|
* |
67
|
|
|
* @return string |
68
|
1 |
|
*/ |
69
|
|
|
public static function makeBodyData() |
70
|
|
|
{ |
71
|
|
|
$data = []; |
72
|
1 |
|
|
73
|
|
|
// Add data related to the "sidebar_scrollbar_theme" configuration. |
74
|
1 |
|
|
75
|
1 |
|
$sbTheme = config('adminlte.sidebar_scrollbar_theme', 'os-theme-light'); |
76
|
|
|
|
77
|
|
|
if ($sbTheme != 'os-theme-light') { |
78
|
|
|
$data[] = "data-scrollbar-theme={$sbTheme}"; |
79
|
|
|
} |
80
|
1 |
|
|
81
|
|
|
// Add data related to the "sidebar_scrollbar_auto_hide" configuration. |
82
|
1 |
|
|
83
|
1 |
|
$sbAutoHide = config('adminlte.sidebar_scrollbar_auto_hide', 'l'); |
84
|
|
|
|
85
|
|
|
if ($sbAutoHide != 'l') { |
86
|
1 |
|
$data[] = "data-scrollbar-auto-hide={$sbAutoHide}"; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
return trim(implode(' ', $data)); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Make and return the set of classes related to the layout configuration. |
94
|
11 |
|
* |
95
|
|
|
* @return array |
96
|
11 |
|
*/ |
97
|
|
|
private static function makeLayoutClasses() |
98
|
|
|
{ |
99
|
|
|
$classes = []; |
100
|
11 |
|
|
101
|
2 |
|
// Add classes related to the "layout_topnav" configuration. |
102
|
|
|
|
103
|
|
|
if (self::isLayoutTopnavEnabled()) { |
104
|
|
|
$classes[] = 'layout-top-nav'; |
105
|
|
|
} |
106
|
11 |
|
|
107
|
3 |
|
// Add classes related to the "layout_boxed" configuration. |
108
|
|
|
|
109
|
|
|
if (self::isLayoutBoxedEnabled()) { |
110
|
|
|
$classes[] = 'layout-boxed'; |
111
|
|
|
} |
112
|
|
|
|
113
|
11 |
|
// Add classes related to fixed sidebar layout configuration. The fixed |
114
|
1 |
|
// sidebar is not compatible with layout topnav. |
115
|
|
|
|
116
|
|
|
if (! self::isLayoutTopnavEnabled() && config('adminlte.layout_fixed_sidebar')) { |
117
|
|
|
$classes[] = 'layout-fixed'; |
118
|
|
|
} |
119
|
|
|
|
120
|
11 |
|
// Add classes related to fixed navbar/footer configuration. The fixed |
121
|
11 |
|
// navbar/footer is not compatible with layout boxed. |
122
|
11 |
|
|
123
|
|
|
if (! self::isLayoutBoxedEnabled()) { |
124
|
|
|
$classes = array_merge($classes, self::makeFixedResponsiveClasses('navbar')); |
125
|
11 |
|
$classes = array_merge($classes, self::makeFixedResponsiveClasses('footer')); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
return $classes; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Make the set of classes related to a fixed responsive configuration. |
133
|
|
|
* |
134
|
11 |
|
* @param string $section The layout section (navbar or footer) |
135
|
|
|
* @return array |
136
|
11 |
|
*/ |
137
|
11 |
|
private static function makeFixedResponsiveClasses($section) |
138
|
|
|
{ |
139
|
11 |
|
$classes = []; |
140
|
2 |
|
$cfg = config("adminlte.layout_fixed_{$section}"); |
141
|
|
|
|
142
|
|
|
if ($cfg === true) { |
143
|
|
|
$cfg = ['xs' => true]; |
144
|
|
|
} |
145
|
11 |
|
|
146
|
11 |
|
// At this point the config should be an array. |
147
|
|
|
|
148
|
|
|
if (! is_array($cfg)) { |
149
|
|
|
return $classes; |
150
|
|
|
} |
151
|
2 |
|
|
152
|
2 |
|
// Make the set of responsive classes in relation to the config. |
153
|
2 |
|
|
154
|
2 |
|
foreach ($cfg as $breakpoint => $enabled) { |
155
|
|
|
if (in_array($breakpoint, self::$screenBreakpoints)) { |
156
|
|
|
$classes[] = self::makeFixedResponsiveClass( |
157
|
|
|
$section, $breakpoint, $enabled |
158
|
|
|
); |
159
|
2 |
|
} |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
return $classes; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* Make a responsive class for the navbar/footer fixed mode on a particular |
167
|
|
|
* breakpoint token. |
168
|
|
|
* |
169
|
|
|
* @param string $section The layout section (navbar or footer) |
170
|
|
|
* @param string $bp The screen breakpoint (xs, sm, md, lg, xl) |
171
|
2 |
|
* @param bool $enabled Whether to enable fixed mode (true, false) |
172
|
|
|
* @return string |
173
|
|
|
*/ |
174
|
|
|
private static function makeFixedResponsiveClass($section, $bp, $enabled) |
175
|
2 |
|
{ |
176
|
|
|
// Create the class prefix. |
177
|
|
|
|
178
|
|
|
$prefix = ($bp === 'xs') ? 'layout' : "layout-{$bp}"; |
179
|
2 |
|
|
180
|
|
|
// Create the class suffix. |
181
|
|
|
|
182
|
|
|
$suffix = $enabled ? 'fixed' : 'not-fixed'; |
183
|
2 |
|
|
184
|
|
|
// Return the responsice class for fixed mode. |
185
|
|
|
|
186
|
|
|
return "{$prefix}-{$section}-{$suffix}"; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* Make the set of classes related to the left sidebar configuration. |
191
|
11 |
|
* |
192
|
|
|
* @return array |
193
|
11 |
|
*/ |
194
|
|
|
private static function makeSidebarClasses() |
195
|
|
|
{ |
196
|
|
|
$classes = []; |
197
|
11 |
|
|
198
|
|
|
// Add classes related to the "sidebar_mini" configuration. |
199
|
11 |
|
|
200
|
11 |
|
if (config('adminlte.sidebar_mini', true) === true) { |
201
|
11 |
|
$classes[] = 'sidebar-mini'; |
202
|
|
|
} elseif (config('adminlte.sidebar_mini', true) == 'md') { |
203
|
|
|
$classes[] = 'sidebar-mini sidebar-mini-md'; |
204
|
|
|
} |
205
|
|
|
|
206
|
11 |
|
// Add classes related to the "sidebar_collapse" configuration. |
207
|
1 |
|
|
208
|
|
|
if (config('adminlte.sidebar_collapse') || View::getSection('sidebar_collapse')) { |
209
|
|
|
$classes[] = 'sidebar-collapse'; |
210
|
11 |
|
} |
211
|
|
|
|
212
|
|
|
return $classes; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* Make the set of classes related to the right sidebar configuration. |
217
|
|
|
* |
218
|
11 |
|
* @return array |
219
|
|
|
*/ |
220
|
11 |
|
private static function makeRightSidebarClasses() |
221
|
|
|
{ |
222
|
|
|
$classes = []; |
223
|
|
|
|
224
|
11 |
|
// Add classes related to the "right_sidebar" configuration. |
225
|
1 |
|
|
226
|
|
|
if (config('adminlte.right_sidebar') && config('adminlte.right_sidebar_push')) { |
227
|
|
|
$classes[] = 'control-sidebar-push'; |
228
|
11 |
|
} |
229
|
|
|
|
230
|
|
|
return $classes; |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* Make the set of classes related to custom body classes configuration. |
235
|
|
|
* |
236
|
11 |
|
* @return array |
237
|
|
|
*/ |
238
|
11 |
|
private static function makeCustomBodyClasses() |
239
|
11 |
|
{ |
240
|
|
|
$classes = []; |
241
|
11 |
|
$cfg = config('adminlte.classes_body', ''); |
242
|
1 |
|
|
243
|
|
|
if (is_string($cfg) && $cfg) { |
244
|
|
|
$classes[] = $cfg; |
245
|
11 |
|
} |
246
|
|
|
|
247
|
|
|
return $classes; |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* Make the set of classes related to the dark mode. |
252
|
|
|
* |
253
|
11 |
|
* @return array |
254
|
|
|
*/ |
255
|
11 |
|
private static function makeDarkModeClasses() |
256
|
11 |
|
{ |
257
|
|
|
$classes = []; |
258
|
11 |
|
$cfg = config('adminlte.layout_dark_mode', false); |
259
|
1 |
|
|
260
|
|
|
if (is_bool($cfg) && $cfg) { |
261
|
|
|
$classes[] = 'dark-mode'; |
262
|
11 |
|
} |
263
|
|
|
|
264
|
|
|
return $classes; |
265
|
|
|
} |
266
|
|
|
} |
267
|
|
|
|