Skip to content

Commit

Permalink
Tweak Row Behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
lrljoe committed Oct 20, 2024
1 parent 10d84a0 commit 3d5c96a
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 7 deletions.
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
8 changes: 4 additions & 4 deletions resources/views/components/includes/loading.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
@props(['colCount' => 1])

@php
$loaderWrapper = $this->getLoadingPlaceHolderWrapperAttributes();
$loaderRow = $this->getLoadingPlaceHolderRowAttributes();
$loaderCell = $this->getLoadingPlaceHolderCellAttributes();
$loaderIcon = $this->getLoadingPlaceHolderIconAttributes();
@endphp

<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)])
$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" {{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,17 @@ public function setLoadingPlaceHolderIconAttributes(array $attributes): self
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('loadingPlaceHolderWrapperAttributes', [...$this->getCustomAttributes(propertyName: 'loadingPlaceHolderWrapperAttributes', default: false, classicMode: true), ...$attributes]);
$this->setCustomAttributes('loadingPlaceHolderRowAttributes', [...$this->getCustomAttributes(propertyName: 'loadingPlaceHolderRowAttributes', default: false, classicMode: true), ...$attributes]);

return $this;
}
Expand Down
2 changes: 2 additions & 0 deletions src/Traits/Styling/HasLoadingPlaceholderStyling.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ trait HasLoadingPlaceholderStyling

protected array $loadingPlaceHolderWrapperAttributes = [];

protected array $loadingPlaceHolderRowAttributes = [];

protected array $loadingPlaceHolderCellAttributes = ['class' => '', 'default' => true];
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ public function getLoadingPlaceHolderIconAttributes(): array

public function getLoadingPlaceHolderWrapperAttributes(): array
{
return $this->getCustomAttributes(propertyName: 'loadingPlaceHolderWrapperAttributes', default: true, classicMode: true);
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
Expand Down
28 changes: 28 additions & 0 deletions tests/Traits/Configuration/LoadingPlaceholderConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,49 @@ public function test_can_set_loading_placeholder_wrapper_attributes(): void
$this->basicTable->setLoadingPlaceholderEnabled();

$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', '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
{
$this->basicTable->setLoadingPlaceholderEnabled();
Expand Down

0 comments on commit 3d5c96a

Please sign in to comment.