@laravel-inertia-toast/react 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +119 -0
- package/package.json +3 -2
package/README.md
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# @laravel-inertia-toast/react
|
|
2
|
+
|
|
3
|
+
React adapter for [Laravel Inertia Toast](https://github.com/veekthoven/laravel-inertia-toast) — beautiful toast notifications for Laravel + Inertia.js applications.
|
|
4
|
+
|
|
5
|
+
## Demo
|
|
6
|
+
|
|
7
|
+
**React:**
|
|
8
|
+

|
|
9
|
+
|
|
10
|
+
**See it in action:**
|
|
11
|
+

|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @laravel-inertia-toast/react
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Setup
|
|
20
|
+
|
|
21
|
+
### 1. Add the Provider
|
|
22
|
+
|
|
23
|
+
Wrap your app with `<ToastProvider>` and add `<Toasts />`:
|
|
24
|
+
|
|
25
|
+
```jsx
|
|
26
|
+
// in your resources/js/app.tsx
|
|
27
|
+
|
|
28
|
+
import { createRoot } from 'react-dom/client';
|
|
29
|
+
import { ToastProvider, Toasts } from '@laravel-inertia-toast/react'
|
|
30
|
+
|
|
31
|
+
setup({ el, App, props }) {
|
|
32
|
+
const root = createRoot(el);
|
|
33
|
+
|
|
34
|
+
root.render(
|
|
35
|
+
<ToastProvider
|
|
36
|
+
config={{
|
|
37
|
+
position: 'top-right'
|
|
38
|
+
duration: 5000,
|
|
39
|
+
maxVisible: 5,
|
|
40
|
+
}}
|
|
41
|
+
>
|
|
42
|
+
<App {...props} />
|
|
43
|
+
<Toasts />
|
|
44
|
+
</ToastProvider>
|
|
45
|
+
);
|
|
46
|
+
},
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### 2. Tailwind CSS
|
|
50
|
+
|
|
51
|
+
Since the toast components use Tailwind classes internally, add the package to Tailwind's source detection.
|
|
52
|
+
|
|
53
|
+
**Tailwind v4** — add this `@source` directive to your CSS file (e.g. `resources/css/app.css`):
|
|
54
|
+
|
|
55
|
+
```css
|
|
56
|
+
@source "../../node_modules/@laravel-inertia-toast/react/dist/**/*.js";
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
**Tailwind v3** — add to `tailwind.config.js`:
|
|
60
|
+
|
|
61
|
+
```js
|
|
62
|
+
module.exports = {
|
|
63
|
+
content: [
|
|
64
|
+
// ...
|
|
65
|
+
'./node_modules/@laravel-inertia-toast/react/dist/**/*.js',
|
|
66
|
+
],
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
> The relative paths above assume standard Laravel project structure. Adjust if your setup differs.
|
|
71
|
+
|
|
72
|
+
## Client-Side Usage
|
|
73
|
+
|
|
74
|
+
Use the `useToast()` hook to trigger toasts from your components:
|
|
75
|
+
|
|
76
|
+
```jsx
|
|
77
|
+
import { useToast } from '@laravel-inertia-toast/react'
|
|
78
|
+
|
|
79
|
+
function MyComponent() {
|
|
80
|
+
const { success, error, info, warning } = useToast()
|
|
81
|
+
|
|
82
|
+
return (
|
|
83
|
+
<button onClick={() => success('Copied to clipboard!')}>
|
|
84
|
+
Copy
|
|
85
|
+
</button>
|
|
86
|
+
)
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Server-Side Usage
|
|
91
|
+
|
|
92
|
+
Pair with the PHP package for server-side toasts:
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
composer require veekthoven/laravel-inertia-toast
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
```php
|
|
99
|
+
use InertiaToast\Facades\Toast;
|
|
100
|
+
|
|
101
|
+
Toast::success('Profile updated!');
|
|
102
|
+
Toast::error('Something went wrong.');
|
|
103
|
+
Toast::info('Check your email for a confirmation link.');
|
|
104
|
+
Toast::warning('Your subscription is about to expire.');
|
|
105
|
+
|
|
106
|
+
return redirect()->route('dashboard');
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
For full documentation, configuration options, and the PHP helper API, see the [main repository](https://github.com/veekthoven/laravel-inertia-toast).
|
|
110
|
+
|
|
111
|
+
## Requirements
|
|
112
|
+
|
|
113
|
+
- React 18+
|
|
114
|
+
- Inertia.js v2.3.3+
|
|
115
|
+
- Tailwind CSS v3 or v4
|
|
116
|
+
|
|
117
|
+
## License
|
|
118
|
+
|
|
119
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@laravel-inertia-toast/react",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "React toast components for Laravel Inertia Toast",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
17
|
"files": [
|
|
18
|
-
"dist"
|
|
18
|
+
"dist",
|
|
19
|
+
"README.md"
|
|
19
20
|
],
|
|
20
21
|
"scripts": {
|
|
21
22
|
"build": "vite build && tsc --emitDeclarationOnly",
|