Skip to content

Commit

Permalink
Add support to set a custom preview image icon to DamVideoBlock, `V…
Browse files Browse the repository at this point in the history
…imeoVideoBlock`, and `YouTubeVideoBlock` (#2615)

Support for the `icon` prop was added in #2542, but there was no easy
way to set the icon.
  • Loading branch information
johnnyomair authored Oct 9, 2024
1 parent 700ddc3 commit ec57e2d
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 6 deletions.
15 changes: 15 additions & 0 deletions .changeset/swift-jobs-dress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
"@comet/cms-site": minor
---

Add support to set a custom preview image icon to `DamVideoBlock`, `VimeoVideoBlock`, and `YouTubeVideoBlock`

Use the `previewImageIcon` prop to pass the icon to the default `VideoPreviewImage` component:

```diff
<DamVideoBlock
data={props}
fill={fill}
+ previewImageIcon={<CustomPlayIcon />}
/>
```
16 changes: 13 additions & 3 deletions demo/site/src/blocks/MediaBlock.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
"use client";
import { DamVideoBlock, OneOfBlock, PropsWithData, SupportedBlocks, VimeoVideoBlock, withPreview, YouTubeVideoBlock } from "@comet/cms-site";
import { MediaBlockData } from "@src/blocks.generated";
import styled from "styled-components";

import { DamImageBlock } from "./DamImageBlock";

const getSupportedBlocks = (fill?: boolean): SupportedBlocks => ({
image: (props) => <DamImageBlock data={props} aspectRatio="inherit" fill={fill} />,
damVideo: (props) => <DamVideoBlock data={props} fill={fill} />,
youTubeVideo: (props) => <YouTubeVideoBlock data={props} fill={fill} />,
vimeoVideo: (props) => <VimeoVideoBlock data={props} fill={fill} />,
damVideo: (props) => <DamVideoBlock data={props} fill={fill} previewImageIcon={<CustomPlayIcon />} />,
youTubeVideo: (props) => <YouTubeVideoBlock data={props} fill={fill} previewImageIcon={<CustomPlayIcon />} />,
vimeoVideo: (props) => <VimeoVideoBlock data={props} fill={fill} previewImageIcon={<CustomPlayIcon />} />,
});

export const MediaBlock = withPreview(
Expand All @@ -17,3 +18,12 @@ export const MediaBlock = withPreview(
},
{ label: "Media" },
);

const CustomPlayIcon = styled.span`
width: 64px;
height: 64px;
box-sizing: border-box;
border-style: solid;
border-width: 32px 0 32px 64px;
border-color: transparent transparent transparent red;
`;
6 changes: 5 additions & 1 deletion packages/site/cms-site/src/blocks/DamVideoBlock.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import { ReactElement, useState } from "react";
import { ReactElement, ReactNode, useState } from "react";
import styled, { css } from "styled-components";

import { DamVideoBlockData } from "../blocks.generated";
Expand All @@ -14,6 +14,7 @@ interface DamVideoBlockProps extends PropsWithData<DamVideoBlockData> {
previewImageSizes?: string;
renderPreviewImage?: (props: VideoPreviewImageProps) => ReactElement;
fill?: boolean;
previewImageIcon?: ReactNode;
}

export const DamVideoBlock = withPreview(
Expand All @@ -23,6 +24,7 @@ export const DamVideoBlock = withPreview(
previewImageSizes,
renderPreviewImage,
fill,
previewImageIcon,
}: DamVideoBlockProps) => {
if (damFile === undefined) {
return <PreviewSkeleton type="media" hasContent={false} />;
Expand All @@ -41,6 +43,7 @@ export const DamVideoBlock = withPreview(
aspectRatio,
sizes: previewImageSizes,
fill: fill,
icon: previewImageIcon,
})
) : (
<VideoPreviewImage
Expand All @@ -49,6 +52,7 @@ export const DamVideoBlock = withPreview(
aspectRatio={aspectRatio}
sizes={previewImageSizes}
fill={fill}
icon={previewImageIcon}
/>
)
) : (
Expand Down
6 changes: 5 additions & 1 deletion packages/site/cms-site/src/blocks/VimeoVideoBlock.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"use client";
import { useState } from "react";
import { ReactNode, useState } from "react";
import styled, { css } from "styled-components";

import { VimeoVideoBlockData } from "../blocks.generated";
Expand Down Expand Up @@ -29,6 +29,7 @@ interface VimeoVideoBlockProps extends PropsWithData<VimeoVideoBlockData> {
previewImageSizes?: string;
renderPreviewImage?: (props: VideoPreviewImageProps) => React.ReactElement;
fill?: boolean;
previewImageIcon?: ReactNode;
}

export const VimeoVideoBlock = withPreview(
Expand All @@ -38,6 +39,7 @@ export const VimeoVideoBlock = withPreview(
previewImageSizes,
renderPreviewImage,
fill,
previewImageIcon,
}: VimeoVideoBlockProps) => {
const [showPreviewImage, setShowPreviewImage] = useState(true);
const hasPreviewImage = !!(previewImage && previewImage.damFile);
Expand Down Expand Up @@ -72,6 +74,7 @@ export const VimeoVideoBlock = withPreview(
aspectRatio,
sizes: previewImageSizes,
fill: fill,
icon: previewImageIcon,
})
) : (
<VideoPreviewImage
Expand All @@ -80,6 +83,7 @@ export const VimeoVideoBlock = withPreview(
aspectRatio={aspectRatio}
sizes={previewImageSizes}
fill={fill}
icon={previewImageIcon}
/>
)
) : (
Expand Down
6 changes: 5 additions & 1 deletion packages/site/cms-site/src/blocks/YouTubeVideoBlock.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import { ReactElement, useState } from "react";
import { ReactElement, ReactNode, useState } from "react";
import styled, { css } from "styled-components";

import { YouTubeVideoBlockData } from "../blocks.generated";
Expand All @@ -26,6 +26,7 @@ interface YouTubeVideoBlockProps extends PropsWithData<YouTubeVideoBlockData> {
previewImageSizes?: string;
renderPreviewImage?: (props: VideoPreviewImageProps) => ReactElement;
fill?: boolean;
previewImageIcon?: ReactNode;
}

export const YouTubeVideoBlock = withPreview(
Expand All @@ -35,6 +36,7 @@ export const YouTubeVideoBlock = withPreview(
previewImageSizes,
renderPreviewImage,
fill,
previewImageIcon,
}: YouTubeVideoBlockProps) => {
const [showPreviewImage, setShowPreviewImage] = useState(true);
const hasPreviewImage = !!(previewImage && previewImage.damFile);
Expand Down Expand Up @@ -71,6 +73,7 @@ export const YouTubeVideoBlock = withPreview(
aspectRatio,
sizes: previewImageSizes,
fill: fill,
icon: previewImageIcon,
})
) : (
<VideoPreviewImage
Expand All @@ -79,6 +82,7 @@ export const YouTubeVideoBlock = withPreview(
aspectRatio={aspectRatio}
sizes={previewImageSizes}
fill={fill}
icon={previewImageIcon}
/>
)
) : (
Expand Down

0 comments on commit ec57e2d

Please sign in to comment.