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

[C] re-write image shaper, wire up captions, etc. #74

Merged
merged 1 commit into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
53 changes: 45 additions & 8 deletions components/content-blocks/Image/Image.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { FunctionComponent } from "react";
import { graphql, useFragment, FragmentType } from "@/gql/public-schema";
import { useTranslation } from "react-i18next";
import withModal from "@/components/hoc/withModal/withModal";
import { BaseContentBlockProps } from "@/components/shapes";
import { imageShaper } from "@/helpers";
import { fluidScale } from "@rubin-epo/epo-react-lib/styles";
import * as Styled from "./styles";

const Fragment = graphql(`
Expand All @@ -13,12 +15,20 @@ const Fragment = graphql(`
image {
url {
directUrlPreview
directUrlOriginal
PNG
HighJPG
LowJPG
preview
}
width
height
additional {
metadata: additional {
AltTextEN
AltTextES
CaptionEN
CaptionES
Credit
}
}
}
Expand All @@ -35,12 +45,42 @@ interface ImageContentBlockProps extends BaseContentBlockProps {
const ImageContentBlock: FunctionComponent<ImageContentBlockProps> = (
props
) => {
const { t } = useTranslation();
const { data, site, isOpen, openModal } = props;
const { caption, layout, image } = useFragment(Fragment, data);
const {
layout,
image: rawImage,
caption: fallbackCaption = "",
} = useFragment(Fragment, data);
const finalLayout = isOpen ? "vertical" : layout;

const image = imageShaper(site, rawImage[0]);

console.log({ image });

if (!image) return null;

const { width, caption = fallbackCaption, credit } = image;

const figCaption = `${caption !== null ? caption : ""}${
credit
? ` ${t("translation:image.credit", {
credit,
interpolation: { escapeValue: false },
})}`
: ""
}`;

return (
<Styled.Container className="content-block">
<Styled.Container
className="content-block"
style={{
"--max-image-width": isOpen ? `${width}px` : "auto",
"--image-content-block-padding": isOpen
? 0
: fluidScale("20px", "10px"),
}}
>
{!isOpen && (
<Styled.ExpandContract
onToggle={openModal}
Expand All @@ -49,15 +89,12 @@ const ImageContentBlock: FunctionComponent<ImageContentBlockProps> = (
/>
)}
<Styled.Figure
caption={caption}
caption={figCaption}
$layout={finalLayout}
$darkMode={isOpen}
withBackground={!isOpen}
>
<Styled.Image
image={imageShaper(site, image[0])}
$layout={finalLayout}
/>
<Styled.Image image={image} $layout={finalLayout} />
</Styled.Figure>
</Styled.Container>
);
Expand Down
11 changes: 7 additions & 4 deletions components/content-blocks/Image/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@ import {
Image as BaseImage,
} from "@rubin-epo/epo-react-lib";
import BaseExpandContract from "@/atomic/ExpandContract/ExpandContract";
import { fluidScale } from "@rubin-epo/epo-react-lib/styles";
import { BREAK_PHABLET } from "@/styles/globalStyles";

interface LayoutProp {
$layout: "vertical" | "horizontal";
}

export const Container = styled.section`
--image-content-block-padding: ${fluidScale("20px", "10px")};
align-self: center;
max-width: var(--max-image-width);
width: 100%;
position: relative;
`;

export const Figure = styled(BaseFigure)<LayoutProp & { $darkMode: boolean }>`
export const Figure = styled(BaseFigure)<
LayoutProp & { $darkMode: boolean; $layout: string }
>`
${({ $layout, $darkMode }) => css`
${$darkMode &&
css`
Expand All @@ -33,7 +36,7 @@ export const Figure = styled(BaseFigure)<LayoutProp & { $darkMode: boolean }>`
padding: 0;
}
`}
padding: ${$darkMode ? 0 : "var(--image-content-block-padding)"};
padding: var(--image-content-block-padding, 0);
`}

&:after {
Expand Down
1 change: 0 additions & 1 deletion components/shapes/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export type { default as Category } from "./category";
export type { default as BaseContentBlockProps } from "./contentBlock";
export type { Image } from "./image";
export type { InternalLink, InternalLinkWithChildren } from "./link";
export type { Locale, Localized } from "./locale";
export type { default as PageData } from "./page";
Expand Down
9 changes: 8 additions & 1 deletion components/templates/InvestigationLandingPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,19 @@ const Fragment = graphql(`
image {
url {
directUrlPreview
directUrlOriginal
PNG
HighJPG
LowJPG
}
width
height
additional {
metadata: additional {
AltTextEN
AltTextES
CaptionEN
CaptionES
Credit
}
}
children {
Expand Down
Loading
Loading