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