-
Notifications
You must be signed in to change notification settings - Fork 1
Feat/110 generic embed #115
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| import React from "react"; | ||
| import { Card, Stack, Title, Text } from "@mantine/core"; | ||
|
Check failure on line 2 in src/components/Embed/Embed.tsx
|
||
|
|
||
| type Kind = "youtube" | "vimeo" | "iframe" | "image"; | ||
|
||
|
|
||
| type Props = { | ||
| header: string; | ||
| kind: Kind; | ||
|
||
| src: string; // iframe src or image src | ||
| description?: string; // optional text under header | ||
| aspectRatio?: `${number} / ${number}` | number; // default 16/9 | ||
| alt?: string; // required if kind="image" | ||
| }; | ||
|
||
|
|
||
| const fixSrc = (kind: Kind, src: string) => { | ||
| if (kind === "youtube") { | ||
| const id = | ||
|
||
| src.match(/(?:v=|youtu\.be\/|\/embed\/)([A-Za-z0-9_-]{6,})/)?.[1] ?? null; | ||
|
||
| return id ? `https://www.youtube.com/embed/${id}` : src; | ||
| } | ||
| if (kind === "vimeo") { | ||
| const id = src.match(/vimeo\.com\/(?:video\/)?(\d+)/)?.[1] ?? null; | ||
| return id ? `https://player.vimeo.com/video/${id}` : src; | ||
| } | ||
| return src; | ||
| }; | ||
|
|
||
| export function Embed({ | ||
| header, | ||
| kind, | ||
| src, | ||
| description, | ||
| aspectRatio = "16 / 9", | ||
| alt, | ||
| }: Props) { | ||
| const normalized = fixSrc(kind, src); | ||
|
||
|
|
||
| return ( | ||
| <div style={{ maxWidth: 960, margin: "0 auto" }}> | ||
| <h2 style={{ margin: "0 0 6px 0" }}>{header}</h2> | ||
| {description ? ( | ||
| <p style={{ margin: "0 0 10px 0", color: "#6b7280" }}>{description}</p> | ||
| ) : null} | ||
|
|
||
| <div | ||
| style={{ | ||
|
||
| position: "relative", | ||
| width: "100%", | ||
| aspectRatio: typeof aspectRatio === "number" ? `${aspectRatio}` : aspectRatio, | ||
| overflow: "hidden", | ||
| borderRadius: 12, | ||
| background: "#00000010", | ||
| }} | ||
| > | ||
| {kind === "image" ? ( | ||
| <img | ||
| src={src} | ||
| alt={alt ?? header} | ||
| style={{ | ||
| position: "absolute", | ||
| inset: 0, | ||
| width: "100%", | ||
| height: "100%", | ||
| objectFit: "cover", | ||
| }} | ||
| loading="lazy" | ||
| /> | ||
| ) : ( | ||
| <iframe | ||
| title={header} | ||
| src={normalized} | ||
| allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" | ||
| allowFullScreen | ||
| style={{ | ||
| position: "absolute", | ||
| inset: 0, | ||
| width: "100%", | ||
| height: "100%", | ||
| border: 0, | ||
| }} | ||
| /> | ||
| )} | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| export default Embed; | ||
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import { Embed } from "../components/Embed/Embed"; | ||
|
|
||
| export default function AIDemoPage() { | ||
| return ( | ||
| <div style={{ padding: 24 }}> | ||
| <Embed | ||
| header="Watch Our AI Demo" | ||
| kind="youtube" | ||
| src="https://www.youtube.com/watch?v=fnuDyLKpt90" // replace with real ID | ||
| /> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue, blocking: We're not looking to embed this as a page at this point.
Please remove this from the routes. We're looking to create reusable design components at the moment, not actually code pages yet.