├── .gitignore
├── CHANGELOG.md
├── README.md
├── composer.json
├── config
└── livewire-toast.php
├── resources
└── views
│ ├── icons
│ ├── error.blade.php
│ ├── info.blade.php
│ ├── success.blade.php
│ └── warning.blade.php
│ └── livewire
│ └── livewire-toast.blade.php
└── src
├── Http
└── Livewire
│ └── LivewireToast.php
└── LivewireToastServiceProvider.php
/.gitignore:
--------------------------------------------------------------------------------
1 | composer.lock
2 | vendor
3 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 | All notable changes to this project will be documented in this file.
3 |
4 | ## [1.0.0] - 2021-05-23
5 | - Initial Release
6 |
7 | ## [1.0.1] - 2021-05-25
8 | - Fixed zoom_in transition
9 | - Introduced Session Flash Support
10 | - Updated README.md
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # livewire-toast
2 | Livewire Package to display Toast Notification based on TALL Stack.
3 |
4 |
0 ) { timeout = setTimeout(() => { show = false }, duration); }"
9 | @click="if(@this.hideOnClick) { show = false; }"
10 | x-show="show"
11 |
12 | @if($transition)
13 | x-transition:enter="transition ease-in-out duration-300"
14 | x-transition:enter-start="opacity-0 transform {{$this->transitioClasses['enter_start_class']}}"
15 | x-transition:enter-end="opacity-100 transform {{$this->transitioClasses['enter_end_class']}}"
16 | x-transition:leave="transition ease-in-out duration-500"
17 | x-transition:leave-start="opacity-100 transform {{$this->transitioClasses['leave_start_class']}}"
18 | x-transition:leave-end="opacity-0 transform {{$this->transitioClasses['leave_end_class']}}"
19 | @endif
20 | >
21 | @if($message)
22 |
23 |
24 | @if($showIcon)
25 |
26 | @include('livewire-toast::icons.' . $type)
27 |
28 | @endif
29 |
30 |
31 | {{$message}}
32 |
33 |
34 | @endif
35 |
36 |
--------------------------------------------------------------------------------
/src/Http/Livewire/LivewireToast.php:
--------------------------------------------------------------------------------
1 | ['rotate-180', 'rotate'],
23 | 'zoom_in' => ['scale-50', 'scale-100'],
24 | 'appear_from_right' => ['translate-x-1/2', 'translate-x-0'],
25 | 'appear_from_left' => ['-translate-x-1/2', 'translate-x-0'],
26 | 'appear_from_below' => ['translate-y-1/2', 'translate-y-0'],
27 | 'appear_from_above' => ['-translate-y-1/2', 'translate-y-0'],
28 | ];
29 |
30 | public function mount()
31 | {
32 | if($message = session('livewire-toast')) {
33 | $this->show($message);
34 | }
35 | }
36 |
37 | public function show($params)
38 | {
39 | $type = '';
40 | if (is_array($params)) {
41 | $this->message = $params['message'] ?? '';
42 | $type = $params['type'] ?? '';
43 | } else {
44 | $this->message = $params;
45 | }
46 | $this->_setType($type);
47 | }
48 |
49 | public function showWarning($message)
50 | {
51 | $this->message = $message;
52 | $this->_setType('warning');
53 | }
54 |
55 | public function showInfo($message)
56 | {
57 | $this->message = $message;
58 | $this->_setType('info');
59 | }
60 |
61 | public function showError($message)
62 | {
63 | $this->message = $message;
64 | $this->_setType('error');
65 | }
66 |
67 | public function showSuccess($message)
68 | {
69 | $this->message = $message;
70 | $this->_setType('success');
71 | }
72 |
73 | public function render()
74 | {
75 | $this->_setBackgroundColor();
76 | $this->_setTextColor();
77 | $this->_setPosition();
78 | $this->_setDuration();
79 | $this->_setIcon();
80 | $this->_setClickHandler();
81 | $this->_setTransition();
82 |
83 | if (!empty($this->message)) {
84 | $this->dispatchBrowserEvent('new-toast');
85 | }
86 | return view('livewire-toast::livewire.livewire-toast');
87 | }
88 |
89 | private function _setType($type = '')
90 | {
91 | if (in_array($type, ['warning', 'info', 'error', 'success'])) {
92 | $this->type = $type;
93 | } else {
94 | $this->type = config('livewire-toast.type');
95 | }
96 | }
97 |
98 | private function _setBackgroundColor()
99 | {
100 | $this->bgColorCss = config('livewire-toast.color.bg.' . $this->type);
101 | }
102 |
103 | private function _setTextColor()
104 | {
105 | $this->textColorCss = config('livewire-toast.text_color');
106 | }
107 |
108 | private function _setPosition()
109 | {
110 | switch (config('livewire-toast.position')) {
111 | case 'top-left':
112 | $this->positionCss = 'top-4 left-4';
113 | break;
114 | case 'top-right':
115 | $this->positionCss = 'top-4 right-4';
116 | break;
117 | case 'bottom-left':
118 | $this->positionCss = 'bottom-4 left-4';
119 | break;
120 | case 'bottom-right':
121 | default:
122 | $this->positionCss = 'bottom-4 right-4';
123 | }
124 | }
125 |
126 | private function _setDuration()
127 | {
128 | $this->duration = (int)config('livewire-toast.duration');
129 | }
130 |
131 | private function _setIcon()
132 | {
133 | $this->showIcon = (boolean)config('livewire-toast.show_icon');
134 | }
135 |
136 | private function _setClickHandler()
137 | {
138 | $this->hideOnClick = (boolean)config('livewire-toast.hide_on_click');
139 | }
140 |
141 | private function _setTransition()
142 | {
143 | $this->transition = (boolean)config('livewire-toast.transition');
144 | if ($this->transition) {
145 | $this->transitioClasses['leave_end_class'] =
146 | $this->transitioClasses['enter_start_class'] =
147 | reset($this->transitions[config('livewire-toast.transition_type')]);
148 |
149 | $this->transitioClasses['leave_start_class'] =
150 | $this->transitioClasses['enter_end_class'] =
151 | end($this->transitions[config('livewire-toast.transition_type')]);
152 | }
153 | }
154 | }
155 |
--------------------------------------------------------------------------------
/src/LivewireToastServiceProvider.php:
--------------------------------------------------------------------------------
1 | loadViewsFrom(__DIR__ . '/../resources/views', 'livewire-toast');
15 |
16 | $this->publishes([
17 | __DIR__.'/../resources/views' => resource_path('views/vendor/livewire-toast')
18 | ], 'views');
19 |
20 | $this->publishes([
21 | __DIR__.'/../config/livewire-toast.php' => base_path('config/livewire-toast.php')
22 | ], 'config');
23 | }
24 |
25 | public function register()
26 | {
27 | $this->mergeConfigFrom(__DIR__ .'/../config/livewire-toast.php', 'livewire-toast');
28 | }
29 | }
30 |
--------------------------------------------------------------------------------