Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(components): add embed component
- Loading branch information
Showing
4 changed files
with
111 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"youtube": { | ||
"provider_name": "YouTube", | ||
"provider_url": "https://www.youtube.com/", | ||
"title": "Michel Sardou - Les lacs du Connemara (Paroles)", | ||
"author_name": "MichelSardouVEVO", | ||
"author_url": "https://www.youtube.com/user/MichelSardouVEVO", | ||
"type": "video", | ||
"height": 113, | ||
"width": 200, | ||
"version": "1.0", | ||
"thumbnail_height": 360, | ||
"thumbnail_width": 480, | ||
"thumbnail_url": "https://i.ytimg.com/vi/bpEmjxobvbY/hqdefault.jpg", | ||
"html": "<iframe width=\"200\" height=\"113\" src=\"https://www.youtube.com/embed/bpEmjxobvbY?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen></iframe>", | ||
"embed_url": "https://www.youtube.com/watch?v=bpEmjxobvbY" | ||
}, | ||
"twitter": { | ||
"provider_name": "Twitter", | ||
"provider_url": "https://twitter.com", | ||
"url": "https://twitter.com/jack/status/20", | ||
"author_name": "jack", | ||
"author_url": "https://twitter.com/jack", | ||
"html": "<blockquote class=\"twitter-tweet\"><p lang=\"en\" dir=\"ltr\">just setting up my twttr</p>— jack (@jack) <a href=\"https://twitter.com/jack/status/20?ref_src=twsrc%5Etfw\">March 21, 2006</a></blockquote>\n<script async src=\"https://platform.twitter.com/widgets.js\" charset=\"utf-8\"></script>\n", | ||
"width": 550, | ||
"height": null, | ||
"type": "rich", | ||
"cache_age": "3153600000", | ||
"version": "1.0", | ||
"embed_url": "https://twitter.com/jack/status/20", | ||
"title": null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<template> | ||
<div class="componentsEmbed"> | ||
<prismic-embed :field="youtube" /> | ||
<prismic-embed :field="twitter" /> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { defineComponent } from "vue"; | ||
import { youtube, twitter } from "./embed.json"; | ||
export default defineComponent({ | ||
name: "ComponentsEmbed", | ||
data() { | ||
return { | ||
youtube, | ||
}; | ||
} | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { | ||
AllowedComponentProps, | ||
ComponentCustomProps, | ||
defineComponent, | ||
h, | ||
PropType, | ||
VNodeProps | ||
} from "vue"; | ||
import { EmbedField } from "../types"; | ||
|
||
export interface PrismicEmbedProps { | ||
field: EmbedField; | ||
wrapper?: string; | ||
} | ||
|
||
export const PrismicEmbedImpl = defineComponent({ | ||
name: "PrismicEmbed", | ||
props: { | ||
field: { | ||
type: Object as PropType<EmbedField>, | ||
required: true | ||
}, | ||
wrapper: { | ||
type: String as PropType<string>, | ||
required: false, | ||
default: "div" | ||
} | ||
}, | ||
render() { | ||
if (!this.field) { | ||
return null; | ||
} | ||
|
||
const { html, embed_url, type, provider_name } = this.field; | ||
|
||
return h(this.wrapper, { | ||
"data-oembed": embed_url, | ||
"data-oembed-type": type, | ||
"data-oembed-provider": provider_name, | ||
innerHTML: html | ||
}); | ||
} | ||
}); | ||
|
||
// export the public type for h/tsx inference | ||
// also to avoid inline import() in generated d.ts files | ||
export const PrismicEmbed = (PrismicEmbedImpl as any) as { | ||
new (): { | ||
$props: AllowedComponentProps & | ||
ComponentCustomProps & | ||
VNodeProps & | ||
PrismicEmbedProps; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters