Skip to content

Commit

Permalink
feat(story-gallery): add gallery to story sidepanel
Browse files Browse the repository at this point in the history
  • Loading branch information
KatvonRivia committed Oct 29, 2019
1 parent 8f3b101 commit d7497ed
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 10 deletions.
5 changes: 4 additions & 1 deletion src/scripts/components/slide/slide.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import React, {FunctionComponent} from 'react';
import {Slide as SlideType} from '../../types/story';
import styles from './slide.styl';
import StoryGallery from '../story-gallery/story-gallery';

interface Props {
slide: SlideType;
}

const Slide: FunctionComponent<Props> = ({slide}) => (
<div className={styles.slide}>
<img src={slide.image} className={styles.previewImage} />
{slide.images && slide.images.length && (
<StoryGallery images={slide.images} />
)}
<div className={styles.content}>
<h1>{slide.title}</h1>
<p>{slide.bodytext}</p>
Expand Down
28 changes: 28 additions & 0 deletions src/scripts/components/story-gallery/story-gallery.styl
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
60 changes: 60 additions & 0 deletions src/scripts/components/story-gallery/story-gallery.tsx
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;
2 changes: 1 addition & 1 deletion src/scripts/types/story.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ export interface Slide {
title: string;
subtitle: string;
bodytext: string;
image: string;
images?: [];
flyTo: GlobeView;
}
17 changes: 13 additions & 4 deletions storage/stories/story1/story1-de.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
"title": "Story slide 1",
"subtitle": "Das ist story slide 1",
"bodytext": "Lorem ipsum dolor sit amet consectetur adipisicing elit. Iste veniam laborum necessitatibus suscipit commodi? Officia ipsum blanditiis itaque, fugiat nostrum, reiciendis doloribus perferendis quisquam iure dolorem dolorum, deleniti cupiditate soluta?",
"image": "https://storage.cloud.google.com/esa-cfs-storage/stories/story1/assets/story1.jpeg",
"images": [
"https://storage.cloud.google.com/esa-cfs-storage/stories/story1/assets/story1.jpeg",
"https://storage.cloud.google.com/esa-cfs-storage/stories/story1/assets/story2.jpeg"
],
"flyTo": {
"position": {
"height": 1000000,
Expand All @@ -23,7 +26,9 @@
"title": "Story slide 2",
"subtitle": "Das ist story slide 2",
"bodytext": "Exercitationem, sapiente. Praesentium quidem mollitia explicabo voluptatem aperiam deleniti ut sunt atque eaque, voluptate commodi in.",
"image": "https://storage.cloud.google.com/esa-cfs-storage/stories/story1/assets/story1.jpeg",
"images": [
"https://storage.cloud.google.com/esa-cfs-storage/stories/story1/assets/story1.jpeg"
],
"flyTo": {
"position": {
"height": 10000000,
Expand All @@ -41,13 +46,17 @@
"title": "Story slide 3",
"subtitle": "Das ist story slide 3",
"bodytext": "Lorem ipsum dolor sit amet consectetur adipisicing elit. Dolor option isi nobis quas ut.",
"image": "https://storage.cloud.google.com/esa-cfs-storage/stories/story1/assets/story1.jpeg"
"images": [
"https://storage.cloud.google.com/esa-cfs-storage/stories/story1/assets/story1.jpeg"
]
},
{
"title": "Story slide 4",
"subtitle": "Das ist story slide 4",
"bodytext": "Praesentium quidem mollitia explicabo voluptatem aperiam deleniti ut sunt atque eaque, voluptate commodi in.",
"image": "https://storage.cloud.google.com/esa-cfs-storage/stories/story1/assets/story1.jpeg"
"images": [
"https://storage.cloud.google.com/esa-cfs-storage/stories/story1/assets/story1.jpeg"
]
}
]
}
17 changes: 13 additions & 4 deletions storage/stories/story1/story1-en.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
"title": "Story slide 1",
"subtitle": "This is story slide 1",
"bodytext": "Lorem ipsum dolor sit amet consectetur adipisicing elit. Iste veniam laborum necessitatibus suscipit commodi? Officia ipsum blanditiis itaque, fugiat nostrum, reiciendis doloribus perferendis quisquam iure dolorem dolorum, deleniti cupiditate soluta?",
"image": "https://storage.cloud.google.com/esa-cfs-storage/stories/story1/assets/story1.jpeg",
"images": [
"https://storage.cloud.google.com/esa-cfs-storage/stories/story1/assets/story1.jpeg",
"https://storage.cloud.google.com/esa-cfs-storage/stories/story1/assets/story2.jpeg"
],
"flyTo": {
"position": {
"height": 1000000,
Expand All @@ -23,7 +26,9 @@
"title": "Story slide 2",
"subtitle": "This is story slide 2",
"bodytext": "Exercitationem, sapiente. Praesentium quidem mollitia explicabo voluptatem aperiam deleniti ut sunt atque eaque, voluptate commodi in.",
"image": "https://storage.cloud.google.com/esa-cfs-storage/stories/story1/assets/story1.jpeg",
"images": [
"https://storage.cloud.google.com/esa-cfs-storage/stories/story1/assets/story1.jpeg"
],
"flyTo": {
"position": {
"height": 10000000,
Expand All @@ -41,13 +46,17 @@
"title": "Story slide 3",
"subtitle": "This is story slide 3",
"bodytext": "Lorem ipsum dolor sit amet consectetur adipisicing elit. Dolor option isi nobis quas ut.",
"image": "https://storage.cloud.google.com/esa-cfs-storage/stories/story1/assets/story1.jpeg"
"images": [
"https://storage.cloud.google.com/esa-cfs-storage/stories/story1/assets/story1.jpeg"
]
},
{
"title": "Story slide 4",
"subtitle": "This is story slide 4",
"bodytext": "Praesentium quidem mollitia explicabo voluptatem aperiam deleniti ut sunt atque eaque, voluptate commodi in.",
"image": "https://storage.cloud.google.com/esa-cfs-storage/stories/story1/assets/story1.jpeg"
"images": [
"https://storage.cloud.google.com/esa-cfs-storage/stories/story1/assets/story1.jpeg"
]
}
]
}

0 comments on commit d7497ed

Please sign in to comment.