Skip to content

Commit

Permalink
feat(doc) Adiciona exemplo de radio
Browse files Browse the repository at this point in the history
  • Loading branch information
cstamagawa committed Feb 1, 2024
1 parent 4ad150e commit 88ac1bd
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 1 deletion.
67 changes: 66 additions & 1 deletion docs/form.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@
<x-form.textarea name="message" label="Mensagem" hint="Max 1000 chars" rows="15" cols="50" maxlength="1000" placeholder="Mensagem..." required/>
</div>
<div class="mb-3">
<x-form.select name="select" label="Select" :values="['' => '-', 'One' => 'One','Two' => 'Two', 'Three' => 'Three']" hint="Selecione uma opção" required/>
<x-form.select name="select" label="Select" :values="['' => '-', 'One' => 'One','Two' => 'Two', 'Three' => 'Three']" hint="Selecione uma opção" required/>
</div>
<div class="mb-3">
<x-form.radio name="radio[]" label="Radio Button" hint="Selecione uma opção" :values="['One' => 'One','Two' => 'Two', 'Three' => 'Three', 'Four' => 'Four']" required/>
</div>
<div class="mb-3">
<x-form.radio name="radio[]" label="Radio Button" inline hint="Selecione uma opção" :values="['One' => 'One','Two' => 'Two', 'Three' => 'Three', 'Four' => 'Four']" required/>
</div>
</x-form>
@enddemo
Expand Down Expand Up @@ -107,3 +113,62 @@

@endverbatim

## Radios

@demo
<div class="mb-3">
<x-form.radio name="radio1[]" :values="['One' => 'One','Two' => 'Two', 'Three' => 'Three', 'Four' => 'Four']"/>
</div>
<div class="mb-3">
<x-form.radio name="radio2[]" label="Radio Button" :values="['One' => 'One','Two' => 'Two', 'Three' => 'Three', 'Four' => 'Four']" required/>
</div>
<div class="mb-3">
<x-form.radio name="radio3[]" label="Radio Button" hint="Selecione uma opção" :values="['One' => 'One','Two' => 'Two', 'Three' => 'Three', 'Four' => 'Four']"/>
</div>
@enddemo

@verbatim

```blade
<div class="mb-3">
<x-form.radio name="radio1[]" :values="[One' => 'One', 'Two' => 'Two', 'Three' => 'Three', 'Four' => 'Four']"/>
</div>
<div class="mb-3">
<x-form.radio name="radio2[]" label="Radio Button" :values="['One' => 'One','Two' => 'Two', 'Three' => 'Three', 'Four' => 'Four']" required/>
</div>
<div class="mb-3">
<x-form.radio name="radio3[]" label="Radio Button" hint="Selecione uma opção" :values="['One' => 'One','Two' => 'Two', 'Three' => 'Three', 'Four' => 'Four']"/>
</div>
```

@endverbatim

## Inline Radios

@demo
<div class="mb-3">
<x-form.radio name="inlineradio1[]" inline :values="['One' => 'One','Two' => 'Two', 'Three' => 'Three', 'Four' => 'Four']"/>
</div>
<div class="mb-3">
<x-form.radio name="inlineradio2[]" inline label="Inline Radio Button" :values="['One' => 'One','Two' => 'Two', 'Three' => 'Three', 'Four' => 'Four']" required/>
</div>
<div class="mb-3">
<x-form.radio name="inlineradio3[]" inline label="Inline Radio Button" hint="Selecione uma opção" :values="['One' => 'One','Two' => 'Two', 'Three' => 'Three', 'Four' => 'Four']"/>
</div>
@enddemo

@verbatim

```blade
<div class="mb-3">
<x-form.radio name="inlineradio1[]" inline :values="['One' => 'One', 'Two' => 'Two', 'Three' => 'Three', 'Four' => 'Four']"/>
</div>
<div class="mb-3">
<x-form.radio name="inlineradio2[]" inline label="Inline Radio" :values="['One' => 'One','Two' => 'Two', 'Three' => 'Three', 'Four' => 'Four']" required/>
</div>
<div class="mb-3">
<x-form.radio name="inlineradio3[]" inline label="Inline Radio" hint="Selecione uma opção" :values="['One' => 'One','Two' => 'Two', 'Three' => 'Three', 'Four' => 'Four']"/>
</div>
```

@endverbatim
1 change: 1 addition & 0 deletions src/Providers/BladeServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,6 @@ public function bootComponents(): void
Blade::component($prefix . 'page.header', Components\Pages\Header::class);
Blade::component($prefix . 'form.textarea', Components\Forms\Inputs\Textarea::class);
Blade::component($prefix . 'form.select', Components\Forms\Inputs\Select::class);
Blade::component($prefix . 'form.radio', Components\Forms\Inputs\Radio::class);
}
}
53 changes: 53 additions & 0 deletions src/View/Components/Forms/Inputs/Radio.php
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 Radio 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="radio" name="{{ $name }}" wire:model="{{ $name }}" {{ $attributes->merge([
'id' => $name . $uuid,
'value' => $key,
])->class([
'form-check-input',
'is-invalid' => $errors->has($name),
])
}}
/>
<span 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;
}
}

0 comments on commit 88ac1bd

Please sign in to comment.