Skip to content

Commit 09832a0

Browse files
Add support for Filament 4 (#31)
* Add support for Filament 4 * Update README to be more clear * Remove extraneous modal buttons * Make light mode borders consistent * Partially fix comment delete not working in comment modals * Style fix
1 parent 40e1f1a commit 09832a0

14 files changed

Lines changed: 110 additions & 80 deletions

File tree

README.md

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,12 @@ class Project extends Model implements Commentable
5050

5151
### Usage with Filament
5252

53-
You can register the plugin in your Panel(s) like so:
54-
55-
```php
56-
use Kirschbaum\Commentions\CommentionsPlugin;
57-
58-
return $panel
59-
->plugins([
60-
CommentionsPlugin::make(),
61-
])
62-
```
63-
6453
There are a couple of ways to use Commentions with Filament.
6554

6655
1. Register the component in your Filament Infolists:
6756

57+
> This works for Filament 3 and 4.
58+
6859
```php
6960
Infolists\Components\Section::make('Comments')
7061
->schema([
@@ -75,6 +66,8 @@ Infolists\Components\Section::make('Comments')
7566

7667
2. Or in your table actions:
7768

69+
If you are using Filament 3, you must use `CommentsTableAction` in your table's `actions` array:
70+
7871
```php
7972
use Kirschbaum\Commentions\Filament\Actions\CommentsTableAction;
8073

@@ -84,8 +77,21 @@ use Kirschbaum\Commentions\Filament\Actions\CommentsTableAction;
8477
])
8578
```
8679

80+
If you are using Filament 4, you should use `CommentsAction` in `recordActions` instead:
81+
82+
```php
83+
use Kirschbaum\Commentions\Filament\Actions\CommentsAction;
84+
85+
->recordActions([
86+
CommentsAction::make()
87+
->mentionables(User::all())
88+
])
89+
````
90+
8791
3. Or as a header action:
8892

93+
> This works for Filament 3 and 4.
94+
8995
```php
9096
use Kirschbaum\Commentions\Filament\Actions\CommentsAction;
9197

@@ -99,7 +105,15 @@ protected function getHeaderActions(): array
99105

100106
***
101107

102-
### Configuring the User model and the mentionables
108+
### Configuration
109+
110+
You can publish the configuration file to make changes.
111+
112+
```bash
113+
php artisan vendor:publish --tag="commentions-config"
114+
```
115+
116+
#### Configuring the User model and the mentionables
103117

104118
If your `User` model lives in a different namespace than `App\Models\User`, you can configure it in `config/commentions.php`:
105119

@@ -109,7 +123,7 @@ If your `User` model lives in a different namespace than `App\Models\User`, you
109123
],
110124
```
111125

112-
### Configuring the Comment model
126+
#### Configuring the Comment model
113127

114128
If you need to customize the Comment model, you can extend the `\Kirschbaum\Commentions\Comment` class and then update the `comment.model` option in your `config/commentions.php` file:
115129

@@ -120,20 +134,20 @@ If you need to customize the Comment model, you can extend the `\Kirschbaum\Comm
120134
],
121135
```
122136

123-
### Configuring Comment permissions
137+
#### Configuring Comment permissions
124138

125139
By default, users can create comments, as well as edit and delete their own comments. You can adjust these permissions by implementing your own policy:
126140

127-
#### 1) Create a custom policy
141+
##### 1) Create a custom policy
128142

129143
```php
130144
namespace App\Policies;
131145

132146
use Kirschbaum\Commentions\Comment;
133147
use Kirschbaum\Commentions\Contracts\Commenter;
134-
use Kirschbaum\Commentions\Policies\CommentPolicy;
148+
use Kirschbaum\Commentions\Policies\CommentPolicy as CommentionsPolicy;
135149

136-
class CommentPolicy extends CommentPolicy
150+
class CommentPolicy extends CommentionsPolicy
137151
{
138152
public function create(Commenter $user): bool
139153
{
@@ -152,7 +166,7 @@ class CommentPolicy extends CommentPolicy
152166
}
153167
```
154168

155-
#### 2) Register your policy in the configuration file
169+
##### 2) Register your policy in the configuration file
156170

157171
Update the `comment.policy` option in your `config/commentions.php` file:
158172

@@ -266,13 +280,13 @@ $comment->getMentioned()->each(function (Commenter $commenter) {
266280

267281
### Polling for new comments
268282

269-
Commentions supports polling for new comments. You can enable it on any component by calling the `pollingInterval` method and passing the number of seconds.
283+
Commentions supports polling for new comments. You can enable it on any component by calling the `poll` method and passing the desired interval.
270284

271285
```php
272286
Infolists\Components\Section::make('Comments')
273287
->schema([
274288
CommentsEntry::make('comments')
275-
->pollingInterval(10)
289+
->poll('10s')
276290
]),
277291
```
278292

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
"illuminate/support": "^11.0|^12.0",
2727
"illuminate/database": "^11.0|^12.0",
2828
"livewire/livewire": "^3.5",
29-
"filament/support": "^3.2",
30-
"filament/notifications": "^3.2",
31-
"filament/filament": "^3.2"
29+
"filament/support": "^3.2|^4.0",
30+
"filament/notifications": "^3.2|^4.0",
31+
"filament/filament": "^3.2|^4.0"
3232
},
3333
"extra": {
3434
"laravel": {

resources/css/commentions.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@import "tailwindcss" source(none) prefix(comm) important;
22

3+
@source "../js/";
34
@source "../views/";
45
@source "../../src";
56

resources/dist/commentions.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/dist/commentions.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/js/commentions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ document.addEventListener('alpine:init', () => {
3030
],
3131
editorProps: {
3232
attributes: {
33-
class: `prose dark:prose-invert prose-sm sm:prose-base lg:prose-lg xl:prose-2xl focus:outline-none p-4 min-w-full w-full rounded-lg border border-gray-300 dark:border-gray-700`,
33+
class: `comm:prose comm:dark:prose-invert comm:prose-sm comm:sm:prose-base comm:lg:prose-lg comm:xl:prose-2xl comm:focus:outline-none comm:p-4 comm:min-w-full comm:w-full comm:rounded-lg comm:border comm:border-gray-300 comm:dark:border-gray-700`,
3434
},
3535
},
3636
placeholder: 'Type something...',

resources/views/comment-list.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div @if ($pollingInterval) wire:poll.{{ $pollingInterval }}s @endif>
1+
<div @if ($pollingInterval) wire:poll.{{ $pollingInterval }} @endif>
22
@if ($this->comments->isEmpty())
33
<div class="comm:flex comm:items-center comm:justify-center comm:p-6 comm:text-center comm:rounded-lg comm:border comm:border-dashed comm:border-gray-300 comm:dark:border-gray-700">
44
<div class="comm:flex comm:flex-col comm:items-center comm:gap-y-2">

resources/views/comment.blade.php

Lines changed: 39 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@use('\Kirschbaum\Commentions\Config')
22

3-
<div class="comm:flex comm:items-start comm:gap-x-4 comm:border comm:p-4 comm:rounded-lg comm:shadow-sm comm:mb-2" id="filament-comment-{{ $comment->getId() }}">
3+
<div class="comm:flex comm:items-start comm:gap-x-4 comm:border comm:border-gray-300 comm:dark:border-gray-700 comm:p-4 comm:rounded-lg comm:shadow-sm comm:mb-2" id="filament-comment-{{ $comment->getId() }}">
44
@if ($avatar = $comment->getAuthorAvatar())
55
<img
66
src="{{ $comment->getAuthorAvatar() }}"
@@ -46,12 +46,44 @@ class="comm:text-xs comm:text-gray-300 comm:ml-1"
4646
@endif
4747

4848
@if (Config::resolveAuthenticatedUser()?->can('delete', $comment))
49-
<x-filament::icon-button
50-
icon="heroicon-s-trash"
51-
wire:click="$dispatch('open-modal', { id: 'delete-comment-modal-{{ $comment->getId() }}' })"
52-
size="xs"
53-
color="gray"
54-
/>
49+
<x-filament::modal
50+
id="delete-comment-modal-{{ $comment->getId() }}"
51+
width="sm"
52+
>
53+
<x-slot name="trigger">
54+
<x-filament::icon-button
55+
icon="heroicon-s-trash"
56+
size="xs"
57+
color="gray"
58+
/>
59+
</x-slot>
60+
61+
<x-slot name="heading">
62+
Delete Comment
63+
</x-slot>
64+
65+
<div class="comm:py-4">
66+
Are you sure you want to delete this comment? This action cannot be undone.
67+
</div>
68+
69+
<x-slot name="footer">
70+
<div class="comm:flex comm:justify-end comm:gap-x-4">
71+
<x-filament::button
72+
wire:click="$dispatch('close-modal', { id: 'delete-comment-modal-{{ $comment->getId() }}' })"
73+
color="gray"
74+
>
75+
Cancel
76+
</x-filament::button>
77+
78+
<x-filament::button
79+
wire:click="delete"
80+
color="danger"
81+
>
82+
Delete
83+
</x-filament::button>
84+
</div>
85+
</x-slot>
86+
</x-filament::modal>
5587
@endif
5688
</div>
5789
@endif
@@ -93,38 +125,4 @@ class="comm:text-xs comm:text-gray-300 comm:ml-1"
93125
@endif
94126
@endif
95127
</div>
96-
97-
@if ($comment->isComment() && \Kirschbaum\Commentions\Config::resolveAuthenticatedUser()?->can('delete', $comment))
98-
<x-filament::modal
99-
id="delete-comment-modal-{{ $comment->getId() }}"
100-
wire:model="showDeleteModal"
101-
width="sm"
102-
>
103-
<x-slot name="heading">
104-
Delete Comment
105-
</x-slot>
106-
107-
<div class="comm:py-4">
108-
Are you sure you want to delete this comment? This action cannot be undone.
109-
</div>
110-
111-
<x-slot name="footer">
112-
<div class="comm:flex comm:justify-end comm:gap-x-4">
113-
<x-filament::button
114-
wire:click="$dispatch('close-modal', { id: 'delete-comment-modal-{{ $comment->getId() }}' })"
115-
color="gray"
116-
>
117-
Cancel
118-
</x-filament::button>
119-
120-
<x-filament::button
121-
wire:click="delete"
122-
color="danger"
123-
>
124-
Delete
125-
</x-filament::button>
126-
</div>
127-
</x-slot>
128-
</x-filament::modal>
129-
@endif
130128
</div>

src/Comment.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use Closure;
77
use DateTime;
88
use Filament\Models\Contracts\HasAvatar;
9-
use Filament\Support\Facades\FilamentColor;
109
use Illuminate\Database\Eloquent\Casts\Attribute;
1110
use Illuminate\Database\Eloquent\Factories\HasFactory;
1211
use Illuminate\Database\Eloquent\Model;
@@ -20,7 +19,6 @@
2019
use Kirschbaum\Commentions\Contracts\Commenter;
2120
use Kirschbaum\Commentions\Contracts\RenderableComment;
2221
use Kirschbaum\Commentions\Database\Factories\CommentFactory;
23-
use Spatie\Color\Rgb;
2422

2523
/**
2624
* @property int $id
@@ -133,9 +131,7 @@ public function getAuthorAvatar(): string
133131
->map(fn (string $segment): string => filled($segment) ? mb_substr($segment, 0, 1) : '')
134132
->join(' ');
135133

136-
$backgroundColor = Rgb::fromString('rgb(' . FilamentColor::getColors()['gray'][950] . ')')->toHex();
137-
138-
return 'https://ui-avatars.com/api/?name=' . urlencode($name) . '&color=FFFFFF&background=' . str($backgroundColor)->after('#');
134+
return 'https://ui-avatars.com/api/?name=' . urlencode($name) . '&color=FFFFFF&background=71717b';
139135
}
140136

141137
public function getBody(): string

src/Filament/Actions/CommentsAction.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ protected function setUp(): void
2525
]))
2626
->modalWidth('xl')
2727
->label('Comments')
28+
->modalSubmitAction(false)
29+
->modalCancelAction(false)
2830
->modalAutofocus(false);
2931
}
3032

0 commit comments

Comments
 (0)