-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(story-gallery): add gallery to story sidepanel
- Loading branch information
1 parent
8f3b101
commit d7497ed
Showing
6 changed files
with
119 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
.storyGallery | ||
position: relative | ||
overflow: hidden | ||
width: 100% | ||
|
||
.buttonContainer | ||
position: absolute | ||
top: 50% | ||
z-index: 1 | ||
display: flex | ||
justify-content: space-between | ||
width: 100% | ||
transform: translateY(-15px) | ||
pointer-events: none | ||
|
||
> * | ||
pointer-events: all | ||
fill: #fff | ||
|
||
.slider | ||
display: flex | ||
width: 100% | ||
height: 100% | ||
|
||
.sliderImage | ||
width: 100% | ||
height: 100% | ||
object-fit: cover |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import React, {FunctionComponent, useState} from 'react'; | ||
import {BackIcon} from '../icons/back-icon'; | ||
import {NextIcon} from '../icons/next-icon'; | ||
|
||
import styles from './story-gallery.styl'; | ||
|
||
interface Props { | ||
images: []; | ||
} | ||
|
||
const StoryGallery: FunctionComponent<Props> = ({images}) => { | ||
const imagesLength = images.length; | ||
const containerWidth = imagesLength * 100; | ||
const imageWidth = 100 / imagesLength; | ||
const [currentIndex, setCurrentIndex] = useState(0); | ||
const showBackButton = currentIndex > 0; | ||
const showNextButton = currentIndex < imagesLength - 1; | ||
|
||
const onBackClick = () => { | ||
if (currentIndex <= 0) { | ||
return null; | ||
} | ||
return setCurrentIndex(currentIndex - 1); | ||
}; | ||
|
||
const onNextClick = () => { | ||
if (currentIndex >= imagesLength - 1) { | ||
return null; | ||
} | ||
return setCurrentIndex(currentIndex + 1); | ||
}; | ||
|
||
return ( | ||
<div className={styles.storyGallery}> | ||
<div className={styles.buttonContainer}> | ||
<div onClick={onBackClick}>{showBackButton ? <BackIcon /> : null}</div> | ||
<div onClick={onNextClick}>{showNextButton ? <NextIcon /> : null}</div> | ||
</div> | ||
<div | ||
className={styles.slider} | ||
style={{ | ||
width: `${containerWidth}%`, | ||
transform: `translateX(-${imageWidth * currentIndex}%)`, | ||
transition: 'transform ease-out 0.50s' | ||
}}> | ||
{images.map((image, index) => ( | ||
<img | ||
className={styles.sliderImage} | ||
src={image} | ||
alt="img" | ||
key={index} | ||
style={{width: `${imageWidth}%`}} | ||
/> | ||
))} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default StoryGallery; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters