@laravel-inertia-toast/react 0.1.1 → 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 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
+ ![React](../demo/react.png)
9
+
10
+ **See it in action:**
11
+ ![Vue](../demo/toast-demo.gif)
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
@@ -2,7 +2,8 @@ import type { ToastItem as ToastItemType, ToastConfig } from '../types';
2
2
  interface ToastItemProps {
3
3
  toast: ToastItemType;
4
4
  config: ToastConfig;
5
+ position: string;
5
6
  onRemove: (id: string) => void;
6
7
  }
7
- export declare function ToastItem({ toast, config, onRemove }: ToastItemProps): import("react/jsx-runtime").JSX.Element;
8
+ export declare function ToastItem({ toast, config, position, onRemove }: ToastItemProps): import("react/jsx-runtime").JSX.Element;
8
9
  export {};
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),r=require("react"),w=require("@inertiajs/react");let j=0;function C(){return`toast-${++j}-${Date.now()}`}const y={duration:5e3,position:"top-right",maxVisible:5,propKey:"toasts"};function k(t,i){switch(i.type){case"ADD":{const a=[{...i.payload,id:C()},...t.items].slice(0,t.config.maxVisible);return{...t,items:a}}case"REMOVE":return{...t,items:t.items.filter(s=>s.id!==i.payload)};case"CLEAR":return{...t,items:[]};default:return t}}const g=r.createContext(null);function R({children:t,config:i}){const s={...y,...i},[a,l]=r.useReducer(k,{items:[],config:s}),f=r.useRef(s);f.current=s,r.useEffect(()=>w.router.on("navigate",o=>{const u=o.detail.page.props[f.current.propKey];u&&Array.isArray(u)&&u.forEach(b=>{l({type:"ADD",payload:b})})}),[]);const c=r.useCallback((n,o,u)=>{l({type:"ADD",payload:{message:n,level:o,duration:u??null}})},[]),h={items:a.items,config:a.config,success:r.useCallback((n,o)=>c(n,"success",o),[c]),error:r.useCallback((n,o)=>c(n,"error",o),[c]),info:r.useCallback((n,o)=>c(n,"info",o),[c]),warning:r.useCallback((n,o)=>c(n,"warning",o),[c]),remove:r.useCallback(n=>l({type:"REMOVE",payload:n}),[]),clear:r.useCallback(()=>l({type:"CLEAR"}),[])};return e.jsx(g.Provider,{value:h,children:t})}function p(){const t=r.useContext(g);if(!t)throw new Error("useToast must be used within a <ToastProvider>");return t}const m={success:"bg-green-50 text-green-800 dark:bg-green-900/30 dark:text-green-300",error:"bg-red-50 text-red-800 dark:bg-red-900/30 dark:text-red-300",warning:"bg-yellow-50 text-yellow-800 dark:bg-yellow-900/30 dark:text-yellow-300",info:"bg-blue-50 text-blue-800 dark:bg-blue-900/30 dark:text-blue-300"},d={success:"text-green-500 dark:text-green-400",error:"text-red-500 dark:text-red-400",warning:"text-yellow-500 dark:text-yellow-400",info:"text-blue-500 dark:text-blue-400"};function N(){return e.jsx("svg",{className:"h-5 w-5",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zm3.857-9.809a.75.75 0 00-1.214-.882l-3.483 4.79-1.88-1.88a.75.75 0 10-1.06 1.061l2.5 2.5a.75.75 0 001.137-.089l4-5.5z",clipRule:"evenodd"})})}function L(){return e.jsx("svg",{className:"h-5 w-5",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zM8.28 7.22a.75.75 0 00-1.06 1.06L8.94 10l-1.72 1.72a.75.75 0 101.06 1.06L10 11.06l1.72 1.72a.75.75 0 101.06-1.06L11.06 10l1.72-1.72a.75.75 0 00-1.06-1.06L10 8.94 8.28 7.22z",clipRule:"evenodd"})})}function T(){return e.jsx("svg",{className:"h-5 w-5",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M8.485 2.495c.673-1.167 2.357-1.167 3.03 0l6.28 10.875c.673 1.167-.17 2.625-1.516 2.625H3.72c-1.347 0-2.189-1.458-1.515-2.625L8.485 2.495zM10 5a.75.75 0 01.75.75v3.5a.75.75 0 01-1.5 0v-3.5A.75.75 0 0110 5zm0 9a1 1 0 100-2 1 1 0 000 2z",clipRule:"evenodd"})})}function z(){return e.jsx("svg",{className:"h-5 w-5",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a.75.75 0 000 1.5h.253a.25.25 0 01.244.304l-.459 2.066A1.75 1.75 0 0010.747 15H11a.75.75 0 000-1.5h-.253a.25.25 0 01-.244-.304l.459-2.066A1.75 1.75 0 009.253 9H9z",clipRule:"evenodd"})})}function M({level:t}){switch(t){case"success":return e.jsx(N,{});case"error":return e.jsx(L,{});case"warning":return e.jsx(T,{});default:return e.jsx(z,{})}}function v({toast:t,config:i,onRemove:s}){const a=r.useRef(null),l=t.duration??i.duration;return r.useEffect(()=>(l>0&&(a.current=setTimeout(()=>{s(t.id)},l)),()=>{a.current&&clearTimeout(a.current)}),[l,t.id,s]),e.jsx("div",{className:`pointer-events-auto w-full max-w-sm overflow-hidden rounded-lg shadow-lg ring-1 ring-black/5 ${m[t.level]??m.info}`,role:"alert",children:e.jsx("div",{className:"p-4",children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("div",{className:`shrink-0 ${d[t.level]??d.info}`,children:e.jsx(M,{level:t.level})}),e.jsx("div",{className:"ml-3 w-0 flex-1",children:e.jsx("p",{className:"text-sm font-medium",children:t.message})}),e.jsx("div",{className:"ml-4 flex shrink-0",children:e.jsxs("button",{type:"button",className:`inline-flex rounded-md focus:outline-none focus:ring-2 focus:ring-offset-2 ${d[t.level]??d.info}`,onClick:()=>s(t.id),children:[e.jsx("span",{className:"sr-only",children:"Close"}),e.jsx("svg",{className:"h-5 w-5",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{d:"M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z"})})]})})]})})})}const x={"top-right":"top-4 right-4 items-end","top-left":"top-4 left-4 items-start","top-center":"top-4 left-1/2 -translate-x-1/2 items-center","bottom-right":"bottom-4 right-4 items-end","bottom-left":"bottom-4 left-4 items-start","bottom-center":"bottom-4 left-1/2 -translate-x-1/2 items-center"};function E(){const{items:t,config:i,remove:s}=p(),a=x[i.position]??x["top-right"];return e.jsx("div",{className:`pointer-events-none fixed z-50 flex w-full max-w-sm flex-col gap-3 ${a}`,"aria-live":"polite",children:t.map(l=>e.jsx(v,{toast:l,config:i,onRemove:s},l.id))})}exports.ToastItem=v;exports.ToastProvider=R;exports.Toasts=E;exports.useToast=p;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),r=require("react"),w=require("@inertiajs/react");let b=0;function y(){return`toast-${++b}-${Date.now()}`}const C={duration:5e3,position:"top-right",maxVisible:5,propKey:"toasts"};function j(e,i){switch(i.type){case"ADD":{const c=[{...i.payload,id:y()},...e.items].slice(0,e.config.maxVisible);return{...e,items:c}}case"REMOVE":return{...e,items:e.items.filter(l=>l.id!==i.payload)};case"CLEAR":return{...e,items:[]};default:return e}}const p=r.createContext(null);function R({children:e,config:i}){const l={...C,...i},[c,n]=r.useReducer(j,{items:[],config:l}),d=r.useRef(l);d.current=l,r.useEffect(()=>w.router.on("flash",o=>{const u=o.detail.flash[d.current.propKey];u&&Array.isArray(u)&&u.forEach(m=>{n({type:"ADD",payload:m})})}),[]);const a=r.useCallback((s,o,u)=>{n({type:"ADD",payload:{message:s,level:o,duration:u??null}})},[]),f={items:c.items,config:c.config,success:r.useCallback((s,o)=>a(s,"success",o),[a]),error:r.useCallback((s,o)=>a(s,"error",o),[a]),info:r.useCallback((s,o)=>a(s,"info",o),[a]),warning:r.useCallback((s,o)=>a(s,"warning",o),[a]),remove:r.useCallback(s=>n({type:"REMOVE",payload:s}),[]),clear:r.useCallback(()=>n({type:"CLEAR"}),[])};return t.jsx(p.Provider,{value:f,children:e})}function h(){const e=r.useContext(p);if(!e)throw new Error("useToast must be used within a <ToastProvider>");return e}const g={success:"bg-green-100 text-green-500",error:"bg-rose-100 text-rose-500",warning:"bg-yellow-100 text-yellow-500",info:"bg-blue-100 text-blue-500"};function T(){return t.jsx("svg",{className:"size-5","aria-hidden":"true",xmlns:"http://www.w3.org/2000/svg",fill:"currentColor",viewBox:"0 0 20 20",children:t.jsx("path",{d:"M10 .5a9.5 9.5 0 1 0 9.5 9.5A9.51 9.51 0 0 0 10 .5Zm3.707 8.207-4 4a1 1 0 0 1-1.414 0l-2-2a1 1 0 0 1 1.414-1.414L9 10.586l3.293-3.293a1 1 0 0 1 1.414 1.414Z"})})}function L(){return t.jsx("svg",{className:"size-5","aria-hidden":"true",xmlns:"http://www.w3.org/2000/svg",fill:"currentColor",viewBox:"0 0 20 20",children:t.jsx("path",{d:"M10 .5a9.5 9.5 0 1 0 9.5 9.5A9.51 9.51 0 0 0 10 .5Zm3.707 11.793a1 1 0 1 1-1.414 1.414L10 11.414l-2.293 2.293a1 1 0 0 1-1.414-1.414L8.586 10 6.293 7.707a1 1 0 0 1 1.414-1.414L10 8.586l2.293-2.293a1 1 0 0 1 1.414 1.414L11.414 10l2.293 2.293Z"})})}function E(){return t.jsx("svg",{className:"size-5",viewBox:"0 0 20 20",fill:"currentColor",children:t.jsx("path",{fillRule:"evenodd",d:"M8.485 2.495c.673-1.167 2.357-1.167 3.03 0l6.28 10.875c.673 1.167-.17 2.625-1.516 2.625H3.72c-1.347 0-2.189-1.458-1.515-2.625L8.485 2.495zM10 5a.75.75 0 01.75.75v3.5a.75.75 0 01-1.5 0v-3.5A.75.75 0 0110 5zm0 9a1 1 0 100-2 1 1 0 000 2z",clipRule:"evenodd"})})}function z(){return t.jsx("svg",{className:"size-5","aria-hidden":"true",xmlns:"http://www.w3.org/2000/svg",fill:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{fillRule:"evenodd",d:"M2.25 12c0-5.385 4.365-9.75 9.75-9.75s9.75 4.365 9.75 9.75-4.365 9.75-9.75 9.75S2.25 17.385 2.25 12zm8.706-1.442c1.146-.573 2.437.463 2.126 1.706l-.709 2.836.042-.02a.75.75 0 01.67 1.34l-.04.022c-1.147.573-2.438-.463-2.127-1.706l.71-2.836-.042.02a.75.75 0 11-.671-1.34l.041-.022zM12 9a.75.75 0 100-1.5.75.75 0 000 1.5z",clipRule:"evenodd"})})}function A({level:e}){switch(e){case"success":return t.jsx(T,{});case"error":return t.jsx(L,{});case"warning":return t.jsx(E,{});default:return t.jsx(z,{})}}function M(e){return e.includes("right")?"translate-x-full":e.includes("left")?"-translate-x-full":e.startsWith("top")?"-translate-y-full":"translate-y-full"}function v({toast:e,config:i,position:l,onRemove:c}){const n=r.useRef(null),[d,a]=r.useState(!1),f=e.duration??i.duration,s=r.useCallback(()=>{n.current&&(clearTimeout(n.current),n.current=null),a(!1)},[]);r.useEffect(()=>{const m=requestAnimationFrame(()=>a(!0));return()=>cancelAnimationFrame(m)},[]),r.useEffect(()=>(f>0&&(n.current=setTimeout(s,f)),()=>{n.current&&clearTimeout(n.current)}),[f,s]);const o=M(l),u=d?"opacity-100 translate-x-0 translate-y-0 duration-300 ease-out":`opacity-0 ${o} duration-200 ease-in`;return t.jsxs("div",{className:`flex items-center rounded-lg bg-white p-4 text-gray-500 shadow min-w-96 transition ${u}`,role:"alert",onTransitionEnd:()=>{d||c(e.id)},children:[t.jsx("div",{className:`inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg ${g[e.level]??g.info}`,children:t.jsx(A,{level:e.level})}),t.jsx("div",{className:"ml-3 text-sm font-normal",children:e.message}),t.jsxs("button",{type:"button",className:"ml-auto inline-flex items-center justify-center h-8 w-8 rounded-lg bg-white p-1.5 text-gray-400 hover:bg-gray-100 hover:text-gray-900 focus:ring-2 focus:ring-gray-300",onClick:s,"aria-label":"Close",children:[t.jsx("span",{className:"sr-only",children:"Close"}),t.jsx("svg",{"aria-hidden":"true",className:"h-5 w-5",fill:"currentColor",viewBox:"0 0 20 20",xmlns:"http://www.w3.org/2000/svg",children:t.jsx("path",{fillRule:"evenodd",d:"M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z",clipRule:"evenodd"})})]})]})}const x={"top-right":"top-4 right-4 items-end","top-left":"top-4 left-4 items-start","top-center":"top-4 left-1/2 -translate-x-1/2 items-center","bottom-right":"bottom-4 right-4 items-end","bottom-left":"bottom-4 left-4 items-start","bottom-center":"bottom-4 left-1/2 -translate-x-1/2 items-center"};function N(){const{items:e,config:i,remove:l}=h(),c=x[i.position]??x["top-right"];return t.jsx("div",{className:`fixed z-50 flex w-full max-w-sm flex-col gap-3 ${c}`,"aria-live":"polite",children:e.map(n=>t.jsx(v,{toast:n,config:i,position:i.position,onRemove:l},n.id))})}exports.ToastItem=v;exports.ToastProvider=R;exports.Toasts=N;exports.useToast=h;
package/dist/index.js CHANGED
@@ -1,29 +1,29 @@
1
- import { jsx as t, jsxs as m } from "react/jsx-runtime";
2
- import { createContext as y, useReducer as C, useRef as v, useEffect as h, useCallback as c, useContext as k } from "react";
3
- import { router as R } from "@inertiajs/react";
4
- let N = 0;
5
- function L() {
6
- return `toast-${++N}-${Date.now()}`;
1
+ import { jsx as t, jsxs as p } from "react/jsx-runtime";
2
+ import { createContext as y, useReducer as b, useRef as w, useEffect as g, useCallback as c, useContext as C, useState as R } from "react";
3
+ import { router as L } from "@inertiajs/react";
4
+ let T = 0;
5
+ function z() {
6
+ return `toast-${++T}-${Date.now()}`;
7
7
  }
8
- const z = {
8
+ const A = {
9
9
  duration: 5e3,
10
10
  position: "top-right",
11
11
  maxVisible: 5,
12
12
  propKey: "toasts"
13
13
  };
14
- function M(e, i) {
14
+ function E(e, i) {
15
15
  switch (i.type) {
16
16
  case "ADD": {
17
- const s = [{
17
+ const a = [{
18
18
  ...i.payload,
19
- id: L()
19
+ id: z()
20
20
  }, ...e.items].slice(0, e.config.maxVisible);
21
- return { ...e, items: s };
21
+ return { ...e, items: a };
22
22
  }
23
23
  case "REMOVE":
24
24
  return {
25
25
  ...e,
26
- items: e.items.filter((r) => r.id !== i.payload)
26
+ items: e.items.filter((l) => l.id !== i.payload)
27
27
  };
28
28
  case "CLEAR":
29
29
  return { ...e, items: [] };
@@ -32,73 +32,74 @@ function M(e, i) {
32
32
  }
33
33
  }
34
34
  const x = y(null);
35
- function j({ children: e, config: i }) {
36
- const r = { ...z, ...i }, [s, o] = C(M, {
35
+ function S({ children: e, config: i }) {
36
+ const l = { ...A, ...i }, [a, n] = b(E, {
37
37
  items: [],
38
- config: r
39
- }), f = v(r);
40
- f.current = r, h(() => R.on("navigate", (l) => {
41
- const d = l.detail.page.props[f.current.propKey];
42
- d && Array.isArray(d) && d.forEach((b) => {
43
- o({ type: "ADD", payload: b });
38
+ config: l
39
+ }), d = w(l);
40
+ d.current = l, g(() => L.on("flash", (o) => {
41
+ const u = o.detail.flash[d.current.propKey];
42
+ u && Array.isArray(u) && u.forEach((m) => {
43
+ n({ type: "ADD", payload: m });
44
44
  });
45
45
  }), []);
46
- const a = c((n, l, d) => {
47
- o({
46
+ const s = c((r, o, u) => {
47
+ n({
48
48
  type: "ADD",
49
- payload: { message: n, level: l, duration: d ?? null }
49
+ payload: { message: r, level: o, duration: u ?? null }
50
50
  });
51
- }, []), w = {
52
- items: s.items,
53
- config: s.config,
54
- success: c((n, l) => a(n, "success", l), [a]),
55
- error: c((n, l) => a(n, "error", l), [a]),
56
- info: c((n, l) => a(n, "info", l), [a]),
57
- warning: c((n, l) => a(n, "warning", l), [a]),
58
- remove: c((n) => o({ type: "REMOVE", payload: n }), []),
59
- clear: c(() => o({ type: "CLEAR" }), [])
51
+ }, []), f = {
52
+ items: a.items,
53
+ config: a.config,
54
+ success: c((r, o) => s(r, "success", o), [s]),
55
+ error: c((r, o) => s(r, "error", o), [s]),
56
+ info: c((r, o) => s(r, "info", o), [s]),
57
+ warning: c((r, o) => s(r, "warning", o), [s]),
58
+ remove: c((r) => n({ type: "REMOVE", payload: r }), []),
59
+ clear: c(() => n({ type: "CLEAR" }), [])
60
60
  };
61
- return /* @__PURE__ */ t(x.Provider, { value: w, children: e });
61
+ return /* @__PURE__ */ t(x.Provider, { value: f, children: e });
62
62
  }
63
- function A() {
64
- const e = k(x);
63
+ function N() {
64
+ const e = C(x);
65
65
  if (!e)
66
66
  throw new Error("useToast must be used within a <ToastProvider>");
67
67
  return e;
68
68
  }
69
- const p = {
70
- success: "bg-green-50 text-green-800 dark:bg-green-900/30 dark:text-green-300",
71
- error: "bg-red-50 text-red-800 dark:bg-red-900/30 dark:text-red-300",
72
- warning: "bg-yellow-50 text-yellow-800 dark:bg-yellow-900/30 dark:text-yellow-300",
73
- info: "bg-blue-50 text-blue-800 dark:bg-blue-900/30 dark:text-blue-300"
74
- }, u = {
75
- success: "text-green-500 dark:text-green-400",
76
- error: "text-red-500 dark:text-red-400",
77
- warning: "text-yellow-500 dark:text-yellow-400",
78
- info: "text-blue-500 dark:text-blue-400"
69
+ const h = {
70
+ success: "bg-green-100 text-green-500",
71
+ error: "bg-rose-100 text-rose-500",
72
+ warning: "bg-yellow-100 text-yellow-500",
73
+ info: "bg-blue-100 text-blue-500"
79
74
  };
80
- function E() {
81
- return /* @__PURE__ */ t("svg", { className: "h-5 w-5", viewBox: "0 0 20 20", fill: "currentColor", children: /* @__PURE__ */ t(
82
- "path",
75
+ function M() {
76
+ return /* @__PURE__ */ t(
77
+ "svg",
83
78
  {
84
- fillRule: "evenodd",
85
- d: "M10 18a8 8 0 100-16 8 8 0 000 16zm3.857-9.809a.75.75 0 00-1.214-.882l-3.483 4.79-1.88-1.88a.75.75 0 10-1.06 1.061l2.5 2.5a.75.75 0 001.137-.089l4-5.5z",
86
- clipRule: "evenodd"
79
+ className: "size-5",
80
+ "aria-hidden": "true",
81
+ xmlns: "http://www.w3.org/2000/svg",
82
+ fill: "currentColor",
83
+ viewBox: "0 0 20 20",
84
+ children: /* @__PURE__ */ t("path", { d: "M10 .5a9.5 9.5 0 1 0 9.5 9.5A9.51 9.51 0 0 0 10 .5Zm3.707 8.207-4 4a1 1 0 0 1-1.414 0l-2-2a1 1 0 0 1 1.414-1.414L9 10.586l3.293-3.293a1 1 0 0 1 1.414 1.414Z" })
87
85
  }
88
- ) });
86
+ );
89
87
  }
90
- function T() {
91
- return /* @__PURE__ */ t("svg", { className: "h-5 w-5", viewBox: "0 0 20 20", fill: "currentColor", children: /* @__PURE__ */ t(
92
- "path",
88
+ function I() {
89
+ return /* @__PURE__ */ t(
90
+ "svg",
93
91
  {
94
- fillRule: "evenodd",
95
- d: "M10 18a8 8 0 100-16 8 8 0 000 16zM8.28 7.22a.75.75 0 00-1.06 1.06L8.94 10l-1.72 1.72a.75.75 0 101.06 1.06L10 11.06l1.72 1.72a.75.75 0 101.06-1.06L11.06 10l1.72-1.72a.75.75 0 00-1.06-1.06L10 8.94 8.28 7.22z",
96
- clipRule: "evenodd"
92
+ className: "size-5",
93
+ "aria-hidden": "true",
94
+ xmlns: "http://www.w3.org/2000/svg",
95
+ fill: "currentColor",
96
+ viewBox: "0 0 20 20",
97
+ children: /* @__PURE__ */ t("path", { d: "M10 .5a9.5 9.5 0 1 0 9.5 9.5A9.51 9.51 0 0 0 10 .5Zm3.707 11.793a1 1 0 1 1-1.414 1.414L10 11.414l-2.293 2.293a1 1 0 0 1-1.414-1.414L8.586 10 6.293 7.707a1 1 0 0 1 1.414-1.414L10 8.586l2.293-2.293a1 1 0 0 1 1.414 1.414L11.414 10l2.293 2.293Z" })
97
98
  }
98
- ) });
99
+ );
99
100
  }
100
- function I() {
101
- return /* @__PURE__ */ t("svg", { className: "h-5 w-5", viewBox: "0 0 20 20", fill: "currentColor", children: /* @__PURE__ */ t(
101
+ function D() {
102
+ return /* @__PURE__ */ t("svg", { className: "size-5", viewBox: "0 0 20 20", fill: "currentColor", children: /* @__PURE__ */ t(
102
103
  "path",
103
104
  {
104
105
  fillRule: "evenodd",
@@ -107,59 +108,97 @@ function I() {
107
108
  }
108
109
  ) });
109
110
  }
110
- function D() {
111
- return /* @__PURE__ */ t("svg", { className: "h-5 w-5", viewBox: "0 0 20 20", fill: "currentColor", children: /* @__PURE__ */ t(
112
- "path",
111
+ function $() {
112
+ return /* @__PURE__ */ t(
113
+ "svg",
113
114
  {
114
- fillRule: "evenodd",
115
- d: "M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a.75.75 0 000 1.5h.253a.25.25 0 01.244.304l-.459 2.066A1.75 1.75 0 0010.747 15H11a.75.75 0 000-1.5h-.253a.25.25 0 01-.244-.304l.459-2.066A1.75 1.75 0 009.253 9H9z",
116
- clipRule: "evenodd"
115
+ className: "size-5",
116
+ "aria-hidden": "true",
117
+ xmlns: "http://www.w3.org/2000/svg",
118
+ fill: "currentColor",
119
+ viewBox: "0 0 24 24",
120
+ children: /* @__PURE__ */ t("path", { fillRule: "evenodd", d: "M2.25 12c0-5.385 4.365-9.75 9.75-9.75s9.75 4.365 9.75 9.75-4.365 9.75-9.75 9.75S2.25 17.385 2.25 12zm8.706-1.442c1.146-.573 2.437.463 2.126 1.706l-.709 2.836.042-.02a.75.75 0 01.67 1.34l-.04.022c-1.147.573-2.438-.463-2.127-1.706l.71-2.836-.042.02a.75.75 0 11-.671-1.34l.041-.022zM12 9a.75.75 0 100-1.5.75.75 0 000 1.5z", clipRule: "evenodd" })
117
121
  }
118
- ) });
122
+ );
119
123
  }
120
- function $({ level: e }) {
124
+ function B({ level: e }) {
121
125
  switch (e) {
122
126
  case "success":
123
- return /* @__PURE__ */ t(E, {});
127
+ return /* @__PURE__ */ t(M, {});
124
128
  case "error":
125
- return /* @__PURE__ */ t(T, {});
126
- case "warning":
127
129
  return /* @__PURE__ */ t(I, {});
128
- default:
130
+ case "warning":
129
131
  return /* @__PURE__ */ t(D, {});
132
+ default:
133
+ return /* @__PURE__ */ t($, {});
130
134
  }
131
135
  }
132
- function B({ toast: e, config: i, onRemove: r }) {
133
- const s = v(null), o = e.duration ?? i.duration;
134
- return h(() => (o > 0 && (s.current = setTimeout(() => {
135
- r(e.id);
136
- }, o)), () => {
137
- s.current && clearTimeout(s.current);
138
- }), [o, e.id, r]), /* @__PURE__ */ t(
136
+ function V(e) {
137
+ return e.includes("right") ? "translate-x-full" : e.includes("left") ? "-translate-x-full" : e.startsWith("top") ? "-translate-y-full" : "translate-y-full";
138
+ }
139
+ function j({ toast: e, config: i, position: l, onRemove: a }) {
140
+ const n = w(null), [d, s] = R(!1), f = e.duration ?? i.duration, r = c(() => {
141
+ n.current && (clearTimeout(n.current), n.current = null), s(!1);
142
+ }, []);
143
+ g(() => {
144
+ const m = requestAnimationFrame(() => s(!0));
145
+ return () => cancelAnimationFrame(m);
146
+ }, []), g(() => (f > 0 && (n.current = setTimeout(r, f)), () => {
147
+ n.current && clearTimeout(n.current);
148
+ }), [f, r]);
149
+ const o = V(l), u = d ? "opacity-100 translate-x-0 translate-y-0 duration-300 ease-out" : `opacity-0 ${o} duration-200 ease-in`;
150
+ return /* @__PURE__ */ p(
139
151
  "div",
140
152
  {
141
- className: `pointer-events-auto w-full max-w-sm overflow-hidden rounded-lg shadow-lg ring-1 ring-black/5 ${p[e.level] ?? p.info}`,
153
+ className: `flex items-center rounded-lg bg-white p-4 text-gray-500 shadow min-w-96 transition ${u}`,
142
154
  role: "alert",
143
- children: /* @__PURE__ */ t("div", { className: "p-4", children: /* @__PURE__ */ m("div", { className: "flex items-start", children: [
144
- /* @__PURE__ */ t("div", { className: `shrink-0 ${u[e.level] ?? u.info}`, children: /* @__PURE__ */ t($, { level: e.level }) }),
145
- /* @__PURE__ */ t("div", { className: "ml-3 w-0 flex-1", children: /* @__PURE__ */ t("p", { className: "text-sm font-medium", children: e.message }) }),
146
- /* @__PURE__ */ t("div", { className: "ml-4 flex shrink-0", children: /* @__PURE__ */ m(
155
+ onTransitionEnd: () => {
156
+ d || a(e.id);
157
+ },
158
+ children: [
159
+ /* @__PURE__ */ t(
160
+ "div",
161
+ {
162
+ className: `inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg ${h[e.level] ?? h.info}`,
163
+ children: /* @__PURE__ */ t(B, { level: e.level })
164
+ }
165
+ ),
166
+ /* @__PURE__ */ t("div", { className: "ml-3 text-sm font-normal", children: e.message }),
167
+ /* @__PURE__ */ p(
147
168
  "button",
148
169
  {
149
170
  type: "button",
150
- className: `inline-flex rounded-md focus:outline-none focus:ring-2 focus:ring-offset-2 ${u[e.level] ?? u.info}`,
151
- onClick: () => r(e.id),
171
+ className: "ml-auto inline-flex items-center justify-center h-8 w-8 rounded-lg bg-white p-1.5 text-gray-400 hover:bg-gray-100 hover:text-gray-900 focus:ring-2 focus:ring-gray-300",
172
+ onClick: r,
173
+ "aria-label": "Close",
152
174
  children: [
153
175
  /* @__PURE__ */ t("span", { className: "sr-only", children: "Close" }),
154
- /* @__PURE__ */ t("svg", { className: "h-5 w-5", viewBox: "0 0 20 20", fill: "currentColor", children: /* @__PURE__ */ t("path", { d: "M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z" }) })
176
+ /* @__PURE__ */ t(
177
+ "svg",
178
+ {
179
+ "aria-hidden": "true",
180
+ className: "h-5 w-5",
181
+ fill: "currentColor",
182
+ viewBox: "0 0 20 20",
183
+ xmlns: "http://www.w3.org/2000/svg",
184
+ children: /* @__PURE__ */ t(
185
+ "path",
186
+ {
187
+ fillRule: "evenodd",
188
+ d: "M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z",
189
+ clipRule: "evenodd"
190
+ }
191
+ )
192
+ }
193
+ )
155
194
  ]
156
195
  }
157
- ) })
158
- ] }) })
196
+ )
197
+ ]
159
198
  }
160
199
  );
161
200
  }
162
- const g = {
201
+ const v = {
163
202
  "top-right": "top-4 right-4 items-end",
164
203
  "top-left": "top-4 left-4 items-start",
165
204
  "top-center": "top-4 left-1/2 -translate-x-1/2 items-center",
@@ -167,20 +206,20 @@ const g = {
167
206
  "bottom-left": "bottom-4 left-4 items-start",
168
207
  "bottom-center": "bottom-4 left-1/2 -translate-x-1/2 items-center"
169
208
  };
170
- function K() {
171
- const { items: e, config: i, remove: r } = A(), s = g[i.position] ?? g["top-right"];
209
+ function F() {
210
+ const { items: e, config: i, remove: l } = N(), a = v[i.position] ?? v["top-right"];
172
211
  return /* @__PURE__ */ t(
173
212
  "div",
174
213
  {
175
- className: `pointer-events-none fixed z-50 flex w-full max-w-sm flex-col gap-3 ${s}`,
214
+ className: `fixed z-50 flex w-full max-w-sm flex-col gap-3 ${a}`,
176
215
  "aria-live": "polite",
177
- children: e.map((o) => /* @__PURE__ */ t(B, { toast: o, config: i, onRemove: r }, o.id))
216
+ children: e.map((n) => /* @__PURE__ */ t(j, { toast: n, config: i, position: i.position, onRemove: l }, n.id))
178
217
  }
179
218
  );
180
219
  }
181
220
  export {
182
- B as ToastItem,
183
- j as ToastProvider,
184
- K as Toasts,
185
- A as useToast
221
+ j as ToastItem,
222
+ S as ToastProvider,
223
+ F as Toasts,
224
+ N as useToast
186
225
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@laravel-inertia-toast/react",
3
- "version": "0.1.1",
3
+ "version": "0.2.1",
4
4
  "description": "React toast components for Laravel Inertia Toast",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -15,14 +15,15 @@
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",
22
23
  "dev": "vite build --watch"
23
24
  },
24
25
  "peerDependencies": {
25
- "@inertiajs/react": "^1.0.0 || ^2.0.0",
26
+ "@inertiajs/react": "^2.3.3",
26
27
  "react": "^18.0.0 || ^19.0.0",
27
28
  "react-dom": "^18.0.0 || ^19.0.0"
28
29
  },