Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/huseyincorakli/custom-toastfy-service-for-react
https://github.com/huseyincorakli/custom-toastfy-service-for-react
Last synced: 8 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/huseyincorakli/custom-toastfy-service-for-react
- Owner: huseyincorakli
- Created: 2023-08-27T05:48:59.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-08-27T05:59:04.000Z (over 1 year ago)
- Last Synced: 2024-04-08T17:12:49.863Z (10 months ago)
- Language: TypeScript
- Size: 50.8 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## main.tsx
```jsx
import ReactDOM from 'react-dom/client'
import App from './App.tsx'
import { ToastifyServiceContainer } from './services/CustomToastfyService.tsx'
import 'react-toastify/dist/ReactToastify.css'
ReactDOM.createRoot(document.getElementById('root')!).render(
<>
>
)
```
## App.tsx
```jsx
import {
ToastifyMessageType,
ToastifyPosition,
ToastifyService
} from './services/CustomToastfyService'
function App () {
const notify = () => {
ToastifyService.notfy('Custom Toastify Service', ToastifyMessageType.Info, {
position: ToastifyPosition.TopCenter
})
}
return (
<>
notify
>
)
}
export default App
```
## Custom Toastr Service
```jsx
import { toast, ToastContainer } from 'react-toastify'export const ToastifyService = {
notfy (
message: string,
type: ToastifyMessageType,
options: Partial
) {
const isHide = options.hide == 1 ? true : false
toast[type](message, {
autoClose: options.timeoutDuration,
hideProgressBar: isHide,
position: options.position
})
}
}export const ToastifyServiceContainer = () => {
return
}
export enum ToastifyPosition {
TopLeft = 'top-left',
TopRight = 'top-right',
TopCenter = 'top-center',
BottomLeft = 'bottom-left',
BottomRight = 'bottom-right',
BottomCenter = 'bottom-center'
}
export enum ToastifyMessageType {
Success = 'success',
Warning = 'warning',
Info = 'info'
}export enum ToastifyTimeoutDuration {
Fast = 2000,
Slow = 5000,
Moderate = 3000
}export enum Hide {
True = 1,
False = 0
}export class CTS_Options {
timeoutDuration?: ToastifyTimeoutDuration = ToastifyTimeoutDuration.Fast
hide?: Hide = Hide.False
position?: ToastifyPosition = ToastifyPosition.TopRight
}
```