Skip to content

Commit

Permalink
Remove redundant props in StoryVideo and StoryImage that are already …
Browse files Browse the repository at this point in the history
…in the shared MediaWrapperProps; better doc for aspectRatioClass; add console warning if video playback is causing error
  • Loading branch information
yvonnetangsu committed Feb 28, 2025
1 parent daf5c73 commit 5dfd1c4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 20 deletions.
8 changes: 6 additions & 2 deletions components/Media/MediaWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ import * as styles from './MediaWrapper.styles';

export type MediaWrapperProps = React.HTMLAttributes<HTMLDivElement> & CaptionProps & {
aspectRatio?: ImageAspectRatioType;
/**
* If different aspect ratios at different breakpoints are needed, ie, using the AspectRatio prop is insufficient,
* pass custom classes into the aspect ratio container using this prop.
*/
aspectRatioClass?: string;
isFullHeight?: boolean;
isParallax?: boolean;
boundingWidth?: 'site' | 'full';
Expand All @@ -21,12 +26,12 @@ export type MediaWrapperProps = React.HTMLAttributes<HTMLDivElement> & CaptionPr
pb?: PaddingType;
animation?: AnimationType;
delay?: number;
aspectRatioClass?: string; // Additional eg, responsive aspect ratio classes
};

export const MediaWrapper = ({
caption,
aspectRatio,
aspectRatioClass,
isFullHeight,
isParallax,
boundingWidth = 'full',
Expand All @@ -37,7 +42,6 @@ export const MediaWrapper = ({
captionBgColor = 'transparent',
animation = 'none',
delay,
aspectRatioClass,
children,
className,
...props
Expand Down
3 changes: 0 additions & 3 deletions components/StoryImage/StoryImage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { MediaWrapper, type MediaWrapperProps } from '@/components/Media';
import { Parallax } from '@/components/Parallax';
import { type PaddingType } from '@/utilities/datasource';
import { getProcessedImage } from '@/utilities/getProcessedImage';
import { getSbImageSize } from '@/utilities/getSbImageSize';
import * as styles from './StoryImage.styles';
Expand All @@ -10,8 +9,6 @@ export type StoryImageProps = React.HTMLAttributes<HTMLDivElement> & MediaWrappe
imageFocus?: string;
isLoadingEager?: boolean;
alt?: string;
pt?: PaddingType;
pb?: PaddingType;
};

export const StoryImage = ({
Expand Down
23 changes: 8 additions & 15 deletions components/Video/StoryVideo.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { useEffect, useRef, useState } from 'react';
import { cnb } from 'cnbuilder';
import { useInView } from 'framer-motion';
import { type AnimationType } from '@/components/Animate';
import { MediaWrapper, type MediaWrapperProps } from '@/components/Media';
import { MutedVideoLoop, VideoButton } from '@/components/Video';
import { type PaddingType } from '@/utilities/datasource';
import * as styles from './StoryVideo.styles';

/**
Expand All @@ -18,11 +16,6 @@ export type StoryVideoProps = React.HTMLAttributes<HTMLDivElement> & Omit<MediaW
videoMp4?: string;
videoPosterSrc?: string;
isFullScreen?: boolean; // Whether the video takes the full width of the device
spacingTop?: PaddingType;
spacingBottom?: PaddingType;
animation?: AnimationType;
delay?: number;
aspectRatioClass?: string;
};

export const StoryVideo = ({
Expand All @@ -33,9 +26,9 @@ export const StoryVideo = ({
aspectRatio,
boundingWidth = 'full',
width,
pt,
pb,
isFullScreen,
spacingTop,
spacingBottom,
captionBgColor = 'transparent',
animation = 'none',
delay,
Expand All @@ -50,17 +43,17 @@ export const StoryVideo = ({
const [isPlaying, setIsPlaying] = useState<boolean>(false);
const [isUserPaused, setIsUserPaused] = useState<boolean>(false);

// Toggle foreground video play/pause
// Toggle video play/pause
const toggleVideo = () => {
if (!videoRef.current) return;

setIsPlaying((prev) => {
if (prev) {
videoRef.current?.pause();
videoRef.current.pause();
setIsUserPaused(true);
} else {
videoRef.current
?.play()
.play()
.catch(() => {});
setIsUserPaused(false);
}
Expand All @@ -77,7 +70,7 @@ export const StoryVideo = ({
if (!video) return;

if (isVideoInView && !isUserPaused) {
video.play().catch(() => {});
video.play().catch((error) => console.warn('Video playback prevented:', error));
} else {
video.pause();
}
Expand All @@ -95,8 +88,8 @@ export const StoryVideo = ({
aspectRatio={aspectRatio}
boundingWidth={boundingWidth}
width={width}
pt={spacingTop}
pb={spacingBottom}
pt={pt}
pb={pb}
animation={animation}
delay={delay}
aspectRatioClass={cnb(aspectRatioClass, styles.videoWrapper)}
Expand Down

0 comments on commit 5dfd1c4

Please sign in to comment.