Skip to content

Commit

Permalink
Move LoadingPlaceholderStyling into new method
Browse files Browse the repository at this point in the history
  • Loading branch information
lrljoe authored Oct 1, 2024
1 parent 61a9b66 commit 141f395
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 74 deletions.
55 changes: 29 additions & 26 deletions resources/views/components/includes/loading.blade.php
Original file line number Diff line number Diff line change
@@ -1,35 +1,38 @@
@aware(['isTailwind', 'isBootstrap', 'tableName', 'component'])
@aware(['tableName'])
@props(['colCount' => 1])

@php
$customAttributes['loader-wrapper'] = $this->getLoadingPlaceHolderWrapperAttributes();
$customAttributes['loader-icon'] = $this->getLoadingPlaceHolderIconAttributes();
$loaderWrapper = $this->getLoadingPlaceHolderWrapperAttributes();
$loaderCell = $this->getLoadingPlaceHolderCellAttributes();
$loaderIcon = $this->getLoadingPlaceHolderIconAttributes();
@endphp
@if($this->hasLoadingPlaceholderBlade())
@include($this->getLoadingPlaceHolderBlade(), ['colCount' => $colCount])
@else

<tr wire:key="{{ $tableName }}-loader"
{{
$attributes->merge($customAttributes['loader-wrapper'])
->class(['hidden w-full text-center h-screen place-items-center align-middle' => $isTailwind && ($customAttributes['loader-wrapper']['default'] ?? true)])
->class(['d-none w-100 text-center h-100 align-items-center' => $isBootstrap && ($customAttributes['loader-wrapper']['default'] ?? true)]);
}}
wire:loading.class.remove="hidden d-none"
>
<td colspan="{{ $colCount }}" wire:key="{{ $tableName }}-loader-column" >
<tr wire:key="{{ $tableName }}-loader" wire:loading.class.remove="hidden d-none" {{
$attributes->merge($loaderWrapper)
->class(['hidden w-full text-center place-items-center align-middle' => $this->isTailwind && ($loaderWrapper['default'] ?? true)])
->class(['d-none w-100 text-center align-items-center' => $this->isBootstrap && ($loaderWrapper['default'] ?? true)])
->except(['default','default-styling','default-colors'])
}}>
<td colspan="{{ $colCount }}" wire:key="{{ $tableName }}-loader-column" {{
$attributes->merge($loaderCell)
->class(['py-4' => $this->isTailwind && ($loaderCell['default'] ?? true)])
->class(['py-4' => $this->isBootstrap && ($loaderCell['default'] ?? true)])
->except(['default','default-styling','default-colors', 'colspan','wire:key'])
}}>
@if($this->hasLoadingPlaceholderBlade())
@include($this->getLoadingPlaceHolderBlade(), ['colCount' => $colCount])
@else

<div class="h-min self-center align-middle text-center">
<div class="lds-hourglass"
{{
$attributes->merge($customAttributes['loader-icon'])
->class(['lds-hourglass' => $isTailwind && ($customAttributes['loader-icon']['default'] ?? true)])
->class(['lds-hourglass' => $isBootstrap && ($customAttributes['loader-icon']['default'] ?? true)])
<div class="lds-hourglass"{{
$attributes->merge($loaderIcon)
->class(['lds-hourglass' => $this->isTailwind && ($loaderIcon['default'] ?? true)])
->class(['lds-hourglass' => $this->isBootstrap && ($loaderIcon['default'] ?? true)])
->except(['default','default-styling','default-colors']);
}}
></div>
<div>{{ $this->getLoadingPlaceholderContent() }}</div>
}}></div>
<div>{!! $this->getLoadingPlaceholderContent() !!}</div>
</div>
</td>
</tr>
@endif
</td>
</tr>

@endif
27 changes: 0 additions & 27 deletions src/Traits/Configuration/LoadingPlaceholderConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,4 @@ public function setLoadingPlaceholderContent(string $content): self
return $this;
}

public function setLoadingPlaceHolderAttributes(array $attributes): self
{
$this->loadingPlaceHolderAttributes = $attributes;

return $this;
}

public function setLoadingPlaceHolderIconAttributes(array $attributes): self
{
$this->loadingPlaceHolderIconAttributes = $attributes;

return $this;
}

public function setLoadingPlaceHolderWrapperAttributes(array $attributes): self
{
$this->loadingPlaceHolderWrapperAttributes = $attributes;

return $this;
}

public function setLoadingPlaceholderBlade(string $customBlade): self
{
$this->loadingPlaceholderBlade = $customBlade;

return $this;
}
}
16 changes: 0 additions & 16 deletions src/Traits/Helpers/LoadingPlaceholderHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,6 @@ public function getLoadingPlaceholderContent(): string
return $this->loadingPlaceholderContent ?? __('livewire-tables:loading');
}

public function getLoadingPlaceholderAttributes(): array
{
return count($this->loadingPlaceHolderAttributes) ? $this->loadingPlaceHolderAttributes : ['default' => true];

}

public function getLoadingPlaceHolderIconAttributes(): array
{
return count($this->loadingPlaceHolderIconAttributes) ? $this->loadingPlaceHolderIconAttributes : ['default' => true];
}

public function getLoadingPlaceHolderWrapperAttributes(): array
{
return count($this->loadingPlaceHolderWrapperAttributes) ? $this->loadingPlaceHolderWrapperAttributes : ['default' => true];
}

public function hasLoadingPlaceholderBlade(): bool
{
return ! is_null($this->getLoadingPlaceHolderBlade());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Rappasoft\LaravelLivewireTables\Traits\Styling\Configuration;

trait LoadingPlaceholderStylingConfiguration
{
public function setLoadingPlaceHolderAttributes(array $attributes): self
{
$this->loadingPlaceHolderAttributes = $attributes;

return $this;
}

public function setLoadingPlaceHolderIconAttributes(array $attributes): self
{
$this->loadingPlaceHolderIconAttributes = $attributes;

return $this;
}

public function setLoadingPlaceHolderWrapperAttributes(array $attributes): self
{
$this->loadingPlaceHolderWrapperAttributes = $attributes;

return $this;
}

public function setLoadingPlaceholderBlade(string $customBlade): self
{
$this->loadingPlaceholderBlade = $customBlade;

return $this;
}

}
21 changes: 21 additions & 0 deletions src/Traits/Styling/HasLoadingPlaceholderStyling.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Rappasoft\LaravelLivewireTables\Traits\Styling;

use Rappasoft\LaravelLivewireTables\Traits\Styling\Configuration\LoadingPlaceholderStylingConfiguration;
use Rappasoft\LaravelLivewireTables\Traits\Styling\Helpers\LoadingPlaceholderStylingHelpers;

trait HasLoadingPlaceholderStyling
{
use LoadingPlaceholderStylingConfiguration,
LoadingPlaceholderStylingHelpers;

protected array $loadingPlaceHolderAttributes = [];

protected array $loadingPlaceHolderIconAttributes = [];

protected array $loadingPlaceHolderWrapperAttributes = [];

protected array $loadingPlaceHolderCellAttributes = ['class' => '', 'default' => true];

}
28 changes: 28 additions & 0 deletions src/Traits/Styling/Helpers/LoadingPlaceholderStylingHelpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Rappasoft\LaravelLivewireTables\Traits\Styling\Helpers;

use Livewire\Attributes\Computed;

trait LoadingPlaceholderStylingHelpers
{
public function getLoadingPlaceholderAttributes(): array
{
return count($this->loadingPlaceHolderAttributes) ? $this->loadingPlaceHolderAttributes : ['default' => true];
}

public function getLoadingPlaceHolderIconAttributes(): array
{
return count($this->loadingPlaceHolderIconAttributes) ? $this->loadingPlaceHolderIconAttributes : ['default' => true];
}

public function getLoadingPlaceHolderWrapperAttributes(): array
{
return count($this->loadingPlaceHolderWrapperAttributes) ? $this->loadingPlaceHolderWrapperAttributes : ['default' => true];
}

public function getLoadingPlaceHolderCellAttributes(): array
{
return count($this->loadingPlaceHolderCellAttributes) ? $this->loadingPlaceHolderCellAttributes : ['default' => true];
}
}
8 changes: 3 additions & 5 deletions src/Traits/WithLoadingPlaceholder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,19 @@

use Rappasoft\LaravelLivewireTables\Traits\Configuration\LoadingPlaceholderConfiguration;
use Rappasoft\LaravelLivewireTables\Traits\Helpers\LoadingPlaceholderHelpers;
use Rappasoft\LaravelLivewireTables\Traits\Styling\HasLoadingPlaceholderStyling;

trait WithLoadingPlaceholder
{
use LoadingPlaceholderConfiguration,
LoadingPlaceholderHelpers;
LoadingPlaceholderHelpers,
HasLoadingPlaceholderStyling;

protected bool $displayLoadingPlaceholder = false;

protected string $loadingPlaceholderContent = 'Loading';

protected ?string $loadingPlaceholderBlade = null;

protected array $loadingPlaceHolderAttributes = [];

protected array $loadingPlaceHolderIconAttributes = [];

protected array $loadingPlaceHolderWrapperAttributes = [];
}

0 comments on commit 141f395

Please sign in to comment.