From 5df9cf23026d1b1223c7de046f00abd0d3608c40 Mon Sep 17 00:00:00 2001 From: HsunPei Wang Date: Sun, 27 Oct 2024 19:44:02 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20:=20reuse=20the=20sticky?= =?UTF-8?q?=20container?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/grouped/StickyContainer.tsx | 19 -------- .../components/grouped/TrackedSection.tsx | 2 +- apps/docs/components/video/StickyVideo.tsx | 30 ++++++------ apps/docs/pages/track_grouped_sections.mdx | 5 +- packages/layout/src/components/index.ts | 1 + .../src/components/sticky/StickyContainer.tsx | 48 +++++++++++++++++++ .../sticky/StickyContainerTailwind.tsx | 30 ++++++++++++ .../layout/src/components/sticky/index.ts | 2 + packages/layout/src/index.ts | 1 + 9 files changed, 99 insertions(+), 39 deletions(-) delete mode 100644 apps/docs/components/grouped/StickyContainer.tsx create mode 100644 packages/layout/src/components/index.ts create mode 100644 packages/layout/src/components/sticky/StickyContainer.tsx create mode 100644 packages/layout/src/components/sticky/StickyContainerTailwind.tsx create mode 100644 packages/layout/src/components/sticky/index.ts diff --git a/apps/docs/components/grouped/StickyContainer.tsx b/apps/docs/components/grouped/StickyContainer.tsx deleted file mode 100644 index 0ae7488..0000000 --- a/apps/docs/components/grouped/StickyContainer.tsx +++ /dev/null @@ -1,19 +0,0 @@ -export interface StickyContainerProps { - /** Background sticky container */ - children: React.ReactNode; - - /** Overlaying content */ - overlay?: React.ReactNode; -} - -export const StickyContainer = ({ overlay, children }: StickyContainerProps) => { - return ( -
- {/* Background */} -
{children}
- - {/* Overlay foreground content */} -
{overlay}
-
- ); -}; diff --git a/apps/docs/components/grouped/TrackedSection.tsx b/apps/docs/components/grouped/TrackedSection.tsx index 47503cb..b327031 100644 --- a/apps/docs/components/grouped/TrackedSection.tsx +++ b/apps/docs/components/grouped/TrackedSection.tsx @@ -15,7 +15,7 @@ export const TrackedSection = ({ className, sectionID }: TrackedSectionProps) => return (
diff --git a/apps/docs/components/video/StickyVideo.tsx b/apps/docs/components/video/StickyVideo.tsx index 76dd644..2247324 100644 --- a/apps/docs/components/video/StickyVideo.tsx +++ b/apps/docs/components/video/StickyVideo.tsx @@ -2,10 +2,9 @@ import { useRef } from 'react'; import { useSectionScrollState } from '@react-scrollytelling/core'; import { useResizeObserver } from '@react-scrollytelling/layout'; +import { StickyContainerTailwind } from '@react-scrollytelling/layout'; import { Video } from '@react-scrollytelling/video'; -import { StickyContainer } from '../grouped/StickyContainer'; - export interface StickyVideoProps { src: string; } @@ -18,19 +17,19 @@ export const StickyVideo = ({ src }: StickyVideoProps) => { const { scrolledRatio } = useSectionScrollState(sectionRef); return ( - -
+
{/* One video height of the empty space */}
{Math.round(scrolledRatio * 100)}% @@ -38,16 +37,15 @@ export const StickyVideo = ({ src }: StickyVideoProps) => {
} + backgroundRef={videoContainerRef} > -
-
- +
diff --git a/packages/layout/src/components/index.ts b/packages/layout/src/components/index.ts new file mode 100644 index 0000000..7fa3183 --- /dev/null +++ b/packages/layout/src/components/index.ts @@ -0,0 +1 @@ +export * from './sticky'; diff --git a/packages/layout/src/components/sticky/StickyContainer.tsx b/packages/layout/src/components/sticky/StickyContainer.tsx new file mode 100644 index 0000000..efcdd44 --- /dev/null +++ b/packages/layout/src/components/sticky/StickyContainer.tsx @@ -0,0 +1,48 @@ +export interface StickyContainerProps { + /** Background sticky container */ + children: React.ReactNode; + + /** Overlaying content */ + overlay?: React.ReactNode; + + /** Ref to the background container */ + backgroundRef?: React.RefObject; +} + +export const StickyContainer = ({ overlay, children, backgroundRef }: StickyContainerProps) => { + return ( +
+ {/* Background */} +
+
+ {children} +
+
+ + {/* Overlay foreground content */} +
+ {overlay} +
+
+ ); +}; diff --git a/packages/layout/src/components/sticky/StickyContainerTailwind.tsx b/packages/layout/src/components/sticky/StickyContainerTailwind.tsx new file mode 100644 index 0000000..2f8ed8b --- /dev/null +++ b/packages/layout/src/components/sticky/StickyContainerTailwind.tsx @@ -0,0 +1,30 @@ +export interface StickyContainerTailwindProps { + /** Background sticky container */ + children: React.ReactNode; + + /** Overlaying content */ + overlay?: React.ReactNode; + + /** Ref to the background container */ + backgroundRef?: React.RefObject; +} + +export const StickyContainerTailwind = ({ + overlay, + children, + backgroundRef, +}: StickyContainerTailwindProps) => { + return ( +
+ {/* Background */} +
+
+ {children} +
+
+ + {/* Overlay foreground content */} +
{overlay}
+
+ ); +}; diff --git a/packages/layout/src/components/sticky/index.ts b/packages/layout/src/components/sticky/index.ts new file mode 100644 index 0000000..e825b28 --- /dev/null +++ b/packages/layout/src/components/sticky/index.ts @@ -0,0 +1,2 @@ +export * from './StickyContainerTailwind'; +export * from './StickyContainer'; diff --git a/packages/layout/src/index.ts b/packages/layout/src/index.ts index 4cc90d0..9330290 100644 --- a/packages/layout/src/index.ts +++ b/packages/layout/src/index.ts @@ -1 +1,2 @@ export * from './hooks'; +export * from './components';