mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-12 13:13:45 +01:00
[web] Scroll to new notification added above domains table GitOrigin-RevId: f62851398de3a54ef07c0e125c65a29dd84af6f8
32 lines
847 B
TypeScript
32 lines
847 B
TypeScript
import Notification, {
|
|
NotificationProps,
|
|
} from '@/shared/components/notification'
|
|
import { useEffect } from 'react'
|
|
import { elementIsInView } from '@/shared/utils/element-in-view'
|
|
|
|
function NotificationScrolledTo({ ...props }: NotificationProps) {
|
|
useEffect(() => {
|
|
if (props.id) {
|
|
const alert = document.getElementById(props.id)
|
|
if (alert && !elementIsInView(alert)) {
|
|
alert.scrollIntoView({ behavior: 'smooth' })
|
|
}
|
|
}
|
|
}, [props])
|
|
|
|
const notificationProps = { ...props }
|
|
|
|
if (!notificationProps.className) {
|
|
notificationProps.className = ''
|
|
}
|
|
|
|
notificationProps.className = `${notificationProps.className} notification-with-scroll-margin`
|
|
|
|
return (
|
|
<div className="notification-list">
|
|
<Notification {...notificationProps} />
|
|
</div>
|
|
)
|
|
}
|
|
export default NotificationScrolledTo
|