refactor: hide challenge modal illustration when shrinked because of keyboard
This commit is contained in:
@@ -22,6 +22,7 @@ import { classNames } from '@standardnotes/utils'
|
|||||||
import ModalOverlay from '../Modal/ModalOverlay'
|
import ModalOverlay from '../Modal/ModalOverlay'
|
||||||
import Modal from '../Modal/Modal'
|
import Modal from '../Modal/Modal'
|
||||||
import { MutuallyExclusiveMediaQueryBreakpoints, useMediaQuery } from '@/Hooks/useMediaQuery'
|
import { MutuallyExclusiveMediaQueryBreakpoints, useMediaQuery } from '@/Hooks/useMediaQuery'
|
||||||
|
import { useAutoElementRect } from '@/Hooks/useElementRect'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
application: WebApplication
|
application: WebApplication
|
||||||
@@ -214,6 +215,11 @@ const ChallengeModal: FunctionComponent<Props> = ({
|
|||||||
const isFullScreenBlocker = challenge.reason === ChallengeReason.ApplicationUnlock
|
const isFullScreenBlocker = challenge.reason === ChallengeReason.ApplicationUnlock
|
||||||
const isMobileOverlay = isMobileScreen && !isFullScreenBlocker
|
const isMobileOverlay = isMobileScreen && !isFullScreenBlocker
|
||||||
|
|
||||||
|
const [modalElement, setModalElement] = useState<HTMLDivElement | null>(null)
|
||||||
|
const modalElementRect = useAutoElementRect(modalElement, {
|
||||||
|
updateOnWindowResize: true,
|
||||||
|
})
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ModalOverlay
|
<ModalOverlay
|
||||||
isOpen={true}
|
isOpen={true}
|
||||||
@@ -221,6 +227,7 @@ const ChallengeModal: FunctionComponent<Props> = ({
|
|||||||
onDismiss={cancelChallenge}
|
onDismiss={cancelChallenge}
|
||||||
dangerouslyBypassFocusLock={bypassModalFocusLock}
|
dangerouslyBypassFocusLock={bypassModalFocusLock}
|
||||||
key={challenge.id}
|
key={challenge.id}
|
||||||
|
ref={setModalElement}
|
||||||
>
|
>
|
||||||
<Modal
|
<Modal
|
||||||
title="Authenticate"
|
title="Authenticate"
|
||||||
@@ -255,7 +262,12 @@ const ChallengeModal: FunctionComponent<Props> = ({
|
|||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
<div className="flex min-h-0 w-full flex-grow flex-col items-center overflow-auto p-8">
|
<div className="flex min-h-0 w-full flex-grow flex-col items-center overflow-auto p-8">
|
||||||
<ProtectedIllustration className="mb-4 h-30 w-30 flex-shrink-0" />
|
<ProtectedIllustration
|
||||||
|
className={classNames(
|
||||||
|
'mb-4 h-30 w-30 flex-shrink-0',
|
||||||
|
modalElementRect && modalElementRect.height < 500 ? 'hidden' : '',
|
||||||
|
)}
|
||||||
|
/>
|
||||||
<div className="mb-3 max-w-76 text-center text-lg font-bold">{challenge.heading}</div>
|
<div className="mb-3 max-w-76 text-center text-lg font-bold">{challenge.heading}</div>
|
||||||
{challenge.subheading && (
|
{challenge.subheading && (
|
||||||
<div className="break-word mb-4 max-w-76 text-center text-sm">{challenge.subheading}</div>
|
<div className="break-word mb-4 max-w-76 text-center text-sm">{challenge.subheading}</div>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
|
import { mergeRefs } from '@/Hooks/mergeRefs'
|
||||||
import { DialogOverlay, DialogOverlayProps } from '@reach/dialog'
|
import { DialogOverlay, DialogOverlayProps } from '@reach/dialog'
|
||||||
import { classNames } from '@standardnotes/snjs'
|
import { classNames } from '@standardnotes/snjs'
|
||||||
import { ReactNode } from 'react'
|
import { ForwardedRef, forwardRef, ReactNode } from 'react'
|
||||||
import { useModalAnimation } from '../Modal/useModalAnimation'
|
import { useModalAnimation } from '../Modal/useModalAnimation'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
@@ -10,23 +11,25 @@ type Props = {
|
|||||||
className?: string
|
className?: string
|
||||||
} & DialogOverlayProps
|
} & DialogOverlayProps
|
||||||
|
|
||||||
const ModalOverlay = ({ isOpen, onDismiss, children, className, ...props }: Props) => {
|
const ModalOverlay = forwardRef(
|
||||||
const [isMounted, setElement] = useModalAnimation(isOpen)
|
({ isOpen, onDismiss, children, className, ...props }: Props, ref: ForwardedRef<HTMLDivElement>) => {
|
||||||
|
const [isMounted, setElement] = useModalAnimation(isOpen)
|
||||||
|
|
||||||
if (!isMounted) {
|
if (!isMounted) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DialogOverlay
|
<DialogOverlay
|
||||||
className={classNames('p-0 md:px-0 md:opacity-100', className)}
|
className={classNames('p-0 md:px-0 md:opacity-100', className)}
|
||||||
onDismiss={onDismiss}
|
onDismiss={onDismiss}
|
||||||
ref={setElement}
|
ref={mergeRefs([setElement, ref])}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
</DialogOverlay>
|
</DialogOverlay>
|
||||||
)
|
)
|
||||||
}
|
},
|
||||||
|
)
|
||||||
|
|
||||||
export default ModalOverlay
|
export default ModalOverlay
|
||||||
|
|||||||
Reference in New Issue
Block a user