Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(imageType): set image types to change object fit #862

Merged
merged 6 commits into from
Mar 17, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,79 @@
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 imageType = imageFits?.find((_, i) => i === index);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const imageFit

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:
imageType === ImageFit.Contain ? 'contain' : 'cover'
}}
src={imageUrl}
/>
{imageCaption && (
<Caption
className={cx(
styles.description,
showLightbox && styles.lightboxDescription
)}
content={imageCaption}
/>
)}
</div>
</div>
);
})}
</div>
);
};

export default StoryGalleryImage;
85 changes: 3 additions & 82 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,11 +33,6 @@
.fullscreenExitIcon:hover
fill: $textColor

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

.buttonContainer
.navIcon
margin: 0 emCalc(50px)
Expand All @@ -66,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 @@ -121,28 +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

.imageInfo
position: relative
display: flex
Expand Down Expand Up @@ -172,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 @@ -187,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)
66 changes: 15 additions & 51 deletions src/scripts/components/stories/story-gallery/story-gallery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +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 {ImageType} from '../../../types/image-type';
import {ImageFit} from '../../../types/image-fit';

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

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

const StoryMedia: FunctionComponent<Props> = ({
const StoryGallery: FunctionComponent<Props> = ({
images,
imageCaptions,
storyId,
mode,
imageTypes
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 @@ -62,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 @@ -104,46 +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 imageType = imageTypes?.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:
imageType === ImageType.Chart ? 'contain' : 'cover'
}}
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 @@ -157,4 +121,4 @@ const StoryMedia: FunctionComponent<Props> = ({
);
};

export default StoryMedia;
export default StoryGallery;
Loading