Skip to content

Instantly share code, notes, and snippets.

@PierreLebedel
Last active October 3, 2024 09:35
Show Gist options
  • Save PierreLebedel/e6a4f2f49483ea95fa852bb706405797 to your computer and use it in GitHub Desktop.
Save PierreLebedel/e6a4f2f49483ea95fa852bb706405797 to your computer and use it in GitHub Desktop.
TallStackUI component to show toast message on Livewire event (to replace Jetstream action-message component for example)
@props(['on', 'method'=>'success', 'title'=>null])
@php
if( !in_array($method, ['success', 'warning', 'error', 'info']) ){
$method = 'info';
}
if( empty($title) && $slot->isEmpty() ){
$title = __('Success');
}
@endphp
<div x-data="{
description: @js($slot->isEmpty() ? null : $slot->toHtml()),
title: @js($title),
}" x-init="@this.on('{{ $on }}', () => {
$interaction('toast').{{ $method }}(title, description).send();
})"></div>
{{-- The toast will be fired on `saved` Livewire event --}}
<x-toast-message on="saved" :title="__('Saved.')">
{{ __('Your content is saved.') }}
</x-toast-message>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment