-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add improvements on the preloader animation * Add tests for the new preloader improvements * Add style CI fix * Refactor: split out logic from LayoutHelper to PreloaderHelper * Apply fix related to style CI
- Loading branch information
Showing
8 changed files
with
242 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,22 @@ | ||
<div class="preloader flex-column justify-content-center align-items-center"> | ||
|
||
{{-- Preloader logo --}} | ||
<img src="{{ asset(config('adminlte.preloader.img.path', 'vendor/adminlte/dist/img/AdminLTELogo.png')) }}" | ||
class="{{ config('adminlte.preloader.img.effect', 'animation__shake') }}" | ||
alt="{{ config('adminlte.preloader.img.alt', 'AdminLTE Preloader Image') }}" | ||
width="{{ config('adminlte.preloader.img.width', 60) }}" | ||
height="{{ config('adminlte.preloader.img.height', 60) }}"> | ||
@inject('preloaderHelper', 'JeroenNoten\LaravelAdminLte\Helpers\PreloaderHelper') | ||
|
||
<div class="{{ $preloaderHelper->makePreloaderClasses() }}" style="{{ $preloaderHelper->makePreloaderStyle() }}"> | ||
|
||
@hasSection('preloader') | ||
|
||
{{-- Use a custom preloader content --}} | ||
@yield('preloader') | ||
|
||
@else | ||
|
||
{{-- Use the default preloader content --}} | ||
<img src="{{ asset(config('adminlte.preloader.img.path', 'vendor/adminlte/dist/img/AdminLTELogo.png')) }}" | ||
class="img-circle {{ config('adminlte.preloader.img.effect', 'animation__shake') }}" | ||
alt="{{ config('adminlte.preloader.img.alt', 'AdminLTE Preloader Image') }}" | ||
width="{{ config('adminlte.preloader.img.width', 60) }}" | ||
height="{{ config('adminlte.preloader.img.height', 60) }}" | ||
style="animation-iteration-count:infinite;"> | ||
|
||
@endif | ||
|
||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
namespace JeroenNoten\LaravelAdminLte\Helpers; | ||
|
||
class PreloaderHelper | ||
{ | ||
/** | ||
* Check if the preloader animation is enabled for the specified mode. | ||
* | ||
* @param string $mode The preloader mode to check. | ||
* @return bool | ||
*/ | ||
public static function isPreloaderEnabled($mode = 'fullscreen') | ||
{ | ||
return config('adminlte.preloader.enabled', false) | ||
&& config('adminlte.preloader.mode', 'fullscreen') == $mode; | ||
} | ||
|
||
/** | ||
* Make and return the set of classes related to the preloader animation. | ||
* | ||
* @return string | ||
*/ | ||
public static function makePreloaderClasses() | ||
{ | ||
// Setup the base set of classes for the preloader. | ||
|
||
$classes = [ | ||
'preloader', | ||
'flex-column', | ||
'justify-content-center', | ||
'align-items-center', | ||
]; | ||
|
||
// When the preloader is attached to the content-wrapper, the CSS | ||
// position attribute should be absolute. | ||
|
||
if (self::isPreloaderEnabled('cwrapper')) { | ||
$classes[] = 'position-absolute'; | ||
} | ||
|
||
return trim(implode(' ', $classes)); | ||
} | ||
|
||
/** | ||
* Make and return the set of styles related to the preloader. | ||
* | ||
* @return string | ||
*/ | ||
public static function makePreloaderStyle() | ||
{ | ||
$styles = []; | ||
|
||
// When the preloader is attached to the content-wrapper, the CSS | ||
// z-index attribute should be less than the value of z-index for the | ||
// sidebars, the top navbar and the footer (they all are between 1030 | ||
// and 1040). This way, we avoid overlapping with those elements. | ||
|
||
if (self::isPreloaderEnabled('cwrapper')) { | ||
$styles[] = 'z-index:1000'; | ||
} | ||
|
||
return trim(implode(';', $styles)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<?php | ||
|
||
use JeroenNoten\LaravelAdminLte\Helpers\PreloaderHelper; | ||
|
||
class PreloaderHelperTest extends TestCase | ||
{ | ||
public function testEnableDisablePreloaderFullscreenMode() | ||
{ | ||
// Test with config enabled. | ||
|
||
config(['adminlte.preloader.enabled' => true]); | ||
|
||
$this->assertTrue(PreloaderHelper::isPreloaderEnabled()); | ||
$this->assertTrue(PreloaderHelper::isPreloaderEnabled('fullscreen')); | ||
$this->assertFalse(PreloaderHelper::isPreloaderEnabled('cwrapper')); | ||
|
||
// Test with config disabled. | ||
|
||
config(['adminlte.preloader.enabled' => false]); | ||
|
||
$this->assertFalse(PreloaderHelper::isPreloaderEnabled()); | ||
$this->assertFalse(PreloaderHelper::isPreloaderEnabled('fullscreen')); | ||
$this->assertFalse(PreloaderHelper::isPreloaderEnabled('cwrapper')); | ||
} | ||
|
||
public function testEnableDisablePreloaderCWrapperMode() | ||
{ | ||
// Test with config enabled. | ||
|
||
config([ | ||
'adminlte.preloader.enabled' => true, | ||
'adminlte.preloader.mode' => 'cwrapper', | ||
]); | ||
|
||
$this->assertFalse(PreloaderHelper::isPreloaderEnabled()); | ||
$this->assertFalse(PreloaderHelper::isPreloaderEnabled('fullscreen')); | ||
$this->assertTrue(PreloaderHelper::isPreloaderEnabled('cwrapper')); | ||
|
||
// Test with config disabled. | ||
|
||
config([ | ||
'adminlte.preloader.enabled' => false, | ||
'adminlte.preloader.mode' => 'cwrapper', | ||
]); | ||
|
||
$this->assertFalse(PreloaderHelper::isPreloaderEnabled()); | ||
$this->assertFalse(PreloaderHelper::isPreloaderEnabled('fullscreen')); | ||
$this->assertFalse(PreloaderHelper::isPreloaderEnabled('cwrapper')); | ||
} | ||
|
||
public function testMakePreloaderClasses() | ||
{ | ||
// Test without config. | ||
|
||
$data = PreloaderHelper::makePreloaderClasses(); | ||
$this->assertEquals( | ||
'preloader flex-column justify-content-center align-items-center', | ||
$data | ||
); | ||
|
||
// Test with cwrapper mode enabled. | ||
|
||
config([ | ||
'adminlte.preloader.enabled' => true, | ||
'adminlte.preloader.mode' => 'cwrapper', | ||
]); | ||
|
||
$data = PreloaderHelper::makePreloaderClasses(); | ||
|
||
$this->assertStringContainsString( | ||
'preloader flex-column justify-content-center align-items-center', | ||
$data | ||
); | ||
|
||
$this->assertStringContainsString('position-absolute', $data); | ||
} | ||
|
||
public function testMakePreloaderStyle() | ||
{ | ||
// Test without config. | ||
|
||
$data = PreloaderHelper::makePreloaderStyle(); | ||
$this->assertEquals('', $data); | ||
|
||
// Test with cwrapper mode enabled. | ||
|
||
config([ | ||
'adminlte.preloader.enabled' => true, | ||
'adminlte.preloader.mode' => 'cwrapper', | ||
]); | ||
|
||
$data = PreloaderHelper::makePreloaderStyle(); | ||
$this->assertStringContainsString('z-index:', $data); | ||
} | ||
} |