-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d9fd44b
commit d5223c7
Showing
3 changed files
with
71 additions
and
55 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 |
---|---|---|
@@ -1,45 +1,45 @@ | ||
import React from 'react' | ||
import React, {useRef, useEffect} from 'react' | ||
import '../css/navbar.css' | ||
import {Toast} from 'bootstrap/dist/js/bootstrap' | ||
|
||
class Toaster extends React.Component | ||
{ | ||
constructor(){ | ||
super() | ||
this.toast = React.createRef(); | ||
} | ||
|
||
componentDidMount() | ||
{ | ||
let toastComponent = new Toast(this.toast.current, {autohide: false}) | ||
export default function Toaster(props){ | ||
const toast = useRef(); | ||
useEffect(()=>{ | ||
// Initialize toaster with autohide as false to prevent auto clearing for toaster message | ||
let toastComponent = new Toast( | ||
toast.current, { | ||
autohide: false | ||
}) | ||
toastComponent.show() | ||
}) | ||
|
||
const clearToastMessage = () =>{ | ||
// Clear toaster meessage | ||
props.setMessage('') | ||
} | ||
|
||
render(){ | ||
return( | ||
<div className='toast-container'> | ||
<div | ||
className= {'toast align-items-center text-white border-0'} | ||
role='alert' | ||
aria-live='assertive' | ||
aria-atomic='true' | ||
ref={this.toast} | ||
> | ||
<div className ={'d-flex'}> | ||
<div className={'toast-body'}> | ||
Hello, world! This is a toast message. | ||
</div> | ||
<button | ||
type='button' | ||
class={'btn-close btn-close-white me-2 m-auto'} | ||
data-bs-dismiss='toast' | ||
aria-label='Close' | ||
> | ||
</button> | ||
return( | ||
<div className='toast-container'> | ||
<div | ||
className= {'toast align-items-center text-white border-0'} | ||
role='alert' | ||
aria-live='assertive' | ||
aria-atomic='true' | ||
ref={toast} | ||
> | ||
<div className ={'d-flex'}> | ||
<div className={'toast-body'}> | ||
{props.message} | ||
</div> | ||
<button | ||
type='button' | ||
class={'btn-close btn-close-white me-2 m-auto'} | ||
aria-label='Close' | ||
onClick={clearToastMessage} | ||
> | ||
</button> | ||
</div> | ||
</div> | ||
) | ||
} | ||
</div> | ||
) | ||
} | ||
export default Toaster |
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
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