-
-
Notifications
You must be signed in to change notification settings - Fork 344
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v3-Move ConfigurableAreas to Own Section WithConfigurableAreas (#1510)
* Move ConfigurableAreas to Own Trait --------- Co-authored-by: lrljoe <[email protected]>
- Loading branch information
Showing
8 changed files
with
135 additions
and
106 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
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
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
37 changes: 37 additions & 0 deletions
37
src/Traits/Configuration/ConfigurableAreasConfiguration.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,37 @@ | ||
<?php | ||
|
||
namespace Rappasoft\LaravelLivewireTables\Traits\Configuration; | ||
|
||
trait ConfigurableAreasConfiguration | ||
{ | ||
/** | ||
* @param array<mixed> $areas | ||
*/ | ||
public function setConfigurableAreas(array $areas): self | ||
{ | ||
$this->configurableAreas = $areas; | ||
|
||
return $this; | ||
} | ||
|
||
public function setHideConfigurableAreasWhenReorderingStatus(bool $status): self | ||
{ | ||
$this->hideConfigurableAreasWhenReorderingStatus = $status; | ||
|
||
return $this; | ||
} | ||
|
||
public function setHideConfigurableAreasWhenReorderingEnabled(): self | ||
{ | ||
$this->setHideConfigurableAreasWhenReorderingStatus(true); | ||
|
||
return $this; | ||
} | ||
|
||
public function setHideConfigurableAreasWhenReorderingDisabled(): self | ||
{ | ||
$this->setHideConfigurableAreasWhenReorderingStatus(false); | ||
|
||
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
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\Traits\Helpers; | ||
|
||
trait ConfigurableAreasHelpers | ||
{ | ||
/** | ||
* @return array<mixed> | ||
*/ | ||
public function getConfigurableAreas(): array | ||
{ | ||
return $this->configurableAreas; | ||
} | ||
|
||
public function hasConfigurableAreaFor(string $area): bool | ||
{ | ||
if ($this->hideConfigurableAreasWhenReorderingIsEnabled() && $this->reorderIsEnabled() && $this->currentlyReorderingIsEnabled()) { | ||
return false; | ||
} | ||
|
||
return isset($this->configurableAreas[$area]) && $this->getConfigurableAreaFor($area) !== null; | ||
} | ||
|
||
/** | ||
* @param string|array<mixed> $area | ||
*/ | ||
public function getConfigurableAreaFor($area): ?string | ||
{ | ||
$area = $this->configurableAreas[$area] ?? null; | ||
|
||
if (is_array($area)) { | ||
return $area[0]; | ||
} | ||
|
||
return $area; | ||
} | ||
|
||
/** | ||
* @param string|array<mixed> $area | ||
* @return array<mixed> | ||
*/ | ||
public function getParametersForConfigurableArea($area): array | ||
{ | ||
$area = $this->configurableAreas[$area] ?? null; | ||
|
||
if (is_array($area) && isset($area[1]) && is_array($area[1])) { | ||
return $area[1]; | ||
} | ||
|
||
return []; | ||
} | ||
|
||
public function getHideConfigurableAreasWhenReorderingStatus(): bool | ||
{ | ||
return $this->hideConfigurableAreasWhenReorderingStatus; | ||
} | ||
|
||
public function hideConfigurableAreasWhenReorderingIsEnabled(): bool | ||
{ | ||
return $this->getHideConfigurableAreasWhenReorderingStatus() === true; | ||
} | ||
|
||
public function hideConfigurableAreasWhenReorderingIsDisabled(): bool | ||
{ | ||
return $this->getHideConfigurableAreasWhenReorderingStatus() === false; | ||
} | ||
} |
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,26 @@ | ||
<?php | ||
|
||
namespace Rappasoft\LaravelLivewireTables\Traits; | ||
|
||
use Rappasoft\LaravelLivewireTables\Traits\Configuration\ConfigurableAreasConfiguration; | ||
use Rappasoft\LaravelLivewireTables\Traits\Helpers\ConfigurableAreasHelpers; | ||
|
||
trait WithConfigurableAreas | ||
{ | ||
use ConfigurableAreasConfiguration, | ||
ConfigurableAreasHelpers; | ||
|
||
protected bool $hideConfigurableAreasWhenReorderingStatus = true; | ||
|
||
protected array $configurableAreas = [ | ||
'before-tools' => null, | ||
'toolbar-left-start' => null, | ||
'toolbar-left-end' => null, | ||
'toolbar-right-start' => null, | ||
'toolbar-right-end' => null, | ||
'before-toolbar' => null, | ||
'after-toolbar' => null, | ||
'before-pagination' => null, | ||
'after-pagination' => null, | ||
]; | ||
} |