Add a trait for inline(row) Fields to alternate to column

This allows the checkbox and toggle, which default to being inside the prefix, to render as columns.
This commit is contained in:
Dan Pock
2021-04-20 10:15:45 -04:00
parent 1f58ca10ac
commit 00f31c98bb
5 changed files with 32 additions and 0 deletions
@@ -7,7 +7,9 @@
:label="$formComponent->getLabel()"
:required="$formComponent->isRequired()"
>
@if(!$formComponent->isColumnLayout())
<x-slot name="labelPrefix">
@endif
<input
{!! $formComponent->isAutofocused() ? 'autofocus' : null !!}
{!! $formComponent->isDisabled() ? 'disabled' : null !!}
@@ -18,5 +20,7 @@
class="rounded text-primary-600 shadow-sm focus:border-primary-700 focus:ring focus:ring-blue-200 focus:ring-opacity-50 {{ $errors->has($formComponent->getName()) ? 'border-danger-600 ' : 'border-gray-300' }}"
{!! Filament\format_attributes($formComponent->getExtraAttributes()) !!}
/>
@if(!$formComponent->isColumnLayout())
</x-slot>
@endif
</x-forms::field-group>
@@ -7,7 +7,9 @@
:label="$formComponent->getLabel()"
:required="$formComponent->isRequired()"
>
@if(!$formComponent->isColumnLayout())
<x-slot name="labelPrefix">
@endif
<button
x-data="{ value: @entangle($formComponent->getName()){{ Str::of($formComponent->getBindingAttribute())->after('wire:model') }} }"
role="switch"
@@ -59,5 +61,7 @@
</span>
</span>
</button>
@if(!$formComponent->isColumnLayout())
</x-slot>
@endif
</x-forms::field-group>
@@ -5,6 +5,7 @@ namespace Filament\Forms\Components;
class Checkbox extends Field
{
use Concerns\CanBeAutofocused;
use Concerns\CanAlternateToColumnLayout;
protected function setUp()
{
@@ -0,0 +1,22 @@
<?php
namespace Filament\Forms\Components\Concerns;
trait CanAlternateToColumnLayout
{
protected $columnLayout = false;
public function columnLayout()
{
$this->configure(function () {
$this->columnLayout = true;
});
return $this;
}
public function isColumnLayout()
{
return $this->columnLayout;
}
}
+1
View File
@@ -8,6 +8,7 @@ use Filament\Forms\Components\Field;
class Toggle extends Field
{
use Concerns\CanBeAutofocused;
use Concerns\CanAlternateToColumnLayout;
protected $onIcon;