mirror of
https://github.com/filamentphp/filament.git
synced 2026-10-24 01:58:00 +08:00
Added layout fieldtype and some cleanup
This commit is contained in:
@@ -16,9 +16,9 @@
|
||||
<x-filament-avatar :size="$size" :user="$user" />
|
||||
@endif
|
||||
</label>
|
||||
@if ($user->avatar && $delete)
|
||||
@if ($user->avatar && $deleteMethod)
|
||||
<button type="button"
|
||||
wire:click="{{ $delete }}"
|
||||
wire:click="{{ $deleteMethod }}"
|
||||
class="absolute top-0 right-0 w-4 h-4 rounded-full bg-gray-800 text-white flex items-center justify-center hover:bg-red-700">
|
||||
<span class="sr-only">{{ __('Delete Avatar') }}</span>
|
||||
<x-heroicon-o-x class="w-3 h-3" />
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
<x-filament::fields :fields="$fields" :class="$class" />
|
||||
@@ -5,7 +5,7 @@ namespace Filament\Fields;
|
||||
class Avatar extends Field {
|
||||
public $avatar;
|
||||
public $user;
|
||||
public $delete;
|
||||
public $deleteMethod;
|
||||
public $size = 64;
|
||||
|
||||
public function avatar($avatar)
|
||||
@@ -20,9 +20,9 @@ class Avatar extends Field {
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function delete($delete)
|
||||
public function deleteMethod($method)
|
||||
{
|
||||
$this->delete = $delete;
|
||||
$this->deleteMethod = $method;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,36 +5,8 @@ namespace Filament\Fields;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class BaseField {
|
||||
public $value;
|
||||
public $id;
|
||||
public $hint;
|
||||
public $help;
|
||||
protected $view;
|
||||
|
||||
public function value($value)
|
||||
{
|
||||
$this->value = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function id($id)
|
||||
{
|
||||
$this->id = $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function hint($hint)
|
||||
{
|
||||
$this->hint = $hint;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function help($help)
|
||||
{
|
||||
$this->help = $help;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function view($view)
|
||||
{
|
||||
$this->view = $view;
|
||||
@@ -44,8 +16,7 @@ class BaseField {
|
||||
public function render()
|
||||
{
|
||||
$view = $this->view ?? 'filament::fields.'.Str::kebab(class_basename(get_called_class()));
|
||||
$data = get_object_vars($this);
|
||||
|
||||
return view($view, $data);
|
||||
return view($view, get_object_vars($this));
|
||||
}
|
||||
}
|
||||
+25
-6
@@ -2,13 +2,14 @@
|
||||
|
||||
namespace Filament\Fields;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Field extends BaseField {
|
||||
public $model;
|
||||
public $value;
|
||||
public $label;
|
||||
public $modelDirective = 'wire:model.defer';
|
||||
public $value;
|
||||
public $id;
|
||||
public $label;
|
||||
public $hint;
|
||||
public $help;
|
||||
public $extraAttributes = [];
|
||||
protected $view;
|
||||
|
||||
@@ -22,21 +23,39 @@ class Field extends BaseField {
|
||||
return new static($model);
|
||||
}
|
||||
|
||||
public function modelDirective($modelDirective)
|
||||
{
|
||||
$this->modelDirective = $modelDirective;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function value($value)
|
||||
{
|
||||
$this->value = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function id($id)
|
||||
{
|
||||
$this->id = $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function label($label)
|
||||
{
|
||||
$this->label = $label;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function modelDirective($modelDirective)
|
||||
public function hint($hint)
|
||||
{
|
||||
$this->modelDirective = $modelDirective;
|
||||
$this->hint = $hint;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function help($help)
|
||||
{
|
||||
$this->help = $help;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ class Fieldset extends BaseField {
|
||||
$this->legend = $legend;
|
||||
}
|
||||
|
||||
public static function legend($legend)
|
||||
public static function make($legend)
|
||||
{
|
||||
return new static($legend);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Filament\Fields;
|
||||
|
||||
class Layout extends BaseField {
|
||||
public $class;
|
||||
public $fields;
|
||||
|
||||
public function __construct($class)
|
||||
{
|
||||
$this->class = $class;
|
||||
}
|
||||
|
||||
public static function make($class)
|
||||
{
|
||||
return new static($class);
|
||||
}
|
||||
|
||||
public function fields(array $fields)
|
||||
{
|
||||
$this->fields = $fields;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ use Illuminate\Support\Facades\{
|
||||
use Filament\Traits\WithNotifications;
|
||||
use Filament\Fields\{
|
||||
Tabs,
|
||||
Layout,
|
||||
Text,
|
||||
Avatar,
|
||||
Fieldset,
|
||||
@@ -82,26 +83,28 @@ class Profile extends Component
|
||||
return [
|
||||
Tabs::label('Profile')
|
||||
->tab('Account', [
|
||||
Text::make('user.name')
|
||||
->label('Name')
|
||||
->extraAttributes([
|
||||
'required' => 'true',
|
||||
]),
|
||||
Text::make('user.email')
|
||||
->type('email')
|
||||
->label('E-Mail Address')
|
||||
->modelDirective('wire:model.lazy')
|
||||
->extraAttributes([
|
||||
'required' => 'true',
|
||||
'autocomplete' => 'email',
|
||||
]),
|
||||
Layout::make('grid grid-cols-1 lg:grid-cols-2 gap-6')->fields([
|
||||
Text::make('user.name')
|
||||
->label('Name')
|
||||
->extraAttributes([
|
||||
'required' => 'true',
|
||||
]),
|
||||
Text::make('user.email')
|
||||
->type('email')
|
||||
->label('E-Mail Address')
|
||||
->modelDirective('wire:model.lazy')
|
||||
->extraAttributes([
|
||||
'required' => 'true',
|
||||
'autocomplete' => 'email',
|
||||
]),
|
||||
]),
|
||||
Avatar::make('avatar')
|
||||
->label('User Photo')
|
||||
->avatar($this->avatar)
|
||||
->user($this->user)
|
||||
->delete('deleteAvatar')
|
||||
->deleteMethod('deleteAvatar')
|
||||
->hint(__('Optional')),
|
||||
Fieldset::legend('Update Password')
|
||||
Fieldset::make('Update Password')
|
||||
->fields([
|
||||
Text::make('password')
|
||||
->type('password')
|
||||
@@ -119,7 +122,7 @@ class Profile extends Component
|
||||
])
|
||||
->hint(__('Optional')),
|
||||
])
|
||||
->class('grid grid-cols-1 gap-6 lg:grid-cols-2'),
|
||||
->class('grid grid-cols-1 lg:grid-cols-2 gap-6'),
|
||||
]),
|
||||
];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user