2021-09-10 16:02:25 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace App\Views\Components\Forms;
|
|
|
|
|
|
|
|
class Input extends FormComponent
|
|
|
|
{
|
2024-05-09 17:55:41 +00:00
|
|
|
protected array $props = ['type'];
|
|
|
|
|
2021-09-10 16:02:25 +00:00
|
|
|
protected string $type = 'text';
|
|
|
|
|
|
|
|
public function render(): string
|
|
|
|
{
|
2024-05-09 17:55:41 +00:00
|
|
|
$this->mergeClass('w-full border-contrast rounded-lg focus:border-contrast border-3 focus-within:ring-accent');
|
2021-10-22 13:11:33 +00:00
|
|
|
|
|
|
|
if ($this->type === 'file') {
|
2024-05-09 17:55:41 +00:00
|
|
|
$this->mergeClass('file:px-3 file:py-2 file:h-[40px] file:font-semibold file:text-skin-muted file:text-sm file:rounded-none file:border-none file:bg-highlight file:cursor-pointer');
|
2021-10-22 13:11:33 +00:00
|
|
|
} else {
|
2024-05-09 17:55:41 +00:00
|
|
|
$this->mergeClass('px-3 py-2');
|
2021-10-22 13:11:33 +00:00
|
|
|
}
|
2021-09-10 16:02:25 +00:00
|
|
|
|
2024-05-09 17:55:41 +00:00
|
|
|
if ($this->isReadonly) {
|
|
|
|
$this->mergeClass('bg-base');
|
2023-10-12 15:52:20 +00:00
|
|
|
} else {
|
2024-05-09 17:55:41 +00:00
|
|
|
$this->mergeClass('bg-elevated');
|
2023-10-12 15:52:20 +00:00
|
|
|
}
|
|
|
|
|
2024-05-09 17:55:41 +00:00
|
|
|
$this->attributes['type'] = $this->type;
|
|
|
|
$this->attributes['value'] = $this->value;
|
|
|
|
|
2024-05-12 18:38:33 +00:00
|
|
|
return form_input($this->attributes, old($this->name, (string) $this->value));
|
2021-09-10 16:02:25 +00:00
|
|
|
}
|
|
|
|
}
|