adrema/app/View/Form/Text.php

62 lines
2.1 KiB
PHP
Raw Normal View History

2024-10-14 21:21:19 +02:00
<?php
namespace App\View\Form;
use App\View\Traits\HasFormDimensions;
use Illuminate\View\Component;
class Text extends Component
{
use HasFormDimensions;
public string $id;
public function __construct(
public string $name,
public string $size = 'default',
public ?string $hint = null,
public bool $required = false,
public string $label = '',
public string $type = 'text'
) {
$this->id = str()->uuid()->toString();
}
public function render()
{
return <<<'HTML'
<label class="flex flex-col group {{$heightClass}}" for="{{$id}}" style="{{$heightVars}}">
@if ($label)
<x-form::label :required="$required">{{$label}}</x-form::label>
@endif
<div class="relative flex-none flex">
<input
2024-10-28 23:14:33 +01:00
@error($name) x-init="tippy($el, {
content: () => '@error($name){{$message}}@enderror',
showOnCreate: true,
theme: 'danger',
placement: 'top-end',
delay: [0, 3000],
})" @enderror
2024-10-14 21:21:19 +02:00
id="{{$id}}"
type="{{$type}}"
@if ($type === 'password') autocomplete="off" @endif
2024-10-14 21:21:19 +02:00
placeholder=""
class="
w-full h-[var(--height)] border-gray-600 border-solid text-gray-300 bg-gray-700 leading-none rounded-lg
group-[.size-default]:border-2 group-[.size-sm]:border
group-[.size-default]:text-sm group-[.size-sm]:text-xs
group-[.size-default]:p-2 group-[.size-sm]:p-1
"
{{ $attributes }}
/>
@if($hint)
<x-form::hint>{{$hint}}</x-form::hint>
@endif
</div>
</label>
HTML;
}
}