-
-
Save gagelafleur/331881d7ef10509c00382a342db15be1 to your computer and use it in GitHub Desktop.
@mentions with Alpine.js, Livewire & Tributeq
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <x-mention wire:model="body" :mentionables="$mentionables" /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace App\Http\Livewire; | |
| use Livewire\Component; | |
| use App\Models\User; | |
| class CreateComment extends Component | |
| { | |
| public $mentionables; | |
| public $body; | |
| public function mount() | |
| { | |
| $this->mentionables = User::all() | |
| ->map(function ($user) { | |
| return [ | |
| 'key' => $user->name, | |
| 'value' => $user->username, | |
| ]; | |
| }); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @props([ | |
| 'mentionables' => [] | |
| ]) | |
| <div | |
| x-data | |
| x-init=' | |
| ()=> { | |
| let tribute = new Tribute({ | |
| trigger: "@", | |
| values: @json($mentionables) | |
| }); | |
| tribute.attach($refs.textarea); | |
| } | |
| ' | |
| wire:ignore | |
| > | |
| <textarea x-ref="textarea" {{ $attributes->merge(['class' => 'form-control']) }}></textarea> | |
| </div> | |
| @once | |
| @push('styles') | |
| <link href="https://unpkg.com/browse/tributejs@5.1.3/dist/tribute.css" rel="stylesheet" /> | |
| @endpush | |
| @push('scripts') | |
| <script src="https://unpkg.com/browse/tributejs@5.1.3/dist/tribute.min.js"></script> | |
| @endpush | |
| @endonce |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment