Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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
}
```