-
-
Notifications
You must be signed in to change notification settings - Fork 342
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1590 from LowerRockLabs/ColorColumn
Add ColorColumn
- Loading branch information
Showing
11 changed files
with
371 additions
and
7 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
Binary file not shown.
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
Binary file not shown.
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,14 @@ | ||
<div @class([ | ||
'items-center content-center place-content-center place-items-center' => $isTailwind, | ||
]) | ||
> | ||
<div {{ $attributeBag->class([ | ||
'h-6 w-6 rounded-md self-center' => $isTailwind && ($attributeBag['default'] ?? (empty($attributeBag['class']) || (!empty($attributeBag['class']) && ($attributeBag['default'] ?? false)))), | ||
]) }} | ||
@style([ | ||
"background-color: {$color}" => $color, | ||
]) | ||
> | ||
</div> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace Rappasoft\LaravelLivewireTables\Views\Columns; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use Rappasoft\LaravelLivewireTables\Exceptions\DataTableConfigurationException; | ||
use Rappasoft\LaravelLivewireTables\Views\Column; | ||
use Rappasoft\LaravelLivewireTables\Views\Traits\Configuration\ColorColumnConfiguration; | ||
use Rappasoft\LaravelLivewireTables\Views\Traits\Helpers\ColorColumnHelpers; | ||
use Rappasoft\LaravelLivewireTables\Views\Traits\IsColumn; | ||
|
||
class ColorColumn extends Column | ||
{ | ||
use IsColumn; | ||
use ColorColumnConfiguration, | ||
ColorColumnHelpers; | ||
|
||
public ?object $colorCallback = null; | ||
|
||
public ?object $attributesCallback = null; | ||
|
||
public string $defaultValue = ''; | ||
|
||
public string $view = 'livewire-tables::includes.columns.color'; | ||
|
||
public function __construct(string $title, ?string $from = null) | ||
{ | ||
parent::__construct($title, $from); | ||
if (! isset($from)) { | ||
$this->label(fn () => null); | ||
} | ||
|
||
} | ||
|
||
public function getContents(Model $row): null|string|\Illuminate\Support\HtmlString|DataTableConfigurationException|\Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View | ||
{ | ||
return view($this->getView()) | ||
->withIsTailwind($this->getComponent()->isTailwind()) | ||
->withIsBootstrap($this->getComponent()->isBootstrap()) | ||
->withColor($this->getColor($row)) | ||
->withAttributeBag($this->getAttributeBag($row)); | ||
} | ||
|
||
public function getValue(Model $row) | ||
{ | ||
return parent::getValue($row) ?? $this->getDefaultValue(); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/Views/Traits/Configuration/ColorColumnConfiguration.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,27 @@ | ||
<?php | ||
|
||
namespace Rappasoft\LaravelLivewireTables\Views\Traits\Configuration; | ||
|
||
trait ColorColumnConfiguration | ||
{ | ||
public function color(callable $callback): self | ||
{ | ||
$this->colorCallback = $callback; | ||
|
||
return $this; | ||
} | ||
|
||
public function attributes(callable $callback): self | ||
{ | ||
$this->attributesCallback = $callback; | ||
|
||
return $this; | ||
} | ||
|
||
public function defaultValue(string $defaultValue): self | ||
{ | ||
$this->defaultValue = $defaultValue; | ||
|
||
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,52 @@ | ||
<?php | ||
|
||
namespace Rappasoft\LaravelLivewireTables\Views\Traits\Helpers; | ||
|
||
use Illuminate\View\ComponentAttributeBag; | ||
|
||
trait ColorColumnHelpers | ||
{ | ||
// TODO: Test | ||
public function getView(): string | ||
{ | ||
return $this->view; | ||
} | ||
|
||
public function getDefaultValue(): string | ||
{ | ||
return $this->defaultValue; | ||
} | ||
|
||
// TODO: Test | ||
public function getColor($row): string | ||
{ | ||
return $this->hasColorCallback() ? app()->call($this->getColorCallback(), ['row' => $row]) : ($this->getValue($row) ?? $this->getDefaultValue()); | ||
} | ||
|
||
// TODO: Test | ||
public function getAttributeBag($row) | ||
{ | ||
return new ComponentAttributeBag($this->hasAttributesCallback() ? app()->call($this->getAttributesCallback(), ['row' => $row]) : []); | ||
} | ||
|
||
public function getColorCallback(): ?callable | ||
{ | ||
return $this->colorCallback; | ||
} | ||
|
||
public function hasColorCallback(): bool | ||
{ | ||
return isset($this->colorCallback); | ||
} | ||
|
||
// TODO: Test | ||
public function getAttributesCallback(): ?callable | ||
{ | ||
return $this->attributesCallback; | ||
} | ||
|
||
public function hasAttributesCallback(): bool | ||
{ | ||
return $this->attributesCallback !== null; | ||
} | ||
} |
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
Oops, something went wrong.