@agney/ir-toast
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -70,6 +70,8 @@ 'use strict'; | ||
return function (message) { | ||
return create({ | ||
var toast = create({ | ||
message: message, | ||
color: color | ||
}); | ||
toast.present(); | ||
return toast; | ||
}; | ||
@@ -76,0 +78,0 @@ }; |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,r=require("react"),t=(e=r)&&"object"==typeof e&&"default"in e?e.default:e,n=require("@ionic/react");function u(){return(u=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e}).apply(this,arguments)}var s=r.createContext(null),o=s.Provider;exports.ToastProvider=function(e){var s=e.value,i=e.children,a=r.useState(!1),c=a[0],l=a[1],f=r.useState(),v=f[0],d=f[1],p=r.useRef(null),g=r.useCallback((function(e){return l(!0),{present:function(e){return function(){d(u({},s,{},e))}}(e),dismiss:function(){var e;null===(e=p.current)||void 0===e||e.dismiss()}}}),[s]),m=r.useMemo((function(){var e=function(e){return function(r){return g({message:r,color:e})}};return{create:g,success:e("success"),error:e("danger"),warning:e("warning")}}),[g]);return t.createElement(o,{value:m},i,t.createElement(n.IonToast,Object.assign({ref:p,isOpen:c,onDidDismiss:function(){return l(!1)}},v)))},exports.useToast=function(){return r.useContext(s)}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,r=require("react"),t=(e=r)&&"object"==typeof e&&"default"in e?e.default:e,n=require("@ionic/react");function u(){return(u=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e}).apply(this,arguments)}var s=r.createContext(null),o=s.Provider;exports.ToastProvider=function(e){var s=e.value,i=e.children,a=r.useState(!1),c=a[0],l=a[1],f=r.useState(),v=f[0],p=f[1],d=r.useRef(null),g=r.useCallback((function(e){return l(!0),{present:function(e){return function(){p(u({},s,{},e))}}(e),dismiss:function(){var e;null===(e=d.current)||void 0===e||e.dismiss()}}}),[s]),m=r.useMemo((function(){var e=function(e){return function(r){var t=g({message:r,color:e});return t.present(),t}};return{create:g,success:e("success"),error:e("danger"),warning:e("warning")}}),[g]);return t.createElement(o,{value:m},i,t.createElement(n.IonToast,Object.assign({ref:d,isOpen:c,onDidDismiss:function(){return l(!1)}},v)))},exports.useToast=function(){return r.useContext(s)}; | ||
//# sourceMappingURL=ir-toast.cjs.production.min.js.map |
@@ -63,6 +63,8 @@ import React, { useContext, useState, useRef, useCallback, useMemo, createContext } from 'react'; | ||
return function (message) { | ||
return create({ | ||
var toast = create({ | ||
message: message, | ||
color: color | ||
}); | ||
toast.present(); | ||
return toast; | ||
}; | ||
@@ -69,0 +71,0 @@ }; |
@@ -5,3 +5,3 @@ { | ||
"author": "Agney Menon <agney@outlook.in>", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"license": "MIT", | ||
@@ -8,0 +8,0 @@ "main": "dist/index.js", |
<h1 align=left>Ionic React Imperative Toast 🥂</h1> | ||
<p> | ||
<a href="https://www.npmjs.com/package/@agney/react-avatar" target="_blank"> | ||
<a href="https://www.npmjs.com/package/@agney/ir-toast" target="_blank"> | ||
<img alt="npm" src="https://img.shields.io/npm/v/@agney/ir-toast"> | ||
@@ -11,3 +11,3 @@ </a> | ||
<a href="https://github.com/agneym/ir-toast/blob/master/LICENSE" target="_blank"> | ||
<img alt="License: MIT" src="https://img.shields.io/github/license/agneym/react-avatar" /> | ||
<img alt="License: MIT" src="https://img.shields.io/github/license/agneym/ir-toast" /> | ||
</a> | ||
@@ -36,4 +36,4 @@ <a href="https://www.npmjs.com/package/@agney/ir-toast" target="_blank"> | ||
<ToastProvider> | ||
// ...rest of your application | ||
<ToastProvider> | ||
// ...rest of your application | ||
</ToastProvider> | ||
</IonApp> | ||
@@ -67,2 +67,85 @@ } | ||
``` | ||
Requires react 16.8 or higher and @ionic/react 5 or higher. | ||
Requires react 16.8 or higher and @ionic/react 5 or higher. | ||
## Properties | ||
### `ToastProvider` | ||
The `useToast` requires the app to be wrapped with a `ToastProvider`. The Provider can also take a `value` as prop which serves as defaults for all toasts created under it. | ||
```typescript | ||
const App: FC = () => { | ||
<IonApp> | ||
<ToastProvider value={{ color: 'primary', duration: 2000 }}> | ||
// ...rest of your application | ||
<ToastProvider> | ||
</IonApp> | ||
} | ||
``` | ||
Supports all properties in [docs](https://ionicframework.com/docs/api/toast#properties). | ||
### `useToast` | ||
Hook to be used in functional components. | ||
```typescript | ||
function Component: FC = () => { | ||
const Toast = useToast(); | ||
const handleClick = () => { | ||
const toast = Toast.create({ message: 'thing' }); | ||
toast.present(); | ||
// When you want to. | ||
toast.dismiss(); | ||
... | ||
} | ||
// ... | ||
} | ||
``` | ||
`Toast` returned from `useToast` supports: | ||
1. `create` | ||
A toast instance is created, takes all the props in [docs](https://ionicframework.com/docs/api/toast#properties) as argument. Returns a toast instance that can be presented by calling `present` and dismissed calling `dismiss` on it. | ||
2. Utility functions: `success`, `warning`, `error` | ||
Takes one argument: message as string. Does not require `present` to be called, directly shows the toast. | ||
```typescript | ||
const toast = toast.success("Success message"); | ||
``` | ||
## 🤝 Contributing | ||
Contributions, issues and feature requests are welcome!<br />Feel free to check [issues page](https://github.com/agneym/ir-toast/issues). | ||
### Development | ||
We use [`yarn` v1](https://classic.yarnpkg.com/) for development. | ||
```sh | ||
yarn | ||
yarn start | ||
``` | ||
### Run tests | ||
```sh | ||
yarn test | ||
``` | ||
## Show your support | ||
Give a ⭐️ if this project helped you! | ||
<a href="https://twitter.com/agneymenon" target="_blank"> | ||
<img alt="Twitter: agneymenon" src="https://img.shields.io/twitter/follow/agneymenon.svg?style=social" /> | ||
</a> | ||
## 📝 License | ||
Copyright © 2020 [Agney Menon <agney@outlook.in>](https://github.com/agneym).<br /> | ||
This project is [MIT](https://github.com/agneym/ir-toast/blob/master/LICENSE) licensed. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
27974
273
148