GrafiteInc/Forms

View on GitHub
src/Html/Button.php

Summary

Maintainability
A
2 hrs
Test Coverage
<?php

namespace Grafite\Forms\Html;

use Grafite\Forms\Html\HtmlSnippet;
use Grafite\Forms\Builders\AttributeBuilder;

class Button extends HtmlSnippet
{
    public static function render($options = [])
    {
        $options['class'] = $options['class'] ?? config('forms.buttons.submit');

        $attributes = app(AttributeBuilder::class)->render($options['attributes']);

        $content = '';

        if (isset($options['content'])) {
            $content = $options['content'];
        }

        throw_if(empty($content), 'You cannot have an empty button');

        return "<button {$attributes}>{$content}</button>";
    }
}