mirror of
https://github.com/filamentphp/filament.git
synced 2026-08-30 17:07:25 +08:00
wip
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
<div class="bg-white space-y-6 shadow-xl rounded p-4 md:p-6">
|
||||
<x-forms::form :schema="$formComponent->getSchema()" />
|
||||
</div>
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Filament\Forms\Components;
|
||||
|
||||
class Card extends Component
|
||||
{
|
||||
public static function make($schema = [])
|
||||
{
|
||||
return (new static())->schema($schema);
|
||||
}
|
||||
}
|
||||
@@ -183,8 +183,7 @@ class Component
|
||||
|
||||
public function getSubform()
|
||||
{
|
||||
return Form::for($this->getLivewire())
|
||||
->schema($this->getSchema());
|
||||
return Form::extend($this)->schema($this->getSchema());
|
||||
}
|
||||
|
||||
public function getValidationAttributes()
|
||||
|
||||
@@ -17,7 +17,7 @@ class Grid extends Component
|
||||
|
||||
public function getColumns()
|
||||
{
|
||||
return $this->columns;
|
||||
return value($this->columns);
|
||||
}
|
||||
|
||||
public function getSubform()
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace Filament\Forms;
|
||||
|
||||
use Filament\Forms\Components\Card;
|
||||
use Filament\Forms\Components\Grid;
|
||||
use Illuminate\Support\Traits\Tappable;
|
||||
|
||||
class Form
|
||||
@@ -12,17 +14,14 @@ class Form
|
||||
|
||||
protected $livewire;
|
||||
|
||||
protected $parent;
|
||||
|
||||
protected $rules = [];
|
||||
|
||||
protected $schema = [];
|
||||
|
||||
protected $validationAttributes = [];
|
||||
|
||||
public function __construct($livewire)
|
||||
{
|
||||
$this->livewire($livewire);
|
||||
}
|
||||
|
||||
public function columns($columns)
|
||||
{
|
||||
$this->columns = $columns;
|
||||
@@ -30,9 +29,14 @@ class Form
|
||||
return $this;
|
||||
}
|
||||
|
||||
public static function extend($form)
|
||||
{
|
||||
return (new static())->parent($form);
|
||||
}
|
||||
|
||||
public static function for($livewire)
|
||||
{
|
||||
return new static($livewire);
|
||||
return (new static())->livewire($livewire);
|
||||
}
|
||||
|
||||
public function getColumns()
|
||||
@@ -69,7 +73,12 @@ class Form
|
||||
|
||||
public function getLivewire()
|
||||
{
|
||||
return $this->livewire;
|
||||
return $this->livewire ?? $this->getParent()->getLivewire();
|
||||
}
|
||||
|
||||
public function getParent()
|
||||
{
|
||||
return $this->parent;
|
||||
}
|
||||
|
||||
public function getRules()
|
||||
@@ -108,6 +117,13 @@ class Form
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function parent($form)
|
||||
{
|
||||
$this->parent = $form;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function rules($rules)
|
||||
{
|
||||
$this->rules = value($rules);
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<x-forms::form :schema="$this->getForm()->getSchema()" :columns="$this->getForm()->getColumns()" />
|
||||
|
||||
<x-filament::button type="submit" color="primary" class="w-full">
|
||||
<x-filament::loader class="w-6 h-6 absolute left-0 ml-2 pointer-events-none" wire:loading />
|
||||
<x-filament::loader wire:target="submit" class="w-6 h-6 absolute left-0 ml-2 pointer-events-none" wire:loading />
|
||||
|
||||
{{ __('filament::auth/login.buttons.submit.label') }}
|
||||
</x-filament::button>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<x-forms::form :schema="$this->getForm()->getSchema()" :columns="$this->getForm()->getColumns()" />
|
||||
|
||||
<x-filament::button type="submit" color="primary" class="w-full">
|
||||
<x-filament::loader class="w-6 h-6 absolute left-0 ml-2 pointer-events-none" wire:loading />
|
||||
<x-filament::loader wire:target="submit" class="w-6 h-6 absolute left-0 ml-2 pointer-events-none" wire:loading />
|
||||
|
||||
{{ __('filament::auth.register') }}
|
||||
</x-filament::button>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<x-forms::form :schema="$this->getForm()->getSchema()" :columns="$this->getForm()->getColumns()" />
|
||||
|
||||
<x-filament::button type="submit" color="primary" class="w-full">
|
||||
<x-filament::loader class="w-6 h-6 absolute left-0 ml-2 pointer-events-none" wire:loading />
|
||||
<x-filament::loader wire:target="submit" class="w-6 h-6 absolute left-0 ml-2 pointer-events-none" wire:loading />
|
||||
|
||||
{{ __('filament::auth/request-password.buttons.submit.label') }}
|
||||
</x-filament::button>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<x-forms::form :schema="$this->getForm()->getSchema()" :columns="$this->getForm()->getColumns()" />
|
||||
|
||||
<x-filament::button type="submit" color="primary" class="w-full">
|
||||
<x-filament::loader class="w-6 h-6 absolute left-0 ml-2 pointer-events-none" wire:loading />
|
||||
<x-filament::loader wire:target="submit" class="w-6 h-6 absolute left-0 ml-2 pointer-events-none" wire:loading />
|
||||
|
||||
{{ __('filament::auth/reset-password.buttons.submit.label') }}
|
||||
</x-filament::button>
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
type="submit"
|
||||
color="primary"
|
||||
>
|
||||
<x-filament::loader wire:target="save" class="w-6 h-6 absolute left-0 ml-2 pointer-events-none" wire:loading />
|
||||
|
||||
{{ __('filament::edit-account.buttons.save.label') }}
|
||||
</x-filament::button>
|
||||
</form>
|
||||
|
||||
@@ -5,21 +5,37 @@
|
||||
/>
|
||||
|
||||
<x-filament::app-content>
|
||||
<x-filament::card>
|
||||
<form
|
||||
wire:submit.prevent="create"
|
||||
class="space-y-6"
|
||||
>
|
||||
@php
|
||||
$schema = $this->getForm()->getSchema();
|
||||
@endphp
|
||||
|
||||
<form wire:submit.prevent="create" class="space-y-6">
|
||||
@if ($this->getForm()->hasWrapper())
|
||||
<x-filament::card class="space-y-6">
|
||||
<x-forms::form :schema="$this->getForm()->getSchema()" :columns="$this->getForm()->getColumns()" />
|
||||
|
||||
<x-filament::button
|
||||
type="submit"
|
||||
color="primary"
|
||||
>
|
||||
<x-filament::loader wire:target="create" class="w-6 h-6 absolute left-0 ml-2 pointer-events-none" wire:loading />
|
||||
|
||||
{{ __(static::$createButtonLabel) }}
|
||||
</x-filament::button>
|
||||
</x-filament::card>
|
||||
@else
|
||||
<x-forms::form :schema="$this->getForm()->getSchema()" :columns="$this->getForm()->getColumns()" />
|
||||
|
||||
<x-filament::button
|
||||
type="submit"
|
||||
color="primary"
|
||||
>
|
||||
<x-filament::loader wire:target="create" class="w-6 h-6 absolute left-0 ml-2 pointer-events-none" wire:loading />
|
||||
|
||||
{{ __(static::$createButtonLabel) }}
|
||||
</x-filament::button>
|
||||
</form>
|
||||
</x-filament::card>
|
||||
@endif
|
||||
</form>
|
||||
</x-filament::app-content>
|
||||
|
||||
<div
|
||||
|
||||
@@ -43,21 +43,37 @@
|
||||
</x-filament::app-header>
|
||||
|
||||
<x-filament::app-content class="space-y-6">
|
||||
<x-filament::card>
|
||||
<form
|
||||
wire:submit.prevent="save"
|
||||
class="space-y-6"
|
||||
>
|
||||
@php
|
||||
$schema = $this->getForm()->getSchema();
|
||||
@endphp
|
||||
|
||||
<form wire:submit.prevent="save" class="space-y-6">
|
||||
@if ($this->getForm()->hasWrapper())
|
||||
<x-filament::card class="space-y-6">
|
||||
<x-forms::form :schema="$this->getForm()->getSchema()" :columns="$this->getForm()->getColumns()" />
|
||||
|
||||
<x-filament::button
|
||||
type="submit"
|
||||
color="primary"
|
||||
>
|
||||
<x-filament::loader wire:target="save" class="w-6 h-6 absolute left-0 ml-2 pointer-events-none" wire:loading />
|
||||
|
||||
{{ __(static::$saveButtonLabel) }}
|
||||
</x-filament::button>
|
||||
</x-filament::card>
|
||||
@else
|
||||
<x-forms::form :schema="$this->getForm()->getSchema()" :columns="$this->getForm()->getColumns()" />
|
||||
|
||||
<x-filament::button
|
||||
type="submit"
|
||||
color="primary"
|
||||
>
|
||||
<x-filament::loader wire:target="save" class="w-6 h-6 absolute left-0 ml-2 pointer-events-none" wire:loading />
|
||||
|
||||
{{ __(static::$saveButtonLabel) }}
|
||||
</x-filament::button>
|
||||
</form>
|
||||
</x-filament::card>
|
||||
@endif
|
||||
</form>
|
||||
|
||||
<x-filament::resources.relations
|
||||
:owner="$record"
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
color="primary"
|
||||
class="w-full sm:w-auto"
|
||||
>
|
||||
<x-filament::loader wire:target="attach" class="w-6 h-6 absolute left-0 ml-2 pointer-events-none" wire:loading />
|
||||
|
||||
{{ __($attachButtonLabel) }}
|
||||
</x-filament::button>
|
||||
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
type="submit"
|
||||
color="primary"
|
||||
>
|
||||
<x-filament::loader wire:target="create" class="w-6 h-6 absolute left-0 ml-2 pointer-events-none" wire:loading />
|
||||
|
||||
{{ __($createButtonLabel) }}
|
||||
</x-filament::button>
|
||||
|
||||
@@ -18,6 +20,8 @@
|
||||
color="primary"
|
||||
wire:click="create(true)"
|
||||
>
|
||||
<x-filament::loader wire:target="create" class="w-6 h-6 absolute left-0 ml-2 pointer-events-none" wire:loading />
|
||||
|
||||
{{ __($createAnotherButtonLabel) }}
|
||||
</x-filament::button>
|
||||
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
type="submit"
|
||||
color="primary"
|
||||
>
|
||||
<x-filament::loader wire:target="save" class="w-6 h-6 absolute left-0 ml-2 pointer-events-none" wire:loading />
|
||||
|
||||
{{ __($saveButtonLabel) }}
|
||||
</x-filament::button>
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Filament\Resources\Forms\Components;
|
||||
|
||||
class Card extends \Filament\Forms\Components\Card
|
||||
{
|
||||
use Concerns\CanBeDependentOnResourceRecord;
|
||||
use Concerns\CanServeResourceSubform;
|
||||
}
|
||||
@@ -8,8 +8,6 @@ trait CanServeResourceSubform
|
||||
{
|
||||
public function getSubform()
|
||||
{
|
||||
return Form::for($this->getLivewire())
|
||||
->model($this->getForm()->getModel())
|
||||
->schema($this->getSchema());
|
||||
return Form::extend($this)->schema($this->getSchema());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,11 +4,31 @@ namespace Filament\Resources\Forms;
|
||||
|
||||
class Form extends \Filament\Forms\Form
|
||||
{
|
||||
protected $hasWrapper = true;
|
||||
|
||||
protected $model;
|
||||
|
||||
public function getModel()
|
||||
{
|
||||
return $this->model;
|
||||
return $this->model ?? $this->getParent()->getModel();
|
||||
}
|
||||
|
||||
public function getSchema()
|
||||
{
|
||||
$schema = parent::getSchema();
|
||||
|
||||
if (! $this->hasWrapper) {
|
||||
return collect($schema)
|
||||
->first()
|
||||
->getSchema();
|
||||
}
|
||||
|
||||
return $schema;
|
||||
}
|
||||
|
||||
public function hasWrapper()
|
||||
{
|
||||
return $this->hasWrapper;
|
||||
}
|
||||
|
||||
public function model($model)
|
||||
@@ -17,4 +37,22 @@ class Form extends \Filament\Forms\Form
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function schema($schema)
|
||||
{
|
||||
if (! is_array($schema)) {
|
||||
$schema = [$schema];
|
||||
|
||||
$this->withoutWrapper();
|
||||
}
|
||||
|
||||
return parent::schema($schema);
|
||||
}
|
||||
|
||||
public function withoutWrapper()
|
||||
{
|
||||
$this->hasWrapper = false;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user