Skip to content
Closed
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
4 changes: 4 additions & 0 deletions components/Clover/CloverViewer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// next/dynamic resolves its target with `require.resolveWeak`, which fails on
// @nulib/clover's import-only `exports`. Dynamically importing this local
// module instead keeps the package behind an ordinary static ESM import.
export { default } from "@nulib/clover";
62 changes: 47 additions & 15 deletions components/Clover/SliderWrapper.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,52 @@
z-index: 0;
--slider-columns: 1;
--slider-gap: 19px;
--clover-thumbnail-width: 100%;
}
/* RC.2 sizes cards with CSS. Match the previous Swiper viewport breakpoints
and the numeric gaps/group sizes in SliderWrapper.tsx. */
.styledSliderIIIFWrapper :global(.clover-slider-slide) {
/* Clover 4's slider is a fixed-height strip of natural-width pictures. Keep
DC's column counts and gaps per breakpoint (formerly also mirrored by the
Clover 3 breakpoints in SliderWrapper.tsx; CSS is now the only source). */
.styledSliderIIIFWrapper :global(.clover-items) {
--clover-items-gap: var(--slider-gap);
}
/* Clover sets an inline `flex: 0 0 auto` on each item, so size it by width. */
.styledSliderIIIFWrapper :global(.clover-items-item) {
width: calc(
(100% - (var(--slider-columns) - 1) * var(--slider-gap)) /
var(--slider-columns)
);
min-width: 0;
}
.styledSliderIIIFWrapper :global(.clover-slider-item) {
.styledSliderIIIFWrapper :global(.clover-items-figure) {
grid-template-columns: 1fr;
}
/* Clover 3.x cropped every thumbnail to a square; Clover 4 keeps each
picture's own proportions. */
.styledSliderIIIFWrapper :global(.clover-items-picture) img {
width: 100%;
min-width: 0;
height: auto;
aspect-ratio: 1;
object-fit: cover;
}
/* Header: match Clover 3.x's purple title and pill-shaped "View all". */
.styledSliderIIIFWrapper :global(.clover-items-header) {
align-items: flex-end;
margin-bottom: var(--dc-space-legacy-4);
}
.styledSliderIIIFWrapper :global(.clover-items-title) {
font-family: var(--dc-font-northwestern-sans-regular);
font-weight: 400;
font-size: 1.25rem;
line-height: 1.12;
color: var(--dc-color-purple);
}
.styledSliderIIIFWrapper :global(.clover-items-homepage) {
padding: 0 var(--dc-space-legacy-3);
border-radius: 38px;
background-color: var(--dc-color-purple);
color: var(--dc-color-white);
font-size: var(--dc-font-size-gr3);
line-height: 1.4rem;
text-decoration: none;
}
@media (min-width: 334px) {
.styledSliderIIIFWrapper {
Expand Down Expand Up @@ -44,18 +77,17 @@
--slider-gap: 49.740556px;
}
}
.styledSliderIIIFWrapper :global(.clover-slider-header-view-all) {
color: var(--dc-color-white);
}
.styledSliderIIIFWrapper :global(.clover-slider-slide)[data-type="collection"] {
display: none;
}
@media (max-width: 575px) {
.styledSliderIIIFWrapper > div > div {
.styledSliderIIIFWrapper :global(.clover-items-header) {
flex-direction: column;
align-items: center;
text-align: center;
}
.styledSliderIIIFWrapper > div > div > div:last-child {
padding-top: var(--dc-space-gr2);
.styledSliderIIIFWrapper :global(.clover-items-homepage) {
margin-inline-start: 0;
margin-top: var(--dc-space-gr2);
}
.styledSliderIIIFWrapper :global(.clover-items-caption) {
text-align: center;
}
}
27 changes: 17 additions & 10 deletions components/Clover/SliderWrapper.test.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { render, waitFor } from "@testing-library/react";
import Slider from "@samvera/clover-iiif/slider";
import { Items } from "@nulib/clover";
import SliderWrapper from "./SliderWrapper";

jest.mock("@samvera/clover-iiif/slider", () => ({
jest.mock("@nulib/clover", () => ({
__esModule: true,
default: jest.fn(() => null),
Items: jest.fn(() => null),
}));

const originalFetch = global.fetch;
Expand All @@ -18,7 +18,10 @@ it("loads a collection with credentials and supplies the resolved items to Clove
type: "Collection",
label: { en: ["Collection"] },
summary: { en: ["Summary"] },
items: [{ id: "https://example.org/manifest", type: "Manifest" }],
items: [
{ id: "https://example.org/manifest", type: "Manifest" },
{ id: "https://example.org/nested", type: "Collection" },
],
};
const fetchMock = jest
.fn()
Expand All @@ -30,16 +33,20 @@ it("loads a collection with credentials and supplies the resolved items to Clove
customViewAll="/search?collection=test"
/>,
);
await waitFor(() => expect(Slider).toHaveBeenCalled());
await waitFor(() => expect(Items).toHaveBeenCalled());
expect(fetchMock).toHaveBeenCalledWith("https://example.org/collection", {
credentials: "include",
signal: expect.any(AbortSignal),
});
expect(jest.mocked(Slider).mock.calls[0][0]).toMatchObject({
items: collection.items,
label: collection.label,
summary: collection.summary,
options: { customViewAll: "/search?collection=test" },
expect(jest.mocked(Items).mock.calls[0][0]).toMatchObject({
layout: "slider",
request: { credentials: "include" },
iiifContent: {
items: [collection.items[0]],
label: collection.label,
summary: collection.summary,
homepage: [{ id: "/search?collection=test" }],
},
});
});

Expand Down
80 changes: 35 additions & 45 deletions components/Clover/SliderWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,9 @@
import styles from "@/components/Clover/SliderWrapper.module.css";
import Slider from "@samvera/clover-iiif/slider";
import type { SliderBreakpoints } from "@samvera/clover-iiif/slider";
import { CLOVER_REQUEST } from "@/components/Clover/clover-request";
import { Items } from "@nulib/clover";
import type { Collection } from "@iiif/presentation-3";
import { useEffect, useState } from "react";
import { gr, rem } from "@/styles/metrics";
import { width } from "@/styles/media";
const breakpoints: SliderBreakpoints = {
[width.xxs]: {
slidesPerGroup: 2,
spaceBetween: rem,
},
[width.xs]: {
slidesPerGroup: 2,
spaceBetween: rem,
},
[width.sm]: {
slidesPerGroup: 3,
spaceBetween: rem,
},
[width.md]: {
slidesPerGroup: 4,
spaceBetween: rem * gr(1),
},
[width.lg]: {
slidesPerGroup: 5,
spaceBetween: rem * gr(1),
},
[width.xl]: {
slidesPerGroup: 6,
spaceBetween: rem * gr(2),
},
};
import { useEffect, useMemo, useState } from "react";

const SliderIIIFWrapper = ({
collectionId,
customViewAll,
Expand All @@ -46,8 +19,8 @@ const SliderIIIFWrapper = ({
}>();
useEffect(() => {
const controller = new AbortController();
// RC.2 declares options.credentials but does not pass it to fetch.
// Resolve the collection here to preserve authenticated cross-origin access.
// Fetch here (rather than handing Clover the URL) so a failed request
// still reaches the page's error boundary and stale requests are aborted.
fetch(url, { credentials: "include", signal: controller.signal })
.then(async (response) => {
if (!response.ok)
Expand All @@ -60,24 +33,41 @@ const SliderIIIFWrapper = ({
});
return () => controller.abort();
}, [url]);

const collection = resource?.url === url ? resource.collection : undefined;
const iiifContent = useMemo(() => {
if (!collection) return undefined;
return {
...collection,
// Clover 3.x rendered nested collections and DC hid them with CSS;
// Clover 4 items carry no type attribute, so drop them here instead.
items: collection.items.filter((item) => item.type !== "Collection"),
// Clover 4's standalone Items links the resource's first homepage as
// "View all" (Clover 3.x's options.customViewAll).
homepage: [
{
id: customViewAll,
type: "Text",
format: "text/html",
label: collection.label,
},
],
};
}, [collection, customViewAll]);

if (resource?.url !== url) return null;
if (resource.error) throw resource.error;
if (!resource.collection) return null;
const collection = resource.collection;
if (!iiifContent) return null;

return (
<div className={styles.styledSliderIIIFWrapper}>
<Slider
items={collection.items}
label={collection.label}
summary={collection.summary}
align="start"
options={{
breakpoints: breakpoints,
credentials: "include",
customViewAll,
}}
<Items
layout="slider"
iiifContent={iiifContent}
request={CLOVER_REQUEST}
/>
</div>
);
};

export default SliderIIIFWrapper;
Loading
Loading