-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add figure customization options (#236)
- Loading branch information
1 parent
f9884f6
commit 3b869a9
Showing
10 changed files
with
197 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { | ||
IIIFExternalWebResource, | ||
InternationalString, | ||
} from "@iiif/presentation-3"; | ||
import { render, screen } from "@testing-library/react"; | ||
|
||
import FigureThumbnail from "./Thumbnail"; | ||
import React from "react"; | ||
|
||
const body: IIIFExternalWebResource = { | ||
id: "https://example.com/iiif/2/image/example.jpg", | ||
type: "Image", | ||
format: "image/jpeg", | ||
width: 500, | ||
height: 500, | ||
service: [ | ||
{ | ||
id: "https://example.com/iiif/2/image", | ||
type: "ImageService2", | ||
profile: "level2", | ||
}, | ||
], | ||
}; | ||
|
||
const label: InternationalString = { | ||
en: ["Test label"], | ||
}; | ||
|
||
describe("<FigureThumbnail />", () => { | ||
it("renders the thumbnail with label as alt", () => { | ||
render(<FigureThumbnail body={body} label={label} />); | ||
|
||
const thumbnail = screen.getByTestId("scroll-figure-thumbnail"); | ||
expect(thumbnail).toBeInTheDocument(); | ||
|
||
const img = thumbnail.querySelector("img"); | ||
expect(img).toBeInTheDocument(); | ||
expect(img).toHaveAttribute( | ||
"src", | ||
"https://example.com/iiif/2/image/full/500,500/0/default.jpg", | ||
); | ||
expect(img).toHaveAttribute("alt", "Test label"); | ||
}); | ||
|
||
it("renders the thumbnail without a service", () => { | ||
render(<FigureThumbnail body={{ ...body, service: undefined }} />); | ||
|
||
const img = screen.getByRole("img"); | ||
expect(img).toBeInTheDocument(); | ||
expect(img).toHaveAttribute( | ||
"src", | ||
"https://example.com/iiif/2/image/example.jpg", | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { | ||
IIIFExternalWebResource, | ||
InternationalString, | ||
} from "@iiif/presentation-3"; | ||
|
||
import { Thumbnail as CloverPrimitivesThumbnail } from "src/components/Primitives"; | ||
import React from "react"; | ||
import { StyledImageViewer } from "src/components/Scroll/Figure/ImageViewer.styled"; | ||
|
||
interface FigureThumbnailProps { | ||
body: IIIFExternalWebResource; | ||
label?: InternationalString | null; | ||
} | ||
|
||
const FigureThumbnail: React.FC<FigureThumbnailProps> = ({ body, label }) => { | ||
return ( | ||
<StyledImageViewer data-testid="scroll-figure-thumbnail"> | ||
<CloverPrimitivesThumbnail | ||
thumbnail={[body]} | ||
style={{ | ||
width: "100%", | ||
height: "100%", | ||
objectFit: "contain", | ||
objectPosition: "center", | ||
}} | ||
altAsLabel={label as InternationalString} | ||
/> | ||
</StyledImageViewer> | ||
); | ||
}; | ||
|
||
export default React.memo(FigureThumbnail); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters