This repository has been archived by the owner on Nov 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
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
15 changed files
with
255 additions
and
65 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
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
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
103 changes: 103 additions & 0 deletions
103
src/app/(main)/(library)/_containers/local-library/_components/library-header.tsx
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,103 @@ | ||
import { atom, useAtomValue } from "jotai" | ||
import Image from "next/image" | ||
import React, { useEffect, useState } from "react" | ||
import { Transition } from "@headlessui/react" | ||
import { cn } from "@/components/ui/core" | ||
import { useWindowScroll } from "react-use" | ||
|
||
export const __libraryHeaderImageAtom = atom<string | null>(null) | ||
|
||
// ugly but works | ||
export function LibraryHeader() { | ||
|
||
const image = useAtomValue(__libraryHeaderImageAtom) | ||
const [actualImage, setActualImage] = useState<string | null>(null) | ||
const [prevImage, setPrevImage] = useState<string | null>(null) | ||
const [dimmed, setDimmed] = useState(false) | ||
|
||
useEffect(() => { | ||
if (actualImage === null) { | ||
setActualImage(image) | ||
} else { | ||
setActualImage(null) | ||
} | ||
const t = setTimeout(() => { | ||
setActualImage(image) | ||
}, 500) | ||
|
||
return () => { | ||
// @ts-ignore | ||
clearTimeout(t) | ||
} | ||
}, [image]) | ||
|
||
useEffect(() => { | ||
if (actualImage) | ||
setPrevImage(actualImage) | ||
}, [actualImage]) | ||
|
||
const { y } = useWindowScroll() | ||
|
||
useEffect(() => { | ||
console.log(y) | ||
if (y > 100) | ||
setDimmed(true) | ||
else | ||
setDimmed(false) | ||
}, [(y > 100)]) | ||
|
||
if (!image) return null | ||
|
||
return ( | ||
<div className={"__header h-[18rem] z-[5] top-0 w-full md:w-[calc(100%-5rem)] fixed group/library-header"}> | ||
<div | ||
className="h-[25rem] z-[0] w-full flex-none object-cover object-center absolute top-0 overflow-hidden"> | ||
<div | ||
className={"w-full absolute z-[2] top-0 h-[15rem] bg-gradient-to-b from-[--background-color] to-transparent via"} | ||
/> | ||
<Transition | ||
show={!!actualImage} | ||
enter="transition-opacity duration-500" | ||
enterFrom="opacity-0" | ||
enterTo="opacity-100" | ||
leave="transition-opacity duration-500" | ||
leaveFrom="opacity-100" | ||
leaveTo="opacity-0" | ||
> | ||
{(actualImage || prevImage) && <Image | ||
src={actualImage || prevImage!} | ||
alt={"banner image"} | ||
fill | ||
quality={100} | ||
priority | ||
sizes="100vw" | ||
className={cn( | ||
"object-cover object-center z-[1] opacity-50 transition-all", | ||
// "group-hover/library-header:opacity-100", | ||
{ "opacity-20": dimmed }, | ||
)} | ||
/>} | ||
</Transition> | ||
{prevImage && <Image | ||
src={prevImage} | ||
alt={"banner image"} | ||
fill | ||
quality={100} | ||
priority | ||
sizes="100vw" | ||
className={cn( | ||
"object-cover object-center z-[1] opacity-50 transition-all", | ||
{ "opacity-10": dimmed }, | ||
)} | ||
/>} | ||
<div | ||
className={"w-full z-[2] absolute bottom-0 h-[40rem] bg-gradient-to-t from-[--background-color] via-opacity-50 via-10% to-transparent"} | ||
/> | ||
<div | ||
className={"w-[4rem] z-[2] absolute top-0 right-0 h-[40rem] bg-gradient-to-l from-[--background-color] via-opacity-50 via-10% to-transparent"} | ||
/> | ||
</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
Oops, something went wrong.