Skip to content

Commit 95369a9

Browse files
authored
Merge pull request #30 from sudhucodes/dev
Add pause on hover for toasts and update package details
2 parents e9da11a + 87df7a7 commit 95369a9

22 files changed

Lines changed: 348 additions & 35 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Fast, flexible, developer-friendly React toast notifications with a clean black
1414
- **Tailwind Driven**: Styled with Tailwind CSS for modern aesthetics.
1515
- **Performance**: Built with tsup for high performance and small bundle size.
1616
- **Customizable**: Easily customize duration, type, and icons.
17+
- **Readable by Default**: Auto-closing toasts pause while hovered.
1718
- **Promise Support**: First-class support for `toast.promise`.
1819

1920
## Installation
@@ -60,6 +61,9 @@ toast.error('An error occurred. Please try again.');
6061
toast.warning('Check your internet connection.');
6162
toast.loading('Saving results...');
6263

64+
// Hover pauses auto close by default
65+
toast('Hover me if you need more time to read', { duration: 5000 });
66+
6367
// Promise toast
6468
toast.promise(saveData(), {
6569
loading: 'Saving...',

apps/docs/CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# docs
22

3+
## 0.2.0
4+
5+
### Minor Changes
6+
7+
- a54010e: feat: add pause on hover functionality for auto-closing toasts and update documentation
8+
9+
### Patch Changes
10+
11+
- Updated dependencies [a54010e]
12+
- react-toast-msg@2.9.0
13+
314
## 0.1.2
415

516
### Patch Changes

apps/docs/app/page.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export default function Page() {
1010
const [ToastContainerConfig, setToastContainerConfig] = useState({
1111
autoClose: 5000,
1212
closeButton: true,
13+
pauseOnHover: true,
1314
});
1415
const [copy, setCopy] = useState<boolean>(false);
1516
const messages = {
@@ -78,6 +79,10 @@ export default function Page() {
7879
</a>{' '}
7980
library, designed to display customizable notification messages.
8081
</p>
82+
<p className="max-w-xl text-center text-sm text-slate-500">
83+
Auto-closing toasts pause while hovered by default. Toggle it below to compare
84+
the behavior.
85+
</p>
8186

8287
<h3 className="mt-8 text-2xl font-bold">Toast Configuration</h3>
8388

@@ -114,6 +119,23 @@ export default function Page() {
114119
<option value="false">False</option>
115120
</select>
116121
</div>
122+
<div className='flex flex-col gap-2'>
123+
<label htmlFor="pauseOnHover">Pause On Hover</label>
124+
<select
125+
id="pauseOnHover"
126+
value={ToastContainerConfig.pauseOnHover ? 'true' : 'false'}
127+
onChange={(e) =>
128+
setToastContainerConfig({
129+
...ToastContainerConfig,
130+
pauseOnHover: e.target.value === 'true',
131+
})
132+
}
133+
className='border border-gray-200 rounded-md px-2 py-1'
134+
>
135+
<option value="true">True</option>
136+
<option value="false">False</option>
137+
</select>
138+
</div>
117139
</div>
118140

119141
<div className="flex flex-wrap items-center justify-center gap-4">
@@ -147,6 +169,12 @@ export default function Page() {
147169
>
148170
Promise (Loader)
149171
</button>
172+
<button
173+
onClick={() => toast('Hover this toast to pause the timer', { duration: 5000 })}
174+
className="rounded-md border border-gray-200 bg-gray-50 px-5 py-2 text-sm hover:bg-gray-200/80 active:scale-95 transition-all duration-300 font-medium text-gray-600"
175+
>
176+
Hover Pause Demo
177+
</button>
150178
<button
151179
onClick={() => toast.error("Critical server error! Please review.", {
152180
autoClose: false

apps/docs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "docs",
3-
"version": "0.1.2",
3+
"version": "0.2.0",
44
"private": true,
55
"scripts": {
66
"dev": "next dev",

apps/test-app/CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# test-app
22

3+
## 0.1.0
4+
5+
### Minor Changes
6+
7+
- a54010e: feat: add pause on hover functionality for auto-closing toasts and update documentation
8+
9+
### Patch Changes
10+
11+
- Updated dependencies [a54010e]
12+
- react-toast-msg@2.9.0
13+
314
## 0.0.2
415

516
### Patch Changes

apps/test-app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "test-app",
33
"private": true,
4-
"version": "0.0.2",
4+
"version": "0.1.0",
55
"type": "module",
66
"scripts": {
77
"dev": "vite",

apps/test-app/src/App.tsx

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@ export default function App() {
44
const btn = "px-4 py-2 rounded-md bg-gray-50 border border-gray-200 hover:bg-gray-100 transition";
55

66
return (
7-
<div className="min-h-screen flex flex-col items-center justify-center gap-6 bg-white">
8-
<ToastContainer autoClose={3000} closeButton />
7+
<div className="min-h-screen flex flex-col items-center justify-center gap-6 bg-white px-4 py-10">
8+
<ToastContainer autoClose={3000} closeButton pauseOnHover />
99

1010
<h1 className="text-3xl font-semibold">React Toast Msg Demo</h1>
11+
<p className="max-w-2xl text-center text-sm text-zinc-500">
12+
Toast timers now pause while you hover them. Use the examples below to try the
13+
default behavior and the per-toast opt-out.
14+
</p>
1115

1216
<div className="flex flex-wrap items-center justify-center gap-4">
1317
<div className="flex flex-col gap-2 w-64 p-5 rounded-lg bg-zinc-50">
@@ -36,6 +40,17 @@ export default function App() {
3640
<button onClick={() => toast.loading("Loading something...")} className={btn}>
3741
Loading Toast
3842
</button>
43+
44+
<button
45+
onClick={() =>
46+
toast("Hover me to pause auto close", {
47+
duration: 5000,
48+
})
49+
}
50+
className={btn}
51+
>
52+
Hover Pauses Timer
53+
</button>
3954
</div>
4055

4156
<div className="flex flex-col gap-2 w-64 p-5 rounded-lg bg-zinc-50">
@@ -79,8 +94,20 @@ export default function App() {
7994
>
8095
Auto Close False
8196
</button>
97+
98+
<button
99+
onClick={() =>
100+
toast("This keeps counting even while hovered", {
101+
duration: 5000,
102+
pauseOnHover: false,
103+
})
104+
}
105+
className={btn}
106+
>
107+
Disable Hover Pause
108+
</button>
82109
</div>
83110
</div>
84111
</div>
85112
);
86-
}
113+
}

content/docs/05-usage/02-advanced.mdx

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,25 @@ If you have an important message that requires the user's explicit attention, yo
2525
toast.error('Critical server error!', { autoClose: false });
2626
```
2727

28+
## Pause On Hover
29+
30+
Auto-closing toasts pause their timer while hovered by default, which gives users time to read longer messages without changing your API calls.
31+
32+
```tsx copy
33+
toast.success('Hover this toast to pause the countdown', {
34+
duration: 5000
35+
});
36+
```
37+
38+
If you want a toast to keep closing on schedule even while hovered, disable it per toast or on the container.
39+
40+
```tsx copy
41+
toast('This toast will keep counting down', {
42+
duration: 5000,
43+
pauseOnHover: false
44+
});
45+
```
46+
2847
## Manual Close Button
2948

3049
You can enable or disable the close button globally in `ToastContainer` or per-toast via the `toast` methods.
@@ -41,11 +60,12 @@ toast.error('Critical error!', { duration: 5000, closeButton: true });
4160
The `ToastContainer` accepts props that apply to all toasts.
4261

4362
```tsx copy
44-
<ToastContainer autoClose={5000} closeButton={true} />
63+
<ToastContainer autoClose={5000} closeButton={true} pauseOnHover={true} />
4564
```
4665

4766
- `autoClose`: Default duration for all toasts in milliseconds. Pass `false` to disable auto-closing globally.
4867
- `closeButton`: Whether to show a close button by default.
68+
- `pauseOnHover`: Pauses the auto-close timer while a user hovers a toast. Defaults to `true`.
4969

5070
## Promises
5171

content/docs/apis/03-container.mdx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ The `ToastContainer` component is the host for all your toast notifications. It
99

1010
The `ToastContainer` component accepts the following props:
1111

12-
| Props | Type | Default | Description |
13-
| :---------- | :------ | :------ | :-------------------------------------------------------------------------- |
14-
| autoClose | number | 3000 | Global default duration for auto-closing toasts. Set to `false` to disable. |
15-
| closeButton | boolean | false | Whether to show a close button on all toasts by default. |
12+
| Props | Type | Default | Description |
13+
| :----------- | :--------------- | :------ | :-------------------------------------------------------------------------- |
14+
| autoClose | number \| boolean | 3000 | Global default duration for auto-closing toasts. Set to `false` to disable. |
15+
| closeButton | boolean | false | Whether to show a close button on all toasts by default. |
16+
| pauseOnHover | boolean | true | Pauses the auto-close timer while a user hovers a toast. |
1617

1718
## Usage
1819

@@ -23,7 +24,7 @@ function Layout({ children }) {
2324
return (
2425
<>
2526
{children}
26-
<ToastContainer autoClose={5000} closeButton />
27+
<ToastContainer autoClose={5000} closeButton pauseOnHover />
2728
</>
2829
);
2930
}

content/docs/apis/04-types.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Used when triggering a toast (internally or via future API extensions).
2121
| duration | number | 3000 | Time in ms before auto-close. |
2222
| closeButton | boolean | false | Whether to show a close button on all toasts by default. |
2323
| autoClose | boolean | number | - | Disable auto-closing (false) or specify custom duration. |
24+
| pauseOnHover | boolean | true | Pause the auto-close timer while the toast is hovered. |
2425

2526

2627
## ToastContainerProps
@@ -31,6 +32,7 @@ Props accepted by the `ToastContainer` component.
3132
| :--- | :--- | :--- | :--- |
3233
| autoClose | number | boolean | 3000 | Global default duration for auto-closing toasts. Set to `false` to disable. |
3334
| closeButton | boolean | false | Whether to show a close button on all toasts by default. |
35+
| pauseOnHover | boolean | true | Pause the auto-close timer while any hovered toast remains visible. |
3436

3537

3638
## ShowToastFn
@@ -41,4 +43,4 @@ The signature for the `toast` function.
4143
| :--- | :--- | :--- | :--- |
4244
| message | string | - | The message to display. |
4345
| type | ToastType | 'default' | The style of the toast. |
44-
| duration | number | 3000 | Time in ms before auto-close. |
46+
| duration | number | 3000 | Time in ms before auto-close. |

0 commit comments

Comments
 (0)