From 8cd300b127198dc441c3e27a50f74633ed520e47 Mon Sep 17 00:00:00 2001 From: Clinton <80900245+pravton@users.noreply.github.com> Date: Tue, 24 Nov 2026 16:52:45 -0500 Subject: [PATCH 1/3] chore: updates the component to render scss as a tab --- .../components/source-tabs/source-tabs.tsx | 47 ++++++++++++++----- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/docs/src/components/source-tabs/source-tabs.tsx b/docs/src/components/source-tabs/source-tabs.tsx index 046b29c..13139f6 100644 --- a/docs/src/components/source-tabs/source-tabs.tsx +++ b/docs/src/components/source-tabs/source-tabs.tsx @@ -2,6 +2,11 @@ import CodeBlock from "@theme/CodeBlock" import TabItem from "@theme/TabItem" import Tabs from "@theme/Tabs" +const hasExtension = (filename: string) => { + const lastDotIndex = filename.lastIndexOf(".") + return lastDotIndex > 0 && lastDotIndex < filename.length - 1 +} + interface SourceTabsProps { // File name without extension, e.g. "BasicGallery". file: string @@ -9,24 +14,44 @@ interface SourceTabsProps { ts: string // The same file imported with `!!ts-to-js!`. js: string + // The same file imported with `!!raw-loader!`. + scss: string } // TypeScript / JavaScript toggle for a demo's source. The `groupId` keeps // the choice in sync across every block and page, and Docusaurus remembers // it between visits. -export function SourceTabs({ file, ts, js }: SourceTabsProps) { +export function SourceTabs({ file, ts, js, scss }: SourceTabsProps) { + const extensionExist = hasExtension(file) + return ( - - - {ts} - - - - - {js} - - + {ts && ( + + + {ts} + + + )} + + {js && ( + + + {js} + + + )} + + {scss && ( + + + {scss} + + + )} ) } From e404414f576b446e145dcfd3190833a36da90422 Mon Sep 17 00:00:00 2001 From: Clinton <80900245+pravton@users.noreply.github.com> Date: Tue, 24 Nov 2026 16:53:35 -0500 Subject: [PATCH 2/3] feature: adds MorphGallery component --- .../morph-gallery/morph-gallery.module.scss | 170 +++++++++ .../demos/morph-gallery/morph-gallery.tsx | 99 ++++++ .../demos/morph-gallery/morph-renderer.ts | 326 ++++++++++++++++++ 3 files changed, 595 insertions(+) create mode 100644 docs/src/components/demos/morph-gallery/morph-gallery.module.scss create mode 100644 docs/src/components/demos/morph-gallery/morph-gallery.tsx create mode 100644 docs/src/components/demos/morph-gallery/morph-renderer.ts diff --git a/docs/src/components/demos/morph-gallery/morph-gallery.module.scss b/docs/src/components/demos/morph-gallery/morph-gallery.module.scss new file mode 100644 index 0000000..9514e92 --- /dev/null +++ b/docs/src/components/demos/morph-gallery/morph-gallery.module.scss @@ -0,0 +1,170 @@ +.root { + width: 100%; + height: auto; + aspect-ratio: 16/9; + overflow: hidden; + border-radius: 10px; + margin-block-end: 16px; +} + +.root > div { + width: 100%; + height: 100%; +} + +.stage { + position: relative; + width: 100%; + height: 100%; +} + +.stage::after { + content: ""; + position: absolute; + inset: auto 0 0; + height: 220px; + background: linear-gradient(to bottom, transparent, rgb(0 0 0 / 65%)); + pointer-events: none; + z-index: 5; +} + +.canvas { + position: absolute; + inset: 0; + display: block; + width: 100%; + height: 100%; +} + +.navPrev, +.navNext { + backdrop-filter: contrast(2) brightness(0.7) blur(10px); + position: absolute; + top: 50%; + transform: translateY(-50%); + width: 44px; + height: 44px; + border-radius: 50%; + background: rgb(255 255 255 / 12%); + border: 1px solid rgb(255 255 255 / 18%); + color: #fff; + display: flex; + align-items: center; + justify-content: center; + cursor: pointer; + z-index: 10; + transition: + background 0.2s ease, + opacity 0.2s ease; +} + +.navPrev:hover, +.navNext:hover { + background: rgb(255 255 255 / 22%); +} + +.navPrev:disabled, +.navNext:disabled { + opacity: 0.25; + pointer-events: none; +} + +.navPrev { + left: 2rem; +} + +.navNext { + right: 2rem; +} + +.thumbs { + position: absolute; + bottom: 2rem; + left: 0; + right: 0; + margin: 0 auto; + + width: max-content; + max-width: calc(100% - 2rem); + + display: flex; + gap: 8px; + list-style: none; + padding: 0 0 10px 0; + z-index: 10; + + overflow-x: auto; + scroll-behavior: smooth; +} +.thumbs::-webkit-scrollbar { + height: 6px; +} +.thumbs::-webkit-scrollbar-track { + background: rgb(255 255 255 / 10%); + border-radius: 4px; +} +.thumbs::-webkit-scrollbar-thumb { + background: rgb(255 255 255 / 30%); + border-radius: 4px; +} +.thumbItem { + list-style: none; + flex-shrink: 0; + margin-block-start: 0; +} + +.thumbButton { + display: block; + padding: 0; + border: 2px solid transparent; + border-radius: 4px; + cursor: pointer; + overflow: hidden; + background: none; + transition: + border-color 0.2s ease, + opacity 0.2s ease; + opacity: 0.55; +} + +.thumbButton[aria-current="true"] { + border-color: #fff; + opacity: 1; +} + +.thumbButton:hover { + opacity: 0.85; +} + +.thumbButton img { + display: block; + width: 80px; + height: 50px; + object-fit: cover; +} + +.srOnly { + position: absolute; + width: 1px; + height: 1px; + padding: 0; + margin: -1px; + overflow: hidden; + clip: rect(0, 0, 0, 0); + white-space: nowrap; + border-width: 0; +} + +@media (max-width: 600px) { + .thumbs { + display: none; + } + + .navPrev { + left: 1rem; + } + + .navNext { + right: 1rem; + } +} diff --git a/docs/src/components/demos/morph-gallery/morph-gallery.tsx b/docs/src/components/demos/morph-gallery/morph-gallery.tsx new file mode 100644 index 0000000..53d6e84 --- /dev/null +++ b/docs/src/components/demos/morph-gallery/morph-gallery.tsx @@ -0,0 +1,99 @@ +import { useEffect, useRef, PropsWithChildren } from "react" +import { + Gallery, + GalleryPagination, + GalleryNav, + GalleryPaginationItem, + useGallery, +} from "@wethegit/react-gallery" +import "@wethegit/react-gallery/style.css" + +import styles from "./morph-gallery.module.scss" + +import { MorphRenderer } from "./morph-renderer" + +import { SLIDES, type Slide } from "../../../data/shared-data" + +export function MorphGallery() { + return ( +
+ +
+ + + + + + + Previous + + + + + + + Next + + + + className={styles.thumbs} + renderPaginationItem={({ item, index, active }) => ( + + {item.alt} + + )} + /> +
+
+
+ ) +} + +function MorphCanvas() { + const canvasRef = useRef(null) + const rendererRef = useRef(null) + const { activeIndex, galleryItems } = useGallery() + const prevIndexRef = useRef(activeIndex) + + useEffect(() => { + if (canvasRef.current === null) return + const renderer = new MorphRenderer(canvasRef.current) + rendererRef.current = renderer + renderer.init(galleryItems.map((i) => i.image)) + return () => renderer.destroy() + }, [galleryItems]) + + useEffect(() => { + const prev = prevIndexRef.current + if (prev !== activeIndex) { + rendererRef.current?.transition(prev, activeIndex) + prevIndexRef.current = activeIndex + } + }, [activeIndex]) + + return