Skip to content

Commit

Permalink
feat(imageType): set image types to change object fit (#862)
Browse files Browse the repository at this point in the history
* feat(imageType): set image types to change object fit

* refactor(sliderImage): move images to own component, rename enum

* refactor(imageFit): change variable name
  • Loading branch information
KatvonRivia authored Mar 17, 2021
1 parent b60527a commit 37e91eb
Show file tree
Hide file tree
Showing 7 changed files with 183 additions and 125 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
@require '../../../../variables.styl'

.lightboxStoryGallery
.slider
align-items: center
height: 100%

.sliderImage
display: flex
justify-content: center
align-items: center
width: 100%
height: 100%

.imageContainer
display: flex
flex-direction: column
justify-content: center
width: 95%
height: 95%

.photo
flex: 1
width: 100%
height: 0

.lightboxDescription
position: inherit
overflow: hidden
padding: emCalc(15px)
height: emCalc(170px, 16)
background: none
pointer-events: none

> div
overflow-y: auto
margin: 0 auto
max-width: 50%
max-height: 100%
width: fit-content
height: 100%
-webkit-line-clamp: initial

.slider
display: flex
height: 100%

.transition
transition: transform ease-out 0.5s

.sliderImage
height: 100%

.imageContainer
position: relative
display: flex
flex-direction: column
width: 100%
height: 100%

.photo
flex: 1
width: 100%
height: 0

@media screen and (max-width: 480px)
.lightboxStoryGallery
.imageContainer
max-width: 100%
max-height: 100%
background-color: $plainBlack

.lightboxDescription
pointer-events: none

> div
overflow: hidden
padding: 0
max-width: 100%
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import React, {FunctionComponent} from 'react';
import cx from 'classnames';

import {getStoryAssetUrl} from '../../../libs/get-story-asset-urls';
import Caption from '../caption/caption';

import {ImageFit} from '../../../types/image-fit';

import styles from './story-gallery-image.styl';

interface Props {
images: string[];
imageCaptions?: string[];
imageFits?: ImageFit[];
storyId: string;
currentIndex: number;
showLightbox: boolean;
}

const StoryGalleryImage: FunctionComponent<Props> = ({
images,
imageCaptions,
storyId,
imageFits,
currentIndex,
showLightbox
}) => {
const containerWidth = images.length * 100;
const imageWidth = 100 / images.length;
const imgClasses = cx(
styles.slider,
showLightbox && styles.lightboxStoryGallery,
images.length > 1 && styles.transition
);

return (
<div
className={imgClasses}
style={{
width: `${containerWidth}%`,
transform: `translateX(-${imageWidth * currentIndex}%)`
}}>
{images.map((image, index) => {
const imageCaption = imageCaptions?.find((_, i) => i === index);
const imageFit = imageFits?.find((_, i) => i === index);
const imageUrl = getStoryAssetUrl(storyId, image);

return (
<div
className={styles.sliderImage}
key={index}
style={{width: `${imageWidth}%`}}>
<div className={styles.imageContainer}>
<img
className={styles.photo}
style={{
objectFit: imageFit === ImageFit.Contain ? 'contain' : 'cover'
}}
src={imageUrl}
/>
{imageCaption && (
<Caption
className={cx(
styles.description,
showLightbox && styles.lightboxDescription
)}
content={imageCaption}
/>
)}
</div>
</div>
);
})}
</div>
);
};

export default StoryGalleryImage;
87 changes: 3 additions & 84 deletions src/scripts/components/stories/story-gallery/story-gallery.styl
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,6 @@
height: 100%
background-color: rgba($plainBlack, 0.8)

.slider
align-items: center
height: 100%

.sliderImage
display: flex
justify-content: center
align-items: center
width: 100%
height: 100%

.imageContainer
display: flex
flex-direction: column
justify-content: center
width: 95%
height: 95%

.fullscreenExitIcon
position: absolute
top: 2%
Expand All @@ -51,12 +33,6 @@
.fullscreenExitIcon:hover
fill: $textColor

.photo
flex: 1
width: 100%
height: 0
object-fit: cover

.buttonContainer
.navIcon
margin: 0 emCalc(50px)
Expand All @@ -67,23 +43,6 @@
left: 0
z-index: 2

.lightboxDescription
position: inherit
overflow: hidden
padding: emCalc(15px)
height: emCalc(170px, 16)
background: none
pointer-events: none

> div
overflow-y: auto
margin: 0 auto
max-width: 50%
max-height: 100%
width: fit-content
height: 100%
-webkit-line-clamp: initial

.buttonContainer
position: absolute
top: 50%
Expand Down Expand Up @@ -122,29 +81,6 @@
.fullscreenIcon:hover
fill: $textColor

.slider
display: flex
height: 100%

.transition
transition: transform ease-out 0.5s

.sliderImage
height: 100%

.imageContainer
position: relative
display: flex
flex-direction: column
width: 100%
height: 100%

.photo
flex: 1
width: 100%
height: 0
object-fit: cover

.imageInfo
position: relative
display: flex
Expand Down Expand Up @@ -174,7 +110,6 @@
border: 1px solid $textDefault
border-radius: 50%
background: rgba($textDefault, 0.31)
// box-shadow: 2px 2px 5px 0px #ccc

.currentProgress
margin: 0 remCalc(5px)
Expand All @@ -189,22 +124,6 @@
padding: 0

.lightboxStoryGallery
.gallery
position: fixed

.imageContainer
max-width: 100%
max-height: 100%
background-color: $plainBlack

.buttonContainer
.navIcon
margin: 0 emCalc(5px)

.lightboxDescription
pointer-events: none

> div
overflow: hidden
padding: 0
max-width: 100%
.buttonContainer
.navIcon
margin: 0 emCalc(5px)
53 changes: 14 additions & 39 deletions src/scripts/components/stories/story-gallery/story-gallery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,31 @@ import cx from 'classnames';
import {PreviousIcon} from '../../main/icons/previous-icon';
import {NextIcon} from '../../main/icons/next-icon';
import {FullscreenIcon} from '../../main/icons/fullscreen-icon';
import {getStoryAssetUrl} from '../../../libs/get-story-asset-urls';
import {useInterval} from '../../../hooks/use-interval';
import config from '../../../config/main';
import Caption from '../caption/caption';
import {CloseIcon} from '../../main/icons/close-icon';
import StoryGalleryImage from '../story-gallery-image/story-gallery-image';

import {StoryMode} from '../../../types/story-mode';
import {ImageFit} from '../../../types/image-fit';

import styles from './story-gallery.styl';

interface Props {
images: string[];
imageCaptions?: string[];
imageFits?: ImageFit[];
storyId: string;
mode: StoryMode | null;
}

const StoryMedia: FunctionComponent<Props> = ({
const StoryGallery: FunctionComponent<Props> = ({
images,
imageCaptions,
storyId,
imageFits,
mode
}) => {
const containerWidth = images.length * 100;
const imageWidth = 100 / images.length;
const [currentIndex, setCurrentIndex] = useState(0);
const [showLightbox, setShowLightbox] = useState(false);
const showPrevButton = currentIndex > 0;
Expand Down Expand Up @@ -59,7 +59,6 @@ const StoryMedia: FunctionComponent<Props> = ({
setCurrentIndex(currentIndex + 1);
};

const imgClasses = cx(styles.slider, images.length > 1 && styles.transition);
const storyGalleryClasses = cx(
styles.storyGallery,
showLightbox && styles.lightboxStoryGallery
Expand Down Expand Up @@ -101,38 +100,14 @@ const StoryMedia: FunctionComponent<Props> = ({
<CloseIcon />
</div>
)}

<div
className={imgClasses}
style={{
width: `${containerWidth}%`,
transform: `translateX(-${imageWidth * currentIndex}%)`
}}>
{images.map((image, index) => {
const imageCaption = imageCaptions?.find((_, i) => i === index);
const imageUrl = getStoryAssetUrl(storyId, image);

return (
<div
className={styles.sliderImage}
key={index}
style={{width: `${imageWidth}%`}}>
<div className={styles.imageContainer}>
<img className={styles.photo} src={imageUrl} />
{imageCaption && (
<Caption
className={cx(
styles.description,
showLightbox && styles.lightboxDescription
)}
content={imageCaption}
/>
)}
</div>
</div>
);
})}
</div>
<StoryGalleryImage
images={images}
imageCaptions={imageCaptions}
storyId={storyId}
imageFits={imageFits}
currentIndex={currentIndex}
showLightbox={showLightbox}
/>
<div className={styles.buttonContainer}>
<div onClick={onPrevClick} className={prevIconClasses}>
<PreviousIcon />
Expand All @@ -146,4 +121,4 @@ const StoryMedia: FunctionComponent<Props> = ({
);
};

export default StoryMedia;
export default StoryGallery;
Loading

0 comments on commit 37e91eb

Please sign in to comment.