From b8cd45eb672da8d74d5684651a2f4da58d23bfac Mon Sep 17 00:00:00 2001 From: Benjamin Cabanes <3447705+bcabanes@users.noreply.github.com> Date: Fri, 3 Nov 2023 16:56:18 -0400 Subject: [PATCH] feat(nx-dev): add short-embed UI interactions and styles The short-embed tag and corresponding CSS have been refactored for better user experience. Styling changes have been made within the `tsx` file to provide a more user-friendly interface. --- nx-dev/nx-dev/styles/main.css | 37 ----- .../ui-markdoc/src/lib/tags/short-embed.tsx | 145 ++++++++++-------- 2 files changed, 81 insertions(+), 101 deletions(-) diff --git a/nx-dev/nx-dev/styles/main.css b/nx-dev/nx-dev/styles/main.css index 1578db92200b9..b74f26ab0560a 100644 --- a/nx-dev/nx-dev/styles/main.css +++ b/nx-dev/nx-dev/styles/main.css @@ -251,40 +251,3 @@ html.dark .adaptive-icon { transform: translateY(0); } } - -#short-embed img { - width: 10rem; - height: auto; - margin: auto; -} - -#short-embed h2 { - font-size: 1.5rem; - font-weight: 600; - margin: 0; -} - -#short-embed button.short-picker { - width: 8rem; -} - -#short-embed iframe { - width: 300px; - height: 534px; - border: none; - border-radius: 0.5rem; - margin-top: 0; - margin-bottom: 0; -} - -#short-embed ul { - padding-left: 0; -} - -#short-embed button label { - cursor: pointer; -} - -#short-embed h3 { - margin: 0.5rem; -} diff --git a/nx-dev/ui-markdoc/src/lib/tags/short-embed.tsx b/nx-dev/ui-markdoc/src/lib/tags/short-embed.tsx index f11f81c778958..6d650b6f9b08b 100644 --- a/nx-dev/ui-markdoc/src/lib/tags/short-embed.tsx +++ b/nx-dev/ui-markdoc/src/lib/tags/short-embed.tsx @@ -6,6 +6,9 @@ import { useState, } from 'react'; import { Schema, Tag } from '@markdoc/markdoc'; +import { Transition } from '@headlessui/react'; +import { Button } from '@nx/nx-dev/ui-common'; +import { XMarkIcon } from '@heroicons/react/24/outline'; interface VideoData { title: string; @@ -55,11 +58,10 @@ export function ShortEmbeds({ }: { videoData: VideoData[]; children: ReactNode; -}) { +}): JSX.Element | null { const [currentVideo, setCurrentVideo] = useState(videoData[0]); - const [show, setShow] = useState(true); + const [isShowing, setIsShowing] = useState(false); const [userInteraction, setUserInteraction] = useState(false); - const [fadingOut, setFadingOut] = useState(false); useLayoutEffect(() => { const [wrapperWidth, viewHeight] = [ @@ -67,70 +69,85 @@ export function ShortEmbeds({ window.innerHeight, ]; const showShort = - !!wrapperWidth && wrapperWidth > 800 && !!viewHeight && viewHeight > 850; - setShow(showShort); - }, [setShow]); + !!wrapperWidth && wrapperWidth > 800 && !!viewHeight && viewHeight > 750; - if (!show) { - return null; - } + const t = setTimeout(() => setIsShowing(showShort), 500); + return () => { + t && clearTimeout(t); + }; + }, [setIsShowing]); + + if (!isShowing) return null; return ( -
- -

Relevant Videos

-
- {children} -
-

More Videos:

-
    - {videoData - .filter(({ embedUrl }) => embedUrl !== currentVideo.embedUrl) - .map((config) => { - const ytUrlPath = config.embedUrl.split('/'); - const ytId = ytUrlPath[ytUrlPath.length - 1]; - const imgUrl = `https://img.youtube.com/vi/${ytId}/0.jpg`; - return ( - - ); - })} -
+
+ +

Relevant Videos

+
+ {children} +
+
Continue with:
+
+ {videoData + .filter( + ({ embedUrl }) => embedUrl !== currentVideo.embedUrl + ) + .map((config) => { + const ytUrlPath = config.embedUrl.split('/'); + const ytId = ytUrlPath[ytUrlPath.length - 1]; + const imgUrl = `https://img.youtube.com/vi/${ytId}/0.jpg`; + return ( +
{ + setUserInteraction(true); + setCurrentVideo(config); + }} + className="hover:cursor-pointer flex text-sm h-24 rounded-lg overflow-hidden border border-slate-200 bg-white/40 shadow-sm transition focus-within:ring-2 focus-within:ring-blue-500 focus-within:ring-offset-2 hover:bg-white dark:border-slate-800/40 dark:bg-slate-800/60 dark:hover:bg-slate-800" + > +
+ {`Another +
+
+ {config.title} +
+
+ ); + })} +
+
+
-
-
+ +
); } @@ -143,17 +160,17 @@ export function ShortVideo({ embedUrl, title }: VideoData) { } return ( -
+
+ />
); }