Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
lrljoe authored Sep 29, 2024
1 parent a7b1579 commit 7d6fac7
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 15 deletions.
12 changes: 8 additions & 4 deletions resources/views/components/tools.blade.php
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>
20 changes: 10 additions & 10 deletions resources/views/components/tools/toolbar.blade.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
@aware(['component', 'tableName','isTailwind','isBootstrap'])
@props([])
@php($toolBarAttributes = $this->getToolBarAttributesBag())

<div @class([
'd-md-flex justify-content-between mb-3' => $this->isBootstrap,
'md:flex md:justify-between mb-4 px-4 md:p-0' => $this->isTailwind,
])
<div
{{
$toolBarAttributes->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'])
}}
>
<div @class([
'd-md-flex' => $this->isBootstrap,
Expand Down Expand Up @@ -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')
<x-livewire-tables::includes.actions/>
Expand All @@ -72,9 +74,7 @@
<x-livewire-tables::tools.toolbar.items.pagination-dropdown />
@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'))
</div>
</div>
@if (
Expand Down
20 changes: 20 additions & 0 deletions src/Traits/Styling/Configuration/ToolsStylingConfiguration.php
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;
}
}
17 changes: 17 additions & 0 deletions src/Traits/Styling/HasToolsStyling.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?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 = ['default-styling' => true, 'default-colors' => true, 'class' => ''];

protected array $toolBarAttributes = ['default-styling' => true, 'default-colors' => true, 'class' => ''];

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

namespace Rappasoft\LaravelLivewireTables\Traits\Styling\Helpers;

use Livewire\Attributes\Computed;
use Illuminate\View\ComponentAttributeBag;

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());

}
}
6 changes: 5 additions & 1 deletion src/Traits/WithTools.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@

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;

protected bool $toolBarStatus = true;


}
29 changes: 29 additions & 0 deletions tests/Traits/Helpers/ToolsStylingHelpersTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?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(['default-styling' => true, 'default-colors' => true, 'class' => ''], $this->basicTable->getToolsAttributesBag()->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(['default-styling' => true, 'default-colors' => true, 'class' => ''], $this->basicTable->getToolBarAttributesBag()->getAttributes());
}

}

0 comments on commit 7d6fac7

Please sign in to comment.