-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(doc) Adiciona exemplo de select
- Loading branch information
1 parent
01249c7
commit 4ad150e
Showing
3 changed files
with
91 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace Agenciafmd\Ui\View\Components\Forms\Inputs; | ||
|
||
use Illuminate\Support\Facades\View; | ||
use Illuminate\View\Component; | ||
|
||
class Select extends Component | ||
{ | ||
public string $uuid; | ||
|
||
public function __construct( | ||
public string $name = '', | ||
public string $label = '', | ||
public string $hint = '', | ||
public array $values = [], | ||
) { | ||
$this->uuid = '-' . str(serialize($this)) | ||
->pipe('md5') | ||
->limit(5, '') | ||
->toString(); | ||
} | ||
|
||
public function render(): string|View | ||
{ | ||
return <<<'HTML' | ||
@if($label) | ||
<x-form.label for="{{ $name . $uuid }}" @class(['required' => $attributes->has('required')])> | ||
{{ str($label)->lower()->ucfirst() }} | ||
</x-form.label> | ||
@endif | ||
<select wire:model="{{ $name }}" {{ $attributes->merge([ | ||
'type' => 'text', | ||
'id' => $name . $uuid, | ||
])->class([ | ||
'form-select', | ||
'is-invalid' => $errors->has($name), | ||
]) | ||
}} | ||
> | ||
<option value="">-</option> | ||
@foreach($values as $key => $value) | ||
<option value="{{ $key }}">{{ $value }}</option> | ||
@endforeach | ||
</select> | ||
<x-form.error field="{{ $name }}"/> | ||
<x-form.hint message="{{ $hint }}"/> | ||
HTML; | ||
} | ||
} |