Commit ef964ab1 authored by Mike Grabowski's avatar Mike Grabowski Committed by GitHub

feat: differentiate modal from bottomsheet (#5387)

* feat: differenciate modal from bottomsheet

* chore: add ability to disable esc/overlay tap to dismiss
parent f3d64b65
...@@ -24,50 +24,51 @@ const StyledDialogOverlay = styled(AnimatedDialogOverlay)<{ scrollOverlay?: bool ...@@ -24,50 +24,51 @@ const StyledDialogOverlay = styled(AnimatedDialogOverlay)<{ scrollOverlay?: bool
} }
` `
type StyledDialogProps = {
$minHeight?: number | false
$maxHeight?: number
$isBottomSheet?: boolean
$scrollOverlay?: boolean
$hideBorder?: boolean
$maxWidth: number
}
const AnimatedDialogContent = animated(DialogContent) const AnimatedDialogContent = animated(DialogContent)
// destructure to not pass custom props to Dialog DOM element const StyledDialogContent = styled(AnimatedDialogContent)<StyledDialogProps>`
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const StyledDialogContent = styled(
({ hideBorder, maxWidth, minHeight, maxHeight, mobile, isOpen, scrollOverlay, ...rest }) => (
<AnimatedDialogContent {...rest} />
)
).attrs({
'aria-label': 'dialog',
})`
overflow-y: auto; overflow-y: auto;
&[data-reach-dialog-content] { &[data-reach-dialog-content] {
margin: auto; margin: auto;
background-color: ${({ theme }) => theme.deprecated_bg0}; background-color: ${({ theme }) => theme.deprecated_bg0};
border: ${({ theme, hideBorder }) => !hideBorder && `1px solid ${theme.deprecated_bg1}`}; border: ${({ theme, $hideBorder }) => !$hideBorder && `1px solid ${theme.deprecated_bg1}`};
box-shadow: ${({ theme }) => theme.deepShadow}; box-shadow: ${({ theme }) => theme.deepShadow};
padding: 0px; padding: 0px;
width: 50vw; width: 50vw;
overflow-y: auto; overflow-y: auto;
overflow-x: hidden; overflow-x: hidden;
align-self: ${({ mobile }) => mobile && 'flex-end'}; align-self: ${({ $isBottomSheet }) => $isBottomSheet && 'flex-end'};
max-width: ${({ maxWidth }) => maxWidth}px; max-width: ${({ $maxWidth }) => $maxWidth}px;
${({ maxHeight }) => ${({ $maxHeight }) =>
maxHeight && $maxHeight &&
css` css`
max-height: ${maxHeight}vh; max-height: ${$maxHeight}vh;
`} `}
${({ minHeight }) => ${({ $minHeight }) =>
minHeight && $minHeight &&
css` css`
min-height: ${minHeight}vh; min-height: ${$minHeight}vh;
`} `}
display: ${({ scrollOverlay }) => (scrollOverlay ? 'inline-table' : 'flex')}; display: ${({ $scrollOverlay }) => ($scrollOverlay ? 'inline-table' : 'flex')};
border-radius: 20px; border-radius: 20px;
${({ theme }) => theme.deprecated_mediaWidth.deprecated_upToMedium` ${({ theme }) => theme.deprecated_mediaWidth.deprecated_upToMedium`
width: 65vw; width: 65vw;
margin: auto; margin: auto;
`} `}
${({ theme, mobile }) => theme.deprecated_mediaWidth.deprecated_upToSmall` ${({ theme, $isBottomSheet }) => theme.deprecated_mediaWidth.deprecated_upToSmall`
width: 85vw; width: 85vw;
${ ${
mobile && $isBottomSheet &&
css` css`
width: 100vw; width: 100vw;
border-radius: 20px; border-radius: 20px;
...@@ -81,7 +82,8 @@ const StyledDialogContent = styled( ...@@ -81,7 +82,8 @@ const StyledDialogContent = styled(
interface ModalProps { interface ModalProps {
isOpen: boolean isOpen: boolean
onDismiss: () => void onDismiss?: () => void
onSwipe?: () => void
minHeight?: number | false minHeight?: number | false
maxHeight?: number maxHeight?: number
maxWidth?: number maxWidth?: number
...@@ -89,6 +91,7 @@ interface ModalProps { ...@@ -89,6 +91,7 @@ interface ModalProps {
children?: React.ReactNode children?: React.ReactNode
scrollOverlay?: boolean scrollOverlay?: boolean
hideBorder?: boolean hideBorder?: boolean
isBottomSheet?: boolean
} }
export default function Modal({ export default function Modal({
...@@ -99,7 +102,9 @@ export default function Modal({ ...@@ -99,7 +102,9 @@ export default function Modal({
maxWidth = 420, maxWidth = 420,
initialFocusRef, initialFocusRef,
children, children,
onSwipe = onDismiss,
scrollOverlay, scrollOverlay,
isBottomSheet = isMobile,
hideBorder = false, hideBorder = false,
}: ModalProps) { }: ModalProps) {
const fadeTransition = useTransition(isOpen, { const fadeTransition = useTransition(isOpen, {
...@@ -116,7 +121,7 @@ export default function Modal({ ...@@ -116,7 +121,7 @@ export default function Modal({
y: state.down ? state.movement[1] : 0, y: state.down ? state.movement[1] : 0,
}) })
if (state.movement[1] > 300 || (state.velocity > 3 && state.direction[1] > 0)) { if (state.movement[1] > 300 || (state.velocity > 3 && state.direction[1] > 0)) {
onDismiss() onSwipe?.()
} }
}, },
}) })
...@@ -127,7 +132,6 @@ export default function Modal({ ...@@ -127,7 +132,6 @@ export default function Modal({
({ opacity }, item) => ({ opacity }, item) =>
item && ( item && (
<StyledDialogOverlay <StyledDialogOverlay
as={AnimatedDialogOverlay}
style={{ opacity: opacity.to({ range: [0.0, 1.0], output: [0, 1] }) }} style={{ opacity: opacity.to({ range: [0.0, 1.0], output: [0, 1] }) }}
onDismiss={onDismiss} onDismiss={onDismiss}
initialFocusRef={initialFocusRef} initialFocusRef={initialFocusRef}
...@@ -141,13 +145,13 @@ export default function Modal({ ...@@ -141,13 +145,13 @@ export default function Modal({
style: { transform: y.interpolate((y) => `translateY(${(y as number) > 0 ? y : 0}px)`) }, style: { transform: y.interpolate((y) => `translateY(${(y as number) > 0 ? y : 0}px)`) },
} }
: {})} : {})}
aria-label="dialog content" aria-label="dialog"
minHeight={minHeight} $minHeight={minHeight}
maxHeight={maxHeight} $maxHeight={maxHeight}
mobile={isMobile} $isBottomSheet={isBottomSheet}
scrollOverlay={scrollOverlay} $scrollOverlay={scrollOverlay}
hideBorder={hideBorder} $hideBorder={hideBorder}
maxWidth={maxWidth} $maxWidth={maxWidth}
> >
{/* prevents the automatic focusing of inputs on mobile by the reach dialog */} {/* prevents the automatic focusing of inputs on mobile by the reach dialog */}
{!initialFocusRef && isMobile ? <div tabIndex={1} /> : null} {!initialFocusRef && isMobile ? <div tabIndex={1} /> : null}
......
...@@ -81,7 +81,7 @@ export function WelcomeModal({ onDismissed }: { onDismissed: () => void }) { ...@@ -81,7 +81,7 @@ export function WelcomeModal({ onDismissed }: { onDismissed: () => void }) {
const theme = useTheme() const theme = useTheme()
return ( return (
<Modal isOpen={isOpen} onDismiss={dismiss} maxWidth={720}> <Modal isOpen={isOpen} onSwipe={dismiss} maxWidth={720} isBottomSheet={false}>
<Container> <Container>
<Background <Background
{...(theme.darkMode ? BACKGROUND_IMAGE.dark : BACKGROUND_IMAGE.light)} {...(theme.darkMode ? BACKGROUND_IMAGE.dark : BACKGROUND_IMAGE.light)}
......
...@@ -80,7 +80,7 @@ export const initialState: UserState = { ...@@ -80,7 +80,7 @@ export const initialState: UserState = {
hideNFTPromoBanner: false, hideNFTPromoBanner: false,
showSurveyPopup: undefined, showSurveyPopup: undefined,
showDonationLink: true, showDonationLink: true,
hideNFTWelcomeModal: true, hideNFTWelcomeModal: false,
} }
const userSlice = createSlice({ const userSlice = createSlice({
......
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