From 555ed0c485df10afa18e70b53b8c8dee12b495c1 Mon Sep 17 00:00:00 2001 From: Anastas Mironov Date: Wed, 24 Jul 2024 12:13:41 +0900 Subject: [PATCH 1/3] fix: slug to right side --- src/UI/Filament/Resources/ArticleResource.php | 64 ++++++++++--------- 1 file changed, 35 insertions(+), 29 deletions(-) diff --git a/src/UI/Filament/Resources/ArticleResource.php b/src/UI/Filament/Resources/ArticleResource.php index ca38a78..072aa59 100644 --- a/src/UI/Filament/Resources/ArticleResource.php +++ b/src/UI/Filament/Resources/ArticleResource.php @@ -7,9 +7,9 @@ use AdminKit\Core\Forms\Components\TranslatableTabs; use AdminKit\SEO\Forms\Components\SEOComponent; use Filament\Forms; -use Filament\Forms\Set; -use Filament\Forms\Get; use Filament\Forms\Form; +use Filament\Forms\Get; +use Filament\Forms\Set; use Filament\Resources\Resource; use Filament\Tables; use Filament\Tables\Table; @@ -25,9 +25,9 @@ class ArticleResource extends Resource public static function form(Form $form): Form { - $rows = []; + $components = []; if (config('admin-kit-articles.image.enabled')) { - $rows[] = Forms\Components\SpatieMediaLibraryFileUpload::make('image') + $components[] = Forms\Components\SpatieMediaLibraryFileUpload::make('image') ->label(__('admin-kit-articles::articles.resource.image')) ->image() ->required() @@ -40,28 +40,11 @@ public static function form(Form $form): Form ->imagePreviewHeight(config('admin-kit-articles.image.preview_height')) // cropper - ->imageEditor(); + ->imageEditor() + ->columnSpan(12); } - $rows[] = Forms\Components\Grid::make(1) - ->schema([ - Forms\Components\TextInput::make('slug') - ->label(__('admin-kit-articles::articles.resource.slug')) - ->disabled(fn (Get $get) => ! $get('slug-editable')) - ->required() - ->unique(Article::class, 'slug', ignoreRecord: true) - ->suffixAction( - Forms\Components\Actions\Action::make('slug-edit') - ->icon(fn (Get $get) => $get('slug-editable') ? 'heroicon-o-lock-closed' : 'heroicon-s-pencil-square') - ->action(function (Set $set, Get $get) { - $set('slug-editable', ! $get('slug-editable')); - })), - Forms\Components\Checkbox::make('slug-editable') - ->default(false) - ->hidden(), - ]); - - $rows[] = TranslatableTabs::make(fn ($locale) => [ + $components[] = TranslatableTabs::make(fn ($locale) => [ Forms\Components\TextInput::make("title.$locale") ->label(__('admin-kit-articles::articles.resource.title')) ->required($locale === app()->getLocale()) @@ -83,10 +66,29 @@ function (string $context, string $state, Set $set, Get $get) use ($locale) { ->label(__('admin-kit-articles::articles.resource.short_content')) ->columnSpan(2), ]) - ->columnSpan(2) + ->columnSpan([ + 12, + 'lg' => 8, + ]) ->columns(); - $rows[] = Forms\Components\Section::make([ + $components[] = Forms\Components\Section::make([ + Forms\Components\TextInput::make('slug') + ->label(__('admin-kit-articles::articles.resource.slug')) + ->disabled(fn (Get $get) => ! $get('slug-editable')) + ->required() + ->unique(Article::class, 'slug', ignoreRecord: true) + ->suffixAction( + Forms\Components\Actions\Action::make('slug-edit') + ->icon(fn (Get $get) => $get('slug-editable') ? 'heroicon-o-lock-closed' : 'heroicon-s-pencil-square') + ->action(function (Set $set, Get $get) { + $set('slug-editable', ! $get('slug-editable')); + })) + ->columnSpan(2), + Forms\Components\Checkbox::make('slug-editable') + ->default(false) + ->hidden(), + Forms\Components\DateTimePicker::make('published_at') ->label(__('admin-kit-articles::articles.resource.published_date')) ->columnSpan(2), @@ -94,13 +96,17 @@ function (string $context, string $state, Set $set, Get $get) use ($locale) { Forms\Components\Toggle::make('pinned') ->label(__('admin-kit-articles::articles.resource.pinned')) ->columnSpan(2), - ]); + ]) + ->columnSpan([ + 12, + 'lg' => 4, + ])->columns(); if (config('admin-kit-articles.seo.enabled')) { - $rows[] = SEOComponent::make(); + $components[] = SEOComponent::make(); } - return $form->schema($rows); + return $form->schema($components)->columns(12); } public static function table(Table $table): Table From 6f650b3e27ebc9656eae2a9405dc549b776e5b9d Mon Sep 17 00:00:00 2001 From: Anastas Mironov Date: Wed, 24 Jul 2024 12:23:56 +0900 Subject: [PATCH 2/3] feat: add published_at.with_time config --- config/admin-kit-articles.php | 4 ++++ src/UI/Filament/Resources/ArticleResource.php | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/config/admin-kit-articles.php b/config/admin-kit-articles.php index 88562e1..dcc0d23 100644 --- a/config/admin-kit-articles.php +++ b/config/admin-kit-articles.php @@ -20,4 +20,8 @@ 'seo' => [ 'enabled' => true, ], + + 'published_at' => [ + 'with_time' => true, + ], ]; diff --git a/src/UI/Filament/Resources/ArticleResource.php b/src/UI/Filament/Resources/ArticleResource.php index 072aa59..f140dae 100644 --- a/src/UI/Filament/Resources/ArticleResource.php +++ b/src/UI/Filament/Resources/ArticleResource.php @@ -7,6 +7,8 @@ use AdminKit\Core\Forms\Components\TranslatableTabs; use AdminKit\SEO\Forms\Components\SEOComponent; use Filament\Forms; +use Filament\Forms\Components\DatePicker; +use Filament\Forms\Components\DateTimePicker; use Filament\Forms\Form; use Filament\Forms\Get; use Filament\Forms\Set; @@ -72,6 +74,8 @@ function (string $context, string $state, Set $set, Get $get) use ($locale) { ]) ->columns(); + $publishedAt = config('admin-kit-articles.published_at.with_time') ? DateTimePicker::class : DatePicker::class; + $components[] = Forms\Components\Section::make([ Forms\Components\TextInput::make('slug') ->label(__('admin-kit-articles::articles.resource.slug')) @@ -89,7 +93,7 @@ function (string $context, string $state, Set $set, Get $get) use ($locale) { ->default(false) ->hidden(), - Forms\Components\DateTimePicker::make('published_at') + $publishedAt::make('published_at') ->label(__('admin-kit-articles::articles.resource.published_date')) ->columnSpan(2), From c47949d6b9a6ed3af8c61b771f70c9b9de3d3ebe Mon Sep 17 00:00:00 2001 From: ast21 Date: Wed, 24 Jul 2024 03:24:49 +0000 Subject: [PATCH 3/3] Fix styling --- src/Models/Article.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Models/Article.php b/src/Models/Article.php index 9109600..a5a63d6 100644 --- a/src/Models/Article.php +++ b/src/Models/Article.php @@ -113,6 +113,6 @@ public function image(): Attribute protected static function newFactory(): ArticleFactory { - return new ArticleFactory(); + return new ArticleFactory; } }