From 1f4dfb9a851561031861b151b173992d782519f7 Mon Sep 17 00:00:00 2001 From: Lucas Teixeira Date: Sun, 15 Nov 2020 14:59:33 -0300 Subject: [PATCH] WJ-117 - New: EntityImage animations; --- src/containers/EntityImage/index.tsx | 61 +++++------ src/containers/EntityImage/styles.ts | 2 + src/containers/EntityImageList/index.tsx | 123 ++++++++++++----------- src/containers/EntityImageList/styles.ts | 11 +- 4 files changed, 109 insertions(+), 88 deletions(-) diff --git a/src/containers/EntityImage/index.tsx b/src/containers/EntityImage/index.tsx index 4af8c9a..c7ed9a9 100644 --- a/src/containers/EntityImage/index.tsx +++ b/src/containers/EntityImage/index.tsx @@ -1,5 +1,6 @@ import React, { useCallback, useEffect, useState } from 'react'; import { useHistory } from 'react-router-dom'; +import { AnimatePresence } from 'framer-motion'; import { BsHeartFill } from 'react-icons/bs'; import { getEntityRoute } from 'shared/helpers'; @@ -96,10 +97,6 @@ const EntityImage: React.FC = ({ } }, [user, favoriteList, entity.id, entity.mediaType]); - if (!entity.featuredImage && !entity.backdrop && !showEmpty) { - return null; - } - if (isLoading) { return ( = ({ } return ( - - {!hideFavoriteButton && ( - - - + + {(entity.featuredImage || entity.backdrop || showEmpty) && ( + + {!hideFavoriteButton && ( + + + + )} + + + + {showInfo && ( + + + {entity.title} + + {!hideSubtitle && ( + {entity?.subtitle} + )} + + )} + + )} - - - - {showInfo && ( - - {entity.title} - {!hideSubtitle && {entity?.subtitle}} - - )} - - + ); }; diff --git a/src/containers/EntityImage/styles.ts b/src/containers/EntityImage/styles.ts index 1dda95f..9bcb356 100644 --- a/src/containers/EntityImage/styles.ts +++ b/src/containers/EntityImage/styles.ts @@ -75,6 +75,8 @@ export const IconButton = styled.button` svg { height: ${Size.Default}; width: ${Size.Default}; + + transition: fill 0.3s; } `; diff --git a/src/containers/EntityImageList/index.tsx b/src/containers/EntityImageList/index.tsx index 5981aae..7036bd6 100644 --- a/src/containers/EntityImageList/index.tsx +++ b/src/containers/EntityImageList/index.tsx @@ -1,4 +1,5 @@ import React, { useCallback, createRef, useState } from 'react'; +import { AnimatePresence } from 'framer-motion'; import { FiChevronLeft, FiChevronRight } from 'react-icons/fi'; @@ -9,6 +10,7 @@ import { Title, ListContainer, ListContent, + EntityImageContainer, PreviousButton, NextButton, MessageContainer, @@ -73,65 +75,68 @@ const EntityImageList: React.FC = ({ }, [itemsContainer, checkButtons]); return ( - - - {title && ( - - {title} - - )} - - {isLoading && ( - - )} - - {!isLoading && data.length > 0 && ( - <> - {showPreviousButton && ( - - - - )} - - - {data.map(entity => ( - - ))} - - - {showNextButton && ( - - - - )} - - )} - - {!isLoading && data.length === 0 && ( - {message} - )} - - + + + + {title && ( + + {title} + + )} + + {isLoading && ( + + )} + + {!isLoading && data.length > 0 && ( + <> + {showPreviousButton && ( + + + + )} + + + {data.map(entity => ( + + + + ))} + + + {showNextButton && ( + + + + )} + + )} + + {!isLoading && data.length === 0 && ( + {message} + )} + + + ); }; diff --git a/src/containers/EntityImageList/styles.ts b/src/containers/EntityImageList/styles.ts index d5bdca5..5d027f1 100644 --- a/src/containers/EntityImageList/styles.ts +++ b/src/containers/EntityImageList/styles.ts @@ -1,4 +1,5 @@ import styled from 'styled-components'; +import { motion } from 'framer-motion'; import DefaultProps from 'shared/types'; import { Container as DefaultContainer, Button } from 'components'; @@ -61,7 +62,9 @@ export const ListContainer = styled.div` } `; -export const ListContent = styled.div` +export const ListContent = styled(motion.div).attrs(() => ({ + // layout: true, +}))` display: inline-flex; padding: 0 2px; margin-top: 2px; @@ -92,6 +95,12 @@ export const ListContent = styled.div` } `; +export const EntityImageContainer = styled(motion.div).attrs(() => ({ + initial: { x: 20, opacity: 0 }, + animate: { x: 0, opacity: 1 }, + exit: { x: -20, opacity: 0 }, +}))``; + export const PreviousButton = styled(Button)` opacity: 0; pointer-events: none;