Skip to content

Commit 141f395

Browse files
authored
Move LoadingPlaceholderStyling into new method
1 parent 61a9b66 commit 141f395

File tree

7 files changed

+116
-74
lines changed

7 files changed

+116
-74
lines changed

resources/views/components/includes/loading.blade.php

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,38 @@
1-
@aware(['isTailwind', 'isBootstrap', 'tableName', 'component'])
1+
@aware(['tableName'])
22
@props(['colCount' => 1])
33

44
@php
5-
$customAttributes['loader-wrapper'] = $this->getLoadingPlaceHolderWrapperAttributes();
6-
$customAttributes['loader-icon'] = $this->getLoadingPlaceHolderIconAttributes();
5+
$loaderWrapper = $this->getLoadingPlaceHolderWrapperAttributes();
6+
$loaderCell = $this->getLoadingPlaceHolderCellAttributes();
7+
$loaderIcon = $this->getLoadingPlaceHolderIconAttributes();
78
@endphp
8-
@if($this->hasLoadingPlaceholderBlade())
9-
@include($this->getLoadingPlaceHolderBlade(), ['colCount' => $colCount])
10-
@else
119

12-
<tr wire:key="{{ $tableName }}-loader"
13-
{{
14-
$attributes->merge($customAttributes['loader-wrapper'])
15-
->class(['hidden w-full text-center h-screen place-items-center align-middle' => $isTailwind && ($customAttributes['loader-wrapper']['default'] ?? true)])
16-
->class(['d-none w-100 text-center h-100 align-items-center' => $isBootstrap && ($customAttributes['loader-wrapper']['default'] ?? true)]);
17-
}}
18-
wire:loading.class.remove="hidden d-none"
19-
>
20-
<td colspan="{{ $colCount }}" wire:key="{{ $tableName }}-loader-column" >
10+
<tr wire:key="{{ $tableName }}-loader" wire:loading.class.remove="hidden d-none" {{
11+
$attributes->merge($loaderWrapper)
12+
->class(['hidden w-full text-center place-items-center align-middle' => $this->isTailwind && ($loaderWrapper['default'] ?? true)])
13+
->class(['d-none w-100 text-center align-items-center' => $this->isBootstrap && ($loaderWrapper['default'] ?? true)])
14+
->except(['default','default-styling','default-colors'])
15+
}}>
16+
<td colspan="{{ $colCount }}" wire:key="{{ $tableName }}-loader-column" {{
17+
$attributes->merge($loaderCell)
18+
->class(['py-4' => $this->isTailwind && ($loaderCell['default'] ?? true)])
19+
->class(['py-4' => $this->isBootstrap && ($loaderCell['default'] ?? true)])
20+
->except(['default','default-styling','default-colors', 'colspan','wire:key'])
21+
}}>
22+
@if($this->hasLoadingPlaceholderBlade())
23+
@include($this->getLoadingPlaceHolderBlade(), ['colCount' => $colCount])
24+
@else
25+
2126
<div class="h-min self-center align-middle text-center">
22-
<div class="lds-hourglass"
23-
{{
24-
$attributes->merge($customAttributes['loader-icon'])
25-
->class(['lds-hourglass' => $isTailwind && ($customAttributes['loader-icon']['default'] ?? true)])
26-
->class(['lds-hourglass' => $isBootstrap && ($customAttributes['loader-icon']['default'] ?? true)])
27+
<div class="lds-hourglass"{{
28+
$attributes->merge($loaderIcon)
29+
->class(['lds-hourglass' => $this->isTailwind && ($loaderIcon['default'] ?? true)])
30+
->class(['lds-hourglass' => $this->isBootstrap && ($loaderIcon['default'] ?? true)])
2731
->except(['default','default-styling','default-colors']);
28-
}}
29-
></div>
30-
<div>{{ $this->getLoadingPlaceholderContent() }}</div>
32+
}}></div>
33+
<div>{!! $this->getLoadingPlaceholderContent() !!}</div>
3134
</div>
32-
</td>
33-
</tr>
35+
@endif
36+
</td>
37+
</tr>
3438

35-
@endif

src/Traits/Configuration/LoadingPlaceholderConfiguration.php

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -32,31 +32,4 @@ public function setLoadingPlaceholderContent(string $content): self
3232
return $this;
3333
}
3434

35-
public function setLoadingPlaceHolderAttributes(array $attributes): self
36-
{
37-
$this->loadingPlaceHolderAttributes = $attributes;
38-
39-
return $this;
40-
}
41-
42-
public function setLoadingPlaceHolderIconAttributes(array $attributes): self
43-
{
44-
$this->loadingPlaceHolderIconAttributes = $attributes;
45-
46-
return $this;
47-
}
48-
49-
public function setLoadingPlaceHolderWrapperAttributes(array $attributes): self
50-
{
51-
$this->loadingPlaceHolderWrapperAttributes = $attributes;
52-
53-
return $this;
54-
}
55-
56-
public function setLoadingPlaceholderBlade(string $customBlade): self
57-
{
58-
$this->loadingPlaceholderBlade = $customBlade;
59-
60-
return $this;
61-
}
6235
}

src/Traits/Helpers/LoadingPlaceholderHelpers.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,6 @@ public function getLoadingPlaceholderContent(): string
1919
return $this->loadingPlaceholderContent ?? __('livewire-tables:loading');
2020
}
2121

22-
public function getLoadingPlaceholderAttributes(): array
23-
{
24-
return count($this->loadingPlaceHolderAttributes) ? $this->loadingPlaceHolderAttributes : ['default' => true];
25-
26-
}
27-
28-
public function getLoadingPlaceHolderIconAttributes(): array
29-
{
30-
return count($this->loadingPlaceHolderIconAttributes) ? $this->loadingPlaceHolderIconAttributes : ['default' => true];
31-
}
32-
33-
public function getLoadingPlaceHolderWrapperAttributes(): array
34-
{
35-
return count($this->loadingPlaceHolderWrapperAttributes) ? $this->loadingPlaceHolderWrapperAttributes : ['default' => true];
36-
}
37-
3822
public function hasLoadingPlaceholderBlade(): bool
3923
{
4024
return ! is_null($this->getLoadingPlaceHolderBlade());
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace Rappasoft\LaravelLivewireTables\Traits\Styling\Configuration;
4+
5+
trait LoadingPlaceholderStylingConfiguration
6+
{
7+
public function setLoadingPlaceHolderAttributes(array $attributes): self
8+
{
9+
$this->loadingPlaceHolderAttributes = $attributes;
10+
11+
return $this;
12+
}
13+
14+
public function setLoadingPlaceHolderIconAttributes(array $attributes): self
15+
{
16+
$this->loadingPlaceHolderIconAttributes = $attributes;
17+
18+
return $this;
19+
}
20+
21+
public function setLoadingPlaceHolderWrapperAttributes(array $attributes): self
22+
{
23+
$this->loadingPlaceHolderWrapperAttributes = $attributes;
24+
25+
return $this;
26+
}
27+
28+
public function setLoadingPlaceholderBlade(string $customBlade): self
29+
{
30+
$this->loadingPlaceholderBlade = $customBlade;
31+
32+
return $this;
33+
}
34+
35+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Rappasoft\LaravelLivewireTables\Traits\Styling;
4+
5+
use Rappasoft\LaravelLivewireTables\Traits\Styling\Configuration\LoadingPlaceholderStylingConfiguration;
6+
use Rappasoft\LaravelLivewireTables\Traits\Styling\Helpers\LoadingPlaceholderStylingHelpers;
7+
8+
trait HasLoadingPlaceholderStyling
9+
{
10+
use LoadingPlaceholderStylingConfiguration,
11+
LoadingPlaceholderStylingHelpers;
12+
13+
protected array $loadingPlaceHolderAttributes = [];
14+
15+
protected array $loadingPlaceHolderIconAttributes = [];
16+
17+
protected array $loadingPlaceHolderWrapperAttributes = [];
18+
19+
protected array $loadingPlaceHolderCellAttributes = ['class' => '', 'default' => true];
20+
21+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace Rappasoft\LaravelLivewireTables\Traits\Styling\Helpers;
4+
5+
use Livewire\Attributes\Computed;
6+
7+
trait LoadingPlaceholderStylingHelpers
8+
{
9+
public function getLoadingPlaceholderAttributes(): array
10+
{
11+
return count($this->loadingPlaceHolderAttributes) ? $this->loadingPlaceHolderAttributes : ['default' => true];
12+
}
13+
14+
public function getLoadingPlaceHolderIconAttributes(): array
15+
{
16+
return count($this->loadingPlaceHolderIconAttributes) ? $this->loadingPlaceHolderIconAttributes : ['default' => true];
17+
}
18+
19+
public function getLoadingPlaceHolderWrapperAttributes(): array
20+
{
21+
return count($this->loadingPlaceHolderWrapperAttributes) ? $this->loadingPlaceHolderWrapperAttributes : ['default' => true];
22+
}
23+
24+
public function getLoadingPlaceHolderCellAttributes(): array
25+
{
26+
return count($this->loadingPlaceHolderCellAttributes) ? $this->loadingPlaceHolderCellAttributes : ['default' => true];
27+
}
28+
}

src/Traits/WithLoadingPlaceholder.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,19 @@
44

55
use Rappasoft\LaravelLivewireTables\Traits\Configuration\LoadingPlaceholderConfiguration;
66
use Rappasoft\LaravelLivewireTables\Traits\Helpers\LoadingPlaceholderHelpers;
7+
use Rappasoft\LaravelLivewireTables\Traits\Styling\HasLoadingPlaceholderStyling;
78

89
trait WithLoadingPlaceholder
910
{
1011
use LoadingPlaceholderConfiguration,
11-
LoadingPlaceholderHelpers;
12+
LoadingPlaceholderHelpers,
13+
HasLoadingPlaceholderStyling;
1214

1315
protected bool $displayLoadingPlaceholder = false;
1416

1517
protected string $loadingPlaceholderContent = 'Loading';
1618

1719
protected ?string $loadingPlaceholderBlade = null;
1820

19-
protected array $loadingPlaceHolderAttributes = [];
2021

21-
protected array $loadingPlaceHolderIconAttributes = [];
22-
23-
protected array $loadingPlaceHolderWrapperAttributes = [];
2422
}

0 commit comments

Comments
 (0)