Skip to content

Commit

Permalink
feat(btn) criar o botão submit
Browse files Browse the repository at this point in the history
  • Loading branch information
irineujunior committed Mar 5, 2024
1 parent 681098d commit 94e0a1b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Providers/BladeServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public function bootComponents(): void
Blade::component($prefix . 'btn', Components\Buttons\Button::class);
Blade::component($prefix . 'btn.link', Components\Buttons\Link::class);
Blade::component($prefix . 'btn.primary', Components\Buttons\Primary::class);
Blade::component($prefix . 'btn.submit', Components\Buttons\Submit::class);
Blade::component($prefix . 'card.body', Components\Card\Body::class);
Blade::component($prefix . 'card', Components\Card\Card::class);
Blade::component($prefix . 'card.footer', Components\Card\Footer::class);
Expand Down
42 changes: 42 additions & 0 deletions src/View/Components/Buttons/Submit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Agenciafmd\Ui\View\Components\Buttons;

use Illuminate\Contracts\View\View;
use Illuminate\View\Component;

class Submit extends Component
{
public function __construct(
public string $label = '',
public string $action = '',
public string $method = 'POST',
)
{
$this->label = $label ?: __('Send');
$this->method = strtoupper($method);
}

public function render(): string|View
{
return <<<'HTML'
<form method="POST" @if($action) action="{{ $action }}" @endif>
@csrf
@method($method)
<button type="submit" {{ $attributes }}>
{{ $slot }}
</button>
</form>
HTML;
}

public function fallback(): string
{
return str($this->label)
->stripTags()
->squish()
->lower()
->ucfirst();
}
}

0 comments on commit 94e0a1b

Please sign in to comment.