Skip to content

Commit

Permalink
feat(doc) Adiciona exemplo de select
Browse files Browse the repository at this point in the history
  • Loading branch information
cstamagawa committed Feb 1, 2024
1 parent 01249c7 commit 4ad150e
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 2 deletions.
42 changes: 40 additions & 2 deletions docs/form.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@

@demo
<x-form>
<x-form.input name="name" label="Nome" required/>
<x-form.textarea name="message" label="Mensagem" hint="Max 1000 chars" rows="15" cols="50" maxlength="1000" placeholder="Mensagem..." required/>
<div class="mb-3">
<x-form.input name="name" label="Nome" required/>
</div>
<div class="mb-3">
<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/>
</div>
</x-form>
@enddemo

Expand Down Expand Up @@ -69,3 +76,34 @@
```

@endverbatim

## Select

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

@verbatim

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

@endverbatim

1 change: 1 addition & 0 deletions src/Providers/BladeServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,6 @@ public function bootComponents(): void
Blade::component($prefix . 'page.form', Components\Pages\Form::class);
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);
}
}
50 changes: 50 additions & 0 deletions src/View/Components/Forms/Inputs/Select.php
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;
}
}

0 comments on commit 4ad150e

Please sign in to comment.