Extract RendersAlpine trait
This commit is contained in:
parent
8b85ae6128
commit
67f45886ea
|
@ -3,13 +3,13 @@
|
||||||
namespace App\View\Form;
|
namespace App\View\Form;
|
||||||
|
|
||||||
use App\View\Traits\HasFormDimensions;
|
use App\View\Traits\HasFormDimensions;
|
||||||
|
use App\View\Traits\RendersAlpine;
|
||||||
use Illuminate\View\Component;
|
use Illuminate\View\Component;
|
||||||
use Illuminate\View\ComponentAttributeBag;
|
|
||||||
|
|
||||||
class Label extends Component
|
class Label extends Component
|
||||||
{
|
{
|
||||||
|
|
||||||
use HasFormDimensions;
|
use HasFormDimensions;
|
||||||
|
use RendersAlpine;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
public bool $required = false,
|
public bool $required = false,
|
||||||
|
@ -17,33 +17,6 @@ class Label extends Component
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function asAlpineString(ComponentAttributeBag $attributes, string $tagName): string
|
|
||||||
{
|
|
||||||
$rawTag = ':' . $tagName;
|
|
||||||
|
|
||||||
if ($attributes->has($rawTag)) {
|
|
||||||
return $attributes->get($rawTag);
|
|
||||||
}
|
|
||||||
|
|
||||||
$output = e($this->{$tagName});
|
|
||||||
return str($output)->swap([
|
|
||||||
'`' => '\\`',
|
|
||||||
'$' => '\\$',
|
|
||||||
'{' => '\\{',
|
|
||||||
'}' => '\\}',
|
|
||||||
])->wrap('`');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function asAlpineBool(ComponentAttributeBag $attributes, string $tagName): string
|
|
||||||
{
|
|
||||||
$rawTag = ':' . $tagName;
|
|
||||||
|
|
||||||
if ($attributes->has($rawTag)) {
|
|
||||||
return $attributes->get($rawTag);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->{$tagName} ? 'true' : 'false';
|
|
||||||
}
|
|
||||||
|
|
||||||
public function render()
|
public function render()
|
||||||
{
|
{
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\View\Traits;
|
||||||
|
|
||||||
|
use Illuminate\View\ComponentAttributeBag;
|
||||||
|
|
||||||
|
trait RendersAlpine
|
||||||
|
{
|
||||||
|
public function asAlpineString(ComponentAttributeBag $attributes, string $tagName): string
|
||||||
|
{
|
||||||
|
$rawTag = ':' . $tagName;
|
||||||
|
|
||||||
|
if ($attributes->has($rawTag)) {
|
||||||
|
return $attributes->get($rawTag);
|
||||||
|
}
|
||||||
|
|
||||||
|
$output = e($this->{$tagName});
|
||||||
|
return str($output)->swap([
|
||||||
|
'`' => '\\`',
|
||||||
|
'$' => '\\$',
|
||||||
|
'{' => '\\{',
|
||||||
|
'}' => '\\}',
|
||||||
|
])->wrap('`');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function asAlpineBool(ComponentAttributeBag $attributes, string $tagName): string
|
||||||
|
{
|
||||||
|
$rawTag = ':' . $tagName;
|
||||||
|
|
||||||
|
if ($attributes->has($rawTag)) {
|
||||||
|
return $attributes->get($rawTag);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->{$tagName} ? 'true' : 'false';
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue