-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
10 changed files
with
295 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
--- | ||
title: Rendering | ||
--- | ||
|
||
import IIIFBadge from "docs/components/IIIFBadge"; | ||
import { Rendering } from "src/components/Primitives"; | ||
import { Tabs, Tab } from "nextra/components"; | ||
|
||
# Rendering | ||
|
||
The Rendering component is used to display a list of alternate formats related to a resource. Whereas SeeAlso is used | ||
to link to a machine-readable resource such as metadata, the Rendering component alerts users that the resource is | ||
available in another format such as PDF or ePub or has a related format. Because of the wide variety of formats that | ||
resources can be available in, the Rendering component is flexible and be of any media type and contain any type of | ||
data. | ||
|
||
<IIIFBadge | ||
href="https://iiif.io/api/presentation/3.0/#rendering" | ||
text={["rendering"]} | ||
/> | ||
|
||
<Tabs items={["Code", "Example", "HTML"]}> | ||
<Tab> | ||
```jsx | ||
<Rendering | ||
rendering={[ | ||
{ | ||
id: "https://fixtures.iiif.io/other/UCLA/kabuki_ezukushi_rtl.pdf", | ||
type: "Text", | ||
label: { | ||
en: ["PDF version"], | ||
}, | ||
format: "application/pdf", | ||
}, | ||
]} | ||
/> | ||
``` | ||
</Tab> | ||
<Tab> | ||
<Rendering | ||
rendering={[ | ||
{ | ||
id: "https://fixtures.iiif.io/other/UCLA/kabuki_ezukushi_rtl.pdf", | ||
type: "Text", | ||
label: { | ||
en: ["PDF version"], | ||
}, | ||
format: "application/pdf", | ||
}, | ||
]} | ||
/> | ||
</Tab> | ||
<Tab> | ||
```html | ||
<ul class="c-PJLV"> | ||
<li class="c-PJLV"> | ||
<a | ||
href="https://fixtures.iiif.io/other/UCLA/kabuki_ezukushi_rtl.pdf" | ||
target="_blank" | ||
> | ||
PDF version | ||
</a> | ||
</li> | ||
</ul> | ||
``` | ||
</Tab> | ||
</Tabs> | ||
|
||
## Usage | ||
|
||
### React | ||
|
||
```jsx | ||
import { Rendering } from "@samvera/clover-iiif/primitives"; | ||
|
||
const CustomRendering = ({ rendering }) => { | ||
return <Rendering rendering={rendering} />; | ||
}; | ||
|
||
export default CustomRendering; | ||
``` | ||
|
||
## API Reference | ||
|
||
| Prop | Type | Default | Required | | ||
| ----------- | ------------------------------------------------------------ | ------- | -------- | | ||
| `as` | `ol`, `ul` | `ul` | -- | | ||
| `rendering` | [rendering](https://iiif.io/api/presentation/3.0/#rendering) | -- | **Yes** | | ||
| `className` | `string`, `undefined` | -- | -- | | ||
| `style` | `CSSProperties`, `undefined` | -- | -- | | ||
| `lang` | `string`, `undefined` | -- | -- | | ||
| `title` | `string`, `undefined` | -- | -- | | ||
| `data-*` | `string`, `undefined` | -- | -- | | ||
| `aria-*` | `AriaAttributes`, `undefined` | -- | -- | | ||
|
||
### Custom Element | ||
|
||
The `Rendering` component can be rendered as either `ol` or `ul` elements. The default is `ul`. | ||
|
||
<Tabs items={["Code", "Example", "HTML"]}> | ||
<Tab> | ||
```jsx | ||
<Rendering | ||
rendering={[ | ||
{ | ||
id: "https://fixtures.iiif.io/other/UCLA/kabuki_ezukushi_rtl.pdf", | ||
type: "Text", | ||
label: { | ||
en: ["PDF version"], | ||
}, | ||
format: "application/pdf", | ||
}, | ||
]} | ||
as="ol" | ||
/> | ||
``` | ||
</Tab> | ||
<Tab> | ||
<Rendering | ||
rendering={[ | ||
{ | ||
id: "https://fixtures.iiif.io/other/UCLA/kabuki_ezukushi_rtl.pdf", | ||
type: "Text", | ||
label: { | ||
en: ["PDF version"], | ||
}, | ||
format: "application/pdf", | ||
}, | ||
]} | ||
as="ol" | ||
/> | ||
</Tab> | ||
<Tab> | ||
```html | ||
<ol class="c-PJLV"> | ||
<li class="c-PJLV"> | ||
<a href="https://fixtures.iiif.io/other/UCLA/kabuki_ezukushi_rtl.pdf"> | ||
PDF version | ||
</a> | ||
</li> | ||
</ol> | ||
``` | ||
</Tab> | ||
</Tabs> |
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,39 @@ | ||
import React from "react"; | ||
import { styled } from "src/styles/stitches.config"; | ||
import { getLabelAsString } from "src/lib/label-helpers"; | ||
import { PrimitivesRendering } from "src/types/primitives"; | ||
import { sanitizeAttributes } from "src/lib/html-element"; | ||
|
||
const StyledRendering = styled("li", {}); | ||
const StyledWrapper = styled("ul", {}); | ||
|
||
const Rendering: React.FC<PrimitivesRendering> = (props) => { | ||
const { as, rendering } = props; | ||
|
||
/** | ||
* Create attributes and remove React props | ||
*/ | ||
const remove = ["as", "rendering"]; | ||
const attributes = sanitizeAttributes(props, remove); | ||
|
||
return ( | ||
<StyledWrapper as={as}> | ||
{rendering && | ||
rendering.map((resource) => { | ||
const label = getLabelAsString( | ||
resource.label, | ||
attributes.lang, | ||
) as string; | ||
return ( | ||
<StyledRendering key={resource.id}> | ||
<a href={resource.id} {...attributes} target="_blank"> | ||
{label ? label : resource.id} | ||
</a> | ||
</StyledRendering> | ||
); | ||
})} | ||
</StyledWrapper> | ||
); | ||
}; | ||
|
||
export default Rendering; |
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,41 @@ | ||
import { render, screen } from "@testing-library/react"; | ||
import { PrimitivesExternalWebResource } from "src/types/primitives"; | ||
import PropertiesRendering from "src/components/Viewer/Properties/Rendering"; | ||
import React from "react"; | ||
|
||
const json: PrimitivesExternalWebResource[] = [ | ||
{ | ||
id: "https://drive.google.com/file/d/1aWo1lORRVTQ0VveV3aP5Ym6hfVXUqr8_/view?usp=sharing", | ||
type: "Text", | ||
label: { | ||
en: ['Download "A study guide: Josh MacPhee"'], | ||
}, | ||
format: "application/pdf", | ||
}, | ||
{ | ||
id: "https://fixtures.iiif.io/other/UCLA/kabuki_ezukushi_rtl.pdf", | ||
type: "Text", | ||
label: { | ||
en: ["PDF version"], | ||
}, | ||
format: "application/pdf", | ||
}, | ||
]; | ||
|
||
describe("IIIF rendering property component", () => { | ||
it("renders", () => { | ||
render(<PropertiesRendering rendering={json} />); | ||
|
||
/** | ||
* test anchors | ||
*/ | ||
const links = screen.getAllByRole("link"); | ||
links.forEach((element, index) => { | ||
const text = json[index].label?.en?.join(", ") as string; | ||
expect(element).toHaveTextContent(text); | ||
|
||
const href = json[index].id as string; | ||
expect(element.getAttribute("href")).toBe(href); | ||
}); | ||
}); | ||
}); |
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,22 @@ | ||
import { PrimitivesExternalWebResource } from "src/types/primitives"; | ||
import { Rendering } from "src/components/Primitives"; | ||
import React from "react"; | ||
|
||
interface PropertiesRenderingProps { | ||
rendering: PrimitivesExternalWebResource[]; | ||
} | ||
|
||
const PropertiesRendering: React.FC<PropertiesRenderingProps> = ({ | ||
rendering, | ||
}) => { | ||
if (rendering?.length === 0) return <></>; | ||
|
||
return ( | ||
<> | ||
<span className="manifest-property-title">Alternate formats</span> | ||
<Rendering rendering={rendering} /> | ||
</> | ||
); | ||
}; | ||
|
||
export default PropertiesRendering; |
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
Oops, something went wrong.