-
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(imageType): set image types to change object fit (#862)
* 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
1 parent
b60527a
commit 37e91eb
Showing
7 changed files
with
183 additions
and
125 deletions.
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
src/scripts/components/stories/story-gallery-image/story-gallery-image.styl
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,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% |
78 changes: 78 additions & 0 deletions
78
src/scripts/components/stories/story-gallery-image/story-gallery-image.tsx
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,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; |
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
Oops, something went wrong.