generated from filamentphp/plugin-skeleton
-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support enums for descriptions and icons
- Loading branch information
Showing
5 changed files
with
246 additions
and
84 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace JaOcero\RadioDeck\Contracts; | ||
|
||
interface HasDescriptions | ||
{ | ||
public function getDescriptions(): ?string; | ||
} |
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,8 @@ | ||
<?php | ||
|
||
namespace JaOcero\RadioDeck\Contracts; | ||
|
||
interface HasIcons | ||
{ | ||
public function getIcons(): ?string; | ||
} |
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,79 @@ | ||
<?php | ||
|
||
namespace JaOcero\RadioDeck\Intermediary; | ||
|
||
use Closure; | ||
|
||
use Filament\Forms\Components\Field; | ||
use Illuminate\Contracts\Support\Htmlable; | ||
use Illuminate\Contracts\Support\Arrayable; | ||
use Filament\Forms\Components\Concerns\HasOptions; | ||
use Filament\Forms\Components\Concerns\HasGridDirection; | ||
use Filament\Forms\Components\Concerns\CanFixIndistinctState; | ||
use Filament\Forms\Components\Concerns\HasExtraInputAttributes; | ||
use Filament\Forms\Components\Concerns\CanDisableOptions as ConcernCanDisableOptions; | ||
use Filament\Forms\Components\Contracts\CanDisableOptions as ContractsCanDisableOptions; | ||
use Filament\Forms\Components\Concerns\CanDisableOptionsWhenSelectedInSiblingRepeaterItems; | ||
|
||
class IntermediaryRadio extends Field implements ContractsCanDisableOptions | ||
{ | ||
use ConcernCanDisableOptions; | ||
use CanDisableOptionsWhenSelectedInSiblingRepeaterItems; | ||
use CanFixIndistinctState; | ||
use HasExtraInputAttributes; | ||
use HasGridDirection; | ||
use HasOptions; | ||
|
||
protected array | string | Arrayable | Closure $descriptions = []; | ||
|
||
/** | ||
* @param array<string | Htmlable> | Arrayable | string | Closure $descriptions | ||
*/ | ||
public function descriptions(array | Arrayable | string | Closure $descriptions): static | ||
{ | ||
$this->descriptions = $descriptions; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @param array-key $value | ||
*/ | ||
public function hasDescription($value): bool | ||
{ | ||
return array_key_exists($value, $this->getDescriptions()); | ||
} | ||
|
||
/** | ||
* @param array-key $value | ||
*/ | ||
public function getDescription($value): string | Htmlable | null | ||
{ | ||
return $this->getDescriptions()[$value] ?? null; | ||
} | ||
|
||
/** | ||
* @return array<string | Htmlable> | ||
*/ | ||
public function getDescriptions(): array | ||
{ | ||
$descriptions = $this->evaluate($this->descriptions); | ||
|
||
if ($descriptions instanceof Arrayable) { | ||
$descriptions = $descriptions->toArray(); | ||
} | ||
|
||
return $descriptions; | ||
} | ||
|
||
public function getDefaultState(): mixed | ||
{ | ||
$state = parent::getDefaultState(); | ||
|
||
if (is_bool($state)) { | ||
return $state ? 1 : 0; | ||
} | ||
|
||
return $state; | ||
} | ||
} |