From d5bdb942a6abffb2af990fde965e1fad3a8696f9 Mon Sep 17 00:00:00 2001 From: Robert Reinhard Date: Tue, 28 Nov 2023 18:31:06 -0800 Subject: [PATCH 1/7] Create ContentfulVisual package Based on NextVisual --- packages/contentful/README.md | 83 +++++++++++++++++++ packages/contentful/cypress.config.ts | 13 +++ .../cypress/component/ContentfulVisual.cy.tsx | 54 ++++++++++++ .../contentful/cypress/support/commands.ts | 36 ++++++++ .../cypress/support/component-index.html | 20 +++++ .../contentful/cypress/support/component.ts | 21 +++++ packages/contentful/cypress/tsconfig.json | 18 ++++ packages/contentful/package.json | 33 ++++++++ packages/contentful/src/ContentfulVisual.tsx | 40 +++++++++ packages/contentful/src/index.ts | 4 + .../src/types/contentfulVisualTypes.ts | 3 + packages/contentful/tsconfig.json | 7 ++ 12 files changed, 332 insertions(+) create mode 100644 packages/contentful/README.md create mode 100644 packages/contentful/cypress.config.ts create mode 100644 packages/contentful/cypress/component/ContentfulVisual.cy.tsx create mode 100644 packages/contentful/cypress/support/commands.ts create mode 100644 packages/contentful/cypress/support/component-index.html create mode 100644 packages/contentful/cypress/support/component.ts create mode 100644 packages/contentful/cypress/tsconfig.json create mode 100644 packages/contentful/package.json create mode 100644 packages/contentful/src/ContentfulVisual.tsx create mode 100644 packages/contentful/src/index.ts create mode 100644 packages/contentful/src/types/contentfulVisualTypes.ts create mode 100644 packages/contentful/tsconfig.json diff --git a/packages/contentful/README.md b/packages/contentful/README.md new file mode 100644 index 0000000..76f8313 --- /dev/null +++ b/packages/contentful/README.md @@ -0,0 +1,83 @@ +# @react-visual/next [![react-visual](https://img.shields.io/endpoint?url=https://cloud.cypress.io/badge/simple/fn6c7w&style=flat&logo=cypress)](https://cloud.cypress.io/projects/fn6c7w/runs) + +Renders images and videos into a container. Features: + +- Uses `next/image` to render images +- Easily render assets using aspect ratios +- Videos are lazyloaded (unless `priority` flag is set) + +## Install + +```sh +yarn add @react-visual/next +``` + +Images will be rendered using `next/image` so expect to do configuration of [`remotePatterns`](https://nextjs.org/docs/app/api-reference/components/image#remotepatterns) for CMS hosted images. + +## Usage + +```jsx +import Visual from '@react-visual/next' + +export default function Example() { + return ( + + ) +} +``` + +For more examples, read [the Cypress component tests](./cypress/component). + +## Props + +### Sources + +| Prop | Type | Description +| -- | -- | -- +| `image` | `string` | URL to an image asset. +| `video` | `string` | URL to a video asset asset. +| `placeholderData` | `string` | A Data URL that is rendered before the image loads via [`next/image`'s `blurDataURL`](https://nextjs.org/docs/pages/api-reference/components/image#blurdataurl). + +### Layout + +| Prop | Type | Description +| -- | -- | -- +| `expand` | `boolean` | Make the Visual fill it's container via CSS using absolute positioning. +| `aspect` | `number` | Force the Visual to a specific aspect ratio. +| `width` | `number`, `string` | A CSS dimension value or a px number. +| `height` | `number`, `string` | A CSS dimension value or a px number. +| `fit` | `string` | An [`object-fit`](https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit) value that is applied to the assets. Defaults to `cover`. +| `position` | `string` | An [`object-position`](https://developer.mozilla.org/en-US/docs/Web/CSS/object-position) value. + +### Loading + +| Prop | Type | Description +| -- | -- | -- +| `priority` | `boolean` | Sets [`next/image`'s `priority`](https://nextjs.org/docs/pages/api-reference/components/image#priority) and videos to not lazy load. +| `sizes` | `string` | Sets [`next/image`'s `sizes`](https://nextjs.org/docs/pages/api-reference/components/image#sizes) prop. +| `imageLoader` | `Function` | This is passed through [to `next/image`'s `loader` prop](https://nextjs.org/docs/app/api-reference/components/image#loader). + +### Video + +| Prop | Type | Description +| -- | -- | -- +| `paused` | `boolean` | Disables autoplay of videos. This prop is reactive, unlike the `paused` property of the html `