Commit ac1bc3b3 authored by Moody Salem's avatar Moody Salem

cleanup(modal): clean up modal code a bit

parent d1063d50
...@@ -87,14 +87,6 @@ const StyledDialogContent = styled(({ minHeight, maxHeight, mobile, isOpen, ...r ...@@ -87,14 +87,6 @@ const StyledDialogContent = styled(({ minHeight, maxHeight, mobile, isOpen, ...r
} }
` `
const HiddenCloseButton = styled.button`
margin: 0;
padding: 0;
width: 0;
height: 0;
border: none;
`
interface ModalProps { interface ModalProps {
isOpen: boolean isOpen: boolean
onDismiss: () => void onDismiss: () => void
...@@ -119,7 +111,7 @@ export default function Modal({ ...@@ -119,7 +111,7 @@ export default function Modal({
leave: { opacity: 0 } leave: { opacity: 0 }
}) })
const [{ xy }, set] = useSpring(() => ({ xy: [0, 0] })) const [{ y }, set] = useSpring(() => ({ y: 0, config: { mass: 1, tension: 210, friction: 20 } }))
const bind = useGesture({ const bind = useGesture({
onDrag: state => { onDrag: state => {
let velocity = state.velocity let velocity = state.velocity
...@@ -130,8 +122,7 @@ export default function Modal({ ...@@ -130,8 +122,7 @@ export default function Modal({
velocity = 8 velocity = 8
} }
set({ set({
xy: state.down ? state.movement : [0, 0], y: state.down ? state.movement[1] : 0
config: { mass: 1, tension: 210, friction: 20 }
}) })
if (velocity > 3 && state.direction[1] > 0) { if (velocity > 3 && state.direction[1] > 0) {
onDismiss() onDismiss()
...@@ -164,18 +155,17 @@ export default function Modal({ ...@@ -164,18 +155,17 @@ export default function Modal({
<animated.div <animated.div
{...bind()} {...bind()}
style={{ style={{
transform: (xy as any).interpolate((x, y) => `translate3d(${0}px,${y > 0 ? y : 0}px,0)`) transform: y.interpolate(y => `translateY(${y > 0 ? y : 0}px)`)
}} }}
> >
<StyledDialogContent <StyledDialogContent
ariaLabel="test" aria-label="dialog content"
style={props} style={props}
hidden={true} hidden={true}
minHeight={minHeight} minHeight={minHeight}
maxHeight={maxHeight} maxHeight={maxHeight}
mobile={isMobile ?? undefined} mobile={isMobile}
> >
<HiddenCloseButton onClick={onDismiss} />
{children} {children}
</StyledDialogContent> </StyledDialogContent>
</animated.div> </animated.div>
...@@ -193,8 +183,13 @@ export default function Modal({ ...@@ -193,8 +183,13 @@ export default function Modal({
({ item, key, props }) => ({ item, key, props }) =>
item && ( item && (
<StyledDialogOverlay key={key} style={props} onDismiss={onDismiss} initialFocusRef={initialFocusRef}> <StyledDialogOverlay key={key} style={props} onDismiss={onDismiss} initialFocusRef={initialFocusRef}>
<StyledDialogContent hidden={true} minHeight={minHeight} maxHeight={maxHeight} isOpen={isOpen}> <StyledDialogContent
<HiddenCloseButton onClick={onDismiss} /> aria-label="dialog content"
hidden={true}
minHeight={minHeight}
maxHeight={maxHeight}
isOpen={isOpen}
>
{children} {children}
</StyledDialogContent> </StyledDialogContent>
</StyledDialogOverlay> </StyledDialogOverlay>
......
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