Skip to content

Commit 15ebc1c

Browse files
committed
feat: document type asset pages
1 parent de9c0e3 commit 15ebc1c

File tree

22 files changed

+276
-136
lines changed

22 files changed

+276
-136
lines changed

app/[locale]/gallery/collections/[gallery]/[asset]/page.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import ImageSizes from "@/components/organisms/gallery/metadata/Sizes";
1212
import AssetTags from "@/components/organisms/gallery/metadata/Tags";
1313
import CantoImage from "@/components/organisms/gallery/CantoImage";
1414
import CantoVideo from "@/components/organisms/gallery/CantoVideo";
15+
import CantoDocument from "@/components/organisms/gallery/CantoDocument";
1516
import AssetMetadata from "@/components/organisms/gallery/metadata/Asset";
1617

1718
export async function generateMetadata({
@@ -29,6 +30,7 @@ export async function generateMetadata({
2930
const assetComponent: Record<SupportedCantoAssetScheme, ComponentType> = {
3031
image: CantoImage,
3132
video: CantoVideo,
33+
document: CantoDocument,
3234
};
3335

3436
const GalleryAsset: FunctionComponent<GalleryAssetProps> = async ({
@@ -72,17 +74,21 @@ const GalleryAsset: FunctionComponent<GalleryAssetProps> = async ({
7274
image: (
7375
<>
7476
<ImageSizes
75-
width={parseInt(width)}
76-
height={parseInt(height)}
77-
{...{ directUrlPreview, directUrlOriginal }}
77+
{...{ width, height, directUrlPreview, directUrlOriginal }}
7878
/>
7979
<AssetTags tags={validTagsOnly} parentUri={parentUri} />
8080
</>
8181
),
8282
video: <AssetTags tags={validTagsOnly} parentUri={parentUri} />,
83+
document: (
84+
<>
85+
<AssetTags tags={validTagsOnly} parentUri={parentUri} />
86+
</>
87+
),
8388
};
8489

8590
const Asset = assetComponent[scheme];
91+
const dateCreated = new Date(DateCreated);
8692

8793
return (
8894
<SingleMediaAsset
@@ -100,14 +106,15 @@ const GalleryAsset: FunctionComponent<GalleryAssetProps> = async ({
100106
parentUri,
101107
id,
102108
name,
109+
scheme,
110+
dateCreated,
103111
}}
104112
/>
105113
}
106114
metadataBlocks={
107115
<AssetMetadata
108116
size={parseInt(size)}
109-
dateCreated={new Date(DateCreated)}
110-
{...{ scheme, width, height }}
117+
{...{ scheme, width, height, dateCreated }}
111118
/>
112119
}
113120
metadataLinks={links[scheme]}

components/atomic/Tile/patterns/SlideTile/styles.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable */
22
import styled from "styled-components";
33
import { MixedLink as BaseMixedLink } from "@rubin-epo/epo-react-lib";
4-
import SharePopupComponent from "@/layout/SharePopup";
4+
import SharePopupComponent from "@/components/molecules/SharePopup";
55
import {
66
BREAK_PHABLET,
77
BREAK_PHABLET_MIN,
@@ -899,10 +899,12 @@ export const PlayButton = styled.span`
899899
`;
900900

901901
export const SharePopup = styled(SharePopupComponent)`
902+
--color-background-button: transparent;
903+
--color-font-button: var(--neutral40);
904+
902905
position: absolute;
903906
inset-block-end: 30px;
904907
inset-inline-end: 30px;
905-
color: var(--neutral40);
906908
907909
@media (max-width: ${BREAK_TABLET}) {
908910
display: none;

components/atomic/Tile/styles.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import styled from "styled-components";
33
import BaseMixedLink from "@rubin-epo/epo-react-lib/MixedLink";
44
import BaseResponsiveImage from "@rubin-epo/epo-react-lib/ResponsiveImage";
5-
import SharePopupComponent from "@/layout/SharePopup";
5+
import SharePopupComponent from "@/components/molecules/SharePopup";
66
import {
77
BREAK_PHABLET,
88
BREAK_PHABLET_MIN,
@@ -818,7 +818,7 @@ export const MixedLink = styled(BaseMixedLink)`
818818
}
819819
820820
&.padded-bottom {
821-
padding-bottom: 49px;
821+
padding-bottom: calc(15px + var(--size-spacing-m));
822822
823823
@media (max-width: ${BREAK_TABLET}) {
824824
padding-bottom: 0;
@@ -909,9 +909,8 @@ export const PlayButton = styled.span`
909909

910910
export const SharePopup = styled(SharePopupComponent)`
911911
position: absolute;
912-
right: 12px;
913-
bottom: 0;
914-
color: var(--neutral40);
912+
inset-block-end: 15px;
913+
inset-inline-end: 15px;
915914
916915
@media (max-width: ${BREAK_TABLET}) {
917916
display: none;

components/content-blocks/Callout/CalloutEntry/styles.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import styled from "styled-components";
22
import { MixedLink } from "@rubin-epo/epo-react-lib";
3-
import SharePopupComponent from "@/layout/SharePopup";
3+
import SharePopupComponent from "@/components/molecules/SharePopup";
44
import {
55
fluidScale,
66
containerRegular,
@@ -201,10 +201,12 @@ export const FooterButton = styled(MixedLink)`
201201
`;
202202

203203
export const SharePopup = styled(SharePopupComponent)`
204+
--color-background-button: transparent;
205+
--color-font-button: var(--neutral40);
206+
204207
position: absolute;
205208
inset-block-end: 30px;
206209
inset-inline-end: 30px;
207-
color: var(--neutral40);
208210
209211
@media (max-width: ${tokens.BREAK_TABLET}) {
210212
display: none;

components/layout/SharePopup/index.js

Lines changed: 0 additions & 56 deletions
This file was deleted.

components/layout/SharePopup/styles.js

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
"use client";
2+
import { FC, useState } from "react";
3+
import { Popover } from "@headlessui/react";
4+
import { usePopper } from "react-popper";
5+
import { useTranslation } from "react-i18next";
6+
import IconComposer from "@rubin-epo/epo-react-lib/IconComposer";
7+
import { isAbsoluteUrl } from "@/helpers";
8+
import ShareButtons from "@/atomic/Share";
9+
import styles from "./styles.module.css";
10+
11+
const BASE_URL = process.env.NEXT_PUBLIC_BASE_URL;
12+
13+
function createFinalUrl(url: string) {
14+
if (isAbsoluteUrl(url)) return url;
15+
16+
const urlObj = new URL(url, BASE_URL);
17+
return urlObj.toString();
18+
}
19+
20+
interface SharePopupProps {
21+
title: string;
22+
url: string;
23+
className?: string;
24+
}
25+
26+
const SharePopup: FC<SharePopupProps> = ({ title, url, className }) => {
27+
const { t } = useTranslation();
28+
const [referenceElement, setReferenceElement] =
29+
useState<HTMLButtonElement | null>(null);
30+
const [popperElement, setPopperElement] = useState<HTMLDivElement | null>(
31+
null
32+
);
33+
const { styles: popperStyles, attributes } = usePopper(
34+
referenceElement,
35+
popperElement,
36+
{
37+
modifiers: [{ name: "offset", options: { offset: [0, 10] } }],
38+
}
39+
);
40+
41+
return (
42+
<Popover className={className}>
43+
<Popover.Button ref={setReferenceElement} className={styles.button}>
44+
<IconComposer size="0.75em" icon="shareToggle" />
45+
<span className="a-hidden">{t("share.label_item", { title })}</span>
46+
</Popover.Button>
47+
<Popover.Panel
48+
ref={setPopperElement}
49+
style={popperStyles.popper}
50+
{...attributes.popper}
51+
className={styles.panel}
52+
>
53+
<ShareButtons title={title} url={createFinalUrl(url)} />
54+
</Popover.Panel>
55+
</Popover>
56+
);
57+
};
58+
59+
SharePopup.displayName = "Layout.SharePopup";
60+
61+
export default SharePopup;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
.button {
2+
aspect-ratio: 1;
3+
background-color: var(
4+
--color-background-button,
5+
var(--color-background-tile-light)
6+
);
7+
border-radius: calc(var(--size-spacing-m) / 2);
8+
border: 1px solid transparent;
9+
box-shadow: 0px 0px 15px 0px rgba(0, 0, 0, 16%);
10+
color: var(--color-font-button, #313333);
11+
font-size: var(--size-spacing-m);
12+
width: var(--size-spacing-m);
13+
display: flex;
14+
align-items: center;
15+
justify-content: center;
16+
17+
&:not(:disabled):hover,
18+
&[data-headlessui-state="open"] {
19+
border-color: var(--color-border-button-hover, #707070);
20+
outline: none;
21+
}
22+
23+
&:focus-visible {
24+
outline: none;
25+
}
26+
}
27+
28+
.panel {
29+
padding: var(--size-spacing-2xs);
30+
background-color: var(--white);
31+
border-radius: 5px;
32+
box-shadow: 5px 15px 35px 8px rgba(0, 0, 0, 13%);
33+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { FC } from "react";
2+
import { DigitalDocument } from "schema-dts";
3+
import Image from "next/image";
4+
import StructuredData from "@/components/atomic/StructuredData";
5+
import { CantoAssetDetailed } from "@/lib/api/galleries/schema";
6+
import { assetAlt } from "@/lib/api/canto/metadata";
7+
import { tokens } from "@rubin-epo/epo-react-lib/styles";
8+
import { resizeCantoImage } from "@/lib/api/canto/resize";
9+
10+
interface CantoDocumentProps {
11+
locale: string;
12+
asset: CantoAssetDetailed;
13+
}
14+
15+
const CantoDocument: FC<CantoDocumentProps> = ({ locale, asset }) => {
16+
const { additional, url, width, height } = asset;
17+
18+
const aspectRatio = width / height;
19+
const landscapeSizes = `(max-width: ${tokens.BREAK_TABLET}) 100vw, 1435px`;
20+
const portraitSizes = `(max-width: ${tokens.BREAK_TABLET}) 100vw, 700px`;
21+
22+
const structuredData: DigitalDocument = {
23+
"@type": "DigitalDocument",
24+
size: asset.size,
25+
url: url.directUrlOriginal,
26+
creditText: asset.additional.Credit || undefined,
27+
encodingFormat: asset.default.ContentType,
28+
dateCreated: asset.default.DateCreated,
29+
thumbnailUrl: resizeCantoImage(url.directUrlPreview, 100),
30+
};
31+
32+
return (
33+
<>
34+
<StructuredData jsonLd={structuredData} />
35+
<Image
36+
{...{ width, height }}
37+
data-cy="canto-image"
38+
alt={assetAlt(additional, locale)}
39+
src={resizeCantoImage(url.directUrlPreview, 2050)}
40+
sizes={aspectRatio < 1 ? portraitSizes : landscapeSizes}
41+
quality={85}
42+
priority
43+
title={asset.name}
44+
/>
45+
</>
46+
);
47+
};
48+
49+
CantoDocument.displayName = "Organism.Gallery.CantoDocument";
50+
51+
export default CantoDocument;

components/organisms/gallery/CantoDownload/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const CantoDownload: FunctionComponent<CantoDownloadProps> = async ({
1919
<Buttonish
2020
data-cy="canto-download"
2121
url={`/api/canto/${scheme}/${contentId}/${directUrlOriginalHash}${search}`}
22-
text={t("gallery.download-original")}
22+
text={t(`gallery.download-${scheme}`)}
2323
download={searchParams.get("name")}
2424
rel="alternate"
2525
/>

0 commit comments

Comments
 (0)