Skip to content

Commit 893a59b

Browse files
Add a VideoPlayer component for markdown
1 parent a210a1e commit 893a59b

4 files changed

Lines changed: 40 additions & 2 deletions

File tree

src/components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export * from './layout';
66
export * from './markdown-renderer/MarkdownRenderer';
77
export * from './project-list/ProjectList';
88
export * from './newsletter/NewsLetter';
9+
export * from './video-player/VideoPlayer';
910
export * from './seo/SEO';
1011
export * from './gatsby-image/StyledGatsbyImage';
1112
export * from './blog-post-card-list/BlogPostCardList';

src/components/markdown-renderer/MarkdownRenderer.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22
import { MDXProvider } from '@mdx-js/react';
3+
import { VideoPlayer } from '../video-player/VideoPlayer';
34

45
import { HeadingProps } from '../heading/Heading';
56
import {
@@ -14,6 +15,7 @@ import {
1415
StyledParagraph,
1516
} from './styles';
1617
import { slugify } from './slugify';
18+
import { InfoCallToAction } from 'components/info-call-to-action/InfoCallToAction';
1719

1820
type MarkdownRendererProps = {
1921
children: React.ReactNode;
@@ -59,6 +61,8 @@ export const MarkdownRenderer = ({ children }: MarkdownRendererProps) => {
5961
a: AnchorLink,
6062
p: StyledParagraph,
6163
span: Span,
64+
VideoPlayer,
65+
InfoCallToAction,
6266
}}
6367
>
6468
{children}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import React from 'react';
2+
import styled from 'styled-components';
3+
import { mb, mt } from 'styled-components-spacing';
4+
5+
type VideoPlayerProps = {
6+
src: string;
7+
caption?: string;
8+
};
9+
10+
const Figure = styled.figure`
11+
${mb(5)};
12+
`;
13+
14+
const Video = styled.video`
15+
max-width: 100%;
16+
height: auto;
17+
display: block;
18+
`;
19+
20+
const Caption = styled.figcaption`
21+
font-family: ${({ theme }) => theme.fonts.body};
22+
font-size: ${({ theme }) => theme.fontSizes.small};
23+
color: ${({ theme }) => theme.colors.primaryText};
24+
text-align: left;
25+
${mt(2)};
26+
`;
27+
28+
export const VideoPlayer = ({ src, caption }: VideoPlayerProps) => {
29+
return (
30+
<Figure>
31+
<Video src={src} controls muted playsInline />
32+
{caption && <Caption>{caption}</Caption>}
33+
</Figure>
34+
);
35+
};

src/posts/react-image-gallery.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ thumbnail:
1111
author: 'Ajeet Chaulagain'
1212
---
1313

14-
import { InfoCallToAction } from "../components/info-call-to-action/InfoCallToAction.tsx"
15-
1614
If you are creating web pages, you might need an image gallery showing multiple images at some point. However, developing an image gallery from scratch is quite an effort as you need to consider several things, such as user experience, customizability, and probably more features support. But a community-loved React package, [react-image-gallery,](https://www.npmjs.com/package/react-image-gallery) will help you develop a beautiful image gallery with a wide range of [features and customizability](https://github.com/xiaolin/react-image-gallery#user-content-features)
1715

1816
React image gallery is one of the [most popular npm package](https://npmtrends.com/react-gallery-swiper-vs-react-grid-gallery-vs-react-image-gallery-vs-react-image-lightbox-vs-react-image-slider-vs-react-images) that provide React component to build highly customizable image galleries. Also, It supports a wide range of features out of the box. These features include swipe gestures for mobile devices, navigation through thumbnails, responsive design, and much more. In this tutorial, you will learn how to build a _beautiful and elegant image gallery_ using a react-image-gallery npm package. Let's get started.

0 commit comments

Comments
 (0)