Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GIVCAMP-282 | React Player preview (light) #216

Merged
merged 14 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions components/EmbedMedia/EmbedMedia.styles.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export const mediaWrapper = '*:!w-full *:!h-full';
export const caption = '*:*:leading-display caption mt-1em max-w-prose-wide';
export const iconWrapper = 'size-50 sm:size-70 bg-black-true/70 border-3 rounded-full border-white group-hocus-within:scale-110 transition group-hocus-within:bg-digital-red';
export const previewIcon = 'text-white size-24 sm:size-30';
19 changes: 19 additions & 0 deletions components/EmbedMedia/EmbedMedia.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { useEffect, useState } from 'react';
import { cnb } from 'cnbuilder';
import ReactPlayer from 'react-player/lazy';
import { Container } from '../Container';
import { FlexBox } from '../FlexBox';
import { WidthBox, type WidthType } from '../WidthBox';
import { HeroIcon } from '../HeroIcon';
import { type PaddingType } from '@/utilities/datasource';
import { type MediaAspectRatioType, mediaAspectRatios } from '@/utilities/datasource';
import * as styles from './EmbedMedia.styles';
Expand All @@ -16,8 +18,16 @@ type EmbedMediaProps = React.HTMLAttributes<HTMLDivElement> & {
spacingTop?: PaddingType;
spacingBottom?: PaddingType;
isCaptionInset?: boolean;
isPreview?: boolean;
previewAriaLabel?: string;
};

const PlayPreviewIcon = (
<FlexBox alignItems="center" justifyContent="center" className={styles.iconWrapper}>
<HeroIcon icon="play" noBaseStyle className={styles.previewIcon} />
</FlexBox>
);

export const EmbedMedia = ({
mediaUrl,
caption,
Expand All @@ -27,6 +37,8 @@ export const EmbedMedia = ({
spacingTop,
spacingBottom,
isCaptionInset,
isPreview,
previewAriaLabel,
className,
...props
}: EmbedMediaProps) => {
Expand Down Expand Up @@ -59,6 +71,13 @@ export const EmbedMedia = ({
height="100%"
url={mediaUrl}
controls
playsinline
light={isPreview ? true : false}
playing={isPreview ? true : false}
playIcon={isPreview ? PlayPreviewIcon : undefined}
// This previewAriaLabel prop is not documented but it is in the React Player source code
previewAriaLabel={isPreview ? previewAriaLabel : undefined}
Comment on lines +78 to +79
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SODA said this makes it ok accessible (it renders a clickable/focusable div). When I have time I'll open a PR to React Player to add a role="button" (SODA suggestion to make it fully accessible).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can always just log a request or file a bug. It is nice of you to submit the PR but sometimes you can just let others know if you don't have the time.

className="group"
/>
)}
</div>
Expand Down
4 changes: 4 additions & 0 deletions components/FeaturedStories/FeatureMasonry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type FeatureMasonryProps = React.HTMLAttributes<HTMLDivElement> & {
imageFocus1?: string;
imageAlt1?: string;
videoUrl?: string;
previewAriaLabel?: string;
caption?: string;
}

Expand All @@ -34,6 +35,7 @@ export const FeatureMasonry = ({
imageFocus1,
imageAlt1,
videoUrl,
previewAriaLabel,
caption,
className,
...props
Expand Down Expand Up @@ -92,8 +94,10 @@ export const FeatureMasonry = ({
</div>
<EmbedMedia
mediaUrl={videoUrl}
isPreview
className="lg:col-span-6 bg-black-70"
aspectRatio="16x9"
previewAriaLabel={previewAriaLabel}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yay reading through the code...

When things are not in the doxn it scares me a bit for if the maintainers are going to continue to maintain the prop. Most of the time it is just because they haven't gotten to the documentation yet and I don't see this as a critical thing but I thought I would share my $0.02 anyhow.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it looks like they recently switched maintainer. I looked at the merged pull request, and looks like this prop was added fairly recently:
cookpete/react-player#1705

I'll give them benefit of the doubt this time 😆

/>
</Grid>
<Text variant="caption" leading="display" className="text-black-70 max-w-prose-wide mt-1em whitespace-pre-line">
Expand Down
4 changes: 2 additions & 2 deletions components/HeroIcon/HeroIcon.styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
XMarkIcon,
} from '@heroicons/react/24/outline';
import { CheckIcon } from '@heroicons/react/16/solid';
import { PlayIcon } from '@heroicons/react/24/solid';
import { PlayIcon } from '@heroicons/react/20/solid';

export const iconMap = {
action: ChevronRightIcon,
Expand Down Expand Up @@ -50,7 +50,7 @@ export const iconMap = {
minus: MinusIcon,
more: ArrowRightIcon,
pause: PauseCircleIcon,
play: PlayCircleIcon,
play: PlayIcon,
'play-outline': PlayCircleIcon,
plus: PlusIcon,
right: ArrowRightIcon,
Expand Down
6 changes: 6 additions & 0 deletions components/Storyblok/SbEmbedMedia.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ type SbEmbedMediaProps = {
spacingBottom?: PaddingType;
isCaptionInset?: boolean;
isCaptionLight?: boolean;
isPreview?: boolean;
previewAriaLabel?: string;
};
};

Expand All @@ -33,6 +35,8 @@ export const SbEmbedMedia = ({
spacingBottom,
isCaptionInset,
isCaptionLight,
isPreview,
previewAriaLabel = 'Play video',
},
blok,
}: SbEmbedMediaProps) => {
Expand All @@ -49,6 +53,8 @@ export const SbEmbedMedia = ({
spacingTop={spacingTop}
spacingBottom={spacingBottom}
isCaptionInset={isCaptionInset}
isPreview={isPreview}
previewAriaLabel={previewAriaLabel}
/>
);
};
3 changes: 3 additions & 0 deletions components/Storyblok/SbFeatureMasonry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export type SbFeatureMasonryProps = {
image1?: SbImageType;
imageAlt1?: string;
videoUrl?: string;
previewAriaLabel?: string;
caption?: string;
};
};
Expand All @@ -25,6 +26,7 @@ export const SbFeatureMasonry = ({
image1: { filename: imageSrc1, focus: imageFocus1 } = {},
imageAlt1,
videoUrl,
previewAriaLabel = 'Play video',
caption,
},
blok,
Expand All @@ -41,6 +43,7 @@ export const SbFeatureMasonry = ({
imageFocus1={imageFocus1}
imageAlt1={imageAlt1}
videoUrl={videoUrl}
previewAriaLabel={previewAriaLabel}
caption={caption}
/>
);
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"framer-motion": "^10.16.4",
"next": "13.4.9",
"react-loading-skeleton": "^3.3.1",
"react-player": "^2.14.1",
"react-player": "^2.15.1",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update react player to latest which included this new previewAriaLabel prop

"storyblok-rich-text-react-renderer-ts": "^3.2.0",
"usehooks-ts": "^2.9.1"
},
Expand Down
Loading