2021-09-10 16:02:25 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace App\Views\Components\Forms;
|
|
|
|
|
|
|
|
class Input extends FormComponent
|
|
|
|
{
|
|
|
|
protected string $type = 'text';
|
|
|
|
|
|
|
|
public function render(): string
|
|
|
|
{
|
2021-09-17 12:48:18 +00:00
|
|
|
$class = 'px-3 py-2 bg-white rounded-lg border-3 focus:ring-2 focus:ring-pine-500 focus:ring-offset-2 focus:ring-offset-pine-100 ' . $this->class;
|
2021-09-10 16:02:25 +00:00
|
|
|
|
|
|
|
if (session()->has('errors')) {
|
|
|
|
$error = session('errors')[$this->name];
|
|
|
|
if ($error) {
|
|
|
|
$class .= ' border-red';
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$class .= ' border-black focus:border-black';
|
|
|
|
}
|
|
|
|
|
2021-09-15 15:58:21 +00:00
|
|
|
$this->attributes['class'] = $class;
|
2021-09-10 16:02:25 +00:00
|
|
|
|
|
|
|
if ($this->required) {
|
2021-09-15 15:58:21 +00:00
|
|
|
$this->attributes['required'] = 'required';
|
2021-09-10 16:02:25 +00:00
|
|
|
}
|
|
|
|
|
2021-09-15 15:58:21 +00:00
|
|
|
return form_input($this->attributes, old($this->name, $this->value));
|
2021-09-10 16:02:25 +00:00
|
|
|
}
|
|
|
|
}
|