Skip to content

Commit

Permalink
Styling for 'medias' component, supporting 1 or 2 images. DDFFORM-73
Browse files Browse the repository at this point in the history
  • Loading branch information
rasben committed Dec 15, 2023
1 parent 13c6838 commit 3a7a3e1
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 6 deletions.
1 change: 1 addition & 0 deletions base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
@import "./src/stories/Library/event-description/event-description";
@import "./src/stories/Library/link-with-icon/link-with-icon";
@import "./src/stories/Library/rich-text/rich-text";
@import "./src/stories/Library/medias/medias";

// Autosuggest block styling needs to be loaded before the rest of the scss for autosuggest
@import "./src/stories/Blocks/autosuggest/autosuggest";
Expand Down
14 changes: 8 additions & 6 deletions src/stories/Library/image-credited/ImageCredited.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { FC } from "react";
type ImageCreditedProps = {
src: string;
alt?: string;
description: string;
year: string;
description?: string;
year?: string;
className?: string;
};

Expand All @@ -21,10 +21,12 @@ const ImageCredited: FC<ImageCreditedProps> = ({
{src ? (
<>
<img src={src} className="image-credited__img" alt={alt} />
<figcaption className="image-credited__info">
<span>{description}</span>
<span>{year}</span>
</figcaption>
{(description || year) && (
<figcaption className="image-credited__info">
<span>{description}</span>
<span>{year}</span>
</figcaption>
)}
</>
) : (
<div className="image-credited__no-image" />
Expand Down
40 changes: 40 additions & 0 deletions src/stories/Library/medias/Medias.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { ComponentStory, ComponentMeta } from "@storybook/react";
import { withDesign } from "storybook-addon-designs";
import Medias from "./Medias";
import ImageCredited from "../image-credited/ImageCredited";

export default {
title: "Library / Medias",
component: Medias,
decorators: [withDesign],
argTypes: {
items: {
// Disabling controls, as the different variations are added already.
control: false,
},
},
parameters: {
design: {
type: "figma",
url: "https://www.figma.com/file/Zx9GrkFA3l4ISvyZD2q0Qi/Designsystem?type=design&node-id=7477-39100&mode=design&t=SREzD6mFi3A15ap4-4",
},
},
} as ComponentMeta<typeof Medias>;

const Template: ComponentStory<typeof Medias> = (args) => <Medias {...args} />;

export const Multiple = Template.bind({});
Multiple.args = {
items: [
<ImageCredited
src="https://i.imgur.com/0Fis99n.jpeg"
description="Happy dog is Happy"
/>,
<ImageCredited src="https://i.imgur.com/KYhYZkp.jpeg" />,
],
};

export const Single = Template.bind({});
Single.args = {
items: [<ImageCredited src="https://i.imgur.com/KYhYZkp.jpeg" />],
};
31 changes: 31 additions & 0 deletions src/stories/Library/medias/Medias.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { FC, ReactNode } from "react";
import clsx from "clsx";

type MediasProps = {
items: ReactNode[];
};

const Medias: FC<MediasProps> = ({ items }) => {
const classes = clsx("medias", {
"medias--multiple": items.length > 1,
"medias--single": items.length <= 1,
});

return (
<div className={classes}>
{items.map((item, index) => {
const itemClasses = clsx("medias__item", {
"medias__item--last": index === items.length - 1,
});

return (
<div key={index} className={itemClasses}>
{item}
</div>
);
})}
</div>
);
};

export default Medias;
68 changes: 68 additions & 0 deletions src/stories/Library/medias/medias.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
$_medias-breakpoint: 550px;

.medias__item {
width: 100%;
box-sizing: border-box;

img {
width: 100%;
height: auto;
aspect-ratio: 33 / 25;
object-fit: cover;
}
}

.medias--single {
max-width: $layout__max-width--single-media;
margin: auto;

.medias__item {
padding: 0 $s-md;
}
}

@include media-query($_medias-breakpoint) {
.medias--multiple {
display: grid;
grid-gap: 8%;
grid-template-columns: auto 40%;
}

.medias__item {
width: 100%;
min-width: 250px;
}

.medias__item--last {
margin-top: 4rem;
}
}

@include media-query($_medias-breakpoint, "max-width") {
.medias--multiple {
.medias__item {
max-width: 330px;
padding-right: $s-lg;
}
.medias__item--last {
max-width: 300px;
margin-top: $s-md;
margin-left: auto;
padding-left: $s-lg;
padding-right: 0;
}
}
}

.medias--multiple {
max-width: $layout__max-width--multiple-medias;
//max-width: 900px;
margin: auto;

.medias__item--last {
img {
aspect-ratio: 1 / 1;
object-fit: cover;
}
}
}
2 changes: 2 additions & 0 deletions src/styles/scss/tools/variables.layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ $layout__max-width--small: 768px;
$layout__max-width--large: 1440px;

$layout__max-width--text: 780px;
$layout__max-width--single-media: 896px;
$layout__max-width--multiple-medias: 1240px;

0 comments on commit 3a7a3e1

Please sign in to comment.