Skip to content

Commit

Permalink
fix alert
Browse files Browse the repository at this point in the history
  • Loading branch information
elevatebart committed Aug 24, 2023
1 parent f75a726 commit 0d90ea9
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions components/Alert/react/Alert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,37 +107,34 @@ export const Alert: React.FC<
: undefined)

const [dismissed, setDismissed] = React.useState(false)
const [durationTimeout, setDurationTimeout] = React.useState<
number | undefined
>(undefined)
const durationTimeout = React.useRef<number | undefined>(undefined)

function clearDurationTimeout() {
const clearDurationTimeout = React.useCallback(() => {
if (durationTimeout) {
clearTimeout(durationTimeout)
setDurationTimeout(undefined)
clearTimeout(durationTimeout.current)
durationTimeout.current = undefined
}
}
}, [])

function dismiss() {
const dismiss = React.useCallback(() => {
setDismissed(true)
onDismiss && onDismiss()
clearDurationTimeout()
}
}, [clearDurationTimeout, setDismissed, onDismiss])

React.useEffect(() => {
if (onDismiss && duration && !durationTimeout) {
setDismissed(false)
if (duration && !durationTimeout.current) {
const timeout = setTimeout(dismiss, duration) as unknown as number
setDurationTimeout(timeout)
durationTimeout.current = timeout
}
return clearDurationTimeout
}, [])
})

React.useEffect(() => {
if (detailsRef.current && contentRef.current) {
new DetailsAnimation(detailsRef.current, contentRef.current)
}
}, [])
})

const detailsRef = React.useRef(null)
const contentRef = React.useRef(null)
Expand All @@ -150,15 +147,15 @@ export const Alert: React.FC<
!notRounded && 'rounded',
'overflow-hidden text-left',
className,
variantClasses.wrapperClass
variantClasses.wrapperClass,
)}
{...rest}
>
<div
className={clsx(
variantClasses.headerClass,
'flex p-[16px]',
sizeClasses
sizeClasses,
)}
>
{!noIcon && Icon && (
Expand Down Expand Up @@ -190,14 +187,14 @@ export const Alert: React.FC<
className={clsx(
'p-[16px] border-t border-t-1 cursor-pointer',
variantClasses.bodyClass,
variantClasses.borderClass
variantClasses.borderClass,
)}
ref={detailsRef}
>
<summary
className={clsx(
'flex font-medium details-none',
variantClasses.detailsHeaderClass
variantClasses.detailsHeaderClass,
)}
>
<IconChevronDownSmall
Expand Down

0 comments on commit 0d90ea9

Please sign in to comment.