mirror of
https://github.com/filamentphp/filament.git
synced 2026-09-24 15:42:09 +08:00
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:
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ use Filament\Forms\Components\Field;
|
||||
class Toggle extends Field
|
||||
{
|
||||
use Concerns\CanBeAutofocused;
|
||||
use Concerns\CanAlternateToColumnLayout;
|
||||
|
||||
protected $onIcon;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user