Notification

ページに1度置き、任意の Alpine コンポーネントから $dispatch("notify", { type, content }) で Toast を出す。position / appearance / size / duration / event-name は props で制御。

bordered-left / md / bottom-right (event: notify)

<x-button color="info" appearance="outline"
    x-on:click="$dispatch('notify', { type: 'info', content: 'Checking for updates…' })">info</x-button>
<x-button color="success" appearance="outline"
    x-on:click="$dispatch('notify', { type: 'success', content: 'Saved' })">success</x-button>
<x-button color="warning" appearance="outline"
    x-on:click="$dispatch('notify', { type: 'warning', content: 'Your plan expires soon' })">warning</x-button>
<x-button color="error" appearance="outline"
    x-on:click="$dispatch('notify', { type: 'error', content: 'Connection failed' })">error</x-button>
<x-button color="neutral" appearance="base-100"
    x-on:click="
        $dispatch('notify', { type: 'success', content: 'First of three' });
        setTimeout(() => $dispatch('notify', { type: 'info', content: 'Second of three' }), 200);
        setTimeout(() => $dispatch('notify', { type: 'warning', content: 'Third of three' }), 400);
    ">stack 3</x-button>
読み込み中…
HTML を読み込めませんでした

solid / top-right / sm (event: notify-solid)

<x-button color="info" appearance="solid" size="sm"
    x-on:click="$dispatch('notify-solid', { type: 'info', content: 'Synced' })">info</x-button>
<x-button color="success" appearance="solid" size="sm"
    x-on:click="$dispatch('notify-solid', { type: 'success', content: 'Deploy succeeded' })">success</x-button>
<x-button color="warning" appearance="solid" size="sm"
    x-on:click="$dispatch('notify-solid', { type: 'warning', content: 'CPU usage is high' })">warning</x-button>
<x-button color="error" appearance="solid" size="sm"
    x-on:click="$dispatch('notify-solid', { type: 'error', content: 'Request timed out' })">error</x-button>
読み込み中…
HTML を読み込めませんでした

soft / bottom-left / lg (event: notify-left)

<x-button color="info" appearance="soft" size="sm"
    x-on:click="$dispatch('notify-left', { type: 'info', content: 'Backup started' })">info</x-button>
<x-button color="success" appearance="soft" size="sm"
    x-on:click="$dispatch('notify-left', { type: 'success', content: 'Archive complete' })">success</x-button>
<x-button color="warning" appearance="soft" size="sm"
    x-on:click="$dispatch('notify-left', { type: 'warning', content: 'Storage is running low' })">warning</x-button>
<x-button color="error" appearance="soft" size="sm"
    x-on:click="$dispatch('notify-left', { type: 'error', content: 'Backup failed' })">error</x-button>
読み込み中…
HTML を読み込めませんでした

outline / top-center / sm (event: notify-top)

<x-button color="info" appearance="outline" size="sm"
    x-on:click="$dispatch('notify-top', { type: 'info', content: 'Shown at the top center' })">info</x-button>
<x-button color="success" appearance="outline" size="sm"
    x-on:click="$dispatch('notify-top', { type: 'success', content: 'Copied' })">success</x-button>
<x-button color="warning" appearance="outline" size="sm"
    x-on:click="$dispatch('notify-top', { type: 'warning', content: 'Your session is expiring' })">warning</x-button>
<x-button color="error" appearance="outline" size="sm"
    x-on:click="$dispatch('notify-top', { type: 'error', content: 'You do not have permission' })">error</x-button>
読み込み中…
HTML を読み込めませんでした

使い方

1. layout に1度だけ置く

<x-notification-system />
読み込み中…
HTML を読み込めませんでした

2. 任意のコンポーネントから dispatch

<button x-on:click="$dispatch('notify', { type: 'success', content: 'Saved' })">
    Save
</button>
読み込み中…
HTML を読み込めませんでした

3. Laravel の session flash でも発火

return redirect()->back()->with('notify', ['type' => 'success', 'content' => 'Saved']);
読み込み中…
HTML を読み込めませんでした

4. 位置・見た目を変えたい時

<x-notification-system position="top-right" appearance="solid" size="sm" :duration="5000" />
読み込み中…
HTML を読み込めませんでした

5. 同じページに複数を共存させたい場合は event-name で分離

<x-notification-system position="top-center" event-name="notify-toast" />
<button x-on:click="$dispatch('notify-toast', { type: 'info', content: '…' })">…</button>
読み込み中…
HTML を読み込めませんでした