Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Transition] Document the grouping feature #24042

Closed
1 task done
cjoecker opened this issue Dec 18, 2020 · 5 comments 路 Fixed by #24049
Closed
1 task done

[Transition] Document the grouping feature #24042

cjoecker opened this issue Dec 18, 2020 · 5 comments 路 Fixed by #24049
Labels
component: transitions This is the name of the generic UI component, not the React module! docs Improvements or additions to the documentation

Comments

@cjoecker
Copy link
Contributor

  • I have searched the issues of this repository and believe that this is not a duplicate.

Summary 馃挕

It will be nice to have something like the AnimatePresence of Framer Motion for Material-UI transitions.
This component creates a copy of the component after unmount. Then it animates the component unmount, and then it deletes the copy.

Motivation 馃敠

When I have a list of components and I remove an item, I want to animate the unmounting process with a Material-UI transition.

If the list is being modified in different parts of the program, to create a timeout for animating, and then removing objects can get messy. Therefore, the approach of AnimatePresence that creates a copy of the component until the transition is done, is a cleaner approach for me.

@cjoecker cjoecker added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Dec 18, 2020
@oliviertassinari oliviertassinari added component: transitions This is the name of the generic UI component, not the React module! and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Dec 18, 2020
@oliviertassinari
Copy link
Member

@cjoecker From what I understand, this is the purpose of this component: https://reactcommunity.org/react-transition-group/transition-group.

@cjoecker
Copy link
Contributor Author

@oliviertassinari you are right, thanks!
I just realized I can use the Collapse Material-UI component with the react-transition-group library :)

Somehow the animation is not working with the Collapse component when I mount a new item. It works only for unmounting.
With Zoom component is working for mounting and unmounting.
Is it a Bug in the Collapse component?

You can check here the codesandbox.

@oliviertassinari
Copy link
Member

oliviertassinari commented Dec 18, 2020

@cjoecker Yeap, my version:

Dec-18-2020 13-51-50

https://codesandbox.io/s/simplecollapse-material-demo-forked-mp2mv?file=/demo.tsx

import * as React from "react";
import { makeStyles, createStyles, Theme } from "@material-ui/core/styles";
import { TransitionGroup } from "react-transition-group";
import Paper from "@material-ui/core/Paper";
import Box from "@material-ui/core/Box";
import Collapse from "@material-ui/core/Collapse";

const useStyles = makeStyles((theme: Theme) =>
  createStyles({
    root: {
      height: 300
    },
    container: {
      display: "flex",
      justifyContent: "space-around",
      height: 120,
      width: 250
    },
    halfWidth: {
      width: "50%"
    },
    paper: {
      margin: theme.spacing(1)
    },
    svg: {
      width: 100,
      height: 100
    },
    polygon: {
      fill: theme.palette.common.white,
      stroke: theme.palette.divider,
      strokeWidth: 1
    }
  })
);

export default function SimpleCollapse() {
  const classes = useStyles();
  const [item, setItem] = React.useState(0);

  console.log("item", item);

  React.useEffect(() => {
    const internval = setInterval(() => {
      setItem((item) => (item + 1) % 2);
    }, 2000);

    return () => {
      clearInterval(internval);
    };
  }, []);

  return (
    <div className={classes.root}>
      <div className={classes.container}>
        <TransitionGroup>
          <Collapse key={item} in>
            <Paper elevation={4} className={classes.paper}>
              <Box sx={{ p: 2 }}>{item}</Box>
            </Paper>
          </Collapse>
        </TransitionGroup>
      </div>
    </div>
  );
}

@oliviertassinari
Copy link
Member

@cjoecker Do you want to update the documentation to mention the grouping feature?

@oliviertassinari oliviertassinari added the docs Improvements or additions to the documentation label Dec 18, 2020
@oliviertassinari oliviertassinari changed the title Create Shallow Copy Component for Unmount Transition [Transition] Cover grouping Dec 18, 2020
@oliviertassinari oliviertassinari changed the title [Transition] Cover grouping [Transition] Document the grouping feature Dec 18, 2020
@cjoecker
Copy link
Contributor Author

@oliviertassinari Sure, I can do it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: transitions This is the name of the generic UI component, not the React module! docs Improvements or additions to the documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants