From 8cc7a68c5db3aa9a24e7860d0b27406c5ebd4c0e Mon Sep 17 00:00:00 2001 From: Benjamin Rasmussen Date: Tue, 12 Dec 2023 23:39:12 +0100 Subject: [PATCH] Styling for 'medias' component, supporting 1 or 2 images. DDFFORM-73 --- base.scss | 1 + .../Library/image-credited/ImageCredited.tsx | 10 +-- src/stories/Library/medias/Medias.stories.tsx | 39 +++++++++++ src/stories/Library/medias/Medias.tsx | 37 ++++++++++ src/stories/Library/medias/medias.scss | 68 +++++++++++++++++++ src/styles/scss/tools/variables.layout.scss | 2 + 6 files changed, 153 insertions(+), 4 deletions(-) create mode 100644 src/stories/Library/medias/Medias.stories.tsx create mode 100644 src/stories/Library/medias/Medias.tsx create mode 100644 src/stories/Library/medias/medias.scss diff --git a/base.scss b/base.scss index 9db830bea..7ba8e3371 100644 --- a/base.scss +++ b/base.scss @@ -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"; diff --git a/src/stories/Library/image-credited/ImageCredited.tsx b/src/stories/Library/image-credited/ImageCredited.tsx index a001caab8..202c7fb8b 100644 --- a/src/stories/Library/image-credited/ImageCredited.tsx +++ b/src/stories/Library/image-credited/ImageCredited.tsx @@ -1,11 +1,11 @@ import clsx from "clsx"; import { FC } from "react"; -type ImageCreditedProps = { +export type ImageCreditedProps = { src: string; alt?: string; - description: string; - year: string; + description?: string; + year?: string; className?: string; }; @@ -18,7 +18,9 @@ const ImageCredited: FC = ({ }) => { return (
- {alt} +
+ {alt} +
{description} {year} diff --git a/src/stories/Library/medias/Medias.stories.tsx b/src/stories/Library/medias/Medias.stories.tsx new file mode 100644 index 000000000..50710614f --- /dev/null +++ b/src/stories/Library/medias/Medias.stories.tsx @@ -0,0 +1,39 @@ +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: { + 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; + +const Template: ComponentStory = (args) => ; + +export const Multiple = Template.bind({}); +Multiple.args = { + items: [ + , + , + ], +}; + +export const Single = Template.bind({}); +Single.args = { + items: [], +}; diff --git a/src/stories/Library/medias/Medias.tsx b/src/stories/Library/medias/Medias.tsx new file mode 100644 index 000000000..ef1bc6a4a --- /dev/null +++ b/src/stories/Library/medias/Medias.tsx @@ -0,0 +1,37 @@ +import { FC, ReactNode } from "react"; + +type MediasProps = { + items: ReactNode[]; +}; + +const Medias: FC = ({ items }) => { + let classes = "medias"; + + if (items.length > 1) { + classes += " medias--multiple"; + } else { + classes += " medias--single"; + } + + return ( +
+ {items.map((item, index) => { + let itemClasses = "medias__item"; + + if (index === 0) { + itemClasses += " medias__item--first"; + } else if (index === items.length - 1) { + itemClasses += " medias__item--last"; + } + + return ( +
+ {item} +
+ ); + })} +
+ ); +}; + +export default Medias; diff --git a/src/stories/Library/medias/medias.scss b/src/stories/Library/medias/medias.scss new file mode 100644 index 000000000..b724b172c --- /dev/null +++ b/src/stories/Library/medias/medias.scss @@ -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; + } + } +} diff --git a/src/styles/scss/tools/variables.layout.scss b/src/styles/scss/tools/variables.layout.scss index 637aa2ab4..39eeb26b4 100644 --- a/src/styles/scss/tools/variables.layout.scss +++ b/src/styles/scss/tools/variables.layout.scss @@ -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;