-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore(readme): add readme * chore(readme): toast config improvements * fix(readme): import useToast
- Loading branch information
Showing
2 changed files
with
112 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2023 Platform Builders | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,94 @@ | ||
![check](https://github.com/platformbuilders/template-hooks/workflows/check/badge.svg) | ||
![check](https://github.com/platformbuilders/react-native-toast/actions/workflows/check.yml/badge.svg) | ||
[![MIT][license-badge]][license] | ||
|
||
# @platformbuilders/use-hooks | ||
[license-badge]: https://img.shields.io/dub/l/vibe-d.svg | ||
[license]: https://raw.githubusercontent.com/platformbuilders/react-native-toast/master/LICENSE.md | ||
|
||
## Hooks Template | ||
# @platformbuilders/react-native-toast | ||
|
||
É só renomear o pacote, criar seu hooks e publicar para ser feliz 🙌 | ||
## Install | ||
|
||
``` | ||
yarn add @platformbuilders/react-native-toast | ||
``` | ||
|
||
## Usage | ||
|
||
### Configure Provider | ||
|
||
```typescript | ||
import { ToastProvider } from '@platformbuilders/react-native-toast'; | ||
import { iconSuccess, iconWarning, iconError, iconCustom } from '~/assets/images'; | ||
|
||
const Provider: FC<PropsWithChildren> = ({ children }) => { | ||
const { ui } = useStores(); | ||
|
||
const toastConfig = { | ||
backgroundColor: { | ||
success: ui?.theme?.success.main as unknown as string, | ||
info: ui?.theme?.info.main as unknown as string, | ||
warning: ui?.theme?.warning.main as unknown as string, | ||
danger: ui?.theme?.danger.main as unknown as string, | ||
}, | ||
icon?: { | ||
success?: { | ||
icon?: iconSuccess, | ||
height?: 24, | ||
width?: 24, | ||
}, | ||
warning?: { | ||
icon?: iconWarning, | ||
height?: 24, | ||
width?: 24, | ||
}, | ||
error?: { | ||
icon?: iconError, | ||
height?: 24, | ||
width?: 24, | ||
}, | ||
custom?: { | ||
icon?: iconCustom, | ||
height?: 24, | ||
width?: 24, | ||
}, | ||
}, | ||
autoHide: { | ||
custom: false, | ||
}, | ||
showCloseButton: { | ||
custom: true, | ||
}, | ||
showIcon: true, | ||
}; | ||
|
||
return (<ToastProvider config={toastConfig}>{children}<ToastProvider>); | ||
}; | ||
``` | ||
|
||
### Usage with Hook useToast | ||
|
||
```typescript | ||
import { useEffect } from 'react'; | ||
import { useToast } from '@platformbuilders/react-native-toast'; | ||
|
||
const FunctionalComponent = () => { | ||
const { showSuccess } = useToast(); | ||
|
||
useEffect(() => { | ||
showSuccess('Example message', 'Example Title', duration: 4000); | ||
}, []); | ||
|
||
return null; | ||
}; | ||
``` | ||
|
||
### Outside Functional Component | ||
|
||
```typescript | ||
import { showSuccess } from '@platformbuilders/react-native-toast'; | ||
import { ERRORS } from '~/utils'; | ||
|
||
export const onExpiredToken = (): void => { | ||
showError(ERRORS.SESSION_EXPIRED); | ||
}; | ||
``` |