Code Monkey home page Code Monkey logo

reacttransitiongroupexample's Introduction

This project was bootstrapped with Create React App.

Transition Group Example

This is an example application using

The App

Screenshot
This app builds a very simple application to showcase transitions in and out of individual items within a transition group.

  • Click the Add Button to see an item transition in
  • Click on the individual item to see it transition out

The main secret sauce is the React-Transition-Group, which allows us to apply classes to enable CSS animations as components are added or removed. In this example a few classes are applied on enter and exit of a Tile.

transition-enter
transition-enter-active
transition-exit
transition-exit-active

<TransitionGroup> needs to be a direct parent to any <CSSTransition> children, otherwise the behavior begins to get wonky.

Structure of the App

App.js


The App component uses react hooks to store the state and also contains the addItem() and removeItem() functions, which update the state with an updated item list. These two functions are passed via props down the application to where they need to go, as opposed to using context.

AddButton.js


The add button receives the addItem() function and runs this function onClick.

TileGroup.js


The tile group uses CSS grid to show the grid of tiles. It utilizes grid-template-columns: repeat(auto-fill, 220px); to keep the layout responsive by flowing items based on the size of the div. I set the component attribute of <TransitionGroup> to <StyledTile> to ensure I didn't need an additional div in the DOM.

This is where the primary implementation of Transition Group is done. A parent TransitionGroup component holds the child CSSTransition children, which specifies a base class for the CSS transition classes (classNames="transition") creates transition-enter, transition-enter-active, etc.

Tile.js


Receives the removeItem() function via props, becoming the onClick handler. Also gets populated with dummy data provided within the addItem() function to show title, subtitle, and readtime.

helpers.js

I used a modified helper function from one of Wes Bos' React Courses to generate random strings to fill the tiles with, just to make the solution look a bit more realistic and appealing.

Available Scripts

Per usual, use npm install to get all the dependencies. In the project directory, you can run:

npm start

Runs the app in the development mode.
Open http://localhost:3000 to view it in the browser.

The page will reload if you make edits.
You will also see any lint errors in the console.

reacttransitiongroupexample's People

Contributors

danmostudco avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.