Skip to content

Commit 9d2ce4f

Browse files
author
Aryan Deora
committed
Releasing v0.5.0
1 parent 5d4849d commit 9d2ce4f

2 files changed

Lines changed: 46 additions & 24 deletions

File tree

README.md

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
<div align="center">
44
<img src="https://badgen.net/npm/v/solid-toast" alt="NPM Version" />
5-
<a href="https://bundlejs.com/?q=skypack%3Asolid-toast&treeshake=%5B%7B+Toaster%2Ctoast+%7D%5D&config=%7B%22analysis%22%3Atrue%2C%22esbuild%22%3A%7B%22external%22%3A%5B%22solid-js%22%5D%7D%7D">
6-
<img src="https://img.shields.io/badge/Bundle%20Size-3.82kb-brightgreen" alt="minzipped size"/>
5+
<a href="https://bundlephobia.com/package/solid-toast">
6+
<img src="https://img.shields.io/badge/Bundle%20Size-4kb-brightgreen" alt="minzipped size"/>
77
</a>
88
<img src="https://github.com/ardeora/solid-toast/workflows/build/badge.svg" alt="Build Status" />
99
</a>
@@ -21,7 +21,7 @@
2121

2222
- **Easily Customizable**
2323
- **Promise API**
24-
- **Lightweight**
24+
- **Lightweight**
2525
- **Accessible**
2626
- **SSR Support**
2727

@@ -61,13 +61,14 @@ const App = () => {
6161
## Documentation
6262

6363
### `toast()` Function
64+
6465
Call this function from anywhere to create a toast.
6566

6667
#### Available Options
68+
6769
You can provide `ToastOptions` as the second argument. They will overwrite all options received from the `<Toaster/>` component.
6870

6971
```js
70-
7172
toast('This is a simple toast!', {
7273
duration: 5000,
7374
position: 'top-right',
@@ -92,38 +93,49 @@ toast('This is a simple toast!', {
9293
role: 'status',
9394
'aria-live': 'polite',
9495
},
95-
})
96+
});
9697
```
9798

9899
#### Creating Toasts
100+
99101
There are several options for creating toasts
100102

101103
##### Blank
104+
102105
```js
103-
toast('This is a blank toast!')
106+
toast('This is a blank toast!');
104107
```
108+
105109
Blank toasts do not come with a default icon. However, you can set a custom JSX Element/Text (Emoji) icon by placing it in the `icon` option.
106110

107111
##### Success
112+
108113
```js
109114
toast.success('Successfully saved!');
110115
```
116+
111117
Creates a notification with an animated checkmark. Color accents can be themed with the `iconTheme` option.
112118

113119
##### Error
120+
114121
```js
115122
toast.error('Something went wrong!');
116123
```
124+
117125
Creates a notification with an animated error icon. Color accents can be themed with the `iconTheme` option.
118126

119127
##### Loading
128+
120129
```js
121130
toast.loading('Loading Photos...');
122131
```
132+
123133
Shows a toast with a loading indicator icon. The content can later be updated with an error or success icon. See how to update the toast content [here](#updating-toasts).
124134

125135
##### Promise
136+
126137
The `promise()` function can be used to create a toast from a promise. This function will automatically show a loading icon and update the toast with the result of the promise.
138+
127139
```jsx
128140
const myPromise = fetchData();
129141

@@ -135,6 +147,7 @@ toast.promise(myPromise, {
135147
```
136148

137149
##### Custom Toast
150+
138151
You also have the ability to completely customize the appearance of your toast.
139152
A custom JSX Element can be passed in like so:
140153

@@ -148,55 +161,61 @@ toast.custom(() => (
148161
```
149162

150163
###### Advanced Option
164+
151165
You can also hook into the toast life-cycle by adding a parameter to the JSX Function call like so:
152166

153167
```jsx
154-
toast.custom((t) => {
155-
<div>
156-
<h1>Custom Toast</h1>
157-
<p>This is a custom toast!</p>
158-
<p>{t.visible ? 'Showing' : 'I will close in 1 second'}</p>
159-
<button
160-
onClick={() => toast.dismiss(t.id)}
161-
>
162-
Close Toast
163-
</button>
164-
</div>
165-
}, {
166-
unmoutDelay: 1000,
167-
})
168+
toast.custom(
169+
(t) => {
170+
<div>
171+
<h1>Custom Toast</h1>
172+
<p>This is a custom toast!</p>
173+
<p>{t.visible ? 'Showing' : 'I will close in 1 second'}</p>
174+
<button onClick={() => toast.dismiss(t.id)}>Close Toast</button>
175+
</div>;
176+
},
177+
{
178+
unmoutDelay: 1000,
179+
}
180+
);
168181
```
169182

170-
171183
#### Helpful Utilities
172184

173185
##### Dismiss Toasts Programatically
186+
174187
You can manually dismiss a notification with `toast.dismiss`. Beware that it triggers the exit animation and does not remove the Toast instantly. Toasts will auto-remove after 500ms by default. You can adjust the dismiss duration with the `unmountDelay` option.
175188

176189
###### Dismiss Single Toast
190+
177191
```js
178192
const toastId = toast.loading('Loading...');
179193
// ...
180194
toast.dismiss(toastId);
181195
```
196+
182197
Dismiss all toasts by omitting all arguments.
183198

184199
###### Dismiss All Toasts
200+
185201
```js
186202
toast.dismiss();
187203
```
188204

189205
##### Remove Toasts Instantly
206+
190207
Toasts can be removed instantly with toast.remove. This will not trigger the exit animation and remove the toast instantly.
208+
191209
```js
192210
toast.remove(toastId);
193211
// or
194212
toast.remove();
195213
```
196214

197-
198215
##### Updating Toasts
216+
199217
Each toast call returns a unique id. Use this `id` in the toast options to update an existing toast.
218+
200219
```js
201220
const toastId = toast.loading('Loading...');
202221
// ...
@@ -206,6 +225,7 @@ toast.success('This worked', {
206225
```
207226

208227
### `Toaster` Component
228+
209229
This component will render all toasts.
210230

211231
#### Available Options
@@ -230,5 +250,7 @@ This component will render all toasts.
230250
```
231251

232252
## Acknowledgements
233-
This project is inspired by
253+
254+
This project is inspired by
255+
234256
- [React Hot Toast](https://github.com/timolins/react-hot-toast)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "solid-toast",
3-
"version": "0.4.0",
3+
"version": "0.5.0",
44
"description": "Customizable Toast Notifications for SolidJS",
55
"main": "dist/cjs/index.js",
66
"module": "dist/esm/index.js",

0 commit comments

Comments
 (0)