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