Added layout fieldtype and some cleanup

This commit is contained in:
Ryan Scherler
2020-12-18 21:39:32 -08:00
parent 2b8f944d17
commit 2eeb258b69
8 changed files with 76 additions and 58 deletions
+2 -2
View File
@@ -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" />
+1
View File
@@ -0,0 +1 @@
<x-filament::fields :fields="$fields" :class="$class" />
+3 -3
View File
@@ -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;
}
+1 -30
View File
@@ -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
View File
@@ -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;
}
+1 -1
View File
@@ -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);
}
+24
View File
@@ -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;
}
}
+19 -16
View File
@@ -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'),
]),
];
}