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 1 commit
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
Expand Up @@ -55,7 +55,6 @@
flex: 1
width: 100%
height: 0
object-fit: cover

.buttonContainer
.navIcon
Expand Down Expand Up @@ -143,7 +142,6 @@
flex: 1
width: 100%
height: 0
object-fit: cover

.imageInfo
position: relative
Expand Down
15 changes: 13 additions & 2 deletions src/scripts/components/stories/story-gallery/story-gallery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import Caption from '../caption/caption';
import {CloseIcon} from '../../main/icons/close-icon';

import {StoryMode} from '../../../types/story-mode';
import {ImageType} from '../../../types/image-type';

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

interface Props {
images: string[];
imageCaptions?: string[];
imageTypes?: ImageType[];
storyId: string;
mode: StoryMode | null;
}
Expand All @@ -25,7 +27,8 @@ const StoryMedia: FunctionComponent<Props> = ({
images,
imageCaptions,
storyId,
mode
mode,
imageTypes
}) => {
const containerWidth = images.length * 100;
const imageWidth = 100 / images.length;
Expand Down Expand Up @@ -110,6 +113,7 @@ const StoryMedia: FunctionComponent<Props> = ({
}}>
{images.map((image, index) => {
const imageCaption = imageCaptions?.find((_, i) => i === index);
const imageType = imageTypes?.find((_, i) => i === index);
const imageUrl = getStoryAssetUrl(storyId, image);

return (
Expand All @@ -118,7 +122,14 @@ const StoryMedia: FunctionComponent<Props> = ({
key={index}
style={{width: `${imageWidth}%`}}>
<div className={styles.imageContainer}>
<img className={styles.photo} src={imageUrl} />
<img
Copy link
Contributor

Choose a reason for hiding this comment

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

The story gallery component is getting really big. Could you clean it up by pulling out a StoryGalleryImage component with captions for example

Copy link
Member Author

Choose a reason for hiding this comment

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

aye 👌 will do

className={styles.photo}
style={{
objectFit:
imageType === ImageType.Chart ? 'contain' : 'cover'
}}
src={imageUrl}
/>
{imageCaption && (
<Caption
className={cx(
Expand Down
1 change: 1 addition & 0 deletions src/scripts/components/stories/story/story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ const Story: FunctionComponent = () => {
<StoryMedia
mode={mode}
images={slide.images}
imageTypes={slide.imageTypes}
imageCaptions={slide.imageCaptions}
storyId={story.id}
/>
Expand Down
4 changes: 4 additions & 0 deletions src/scripts/types/image-type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export enum ImageType {
Photo = 'photo',
Chart = 'chart'
Copy link
Contributor

Choose a reason for hiding this comment

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

Chart is probably not the best type here. It could be any other image which should be contained. Why not call it what it is like 'contain' and 'cover'?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, i can change it. I just thought contain and cover would be a bit confusing in the story mapper.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes good point, but I guess labeling a photograph as "chart" just to display it as contained is more confusing. At least for me 😄

}
2 changes: 2 additions & 0 deletions src/scripts/types/story.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {GlobeView} from './globe-view';
import {StoryLayer} from './story-layer';
import {SlideType} from './slide-type';
import {Marker} from './marker-type';
import {ImageType} from './image-type';

export interface Story {
id: string;
Expand All @@ -14,6 +15,7 @@ export interface Slide {
shortText?: string;
images?: string[];
imageCaptions?: string[];
imageTypes?: ImageType[];
videoId?: string;
layer?: StoryLayer[];
layerDescription?: string;
Expand Down