Skip to content

Commit

Permalink
Added method to get case color
Browse files Browse the repository at this point in the history
  • Loading branch information
juniwalk authored Jan 28, 2025
1 parent c230a1f commit dee343c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 12 deletions.
26 changes: 20 additions & 6 deletions src/Controls/CheckboxListEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,25 +119,39 @@ public function setDisabled(array|bool $value = true): static

public function isDisabled(mixed $key = null): bool
{
$key = $this->enumType::make($key, false);
$enum = $this->enumType::make($key, false);

if (!$key || !is_array($this->disabled)) { // @phpstan-ignore-line
if (!$enum || !is_array($this->disabled)) { // @phpstan-ignore-line
return parent::isDisabled();
}

return $this->disabled[$key->value] ?? false; // @phpstan-ignore-line
return $this->disabled[$enum->value] ?? false; // @phpstan-ignore-line
}


public function isActive(mixed $key = null): bool
{
$key = $this->enumType::make($key, false);
$enum = $this->enumType::make($key, false);

if (!$key || !is_iterable($this->value)) {
if (!$enum || !is_iterable($this->value)) {
return false;
}

$values = iterator_to_array($this->value);
return in_array($key->value, $values, true);
return in_array($enum->value, $values, true);
}


public function getColor(mixed $key, bool $outline = true): string
{
$enum = $this->enumType::make($key, false);

if ($outline && $this->isDisabled($enum) && $this->isActive($enum)) {
$outline = false;
}

return $enum->color()->for(
$outline ? 'btn-outline' : 'btn'
);
}
}
26 changes: 20 additions & 6 deletions src/Controls/RadioListEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,24 +104,38 @@ public function setDisabled(array|bool $value = true): static

public function isDisabled(mixed $key = null): bool
{
$key = $this->enumType::make($key, false);
$enum = $this->enumType::make($key, false);

if (!$key || !is_array($this->disabled)) { // @phpstan-ignore-line
if (!$enum || !is_array($this->disabled)) { // @phpstan-ignore-line
return parent::isDisabled();
}

return $this->disabled[$key->value] ?? false; // @phpstan-ignore-line
return $this->disabled[$enum->value] ?? false; // @phpstan-ignore-line
}


public function isActive(mixed $key = null): bool
{
$key = $this->enumType::make($key, false);
$enum = $this->enumType::make($key, false);

if (!$key || !is_scalar($this->value)) {
if (!$enum || !is_scalar($this->value)) {
return false;
}

return $key->value === $this->value;
return $enum->value === $this->value;
}


public function getColor(mixed $key, bool $outline = true): string
{
$enum = $this->enumType::make($key, false);

if ($outline && $this->isDisabled($enum) && $this->isActive($enum)) {
$outline = false;
}

return $enum->color()->for(
$outline ? 'btn-outline' : 'btn'
);
}
}

0 comments on commit dee343c

Please sign in to comment.