Skip to content

Commit

Permalink
not even sure
Browse files Browse the repository at this point in the history
  • Loading branch information
arzafran committed Jun 17, 2024
1 parent 6693797 commit cdcf2ed
Show file tree
Hide file tree
Showing 10 changed files with 219 additions and 33 deletions.
25 changes: 25 additions & 0 deletions app/(pages)/(components)/page-transition/transition.context.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use client'

import gsap from 'gsap'
import { createContext, useState } from 'react'

const TransitionContext = createContext({})

const TransitionProvider = ({ children }) => {
const [timeline, setTimeline] = useState(() =>
gsap.timeline({ paused: true }),
)

return (
<TransitionContext.Provider
value={{
timeline,
setTimeline,
}}
>
{children}
</TransitionContext.Provider>
)
}

export { TransitionContext, TransitionProvider }
52 changes: 30 additions & 22 deletions app/(pages)/(components)/wrapper/index.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,37 @@
import cn from 'clsx'
import { Lenis } from 'libs/lenis'
import { Canvas } from 'libs/webgl/components/canvas'
import { forwardRef } from 'react'
import { Footer } from '../footer'
import { Navigation } from '../navigation'
import s from './wrapper.module.scss'

export function Wrapper({
children,
theme = 'light',
lenis = true,
lenisOptions = {},
webgl = false,
className,
}) {
return (
<>
{lenis && <Lenis root options={lenisOptions} />}
{webgl && <Canvas root />}
<div className={cn(s.wrapper, `theme-${theme}`, className)}>
<Navigation />
<main role="main" className={s.main}>
{children}
</main>
<Footer />
</div>
</>
)
}
export const Wrapper = forwardRef(
(
{
children,
theme = 'light',
lenis = true,
lenisOptions = {},
webgl = false,
className,
},
ref,
) => {
return (
<>
{lenis && <Lenis root options={lenisOptions} />}
<div className={cn(s.wrapper, `theme-${theme}`, className)}>
<Navigation />
<main ref={ref} role="main" className={s.main}>
{webgl && <Canvas root />}
{children}
</main>
<Footer />
</div>
</>
)
},
)

Wrapper.displayName = 'Wrapper'
14 changes: 14 additions & 0 deletions app/(pages)/home/home.module.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
.page {
text-transform: uppercase;
font-family: var(--font-ibm-plex-mono);

.inner {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
flex-grow: 1;
width: 50%;
margin: auto;

@include mobile {
padding: 0 mobile-vw(16px);
}
}
}
46 changes: 44 additions & 2 deletions app/(pages)/home/page.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,52 @@
'use client'

import { useGSAP } from '@gsap/react'
import gsap from 'gsap'
import { useContext, useRef } from 'react'
import { TransitionContext } from '../(components)/page-transition/transition.context'
import { Wrapper } from '../(components)/wrapper'
import s from './home.module.scss'

gsap.registerPlugin(useGSAP)

export default function Home() {
const { timeline } = useContext(TransitionContext)
const container = useRef(null)

useGSAP(
() => {
gsap.fromTo(
'p',
{ y: 30, opacity: 0 },
{ y: 0, opacity: 1, stagger: 0.25 },
)
timeline.add(gsap.to(container.current, { opacity: 0 }))
},
{ scope: container },
)

return (
<Wrapper theme="red" className={s.page}>
{/* content */}
<Wrapper ref={container} theme="red" className={s.page}>
<section className={s.inner}>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit.
Necessitatibus, nobis. Adipisci debitis maiores dolorem optio
architecto omnis dolor dolores autem. Vel doloribus, placeat ipsam
harum quasi velit cumque dignissimos doloremque?
</p>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit.
Necessitatibus, nobis. Adipisci debitis maiores dolorem optio
architecto omnis dolor dolores autem. Vel doloribus, placeat ipsam
harum quasi velit cumque dignissimos doloremque?
</p>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit.
Necessitatibus, nobis. Adipisci debitis maiores dolorem optio
architecto omnis dolor dolores autem. Vel doloribus, placeat ipsam
harum quasi velit cumque dignissimos doloremque?
</p>
</section>
</Wrapper>
)
}
40 changes: 37 additions & 3 deletions app/(pages)/hubspot/page.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,48 @@
'use client'

import { useGSAP } from '@gsap/react'
import gsap from 'gsap'
import { Form } from 'libs/form'
import { getForm } from 'libs/hubspot-forms/fetch-form'
import { useContext, useEffect, useRef } from 'react'
import { TransitionContext } from '../(components)/page-transition/transition.context'
import { Wrapper } from '../(components)/wrapper'
import { Subscribe } from './(components)/subscribe'
import s from './hubspot.module.scss'

export default async function Hubspot() {
const { form } = await getForm(process.env.NEXT_HUSBPOT_FORM_ID)
gsap.registerPlugin(useGSAP)

export default function Hubspot() {
const { form } = getForm(process.env.NEXT_HUSBPOT_FORM_ID)
const { timeline } = useContext(TransitionContext)
const container = useRef(null)

useGSAP(
() => {
const targets = gsap.utils.toArray(['p', 'form'])

gsap.fromTo(
targets,
{ x: 30, opacity: 0 },
{ x: 0, opacity: 1, stagger: 0.25 },
)
timeline.add(gsap.to(container.current, { opacity: 0 }))
},
{ scope: container },
)

useEffect(() => {
const currentContainer = container.current

return () => {
if (currentContainer) {
timeline.to(currentContainer, { opacity: 0, duration: 0.5 })
}
}
}, [timeline, container])

return (
<Wrapper theme="red" className={s.page}>
<Wrapper ref={container} theme="red" className={s.page}>
<div className={s.inner}>
<p className={s.title}>subscribe for more Satūs</p>
<Form
Expand Down
3 changes: 2 additions & 1 deletion app/(pages)/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import AppData from '../../package.json'

import 'styles/global.scss'
import { fonts } from '../fonts'
import { TransitionProvider } from './(components)/page-transition/transition.context'

const APP_NAME = AppData.name
const APP_DEFAULT_TITLE = 'Satūs'
Expand Down Expand Up @@ -70,7 +71,7 @@ export default async function Layout({ children }) {
{GTM_ID && <GoogleTagManager gtmId={GTM_ID} />}
<body>
<RealViewport />
{children}
<TransitionProvider>{children}</TransitionProvider>
<Debug />
<GSAP />
</body>
Expand Down
29 changes: 27 additions & 2 deletions app/(pages)/r3f/page.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,37 @@
'use client'

import { useGSAP } from '@gsap/react'
import gsap from 'gsap'
import { TheatreProjectProvider } from 'libs/theatre'
import { useContext, useRef } from 'react'
import { TransitionContext } from '../(components)/page-transition/transition.context'
import { Wrapper } from '../(components)/wrapper'
import { Box } from './(components)/box'
import s from './r3f.module.scss'

export default function Home() {
gsap.registerPlugin(useGSAP)

export default function R3fPage() {
const { timeline } = useContext(TransitionContext)
const container = useRef(null)

useGSAP(
() => {
const targets = gsap.utils.toArray(['div'])

gsap.fromTo(
targets,
{ y: 30, opacity: 0 },
{ y: 0, opacity: 1, stagger: 0.25 },
)
timeline.add(gsap.to(container.current, { opacity: 0 }))
},
{ scope: container },
)

return (
<TheatreProjectProvider id="Satus-R3f" config="/config/Satus-R3f.json">
<Wrapper theme="red" className={s.page} webgl={true}>
<Wrapper ref={container} theme="red" className={s.page} webgl={true}>
<Box />
</Wrapper>
</TheatreProjectProvider>
Expand Down
31 changes: 28 additions & 3 deletions app/(pages)/template.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
import { PageTransition } from 'app/(pages)/(components)/page-transition'
'use client'

export default function Template({ children }) {
return <PageTransition>{children}</PageTransition>
import { useGSAP } from '@gsap/react'

import gsap from 'gsap'

import { useContext, useEffect, useState } from 'react'
import { TransitionContext } from './(components)/page-transition/transition.context'

gsap.registerPlugin(useGSAP)

export default function Template(props) {
const { children } = props
const [displayChildren, setDisplayChildren] = useState(children)
const { timeline } = useContext(TransitionContext)

useEffect(() => {
console.log('pause', props)
timeline.pause().clear()
return () => {
console.log('play', props)
timeline.play().then(() => {
window.scrollTo(0, 0)
setDisplayChildren(children)
})
}
}, [children])

return displayChildren
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"dependencies": {
"@darkroom.engineering/hamo": "0.6.42",
"@darkroom.engineering/tempus": "0.0.46",
"@gsap/react": "^2.1.1",
"@next/third-parties": "^14.2.4",
"@radix-ui/react-select": "^2.0.0",
"@react-three/drei": "^9.106.0",
Expand Down
11 changes: 11 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cdcf2ed

Please sign in to comment.