generated from xhofe/solid-lib
-
Notifications
You must be signed in to change notification settings - Fork 443
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add sidebar for the tree of folders * feat: add sidebar for the tree of folders * fix: css transform overlay may block pointer event * feat: show empty icon in sidebar * fix: should close folder in folder tree while failed * fix: sidebar shadow & more smooth animation while reset sidebar
- Loading branch information
Showing
8 changed files
with
238 additions
and
29 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,109 @@ | ||
import { Box } from "@hope-ui/solid" | ||
import { Motion } from "@motionone/solid" | ||
import { useLocation } from "@solidjs/router" | ||
import { | ||
Show, | ||
createEffect, | ||
createMemo, | ||
createSignal, | ||
on, | ||
onCleanup, | ||
onMount, | ||
} from "solid-js" | ||
import { FolderTree, FolderTreeHandler } from "~/components" | ||
import { useRouter } from "~/hooks" | ||
import { local, objStore } from "~/store" | ||
import { objBoxRef } from "./Obj" | ||
|
||
function SidebarPannel() { | ||
const { to } = useRouter() | ||
const location = useLocation() | ||
|
||
const [folderTreeHandler, setFolderTreeHandler] = | ||
createSignal<FolderTreeHandler>() | ||
const [sideBarRef, setSideBarRef] = createSignal<HTMLDivElement>() | ||
const [offsetX, setOffsetX] = createSignal<number | string>(-999) | ||
|
||
const showFullSidebar = () => setOffsetX(0) | ||
const resetSidebar = () => { | ||
const $objBox = objBoxRef() | ||
const $sideBar = sideBarRef() | ||
if (!$objBox || !$sideBar) return | ||
const gap = $objBox.offsetLeft > 50 ? 16 : 0 | ||
if ($sideBar.clientWidth < $objBox.offsetLeft - gap) { | ||
setOffsetX(0) | ||
} else { | ||
setOffsetX(`calc(-100% + ${$objBox.offsetLeft}px - ${gap}px)`) | ||
} | ||
} | ||
|
||
let rafId: number | ||
|
||
onMount(() => { | ||
const handler = folderTreeHandler() | ||
handler?.setPath(location.pathname) | ||
rafId = requestAnimationFrame(resetSidebar) | ||
window.addEventListener("resize", resetSidebar) | ||
onCleanup(() => window.removeEventListener("resize", resetSidebar)) | ||
}) | ||
|
||
createEffect( | ||
on( | ||
() => objStore.state, | ||
() => { | ||
cancelAnimationFrame(rafId) | ||
rafId = requestAnimationFrame(resetSidebar) | ||
}, | ||
), | ||
) | ||
|
||
createEffect( | ||
on( | ||
() => location.pathname, | ||
() => { | ||
const handler = folderTreeHandler() | ||
handler?.setPath(location.pathname) | ||
}, | ||
), | ||
) | ||
|
||
return ( | ||
<Box | ||
as={Motion.div} | ||
initial={{ x: -999 }} | ||
animate={{ x: offsetX() }} | ||
zIndex="$overlay" | ||
pos="fixed" | ||
left={3} // width of outline shadow | ||
top={3} | ||
h="calc(100vh - 6px)" | ||
minW={180} | ||
p="$2" | ||
overflow="auto" | ||
shadow="$lg" | ||
rounded="$lg" | ||
bgColor="white" | ||
_dark={{ bgColor: "$neutral3" }} | ||
onMouseEnter={showFullSidebar} | ||
onMouseLeave={resetSidebar} | ||
ref={(el: HTMLDivElement) => setSideBarRef(el)} | ||
> | ||
<FolderTree | ||
autoOpen | ||
showEmptyIcon | ||
onChange={(path) => to(path)} | ||
handle={(handler) => setFolderTreeHandler(handler)} | ||
/> | ||
</Box> | ||
) | ||
} | ||
|
||
export function Sidebar() { | ||
const visible = createMemo(() => local["show_sidebar"] !== "none") | ||
|
||
return ( | ||
<Show when={visible()}> | ||
<SidebarPannel /> | ||
</Show> | ||
) | ||
} |
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