Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loading Placeholder Adjustments #1987

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion docs/misc/loading-placeholder.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ You may use this method to set custom text for the placeholder:
$this->setLoadingPlaceholderContent('Text To Display');
}
```
### setLoadingPlaceHolderWrapperAttributes
### setLoadingPlaceHolderWrapperAttributes (Deprecated)

This is replaced by setLoadingPlaceHolderRowAttributes, but remains functional.

This method allows you to customise the attributes for the <tr> element used as a Placeholder when the table is loading. Similar to other setAttribute methods, this accepts a range of attributes, and a boolean "default", which will enable/disable the default attributes.

Expand All @@ -62,6 +64,22 @@ This method allows you to customise the attributes for the <tr> element us

```

### setLoadingPlaceHolderRowAttributes

Replaces setLoadingPlaceHolderWrapperAttributes
This method allows you to customise the attributes for the <tr> element used as a Placeholder when the table is loading. Similar to other setAttribute methods, this accepts a range of attributes, and a boolean "default", which will enable/disable the default attributes.

```php
public function configure(): void
{
$this->setLoadingPlaceHolderRowAttributes([
'class' => 'text-bold',
'default' => false,
]);
}

```

### setLoadingPlaceHolderIconAttributes

This method allows you to customise the attributes for the <div> element that is used solely for the PlaceholderIcon. Similar to other setAttribute methods, this accepts a range of attributes, and a boolean "default", which will enable/disable the default attributes.
Expand Down
2 changes: 2 additions & 0 deletions resources/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"livewire-tables::Deselect All": "Deselect All",
"livewire-tables::Done Reordering": "Done Reordering",
"livewire-tables::Filters": "Filters",
"livewire-tables::loading": "Loading",
"livewire-tables::max": "Max",
"livewire-tables::min": "Min",
"livewire-tables::not_applicable": "N/A",
Expand Down Expand Up @@ -45,6 +46,7 @@
"Deselect All": "Deselect All",
"Done Reordering": "Done Reordering",
"Filters": "Filters",
"loading": "Loading",
"max": "Max",
"min": "Min",
"not_applicable": "N/A",
Expand Down
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();
$loaderRow = $this->getLoadingPlaceHolderRowAttributes();
$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($loaderRow)
->class(['hidden w-full text-center place-items-center align-middle' => $this->isTailwind && ($loaderRow['default'] ?? true)])
->class(['d-none w-100 text-center align-items-center' => $this->isBootstrap && ($loaderRow['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
21 changes: 0 additions & 21 deletions src/Traits/Configuration/LoadingPlaceholderConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,6 @@ 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;
Expand Down
18 changes: 1 addition & 17 deletions src/Traits/Helpers/LoadingPlaceholderHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,7 @@ public function getDisplayLoadingPlaceholder(): bool

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];
return $this->loadingPlaceholderContent ?? __('livewire-tables::loading');
}

public function hasLoadingPlaceholderBlade(): bool
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Rappasoft\LaravelLivewireTables\Traits\Styling\Configuration;

trait LoadingPlaceholderStylingConfiguration
{
public function setLoadingPlaceHolderAttributes(array $attributes): self
{
$this->setCustomAttributes('loadingPlaceHolderAttributes', [...$this->getCustomAttributes(propertyName: 'loadingPlaceHolderAttributes', default: false, classicMode: true), ...$attributes]);

return $this;
}

public function setLoadingPlaceHolderIconAttributes(array $attributes): self
{
$this->setCustomAttributes('loadingPlaceHolderIconAttributes', [...$this->getCustomAttributes(propertyName: 'loadingPlaceHolderIconAttributes', default: false, classicMode: true), ...$attributes]);

return $this;
}

public function setLoadingPlaceHolderRowAttributes(array $attributes): self
{
$this->setCustomAttributes('loadingPlaceHolderRowAttributes', [...$this->getCustomAttributes(propertyName: 'loadingPlaceHolderRowAttributes', default: false, classicMode: true), ...$attributes]);

return $this;
}

public function setLoadingPlaceHolderWrapperAttributes(array $attributes): self
{
$this->setCustomAttributes('loadingPlaceHolderRowAttributes', [...$this->getCustomAttributes(propertyName: 'loadingPlaceHolderRowAttributes', default: false, classicMode: true), ...$attributes]);

return $this;
}
}
22 changes: 22 additions & 0 deletions src/Traits/Styling/HasLoadingPlaceholderStyling.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?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 $loadingPlaceHolderRowAttributes = [];

protected array $loadingPlaceHolderCellAttributes = ['class' => '', 'default' => true];
}
36 changes: 36 additions & 0 deletions src/Traits/Styling/Helpers/LoadingPlaceholderStylingHelpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Rappasoft\LaravelLivewireTables\Traits\Styling\Helpers;

use Livewire\Attributes\Computed;

trait LoadingPlaceholderStylingHelpers
{
public function getLoadingPlaceholderAttributes(): array
{
return $this->getCustomAttributes(propertyName: 'loadingPlaceHolderAttributes', default: true, classicMode: true);

}

public function getLoadingPlaceHolderIconAttributes(): array
{
return $this->getCustomAttributes(propertyName: 'loadingPlaceHolderIconAttributes', default: true, classicMode: true);

}

public function getLoadingPlaceHolderWrapperAttributes(): array
{
return $this->getCustomAttributes(propertyName: 'loadingPlaceHolderRowAttributes', default: true, classicMode: true);
}

public function getLoadingPlaceHolderRowAttributes(): array
{
return $this->getCustomAttributes(propertyName: 'loadingPlaceHolderRowAttributes', default: true, classicMode: true);
}

public function getLoadingPlaceHolderCellAttributes(): array
{
return $this->getCustomAttributes(propertyName: 'loadingPlaceHolderCellAttributes', default: true, classicMode: true);

}
}
10 changes: 3 additions & 7 deletions src/Traits/WithLoadingPlaceholder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,17 @@

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 = [];
}
64 changes: 58 additions & 6 deletions tests/Traits/Configuration/LoadingPlaceholderConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,35 +48,87 @@ public function test_can_set_loading_placeholder_attributes(): void
{
$this->basicTable->setLoadingPlaceholderEnabled();

$this->assertSame(['default' => true], $this->basicTable->getLoadingPlaceHolderAttributes());
$this->assertSame(['default' => true, 'default' => true, 'default-colors' => true, 'default-styling' => true], $this->basicTable->getLoadingPlaceHolderAttributes());

$this->basicTable->setLoadingPlaceHolderAttributes(['class' => 'test12345']);

$this->assertSame(['class' => 'test12345'], $this->basicTable->getLoadingPlaceHolderAttributes());
$this->assertSame(['class' => 'test12345', 'default' => false, 'default-colors' => false, 'default-styling' => false], $this->basicTable->getLoadingPlaceHolderAttributes());

$this->basicTable->setLoadingPlaceHolderAttributes(['class' => 'test12345', 'default' => true, 'default-colors' => true, 'default-styling' => true]);

$this->assertSame(['class' => 'test12345', 'default' => true, 'default-colors' => true, 'default-styling' => true], $this->basicTable->getLoadingPlaceHolderAttributes());

$this->basicTable->setLoadingPlaceHolderAttributes(['class' => 'test12345', 'default' => false, 'default-colors' => false, 'default-styling' => true]);

$this->assertSame(['class' => 'test12345', 'default' => false, 'default-colors' => false, 'default-styling' => true], $this->basicTable->getLoadingPlaceHolderAttributes());

}

public function test_can_set_loading_placeholder_icon_attributes(): void
{
$this->basicTable->setLoadingPlaceholderEnabled();

$this->assertSame(['default' => true], $this->basicTable->getLoadingPlaceHolderIconAttributes());
$this->assertSame(['default' => true, 'default-colors' => true, 'default-styling' => true], $this->basicTable->getLoadingPlaceHolderIconAttributes());

$this->basicTable->setLoadingPlaceHolderIconAttributes(['class' => 'test123']);

$this->assertSame(['class' => 'test123'], $this->basicTable->getLoadingPlaceHolderIconAttributes());
$this->assertSame(['class' => 'test123', 'default' => false, 'default-colors' => false, 'default-styling' => false], $this->basicTable->getLoadingPlaceHolderIconAttributes());

$this->basicTable->setLoadingPlaceHolderIconAttributes(['class' => 'test123', 'default' => true, 'default-colors' => true, 'default-styling' => true]);

$this->assertSame(['class' => 'test123', 'default' => true, 'default-colors' => true, 'default-styling' => true], $this->basicTable->getLoadingPlaceHolderIconAttributes());

$this->basicTable->setLoadingPlaceHolderIconAttributes(['class' => 'test123', 'default' => false, 'default-colors' => false, 'default-styling' => true]);

$this->assertSame(['class' => 'test123', 'default' => false, 'default-colors' => false, 'default-styling' => true], $this->basicTable->getLoadingPlaceHolderIconAttributes());

}

public function test_can_set_loading_placeholder_wrapper_attributes(): void
{
$this->basicTable->setLoadingPlaceholderEnabled();

$this->assertSame(['default' => true], $this->basicTable->getLoadingPlaceHolderWrapperAttributes());
$this->assertSame(['default' => true, 'default-colors' => true, 'default-styling' => true], $this->basicTable->getLoadingPlaceHolderWrapperAttributes());
$this->assertSame(['default' => true, 'default-colors' => true, 'default-styling' => true], $this->basicTable->getLoadingPlaceHolderRowAttributes());

$this->basicTable->setLoadingPlaceHolderWrapperAttributes(['class' => 'test1234567-wrapper']);

$this->assertSame(['class' => 'test1234567-wrapper'], $this->basicTable->getLoadingPlaceHolderWrapperAttributes());
$this->assertSame(['class' => 'test1234567-wrapper', 'default' => false, 'default-colors' => false, 'default-styling' => false], $this->basicTable->getLoadingPlaceHolderWrapperAttributes());
$this->assertSame(['class' => 'test1234567-wrapper', 'default' => false, 'default-colors' => false, 'default-styling' => false], $this->basicTable->getLoadingPlaceHolderRowAttributes());

$this->basicTable->setLoadingPlaceHolderWrapperAttributes(['class' => 'test1234567-wrapper', 'default' => true, 'default-colors' => true, 'default-styling' => true]);

$this->assertSame(['class' => 'test1234567-wrapper', 'default' => true, 'default-colors' => true, 'default-styling' => true], $this->basicTable->getLoadingPlaceHolderWrapperAttributes());
$this->assertSame(['class' => 'test1234567-wrapper', 'default' => true, 'default-colors' => true, 'default-styling' => true], $this->basicTable->getLoadingPlaceHolderRowAttributes());

$this->basicTable->setLoadingPlaceHolderWrapperAttributes(['class' => 'test1234567-wrapper', 'default' => false, 'default-colors' => false, 'default-styling' => true]);

$this->assertSame(['class' => 'test1234567-wrapper', 'default' => false, 'default-colors' => false, 'default-styling' => true], $this->basicTable->getLoadingPlaceHolderWrapperAttributes());
$this->assertSame(['class' => 'test1234567-wrapper', 'default' => false, 'default-colors' => false, 'default-styling' => true], $this->basicTable->getLoadingPlaceHolderRowAttributes());

}

public function test_can_set_loading_placeholder_row_attributes(): void
{
$this->basicTable->setLoadingPlaceholderEnabled();

$this->assertSame(['default' => true, 'default-colors' => true, 'default-styling' => true], $this->basicTable->getLoadingPlaceHolderRowAttributes());

$this->basicTable->setLoadingPlaceHolderRowAttributes(['class' => 'test1234567-wrapper']);

$this->assertSame(['class' => 'test1234567-wrapper', 'default' => false, 'default-colors' => false, 'default-styling' => false], $this->basicTable->getLoadingPlaceHolderRowAttributes());
$this->assertSame(['class' => 'test1234567-wrapper', 'default' => false, 'default-colors' => false, 'default-styling' => false], $this->basicTable->getLoadingPlaceHolderWrapperAttributes());

$this->basicTable->setLoadingPlaceHolderRowAttributes(['class' => 'test1234567-wrapper', 'default' => true, 'default-colors' => true, 'default-styling' => true]);

$this->assertSame(['class' => 'test1234567-wrapper', 'default' => true, 'default-colors' => true, 'default-styling' => true], $this->basicTable->getLoadingPlaceHolderRowAttributes());
$this->assertSame(['class' => 'test1234567-wrapper', 'default' => true, 'default-colors' => true, 'default-styling' => true], $this->basicTable->getLoadingPlaceHolderWrapperAttributes());

$this->basicTable->setLoadingPlaceHolderRowAttributes(['class' => 'test1234567-wrapper', 'default' => false, 'default-colors' => false, 'default-styling' => true]);

$this->assertSame(['class' => 'test1234567-wrapper', 'default' => false, 'default-colors' => false, 'default-styling' => true], $this->basicTable->getLoadingPlaceHolderRowAttributes());
$this->assertSame(['class' => 'test1234567-wrapper', 'default' => false, 'default-colors' => false, 'default-styling' => true], $this->basicTable->getLoadingPlaceHolderWrapperAttributes());

}

public function test_can_set_loading_placeholder_custom_blade(): void
Expand Down