-
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 checkbox
- Loading branch information
1 parent
88ac1bd
commit 9bf2239
Showing
4 changed files
with
126 additions
and
11 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,53 @@ | ||
<?php | ||
|
||
namespace Agenciafmd\Ui\View\Components\Forms\Inputs; | ||
|
||
use Illuminate\Support\Facades\View; | ||
use Illuminate\View\Component; | ||
|
||
class Checkbox extends Component | ||
{ | ||
public string $uuid; | ||
|
||
public function __construct( | ||
public string $name = '', | ||
public string $label = '', | ||
public string $hint = '', | ||
public string $inline = '', | ||
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 | ||
@foreach($values as $key => $value) | ||
<label class="form-check @if($inline) form-check-inline @endif"> | ||
<input type="checkbox" @if($value == 'Disabled checkbox') disabled @endif @if($value == 'Checked checkbox') checked @endif name="{{ $name }}" wire:model="{{ $name }}" {{ $attributes->merge([ | ||
'id' => $name . $uuid, | ||
'value' => $key, | ||
])->class([ | ||
'form-check-input', | ||
'is-invalid' => $errors->has($name), | ||
]) | ||
}} | ||
/> | ||
<span class="form-check-label" for="{{ $name . $uuid }}" @class(['required' => $attributes->has('required')])> | ||
{{ str($value)->lower()->ucfirst() }} | ||
</span> | ||
</label> | ||
@endforeach | ||
<x-form.error field="{{ $name }}"/> | ||
<x-form.hint message="{{ $hint }}"/> | ||
HTML; | ||
} | ||
} |
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