Commit 3d37ab32 authored by ioedeveloper's avatar ioedeveloper

Set timeout

parent 46af2510
...@@ -5,7 +5,7 @@ import './toaster.css' ...@@ -5,7 +5,7 @@ import './toaster.css'
/* eslint-disable-next-line */ /* eslint-disable-next-line */
export interface ToasterProps { export interface ToasterProps {
message: any message: any
opts?: ToasterOptions timeOut?: number
} }
export interface ToasterOptions { export interface ToasterOptions {
...@@ -14,40 +14,33 @@ export interface ToasterOptions { ...@@ -14,40 +14,33 @@ export interface ToasterOptions {
export const Toaster = (props: ToasterProps) => { export const Toaster = (props: ToasterProps) => {
const [state, setState] = useState({ const [state, setState] = useState({
timeOutId: null,
message: '', message: '',
hiding: false hide: false,
timeOutId: null,
timeOut: props.timeOut || 700
}) })
const opts = defaultOptions(props.opts)
useEffect(() => { useEffect(() => {
let timeOutId = null
if (props.message) { if (props.message) {
timeOutId = setTimeout(() => { const timeOutId = setTimeout(() => {
setState(prevState => { setState(prevState => {
return { return { ...prevState, hide: true }
...prevState,
hiding: true
}
}) })
}, opts.time) }, state.timeOut)
}
setState(prevState => { console.log('timeOutId: ', timeOutId)
return { setState(prevState => {
...prevState, return { ...prevState, hide: false, timeOutId, message: props.message }
message: props.message, })
hiding: false, }
timeOutId
}
})
}, [props.message]) }, [props.message])
const shortTooltipText = state.message.length > 201 ? state.message.substring(0, 200) + '...' : state.message const shortTooltipText = state.message.length > 201 ? state.message.substring(0, 200) + '...' : state.message
function hide () { function hide () {
if (state.timeOutId) clearTimeout(state.timeOutId) if (!state.hide) {
clearTimeout(state.timeOutId)
}
} }
function showFullMessage () { function showFullMessage () {
...@@ -59,7 +52,7 @@ export const Toaster = (props: ToasterProps) => { ...@@ -59,7 +52,7 @@ export const Toaster = (props: ToasterProps) => {
} }
// out() // out()
const animate = state.timeOutId ? (state.hiding ? 'remixui_animateBottom' : 'remixui_animateTop') : '' const animate = state.timeOutId ? (state.hide ? 'remixui_animateBottom' : 'remixui_animateTop') : ''
// const hide = state.timeOutId // const hide = state.timeOutId
const className = `remixui_tooltip alert alert-info p-2 ${animate}` const className = `remixui_tooltip alert alert-info p-2 ${animate}`
return ( return (
...@@ -78,13 +71,6 @@ export const Toaster = (props: ToasterProps) => { ...@@ -78,13 +71,6 @@ export const Toaster = (props: ToasterProps) => {
export default Toaster export default Toaster
const defaultOptions = (opts) : ToasterOptions => {
opts = opts || {}
return {
time: opts.time || 7000
}
}
/* /*
const animation = (tooltip, anim) => { const animation = (tooltip, anim) => {
tooltip.classList.remove(css.animateTop.className) tooltip.classList.remove(css.animateTop.className)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment