-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
312 additions
and
24 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { useEffect, useState } from 'react'; | ||
|
||
export const useDocument = () => { | ||
return import.meta.env.SSR ? undefined : document; | ||
}; | ||
|
||
export const useDocumentScroll = () => { | ||
const document = useDocument(); | ||
|
||
const [state, setState] = useState({ | ||
x: 0, | ||
y: 0 | ||
}); | ||
|
||
useEffect(() => { | ||
const handler = () => { | ||
if (document?.documentElement) { | ||
setState({ | ||
x: document.documentElement.scrollLeft, | ||
y: document.documentElement.scrollTop | ||
}); | ||
} | ||
}; | ||
|
||
if (document) { | ||
document.addEventListener('scroll', handler, { | ||
capture: false, | ||
passive: true | ||
}); | ||
} | ||
|
||
return () => { | ||
if (document) { | ||
document.removeEventListener('scroll', handler); | ||
} | ||
}; | ||
}, [document]); | ||
|
||
return state; | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { NavLink } from '@remix-run/react'; | ||
import { atom, useAtom } from 'jotai'; | ||
import { useEffect, useRef, useState } from 'react'; | ||
|
||
import { useDocumentScroll } from '~/hooks'; | ||
|
||
const NavHeight = 40; | ||
|
||
const TitleHeight = 152; | ||
|
||
export const heroHeightAtom = atom((get) => NavHeight + TitleHeight); | ||
|
||
export default function Layout(props: { children?: React.ReactNode }) { | ||
const { x, y } = useDocumentScroll(); | ||
const [heroHeight] = useAtom(heroHeightAtom); | ||
|
||
return ( | ||
<div className="w-full" style={{ '--hero-height': `${heroHeight}px` }}> | ||
<Header scrollY={y}></Header> | ||
<div className="flex pt-$hero-height"> | ||
<div className="w-[300px] border-r-1 h-[150vh]"></div> | ||
<div className="flex-auto">{props.children}</div> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
|
||
|
||
function Header(props: { scrollY: number }) { | ||
const { scrollY } = props; | ||
const [heroHeight, setHeroHeright] = useAtom(heroHeightAtom); | ||
|
||
const titleTop = Math.min(TitleHeight, scrollY); | ||
|
||
return ( | ||
<div className="w-full fixed bg-[#fef8f7]" style={{ height: `${heroHeight}px` }}> | ||
<nav className="px-8 py-2 flex gap-2"> | ||
<div>🌸 Anime Garden</div> | ||
<div>动画</div> | ||
</nav> | ||
<div className='w-full'> | ||
<div className="w-full pt-4rem pb-3rem text-4xl font-quicksand font-bold text-center select-none outline-none absolute" style={{ top: `-${titleTop}px` }}> | ||
<NavLink to="/">🌸 Anime Garden</NavLink> | ||
</div> | ||
<div className="w-full pt-4 flex justify-center pb-6rem absolute" style={{ top: `${TitleHeight - titleTop}px` }}> | ||
<div className="rounded-md h-16 w-[600px] border bg-white"></div> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,15 @@ | ||
/// <reference types="unplugin-info/client" /> | ||
|
||
import type * as CSS from 'csstype'; | ||
|
||
declare module '~build/meta' { | ||
export const APP_HOST: string; | ||
|
||
export const SERVER_URL: string; | ||
} | ||
|
||
declare module 'csstype' { | ||
interface Properties { | ||
'--hero-height'?: string; | ||
} | ||
} |
This file contains 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
Oops, something went wrong.