mars-v2-frontend/src/components/Modal.tsx
Bob van der Helm 65ee49a3cd
🌟 Add HLS Vault Modal (#595)
* 🌟 Add HLS Vault Modal

* 🛠️ Fix failing build

* fix: keep the selected accountId if its present int the url (#588)

* Link changelog (#589)

* env: update RPC endpoint

* feat: added changelog link to the footer version

* Refactor balances table (#590)

* env: update env.example after last sync

* tidy: refactored AccountBalancesTable

* fix: updated isCard to hideCard

* fix: do update the health on sliding the margin back to 0 (#593)

* fix: disable highlighting on non-expandable rows (#592)

* Healthfactor adjustments (#594)

* fix: do update the health on sliding the margin back to 0

* MP-3531: first updates on the health bars

* fix: added exponential function for health percentage

* fix: build fix

* tidy: refactor

* tidy: cleanup

* feat: added new curve

* fix: base set to 3.5

* env: version update

* 🌟 Add HLS Vault Modal

* Use `DisplayCurrency` in subtitle header

* 🔥Remove redundant component

---------

Co-authored-by: Linkie Link <linkielink.dev@gmail.com>
2023-10-30 12:47:52 +01:00

80 lines
2.1 KiB
TypeScript

import classNames from 'classnames'
import { ReactNode, useEffect, useRef } from 'react'
import EscButton from 'components/Button/EscButton'
import Card from 'components/Card'
interface Props {
header: string | ReactNode
headerClassName?: string
hideCloseBtn?: boolean
children?: ReactNode | string
content?: ReactNode | string
className?: string
contentClassName?: string
modalClassName?: string
onClose: () => void
hideTxLoader?: boolean
dialogId?: string
}
export default function Modal(props: Props) {
const ref: React.RefObject<HTMLDialogElement> = useRef(null)
const modalClassName = props.modalClassName ?? 'max-w-modal'
function onClose() {
ref.current?.close()
props.onClose()
}
useEffect(() => {
ref.current?.showModal()
document.body.classList.add('h-screen', 'overflow-hidden')
}, [])
// close dialog on unmount
useEffect(() => {
const dialog = ref.current
return () => {
dialog?.removeAttribute('open')
dialog?.close()
document.body.classList.remove('h-screen', 'overflow-hidden')
}
}, [])
return (
<dialog
ref={ref}
onCancel={onClose}
className={classNames(
`w-screen border-none bg-transparent text-white`,
'focus-visible:outline-none',
'max-h-full scrollbar-hide',
'backdrop:bg-black/50 backdrop:backdrop-blur-sm',
modalClassName,
)}
id={props.dialogId ? props.dialogId : 'modal'}
>
<Card
className={classNames(
'flex max-w-full flex-1 bg-white/5 backdrop-blur-3xl',
props.className,
)}
>
<div className={classNames('flex justify-between', props.headerClassName)}>
{props.header}
{!props.hideCloseBtn && <EscButton onClick={props.onClose} />}
</div>
<div
className={classNames(
props.contentClassName,
'flex-1 overflow-y-scroll scrollbar-hide relative',
)}
>
{props.children ? props.children : props.content}
</div>
</Card>
</dialog>
)
}