From 4d7f2c386a41e254d1ce0f8908e84114ae9dac48 Mon Sep 17 00:00:00 2001 From: Niaz Faridani-Rad Date: Tue, 15 Jun 2021 15:15:42 +0200 Subject: [PATCH 1/2] Add option to select images --- src/components/Tile/Tile.js | 39 +++++++++++++++++++++++++++------- src/components/Tile/styles.css | 25 +++++++++++++++++++++- src/index.js | 19 ++++++++++++++++- 3 files changed, 73 insertions(+), 10 deletions(-) diff --git a/src/components/Tile/Tile.js b/src/components/Tile/Tile.js index 7da6cd8..21a51f3 100644 --- a/src/components/Tile/Tile.js +++ b/src/components/Tile/Tile.js @@ -13,11 +13,15 @@ const Tile = React.memo(function Tile({ getUrl, activeTileUrl, handleClick, + handleSelection, + selected, + selectable, windowHeight, scrollSpeed, settings, }) { - + const isSelectable = selectable + const isSelected = selected const isExpanded = activeTileUrl === item.url const isVideo = item.url.includes('.mp4') || item.url.includes('.mov') const [isFullSizeLoaded, setFullSizeLoaded] = useState(isVideo ? true : false) @@ -29,12 +33,16 @@ const Tile = React.memo(function Tile({ // screenCenter is positioning logic for when the item is active and expanded const screenCenter = `translate3d(${offsetX}px, ${offsetY}px, 0)` - const { width, height, transform, zIndex } = useSpring({ + const { width, height, transform, zIndex, marginLeft, marginRight, marginTop, marginBottom } = useSpring({ transform: isExpanded ? screenCenter : gridPosition, zIndex: isExpanded ? 10 : 0, // 10 so that it takes a little longer before settling at 0 - width: isExpanded ? Math.ceil(calcWidth) + 'px' : item.style.width + 'px', - height: isExpanded ? Math.ceil(calcHeight) + 'px' : item.style.height + 'px', - config: { mass: 1.5, tension: 400, friction: 40 } + width: isExpanded ? Math.ceil(calcWidth) + 'px' : isSelected ? item.style.width - item.style.width * 0.1 + 'px' : item.style.width + 'px', + height: isExpanded ? Math.ceil(calcHeight) + 'px' : isSelected ? item.style.height - item.style.height * 0.1 + 'px' : item.style.height + 'px', + config: { mass: 1.5, tension: 400, friction: 40 }, + marginLeft: isSelected && !isExpanded ? item.style.width * 0.05 : 0, + marginRight: isSelected && !isExpanded ? item.style.width * 0.05 : 0, + marginTop: isSelected && !isExpanded ? item.style.height * 0.05 : 0, + marginBottom: isSelected && !isExpanded ? item.style.height * 0.05 : 0, }) return ( @@ -47,7 +55,11 @@ const Tile = React.memo(function Tile({ zIndex: zIndex.interpolate(t => Math.round(t)), width: width.interpolate(t => t), height: height.interpolate(t => t), - transform: transform.interpolate(t => t) + transform: transform.interpolate(t => t), + marginLeft: marginLeft.interpolate(t => t), + marginRight: marginRight.interpolate(t => t), + marginTop: marginTop.interpolate(t => t), + marginBottom: marginBottom.interpolate(t => t) }} > @@ -62,7 +74,7 @@ const Tile = React.memo(function Tile({ alt="" /> } - + {(scrollSpeed === 'slow' ) && !isVideo && // grid image )} - + {isExpanded && isVideo && ( // full size expanded video