Skip to content

Commit

Permalink
fix: slide issue
Browse files Browse the repository at this point in the history
  • Loading branch information
surajahmed committed Jan 7, 2022
1 parent 5c2f35b commit 2224c95
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 70 deletions.
2 changes: 1 addition & 1 deletion src/components/composites/AlertDialog/AlertDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const AlertDialog = (
)}
</Fade>
{animationPreset === 'slide' ? (
<Slide in={visible} duration={200}>
<Slide overlay={false} in={visible} duration={200}>
<FocusScope
contain={visible}
autoFocus={visible && !initialFocusRef}
Expand Down
2 changes: 1 addition & 1 deletion src/components/composites/Modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const Modal = (
)}
</Fade>
{animationPreset === 'slide' ? (
<Slide in={visible} duration={200}>
<Slide in={visible} overlay={false} duration={200}>
<FocusScope
contain={visible}
autoFocus={visible && !initialFocusRef}
Expand Down
144 changes: 76 additions & 68 deletions src/components/composites/Transitions/Slide.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React from 'react';
import React, { forwardRef, memo } from 'react';
import Box from '../../primitives/Box';
import { useThemeProps } from '../../../hooks/useThemeProps';
import type { ISlideProps } from './types';
import PresenceTransition from './PresenceTransition';
import { useHasResponsiveProps } from '../../../hooks/useHasResponsiveProps';
import { Overlay } from '../../primitives';

const holderStyle: any = {
top: {
Expand All @@ -28,77 +29,72 @@ const holderStyle: any = {
},
};

const Slide = ({ children, ...props }: ISlideProps, ref: any) => {
const { in: visible, placement, duration } = useThemeProps('Slide', props);
const [containerOpacity, setContainerOpacity] = React.useState(0);
const [size, setSize] = React.useState(0);
const provideSize = (layoutSize: any) => {
if (placement === 'right' || placement === 'left')
setSize(layoutSize.width);
else setSize(layoutSize.height);
setContainerOpacity(1);
};
export const Slide = memo(
forwardRef(({ children, ...props }: ISlideProps, ref: any) => {
const { in: visible, placement, overlay, duration } = useThemeProps(
'Slide',
props
);
const [containerOpacity, setContainerOpacity] = React.useState(0);
const [size, setSize] = React.useState(0);
const provideSize = (layoutSize: any) => {
if (placement === 'right' || placement === 'left')
setSize(layoutSize.width);
else setSize(layoutSize.height);
setContainerOpacity(1);
};

const transition = { duration };
const transition = { duration };

const animationStyle: any = {
top: {
initial: {
translateY: -size,
const animationStyle: any = {
top: {
initial: {
translateY: -size,
},
animate: {
translateY: 0,
transition,
},
},
animate: {
translateY: 0,
transition,
bottom: {
initial: {
translateY: size,
},
animate: {
translateY: 0,
transition,
},
exit: {
translateY: size,
transition,
},
},
},
bottom: {
initial: {
translateY: size,
left: {
initial: {
translateX: -size,
},
animate: {
translateX: 0,
transition,
},
},
animate: {
translateY: 0,
transition,
right: {
initial: {
translateX: size,
},
animate: {
translateX: 0,
transition,
},
},
exit: {
translateY: size,
transition,
},
},
left: {
initial: {
translateX: -size,
},
animate: {
translateX: 0,
transition,
},
},
right: {
initial: {
translateX: size,
},
animate: {
translateX: 0,
transition,
},
},
};
};

//TODO: refactor for responsive prop
if (useHasResponsiveProps(props)) {
return null;
}
//TODO: refactor for responsive prop
if (useHasResponsiveProps(props)) {
return null;
}

return (
<Box
w="100%"
h="100%"
position="fixed"
left="0"
top="0"
pointerEvents="box-none"
overflow="hidden"
>
const slideComponent = (
<PresenceTransition
visible={visible}
{...animationStyle[placement]}
Expand All @@ -119,8 +115,20 @@ const Slide = ({ children, ...props }: ISlideProps, ref: any) => {
{children}
</Box>
</PresenceTransition>
</Box>
);
};
);

if (overlay) {
return (
<Overlay isOpen={true}>
<Box w="100%" h="100%" pointerEvents="box-none" overflow="hidden">
{slideComponent}
</Box>
</Overlay>
);
} else {
return slideComponent;
}
})
);

export default React.memo(React.forwardRef(Slide));
export default Slide;
1 change: 1 addition & 0 deletions src/components/composites/Transitions/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export type ISlideProps = IBoxProps<ISlideProps> & {
duration?: number;
delay?: number;
placement?: 'top' | 'bottom' | 'right' | 'left';
overlay?: boolean;
};
export type ISlideFadeProps = IBoxProps<ISlideFadeProps> & {
in?: boolean;
Expand Down
1 change: 1 addition & 0 deletions src/theme/components/transitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const ScaleFade = {
const slideDefaultProps = {
duration: 500,
placement: 'bottom',
overlay: true,
};

export const Slide = {
Expand Down

0 comments on commit 2224c95

Please sign in to comment.