-
-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ToolsAttributes and ToolbarAttributes (#1982)
* Initial Commit * Fix styling * Add getCustomAttributesBagFromArray * Fix styling * Reorder Array * Reorder Initial Array - Add Additional Test * Fix styling * Add More Tests --------- Co-authored-by: lrljoe <lrljoe@users.noreply.github.com>
- Loading branch information
Showing
8 changed files
with
161 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
@aware(['component','isTailwind','isBootstrap']) | ||
@php($toolsAttributes = $this->getToolsAttributesBag()) | ||
|
||
<div @class([ | ||
'flex-col' => $isTailwind, | ||
'd-flex flex-column ' => ($isBootstrap), | ||
])> | ||
<div {{ | ||
$toolsAttributes->merge() | ||
->class(['flex-col' => $isTailwind && ($toolsAttributes['default-styling'] ?? true)]) | ||
->class(['d-flex flex-column' => $isBootstrap && ($toolsAttributes['default-styling'] ?? true)]) | ||
->except(['default','default-styling','default-colors']) | ||
}} | ||
> | ||
{{ $slot }} | ||
</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
20 changes: 20 additions & 0 deletions
20
src/Traits/Styling/Configuration/ToolsStylingConfiguration.php
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,20 @@ | ||
<?php | ||
|
||
namespace Rappasoft\LaravelLivewireTables\Traits\Styling\Configuration; | ||
|
||
trait ToolsStylingConfiguration | ||
{ | ||
public function setToolsAttributes(array $toolsAttributes = []): self | ||
{ | ||
$this->setCustomAttributes(propertyName: 'toolsAttributes', customAttributes: $toolsAttributes); | ||
|
||
return $this; | ||
} | ||
|
||
public function setToolBarAttributes(array $toolBarAttributes = []): self | ||
{ | ||
$this->setCustomAttributes(propertyName: 'toolBarAttributes', customAttributes: $toolBarAttributes); | ||
|
||
return $this; | ||
} | ||
} |
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,16 @@ | ||
<?php | ||
|
||
namespace Rappasoft\LaravelLivewireTables\Traits\Styling; | ||
|
||
use Rappasoft\LaravelLivewireTables\Traits\Styling\Configuration\ToolsStylingConfiguration; | ||
use Rappasoft\LaravelLivewireTables\Traits\Styling\Helpers\ToolsStylingHelpers; | ||
|
||
trait HasToolsStyling | ||
{ | ||
use ToolsStylingConfiguration, | ||
ToolsStylingHelpers; | ||
|
||
protected array $toolsAttributes = ['class' => '', 'default-colors' => true, 'default-styling' => true]; | ||
|
||
protected array $toolBarAttributes = ['class' => '', 'default-colors' => true, 'default-styling' => true]; | ||
} |
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,32 @@ | ||
<?php | ||
|
||
namespace Rappasoft\LaravelLivewireTables\Traits\Styling\Helpers; | ||
|
||
use Illuminate\View\ComponentAttributeBag; | ||
use Livewire\Attributes\Computed; | ||
|
||
trait ToolsStylingHelpers | ||
{ | ||
protected function getToolsAttributes(): array | ||
{ | ||
return $this->getCustomAttributes(propertyName: 'toolsAttributes', default: false, classicMode: false); | ||
} | ||
|
||
#[Computed] | ||
public function getToolsAttributesBag(): ComponentAttributeBag | ||
{ | ||
return $this->getCustomAttributesBagFromArray($this->getToolsAttributes()); | ||
} | ||
|
||
protected function getToolBarAttributes(): array | ||
{ | ||
return $this->getCustomAttributes(propertyName: 'toolBarAttributes', default: false, classicMode: false); | ||
} | ||
|
||
#[Computed] | ||
public function getToolBarAttributesBag(): ComponentAttributeBag | ||
{ | ||
return $this->getCustomAttributesBagFromArray($this->getToolBarAttributes()); | ||
|
||
} | ||
} |
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,67 @@ | ||
<?php | ||
|
||
namespace Rappasoft\LaravelLivewireTables\Tests\Traits\Helpers; | ||
|
||
use Rappasoft\LaravelLivewireTables\Tests\TestCase; | ||
|
||
final class ToolsStylingHelpersTest extends TestCase | ||
{ | ||
public function test_can_get_tools_attributes_initial_status(): void | ||
{ | ||
$this->assertTrue($this->basicTable->hasCustomAttributes('toolsAttributes')); | ||
} | ||
|
||
public function test_can_get_tools_attributes_initial_values(): void | ||
{ | ||
$this->assertSame(['class' => '', 'default-colors' => true, 'default-styling' => true], $this->basicTable->getToolsAttributesBag()->getAttributes()); | ||
} | ||
|
||
public function test_can_change_tools_attributes_initial_values(): void | ||
{ | ||
$this->basicTable->setToolsAttributes(['class' => 'bg-red-500', 'default-colors' => true, 'default-styling' => true]); | ||
$this->assertSame(['class' => 'bg-red-500', 'default-colors' => true, 'default-styling' => true], $this->basicTable->getToolsAttributesBag()->getAttributes()); | ||
$this->assertSame(['class' => '', 'default-colors' => true, 'default-styling' => true], $this->basicTable->getToolBarAttributesBag()->getAttributes()); | ||
} | ||
|
||
public function test_can_change_tools_attributes_initial_values_no_defaults(): void | ||
{ | ||
$this->basicTable->setToolsAttributes(['class' => 'bg-amber-500']); | ||
$this->assertSame(['class' => 'bg-amber-500', 'default-colors' => false, 'default-styling' => false], $this->basicTable->getToolsAttributesBag()->getAttributes()); | ||
$this->assertSame(['class' => '', 'default-colors' => true, 'default-styling' => true], $this->basicTable->getToolBarAttributesBag()->getAttributes()); | ||
|
||
} | ||
|
||
public function test_can_get_toolbar_attributes_initial_status(): void | ||
{ | ||
$this->assertTrue($this->basicTable->hasCustomAttributes('toolBarAttributes')); | ||
} | ||
|
||
public function test_can_get_toolbar_attributes_initial_values(): void | ||
{ | ||
$this->assertSame(['class' => '', 'default-colors' => true, 'default-styling' => true], $this->basicTable->getToolBarAttributesBag()->getAttributes()); | ||
} | ||
|
||
public function test_can_change_toolbar_attributes_initial_values(): void | ||
{ | ||
$this->basicTable->setToolBarAttributes(['class' => 'bg-blue-500', 'default-colors' => true, 'default-styling' => true]); | ||
$this->assertSame(['class' => 'bg-blue-500', 'default-colors' => true, 'default-styling' => true], $this->basicTable->getToolBarAttributesBag()->getAttributes()); | ||
$this->assertSame(['class' => '', 'default-colors' => true, 'default-styling' => true], $this->basicTable->getToolsAttributesBag()->getAttributes()); | ||
|
||
} | ||
|
||
public function test_can_change_toolbar_attributes_initial_values_no_defaults(): void | ||
{ | ||
$this->basicTable->setToolBarAttributes(['class' => 'bg-green-500']); | ||
$this->assertSame(['class' => 'bg-green-500', 'default-colors' => false, 'default-styling' => false], $this->basicTable->getToolBarAttributesBag()->getAttributes()); | ||
$this->assertSame(['class' => '', 'default-colors' => true, 'default-styling' => true], $this->basicTable->getToolsAttributesBag()->getAttributes()); | ||
} | ||
|
||
public function test_can_change_tools_and_toolbar_attributes_initial_values_no_defaults(): void | ||
{ | ||
$this->basicTable->setToolsAttributes(['class' => 'bg-amber-500'])->setToolBarAttributes(['class' => 'bg-green-500']); | ||
|
||
$this->assertSame(['class' => 'bg-amber-500', 'default-colors' => false, 'default-styling' => false], $this->basicTable->getToolsAttributesBag()->getAttributes()); | ||
|
||
$this->assertSame(['class' => 'bg-green-500', 'default-colors' => false, 'default-styling' => false], $this->basicTable->getToolBarAttributesBag()->getAttributes()); | ||
} | ||
} |