-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Styled book page, author list, and file list components
- Loading branch information
Showing
19 changed files
with
303 additions
and
187 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
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
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,60 @@ | ||
"use client"; | ||
|
||
import {JSX, useLayoutEffect, useRef} from "react"; | ||
import {useBoolean} from "usehooks-ts"; | ||
import useFocusOnRender from "@lib/hooks/useFocusOnRender"; | ||
import {ChevronDownIcon} from "@heroicons/react/20/solid"; | ||
|
||
const BookAwards = ({children}: { children: JSX.Element[] }) => { | ||
const top = children.slice(0, 3) | ||
const bottom = children.slice(3); | ||
const firstBottomRef = useRef<HTMLLIElement>(null) | ||
const {value: showingMore, setTrue: showMore} = useBoolean(false) | ||
const {value: focusOnElement, setTrue: enableFocusElement, setFalse: disableFocusElement} = useBoolean(false) | ||
|
||
const setFocusOnItem = useFocusOnRender(firstBottomRef, false); | ||
|
||
useLayoutEffect(() => { | ||
if (focusOnElement) setFocusOnItem() | ||
}, [focusOnElement, setFocusOnItem]); | ||
|
||
return ( | ||
<div> | ||
<ul className="list-unstyled mb-10"> | ||
{top.map((item, i) => | ||
<li className="mb-10" key={`top-award-${i}`}> | ||
{item} | ||
</li> | ||
)} | ||
{showingMore && | ||
<> | ||
{bottom.map((item, i) => | ||
<li | ||
className="mb-10" | ||
key={`bottom-award-${i}`} | ||
ref={i === 0 ? firstBottomRef : undefined} | ||
tabIndex={i === 0 ? 0 : undefined} | ||
onBlur={disableFocusElement} | ||
> | ||
{item} | ||
</li> | ||
)} | ||
</> | ||
} | ||
</ul> | ||
|
||
{(bottom && !showingMore) && | ||
<button | ||
className="flex items-center gap-3" | ||
onClick={() => { | ||
enableFocusElement() | ||
showMore() | ||
}} | ||
> | ||
<ChevronDownIcon width={24} className="text-fog-dark shrink-0"/> Read more | ||
</button> | ||
} | ||
</div> | ||
) | ||
} | ||
export default BookAwards; |
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.