diff --git a/src/components/expandGrid/ExpandGrid.js b/src/components/expandGrid/ExpandGrid.js index 3a80d51b..8fb8dddb 100644 --- a/src/components/expandGrid/ExpandGrid.js +++ b/src/components/expandGrid/ExpandGrid.js @@ -1,16 +1,19 @@ -import React, { useRef, useState } from "react" +import React, { useEffect, useRef, useState } from "react" import { Flipper, Flipped } from "react-flip-toolkit" import MarkdownView from "react-showdown" import "./expandGrid.scss" const ExpandGrid = ({ data }) => { return ( -
+

{data.title}

{data.subtitle}
- +
@@ -32,6 +35,9 @@ const ListItem = ({ index, onClick, data }) => {
onClick(index)}>
+
+

Ver mas

+
{ ) } -const ExpandedListItem = ({ index, onClick, data, scrollToRef }) => { - const scrollRef = useRef(null) - +const ExpandedListItem = ({ index, data }) => { return ( { - scrollToRef(scrollRef) setTimeout(() => { el.classList.add("animated-in") }, 400) @@ -70,6 +73,9 @@ const ExpandedListItem = ({ index, onClick, data, scrollToRef }) => { >
+
+

+
{ > -
@@ -91,45 +96,56 @@ const ExpandedListItem = ({ index, onClick, data, scrollToRef }) => { } const AnimatedList = ({ items }) => { - const [focused, setFocused] = useState(null) + const [itemsArray, setItemsArray] = useState({ items, focused: null }) const scrollRef = useRef(null) + + useEffect(() => { + setItemsArray(prev => ({ ...prev, focused: items[0].id })) + }, []) + const onClick = index => { - setFocused(focused === index ? null : index) - if (focused !== null) { - scrollToRef(scrollRef) + for (let i = 0; i < items.length; i++) { + const item = itemsArray.items[i] + if (item.id === index) { + setItemsArray(prevItems => ({ + items: [ + item, + ...prevItems.items.slice(0, i), + ...prevItems.items.slice(i + 1), + ], + focused: item.id, + })) + break + } } } - const scrollToRef = ref => window.scrollTo(0, ref.current.offsetTop - 40) return (
    - {items.map((item, index) => { + {itemsArray.items.map(item => { return ( <> - {index === focused ? ( + {item.id === itemsArray.focused ? ( ) : ( diff --git a/src/components/expandGrid/expandGrid.scss b/src/components/expandGrid/expandGrid.scss index a8dc45e7..6d2ffdb7 100644 --- a/src/components/expandGrid/expandGrid.scss +++ b/src/components/expandGrid/expandGrid.scss @@ -1,4 +1,4 @@ -@import "../../styles/global.scss"; +@import ".././../styles/global.scss"; .expandGrid { display: flex; @@ -29,7 +29,7 @@ display: flex; flex-direction: row; flex-wrap: wrap; - padding: 0; + padding: 0 5em; width: 100%; } @@ -37,6 +37,9 @@ border-radius: 8px; margin: 5px; flex: 0 1 calc(calc(100% / 3) - 10px); + &-focus { + flex: 0 1 calc(calc(100% / 3) - 10px); + } background-color: #ececec; cursor: pointer; @@ -62,6 +65,7 @@ display: flex; flex-direction: row; height: 100%; + position: relative; @media screen and (max-width: 890px) { flex-direction: column; align-items: unset; @@ -104,13 +108,32 @@ .additional-content { width: 100%; - margin-top: 2rem; - + overflow: hidden; @media screen and (max-width: 890px) { margin: 0; } } +.listItem-more{ + position: absolute; + inset: 0 0 0 0; + display: flex; + align-items: center; + justify-content: center; + transition: opacity 200ms ease; + opacity: 1; + p{ + padding: 0; + margin: 0; + @include primaryBtn; + } + &-expanded{ + @extend .listItem-more; + opacity: 0; + padding: 0 !important; + } +} + .additional-content > div { opacity: 0; border-radius: 3px;