<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Pedro Henrique</title>
    <description>The latest articles on Forem by Pedro Henrique (@ph7jack).</description>
    <link>https://forem.com/ph7jack</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F455270%2F9e17737a-d7b4-4393-af8a-db39e00c3ff7.jpeg</url>
      <title>Forem: Pedro Henrique</title>
      <link>https://forem.com/ph7jack</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/ph7jack"/>
    <language>en</language>
    <item>
      <title>Livewire Components</title>
      <dc:creator>Pedro Henrique</dc:creator>
      <pubDate>Thu, 22 Jul 2021 12:45:58 +0000</pubDate>
      <link>https://forem.com/ph7jack/livewire-components-4jlh</link>
      <guid>https://forem.com/ph7jack/livewire-components-4jlh</guid>
      <description>&lt;p&gt;Starting the tallstack development sometimes is exhaustive, create all forms components, buttons, cards.... Wireui has a lot of blade components ready to use.&lt;/p&gt;

&lt;p&gt;Advantages:&lt;br&gt;
Notifications, Dialogs, modals and form components&lt;/p&gt;

&lt;p&gt;Enjoy the livewire components&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/PH7-Jack/wireui"&gt;https://github.com/PH7-Jack/wireui&lt;/a&gt;&lt;/p&gt;

</description>
      <category>livewire</category>
      <category>alpinejs</category>
      <category>blade</category>
      <category>laravel</category>
    </item>
    <item>
      <title>Livewire UI Components</title>
      <dc:creator>Pedro Henrique</dc:creator>
      <pubDate>Wed, 16 Sep 2020 01:17:28 +0000</pubDate>
      <link>https://forem.com/ph7jack/livewire-ui-components-49d2</link>
      <guid>https://forem.com/ph7jack/livewire-ui-components-49d2</guid>
      <description>&lt;p&gt;I created this package to make the development with livewire simpler and faster, this project will be a library of components and some cool features for projects with livewire&lt;/p&gt;

&lt;p&gt;Still in development, some things can be modified&lt;/p&gt;

&lt;p&gt;Links:&lt;br&gt;
&lt;a href="https://github.com/PH7-Jack/wireui"&gt;https://github.com/PH7-Jack/wireui&lt;/a&gt;&lt;/p&gt;

</description>
      <category>livewire</category>
      <category>laravel</category>
      <category>php</category>
    </item>
    <item>
      <title>Global livewire notifications with SweetAlert</title>
      <dc:creator>Pedro Henrique</dc:creator>
      <pubDate>Wed, 19 Aug 2020 13:07:06 +0000</pubDate>
      <link>https://forem.com/ph7jack/global-livewire-notifications-3aba</link>
      <guid>https://forem.com/ph7jack/global-livewire-notifications-3aba</guid>
      <description>&lt;p&gt;EDIT: I created a new idea for this, go to &lt;a href="https://github.com/PH7-Jack/wireui"&gt;https://github.com/PH7-Jack/wireui&lt;/a&gt; to know&lt;/p&gt;

&lt;p&gt;It is normal in all software after performing an action, showing a confirmation message or even a warning. With Livewire software development is simpler in some ways, but showing notifications can be a bit of a chore at first. With that, we can take advantage of what Livewire has in its ecosystem for our benefit.&lt;br&gt;
Let's use Livewire &lt;a href="https://laravel-livewire.com/docs/events"&gt;events&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  Step 1
&lt;/h1&gt;
&lt;h1&gt;
  
  
  Add listeners
&lt;/h1&gt;

&lt;p&gt;In this step, we will prepare the project to listen to livewire events&lt;br&gt;
In your global layout file, place the following listener (in my case it's &lt;code&gt;resources/views/components/layouts/base.blade.php&lt;/code&gt;):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;head&amp;gt;
...
&amp;lt;link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/limonte-sweetalert2/7.33.1/sweetalert2.css" /&amp;gt;
...
&amp;lt;/head&amp;gt;

...
&amp;lt;script src="https://cdn.jsdelivr.net/npm/sweetalert2@9"&amp;gt;&amp;lt;/script&amp;gt;
 &amp;lt;script&amp;gt;
        const SwalModal = (icon, title, html) =&amp;gt; {
            Swal.fire({
                icon,
                title,
                html
            })
        }

        const SwalConfirm = (icon, title, html, confirmButtonText, method, params, callback) =&amp;gt; {
            Swal.fire({
                icon,
                title,
                html,
                showCancelButton: true,
                confirmButtonColor: '#3085d6',
                cancelButtonColor: '#d33',
                confirmButtonText,
                reverseButtons: true,
            }).then(result =&amp;gt; {
                if (result.value) {
                    return livewire.emit(method, params)
                }

                if (callback) {
                    return livewire.emit(callback)
                }
            })
        }

        const SwalAlert = (icon, title, timeout = 7000) =&amp;gt; {
            const Toast = Swal.mixin({
                toast: true,
                position: 'top-end',
                showConfirmButton: false,
                timer: timeout,
                onOpen: toast =&amp;gt; {
                    toast.addEventListener('mouseenter', Swal.stopTimer)
                    toast.addEventListener('mouseleave', Swal.resumeTimer)
                }
            })

            Toast.fire({
                icon,
                title
            })
        }

        document.addEventListener('DOMContentLoaded', () =&amp;gt; { 
            this.livewire.on('swal:modal', data =&amp;gt; {
                SwalModal(data.icon, data.title, data.text)
            })

            this.livewire.on('swal:confirm', data =&amp;gt; {
                SwalConfirm(data.icon, data.title, data.text, data.confirmText, data.method, data.params, data.callback)
            })

            this.livewire.on('swal:alert', data =&amp;gt; {
                SwalAlert(data.icon, data.title, data.timeout)
            }) 
        })
    &amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These methods and listeners will show confirmation notifications or confirmation alerts globally in your project, being able to broadcast directly from Livewire&lt;/p&gt;

&lt;h2&gt;
  
  
  How to fire theses functions?
&lt;/h2&gt;

&lt;p&gt;In every Livewire component you can send events using the code below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php

namespace App\Http\Livewire;

use Livewire\Component;

class MyComponent extends Component
{
    public function render()
    { 
        return view('livewire.shared.my-component');
    }

    public function showModal()
    { 
        $this-&amp;gt;emit('swal:modal', [
            'type'  =&amp;gt; 'success',
            'title' =&amp;gt; 'Success!!',
            'text'  =&amp;gt; "This is a success message",
        ]);
    }

    public function showAlert()
    { 
        $this-&amp;gt;emit('swal:alert', [
            'type'    =&amp;gt; 'success',
            'title'   =&amp;gt; 'This is a success alert!!', 
            'timeout' =&amp;gt; 10000
        ]);
    }

    public function showConfirmation()
    { 
        $this-&amp;gt;emit("swal:confirm", [
            'type'        =&amp;gt; 'warning',
            'title'       =&amp;gt; 'Are you sure?',
            'text'        =&amp;gt; "You won't be able to revert this!",
            'confirmText' =&amp;gt; 'Yes, delete!',
            'method'      =&amp;gt; 'appointments:delete',
            'params'      =&amp;gt; [], // optional, send params to success confirmation
            'callback'    =&amp;gt; '', // optional, fire event if no confirmed
        ]);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>livewire</category>
      <category>laravel</category>
      <category>sweetalert</category>
    </item>
  </channel>
</rss>
