diff --git a/resources/views/components/tools.blade.php b/resources/views/components/tools.blade.php index 4a5dfa7b8..bdb31a745 100644 --- a/resources/views/components/tools.blade.php +++ b/resources/views/components/tools.blade.php @@ -1,8 +1,12 @@ @aware(['component','isTailwind','isBootstrap']) +@php($toolsAttributes = $this->getToolsAttributesBag()) -
$isTailwind, - 'd-flex flex-column ' => ($isBootstrap), -])> +
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 }}
diff --git a/resources/views/components/tools/toolbar.blade.php b/resources/views/components/tools/toolbar.blade.php index 8a3c8901b..65e8c086b 100644 --- a/resources/views/components/tools/toolbar.blade.php +++ b/resources/views/components/tools/toolbar.blade.php @@ -1,10 +1,14 @@ @aware(['component', 'tableName','isTailwind','isBootstrap']) @props([]) +@php($toolBarAttributes = $this->getToolBarAttributesBag()) -
$this->isBootstrap, - 'md:flex md:justify-between mb-4 px-4 md:p-0' => $this->isTailwind, - ]) +
merge() + ->class(['md:flex md:justify-between mb-4 px-4 md:p-0' => $isTailwind && ($toolBarAttributes['default-styling'] ?? true)]) + ->class(['d-md-flex justify-content-between mb-3' => $isBootstrap && ($toolBarAttributes['default-styling'] ?? true)]) + ->except(['default','default-styling','default-colors']) + }} >
$this->isBootstrap, @@ -52,9 +56,7 @@ 'md:flex md:items-center space-y-4 md:space-y-0 md:space-x-2' => $this->isTailwind, ]) > - @if ($this->hasConfigurableAreaFor('toolbar-right-start')) - @include($this->getConfigurableAreaFor('toolbar-right-start'), $this->getParametersForConfigurableArea('toolbar-right-start')) - @endif + @includeWhen($this->hasConfigurableAreaFor('toolbar-right-start'), $this->getConfigurableAreaFor('toolbar-right-start'), $this->getParametersForConfigurableArea('toolbar-right-start')) @if($this->hasActions && $this->showActionsInToolbar && $this->getActionsPosition == 'right') @@ -72,9 +74,7 @@ @endif - @if ($this->hasConfigurableAreaFor('toolbar-right-end')) - @include($this->getConfigurableAreaFor('toolbar-right-end'), $this->getParametersForConfigurableArea('toolbar-right-end')) - @endif + @includeWhen($this->hasConfigurableAreaFor('toolbar-right-end'), $this->getConfigurableAreaFor('toolbar-right-end'), $this->getParametersForConfigurableArea('toolbar-right-end'))
@if ( diff --git a/src/Traits/Core/HasCustomAttributes.php b/src/Traits/Core/HasCustomAttributes.php index 99afeb4c4..cbc3bcd85 100644 --- a/src/Traits/Core/HasCustomAttributes.php +++ b/src/Traits/Core/HasCustomAttributes.php @@ -46,4 +46,9 @@ public function setCustomAttributes(string $propertyName, array $customAttribute return $this; } + + public function getCustomAttributesBagFromArray(array $attributesArray): ComponentAttributeBag + { + return new ComponentAttributeBag($attributesArray); + } } diff --git a/src/Traits/Styling/Configuration/ToolsStylingConfiguration.php b/src/Traits/Styling/Configuration/ToolsStylingConfiguration.php new file mode 100644 index 000000000..9b2ca17f4 --- /dev/null +++ b/src/Traits/Styling/Configuration/ToolsStylingConfiguration.php @@ -0,0 +1,20 @@ +setCustomAttributes(propertyName: 'toolsAttributes', customAttributes: $toolsAttributes); + + return $this; + } + + public function setToolBarAttributes(array $toolBarAttributes = []): self + { + $this->setCustomAttributes(propertyName: 'toolBarAttributes', customAttributes: $toolBarAttributes); + + return $this; + } +} diff --git a/src/Traits/Styling/HasToolsStyling.php b/src/Traits/Styling/HasToolsStyling.php new file mode 100644 index 000000000..a56123311 --- /dev/null +++ b/src/Traits/Styling/HasToolsStyling.php @@ -0,0 +1,16 @@ + '', 'default-colors' => true, 'default-styling' => true]; + + protected array $toolBarAttributes = ['class' => '', 'default-colors' => true, 'default-styling' => true]; +} diff --git a/src/Traits/Styling/Helpers/ToolsStylingHelpers.php b/src/Traits/Styling/Helpers/ToolsStylingHelpers.php new file mode 100644 index 000000000..95aa8684f --- /dev/null +++ b/src/Traits/Styling/Helpers/ToolsStylingHelpers.php @@ -0,0 +1,32 @@ +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()); + + } +} diff --git a/src/Traits/WithTools.php b/src/Traits/WithTools.php index 31d91a57a..8ede2e382 100644 --- a/src/Traits/WithTools.php +++ b/src/Traits/WithTools.php @@ -4,11 +4,13 @@ use Rappasoft\LaravelLivewireTables\Traits\Configuration\ToolsConfiguration; use Rappasoft\LaravelLivewireTables\Traits\Helpers\ToolsHelpers; +use Rappasoft\LaravelLivewireTables\Traits\Styling\HasToolsStyling; trait WithTools { use ToolsConfiguration, - ToolsHelpers; + ToolsHelpers, + HasToolsStyling; protected bool $toolsStatus = true; diff --git a/tests/Traits/Helpers/ToolsStylingHelpersTest.php b/tests/Traits/Helpers/ToolsStylingHelpersTest.php new file mode 100644 index 000000000..560385a89 --- /dev/null +++ b/tests/Traits/Helpers/ToolsStylingHelpersTest.php @@ -0,0 +1,67 @@ +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()); + } +}