Last active
September 27, 2025 16:27
-
-
Save inxilpro/e9a15f7f97887851543168a76640f1fa to your computer and use it in GitHub Desktop.
This file contains hidden or 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
@props([ | |
'src', | |
'title' => null, | |
'alt' => null, | |
]) | |
@php | |
preg_match('/.*\/embed\/([^?&\/]+)/m', $src, $matches); | |
$id = $matches[1]; | |
$alt ??= $title ?? 'Embedded YouTube video'; | |
@endphp | |
<figure | |
x-data="{ activated: false, loaded: false }" | |
{{ $attributes->except('x-data')->class('aspect-video w-full grid grid-cols-1 grid-rows-1') }} | |
> | |
<template x-if="activated"> | |
<iframe | |
@load="loaded = true" | |
class="z-10 col-start-1 row-start-1 w-full rounded-md border aspect-video" | |
src="https://www.youtube-nocookie.com/embed/{{ $id }}?autoplay=1" | |
frameborder="0" | |
allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" | |
allowfullscreen | |
></iframe> | |
</template> | |
<div | |
class="relative z-0 col-start-1 row-start-1 w-full aspect-video" | |
@click.prevent="activated = true" | |
x-show="! loaded" | |
> | |
<img | |
src="https://i.ytimg.com/vi/{{ $id }}/maxresdefault.jpg" | |
class="w-full rounded-md border aspect-video" | |
alt="{{ $alt }}" | |
/> | |
@if($title) | |
<figcaption | |
class="absolute top-0 right-0 left-0 py-2 px-4 pb-8 text-sm font-semibold text-white bg-gradient-to-b to-transparent rounded-t-md from-black/60 text-shadow" | |
> | |
{{ $title }} | |
</figcaption> | |
@endif | |
<button | |
x-show="! activated" | |
class="flex absolute inset-0 justify-center items-center bg-transparent rounded-md border-0 opacity-70 cursor-pointer hover:opacity-90 focus-visible:ring-2 focus-visible:ring-blue-600 focus-visible:ring-opacity-100 focus-visible:ring-offset-2 group outline-0" | |
> | |
<svg viewBox="0 0 68 48" class="w-16 opacity-80 md:w-24 hover:opacity-100"> | |
<path | |
d="M66.52,7.74c-0.78-2.93-2.49-5.41-5.42-6.19C55.79,.13,34,0,34,0S12.21,.13,6.9,1.55 C3.97,2.33,2.27,4.81,1.48,7.74C0.06,13.05,0,24,0,24s0.06,10.95,1.48,16.26c0.78,2.93,2.49,5.41,5.42,6.19 C12.21,47.87,34,48,34,48s21.79-0.13,27.1-1.55c2.93-0.78,4.64-3.26,5.42-6.19C67.94,34.95,68,24,68,24S67.94,13.05,66.52,7.74z" | |
fill="#f03" | |
></path> | |
<path d="M 45,24 27,14 27,34" fill="#fff"></path> | |
</svg> | |
</button> | |
</div> | |
</figure> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment