Skip to content

Commit

Permalink
Merge pull request #1169 from j-hertzog/fix/update-react-prose
Browse files Browse the repository at this point in the history
#724 Update react-pose(deprecated) to framer-motion
  • Loading branch information
chrismclarke authored Jul 15, 2021
2 parents c00e699 + 9b3560f commit f4529e6
Show file tree
Hide file tree
Showing 5 changed files with 766 additions and 917 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"final-form-arrays": "^3.0.2",
"final-form-calculate": "^1.3.2",
"firebase": "^8.6.3",
"framer-motion": "^4.1.17",
"fuse.js": "^6.4.6",
"is-url": "^1.2.4",
"leaflet": "^1.5.1",
Expand Down Expand Up @@ -97,7 +98,6 @@
"react-linkify": "^0.2.2",
"react-player": "^1.15.3",
"react-portal": "^4.2.0",
"react-pose": "^4.0.8",
"react-router": "^5.2.0",
"react-router-breadcrumbs-hoc": "^3.2.0",
"react-router-dom": "^5.2.0",
Expand Down
27 changes: 13 additions & 14 deletions src/components/Animations/FadeInOut.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react'
import posed, { PoseGroup } from 'react-pose'
import { motion } from 'framer-motion'

interface IProps {
show: boolean
Expand All @@ -8,10 +8,17 @@ interface IState {
show: boolean
}

const AnimationContainer = posed.div({
enter: { opacity: 1 },
exit: { y: 5, opacity: 0 },
})
const AnimationContainer = (props?: React.ReactNode) => {
return (
<motion.div layout
key={'animationContainer'}
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ y: 5, opacity: 0 }}>
{ props }
</motion.div>
)
}

export class FadeInOut extends React.Component<IProps, IState> {
constructor(props: IProps) {
Expand All @@ -25,14 +32,6 @@ export class FadeInOut extends React.Component<IProps, IState> {
}

render() {
return (
<PoseGroup>
{this.state.show && (
<AnimationContainer key="animationContainer">
{this.props.children}
</AnimationContainer>
)}
</PoseGroup>
)
return this.state.show ? AnimationContainer(this.props.children) : AnimationContainer();
}
}
53 changes: 28 additions & 25 deletions src/pages/Howto/Content/Common/Howto.form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Flex from 'src/components/Flex'
import { TagsSelectField } from 'src/components/Form/TagsSelect.field'
import { ImageInputField } from 'src/components/Form/ImageInput.field'
import { FileInputField } from 'src/components/Form/FileInput.field'
import posed, { PoseGroup } from 'react-pose'
import { motion, AnimatePresence } from 'framer-motion'
import { inject, observer } from 'mobx-react'
import { stripSpecialCharacters } from 'src/utils/helpers'
import { PostingGuidelines } from './PostingGuidelines'
Expand Down Expand Up @@ -48,29 +48,32 @@ interface IInjectedProps extends IProps {
howtoStore: HowtoStore
}

const AnimationContainer = posed.div({
// use flip pose to prevent default spring action on list item removed
flip: {
transition: {
// type: 'tween',
// ease: 'linear',
const AnimationContainer = (props: any) => {
const variants = {
pre: {
opacity: 0
},
},
// use a pre-enter pose as otherwise default will be the exit state and so will animate
// horizontally as well
preEnter: {
opacity: 0,
},
enter: {
opacity: 1,
duration: 200,
applyAtStart: { display: 'block' },
},
exit: {
applyAtStart: { display: 'none' },
duration: 200,
},
})
enter: {
opacity: 1,
duration: .200,
display: "block",
},
post: {
display: "none",
duration: .200,
top: '-100%',
},
}
return (
<motion.div layout
initial="pre"
animate="enter"
exit="post"
variants={variants}>
{ props.children }
</motion.div>
)
}

const FormContainer = styled.form`
width: 100%;
Expand Down Expand Up @@ -376,7 +379,7 @@ export class HowtoForm extends React.PureComponent<IProps, IState> {
<FieldArray name="steps" isEqual={COMPARISONS.step}>
{({ fields }) => (
<>
<PoseGroup preEnterPose="preEnter">
<AnimatePresence>
{fields.map((name, index: number) => (
<AnimationContainer
key={fields.value[index]._animationKey}
Expand All @@ -397,7 +400,7 @@ export class HowtoForm extends React.PureComponent<IProps, IState> {
/>
</AnimationContainer>
))}
</PoseGroup>
</AnimatePresence>
<Flex>
<Button
icon={'add'}
Expand Down
37 changes: 22 additions & 15 deletions src/pages/common/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import styled from 'styled-components'
import Profile from 'src/pages/common/Header/Menu/Profile/Profile'
import MenuDesktop from 'src/pages/common/Header/Menu/MenuDesktop'
import MenuMobilePanel from 'src/pages/common/Header/Menu/MenuMobile/MenuMobilePanel'
import posed, { PoseGroup } from 'react-pose'
import { motion } from 'framer-motion'
import Logo from 'src/pages/common/Header/Menu/Logo/Logo'
import theme from 'src/themes/styled.theme'
import HamburgerMenu from 'react-hamburger-menu'
Expand Down Expand Up @@ -40,18 +40,27 @@ const DesktopMenuWrapper = styled(Flex)`
}
`

const AnimationContainer = posed.div({
enter: {
duration: 250,
position: 'relative',
top: '0',
},
exit: {
duration: 250,
position: 'relative',
top: '-100%',
},
})
const AnimationContainer = (props: any) => {
const variants = {
visible: {
duration: .250,
top: '0',
},
hidden: {
duration: .250,
top: '-100%',
},
}
return (
<motion.div layout
style={{ position: "relative" }}
initial="hidden"
animate="visible"
variants={variants}>
{ props.children }
</motion.div>
)
}

@inject('mobileMenuStore')
@observer
Expand Down Expand Up @@ -102,15 +111,13 @@ export class Header extends Component<IProps> {
</Flex>
</MobileMenuWrapper>
</Flex>
<PoseGroup>
{menu.showMobilePanel && (
<AnimationContainer key={'mobilePanelContainer'}>
<MobileMenuWrapper>
<MenuMobilePanel />
</MobileMenuWrapper>
</AnimationContainer>
)}
</PoseGroup>
</>
)
}
Expand Down
Loading

0 comments on commit f4529e6

Please sign in to comment.