Skip to content

Commit

Permalink
Feat: provider-switcher
Browse files Browse the repository at this point in the history
  • Loading branch information
luciobenini committed Nov 28, 2021
1 parent f8ddf2c commit ad6c6a4
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@pittica/gatsby-plugin-video",
"private": false,
"description": "Video embed plugin for GatsbyJS.",
"version": "1.0.1",
"version": "1.1.0",
"author": {
"name": "Lucio Benini",
"email": "info@pittica.com",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
74 changes: 74 additions & 0 deletions src/components/switcher.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import React from "react"
import PropTypes from "prop-types"

import Dailymotion from "./providers/dailymotion"
import PornHub from "./providers/pornhub"
import YouTube from "./providers/youtube"
import Vimeo from "./providers/vimeo"

import getProvider from "../utils/get-provider"

export default function Switcher({ url, width, height, title, className }) {
const { id, provider } = getProvider(url)

switch (provider) {
case "Dailymotion":
return (
<Dailymotion
id={id}
width={width}
height={height}
className={className}
title={title}
/>
)
case "PornHub":
return (
<PornHub
id={id}
width={width}
height={height}
className={className}
title={title}
/>
)
case "YouTube":
return (
<YouTube
id={id}
width={width}
height={height}
className={className}
title={title}
/>
)
case "Vimeo":
return (
<Vimeo
id={id}
width={width}
height={height}
className={className}
title={title}
/>
)
default:
return (
<a href={url} title={title} className={className}>
{url}
</a>
)
}
}

Switcher.propTypes = {
url: PropTypes.string.isRequired,
width: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
height: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
title: PropTypes.string.isRequired,
className: PropTypes.string,
}

Switcher.defaultProps = {
className: "video",
}
11 changes: 7 additions & 4 deletions src/index.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import Dailymotion from "./components/dailymotion"
import PornHub from "./components/pornhub"
import YouTube from "./components/youtube"
import Vimeo from "./components/vimeo"
import Dailymotion from "./components/providers/dailymotion"
import PornHub from "./components/providers/pornhub"
import YouTube from "./components/providers/youtube"
import Vimeo from "./components/providers/vimeo"

import Switcher from "./components/switcher"

import getProvider from "./utils/get-provider"
import providers from "./utils/providers"

export { Dailymotion, PornHub, YouTube, Vimeo, getProvider, providers }
export default Switcher

0 comments on commit ad6c6a4

Please sign in to comment.