Skip to content

Commit 49730de

Browse files
authored
Merge pull request #131 from lara-zeus/add-tiptap
Add tiptap editor
2 parents a68fc85 + 4929c82 commit 49730de

File tree

6 files changed

+90
-78
lines changed

6 files changed

+90
-78
lines changed

composer.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@
3737
"filament/spatie-laravel-media-library-plugin": "^3.0@beta",
3838
"filament/spatie-laravel-tags-plugin": "^3.0@beta",
3939
"spatie/laravel-medialibrary": "^10.0.0",
40+
"awcodes/filament-tiptap-editor": "^3.0",
4041
"spatie/laravel-sluggable": "^3.3",
4142
"spatie/laravel-tags": "^4.4",
43+
"andrewdwallo/filament-selectify": "^2.0",
4244
"lara-zeus/core": "^3.0"
4345
},
4446
"require-dev": {

src/Filament/Resources/FaqResource.php

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace LaraZeus\Sky\Filament\Resources;
44

55
use Filament\Forms\Components\RichEditor;
6+
use Filament\Forms\Components\Section;
67
use Filament\Forms\Components\SpatieTagsInput;
78
use Filament\Forms\Components\Textarea;
89
use Filament\Forms\Form;
@@ -46,21 +47,25 @@ public static function form(Form $form): Form
4647
{
4748
return $form
4849
->schema([
49-
Textarea::make('question')
50-
->label(__('Question'))
51-
->required()
52-
->maxLength(65535)
53-
->columnSpan(2),
50+
Section::make(__('Library File'))
51+
->columns(2)
52+
->schema([
53+
Textarea::make('question')
54+
->label(__('Question'))
55+
->required()
56+
->maxLength(65535)
57+
->columnSpan(2),
5458

55-
RichEditor::make('answer')
56-
->label(__('Answer'))
57-
->required()
58-
->maxLength(65535)
59-
->columnSpan(2),
59+
RichEditor::make('answer')
60+
->label(__('Answer'))
61+
->required()
62+
->maxLength(65535)
63+
->columnSpan(2),
6064

61-
SpatieTagsInput::make('category')
62-
->type('faq')
63-
->label(__('FAQ Categories')),
65+
SpatieTagsInput::make('category')
66+
->type('faq')
67+
->label(__('FAQ Categories')),
68+
]),
6469
]);
6570
}
6671

src/Filament/Resources/LibraryResource.php

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace LaraZeus\Sky\Filament\Resources;
44

5-
use Filament\Forms\Components\Radio;
65
use Filament\Forms\Components\Section;
76
use Filament\Forms\Components\Select;
87
use Filament\Forms\Components\SpatieMediaLibraryFileUpload;
@@ -24,6 +23,7 @@
2423
use LaraZeus\Sky\Filament\Resources\LibraryResource\Pages;
2524
use LaraZeus\Sky\Models\Library;
2625
use LaraZeus\Sky\SkyPlugin;
26+
use Wallo\FilamentSelectify\Components\ButtonGroup;
2727

2828
class LibraryResource extends SkyResource
2929
{
@@ -42,56 +42,59 @@ public static function form(Form $form): Form
4242
{
4343
return $form
4444
->schema([
45-
TextInput::make('title')
46-
->label(__('Library Title'))
47-
->required()
48-
->maxLength(255)
49-
->live(onBlur: true)
50-
->afterStateUpdated(function (Set $set, $state, $context) {
51-
if ($context === 'edit') {
52-
return;
53-
}
54-
55-
$set('slug', Str::slug($state));
56-
}),
57-
58-
TextInput::make('slug')
59-
->unique(ignorable: fn (?Library $record): ?Library => $record)
60-
->required()
61-
->maxLength(255)
62-
->label(__('Library Slug')),
63-
64-
Textarea::make('description')
65-
->maxLength(255)
66-
->label(__('Library Description'))
67-
->columnSpan(2),
68-
69-
SpatieTagsInput::make('category')
70-
->type('library')
71-
->label(__('Library Categories')),
72-
73-
Select::make('type')
74-
->label(__('Library Type'))
75-
->visible(SkyPlugin::get()->getLibraryTypes() !== null)
76-
->options(SkyPlugin::get()->getLibraryTypes()),
45+
Section::make(__('Library File'))
46+
->columns(2)
47+
->schema([
48+
TextInput::make('title')
49+
->label(__('Library Title'))
50+
->required()
51+
->maxLength(255)
52+
->live(onBlur: true)
53+
->afterStateUpdated(function (Set $set, $state, $context) {
54+
if ($context === 'edit') {
55+
return;
56+
}
57+
58+
$set('slug', Str::slug($state));
59+
}),
60+
61+
TextInput::make('slug')
62+
->unique(ignorable: fn (?Library $record): ?Library => $record)
63+
->required()
64+
->maxLength(255)
65+
->label(__('Library Slug')),
66+
67+
Textarea::make('description')
68+
->maxLength(255)
69+
->label(__('Library Description'))
70+
->columnSpan(2),
71+
72+
SpatieTagsInput::make('category')
73+
->type('library')
74+
->label(__('Library Categories')),
75+
76+
Select::make('type')
77+
->label(__('Library Type'))
78+
->visible(SkyPlugin::get()->getLibraryTypes() !== null)
79+
->options(SkyPlugin::get()->getLibraryTypes()),
80+
]),
7781

7882
Section::make(__('Library File'))
83+
->collapsible()
84+
->compact()
7985
->schema([
80-
Radio::make('upload_or_url')
81-
->label('')
86+
ButtonGroup::make('upload_or_url')
8287
->live()
8388
->dehydrated(false)
8489
->afterStateHydrated(function (Set $set, Get $get) {
8590
$setVal = ($get('file_path') === null) ? 'upload' : 'url';
8691
$set('upload_or_url', $setVal);
8792
})
88-
->default('upload')
8993
->options([
9094
'upload' => __('upload'),
9195
'url' => __('url'),
9296
])
93-
->inline(),
94-
97+
->default('upload'),
9598
SpatieMediaLibraryFileUpload::make('file_path_upload')
9699
->collection('library')
97100
->multiple()
@@ -103,8 +106,7 @@ public static function form(Form $form): Form
103106
->label(__('file url'))
104107
->visible(fn (Get $get) => $get('upload_or_url') === 'url')
105108
->url(),
106-
])
107-
->collapsible(),
109+
]),
108110
]);
109111
}
110112

src/Filament/Resources/PageResource.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use Filament\Forms\Components\DateTimePicker;
66
use Filament\Forms\Components\Hidden;
77
use Filament\Forms\Components\Placeholder;
8-
use Filament\Forms\Components\Radio;
98
use Filament\Forms\Components\Select;
109
use Filament\Forms\Components\SpatieMediaLibraryFileUpload;
1110
use Filament\Forms\Components\Tabs;
@@ -34,6 +33,7 @@
3433
use LaraZeus\Sky\Filament\Resources\PageResource\Pages;
3534
use LaraZeus\Sky\Models\Post;
3635
use LaraZeus\Sky\SkyPlugin;
36+
use Wallo\FilamentSelectify\Components\ButtonGroup;
3737

3838
class PageResource extends SkyResource
3939
{
@@ -124,20 +124,19 @@ public static function form(Form $form): Form
124124
]),
125125
Tabs\Tab::make(__('Image'))->schema([
126126
Placeholder::make(__('Featured Image')),
127-
Radio::make('featured_image_type')
128-
->label('')
127+
ButtonGroup::make('featured_image_type')
129128
->live()
129+
->label('')
130130
->dehydrated(false)
131131
->afterStateHydrated(function (Set $set, Get $get) {
132132
$setVal = ($get('featured_image') === null) ? 'upload' : 'url';
133133
$set('featured_image_type', $setVal);
134134
})
135-
->default('upload')
136135
->options([
137136
'upload' => __('upload'),
138137
'url' => __('url'),
139138
])
140-
->inline(),
139+
->default('upload'),
141140
SpatieMediaLibraryFileUpload::make('featured_image_upload')
142141
->collection('pages')
143142
->visible(fn (Get $get) => $get('featured_image_type') === 'upload')

src/Filament/Resources/PostResource.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use Filament\Forms\Components\DateTimePicker;
66
use Filament\Forms\Components\Hidden;
77
use Filament\Forms\Components\Placeholder;
8-
use Filament\Forms\Components\Radio;
98
use Filament\Forms\Components\Select;
109
use Filament\Forms\Components\SpatieMediaLibraryFileUpload;
1110
use Filament\Forms\Components\SpatieTagsInput;
@@ -35,6 +34,7 @@
3534
use LaraZeus\Sky\Filament\Resources\PostResource\Pages;
3635
use LaraZeus\Sky\Models\Post;
3736
use LaraZeus\Sky\SkyPlugin;
37+
use Wallo\FilamentSelectify\Components\ButtonGroup;
3838

3939
// @mixin Builder<PostScope>
4040
class PostResource extends SkyResource
@@ -126,21 +126,19 @@ public static function form(Form $form): Form
126126

127127
Tabs\Tab::make(__('Image'))->schema([
128128
Placeholder::make(__('Featured Image')),
129-
Radio::make('featured_image_type')
130-
->label('')
129+
ButtonGroup::make('featured_image_type')
131130
->live()
131+
->label('')
132132
->dehydrated(false)
133133
->afterStateHydrated(function (Set $set, Get $get) {
134134
$setVal = ($get('featured_image') === null) ? 'upload' : 'url';
135135
$set('featured_image_type', $setVal);
136136
})
137-
->default('upload')
138137
->options([
139138
'upload' => __('upload'),
140139
'url' => __('url'),
141140
])
142-
->inline(),
143-
141+
->default('upload'),
144142
SpatieMediaLibraryFileUpload::make('featured_image_upload')
145143
->collection('posts')
146144
->visible(fn (Get $get) => $get('featured_image_type') === 'upload')

src/Filament/Resources/TagResource.php

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace LaraZeus\Sky\Filament\Resources;
44

5+
use Filament\Forms\Components\Section;
56
use Filament\Forms\Components\Select;
67
use Filament\Forms\Components\TextInput;
78
use Filament\Forms\Form;
@@ -34,20 +35,25 @@ public static function form(Form $form): Form
3435
{
3536
return $form
3637
->schema([
37-
TextInput::make('name')
38-
->required()
39-
->maxLength(255)
40-
->label(__('Tag.Name'))
41-
->live(onBlur: true)
42-
->afterStateUpdated(function (Set $set, $state) {
43-
$set('slug', Str::slug($state));
44-
}),
45-
TextInput::make('slug')
46-
->unique(ignorable: fn (?Model $record): ?Model => $record)
47-
->required()
48-
->maxLength(255),
49-
Select::make('type')
50-
->options(SkyPlugin::get()->getTagTypes()),
38+
Section::make()
39+
->columns(2)
40+
->schema([
41+
TextInput::make('name')
42+
->required()
43+
->maxLength(255)
44+
->label(__('Tag.Name'))
45+
->live(onBlur: true)
46+
->afterStateUpdated(function (Set $set, $state) {
47+
$set('slug', Str::slug($state));
48+
}),
49+
TextInput::make('slug')
50+
->unique(ignorable: fn (?Model $record): ?Model => $record)
51+
->required()
52+
->maxLength(255),
53+
Select::make('type')
54+
->columnSpan(2)
55+
->options(SkyPlugin::get()->getTagTypes()),
56+
]),
5157
]);
5258
}
5359

0 commit comments

Comments
 (0)