-
-
Notifications
You must be signed in to change notification settings - Fork 772
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Innei <i@innei.in>
- Loading branch information
Showing
6 changed files
with
126 additions
and
1 deletion.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,87 @@ | ||
import React, { useEffect, useMemo, useState } from 'react' | ||
import { atom, useStore } from 'jotai' | ||
import { Drawer } from 'vaul' | ||
import type { FC, PropsWithChildren } from 'react' | ||
|
||
export interface PresentSheetProps { | ||
content: JSX.Element | FC | ||
open?: boolean | ||
onOpenChange?: (value: boolean) => void | ||
title?: string | ||
zIndex?: number | ||
dismissible?: boolean | ||
} | ||
|
||
export const sheetStackAtom = atom([] as HTMLDivElement[]) | ||
|
||
export const PresentSheet: FC<PropsWithChildren<PresentSheetProps>> = ( | ||
props, | ||
) => { | ||
const { content, children, zIndex = 998, title, dismissible = true } = props | ||
const nextRootProps = useMemo(() => { | ||
const nextProps = {} as any | ||
if (props.open !== undefined) { | ||
nextProps.open = props.open | ||
} | ||
|
||
if (props.onOpenChange !== undefined) { | ||
nextProps.onOpenChange = props.onOpenChange | ||
} | ||
|
||
return nextProps | ||
}, [props]) | ||
const [holderRef, setHolderRef] = useState<HTMLDivElement | null>() | ||
const store = useStore() | ||
|
||
useEffect(() => { | ||
const holder = holderRef | ||
if (!holder) return | ||
store.set(sheetStackAtom, (p) => { | ||
return p.concat(holder) | ||
}) | ||
|
||
return () => { | ||
store.set(sheetStackAtom, (p) => { | ||
return p.filter((item) => item !== holder) | ||
}) | ||
} | ||
}, [holderRef, store]) | ||
|
||
const Root = Drawer.Root | ||
|
||
const overlayZIndex = zIndex - 1 | ||
const contentZIndex = zIndex | ||
|
||
return ( | ||
<Root dismissible={dismissible} {...nextRootProps}> | ||
<Drawer.Trigger asChild>{children}</Drawer.Trigger> | ||
<Drawer.Portal> | ||
<Drawer.Content | ||
style={{ | ||
zIndex: contentZIndex, | ||
}} | ||
className="fixed bottom-0 left-0 right-0 mt-24 flex max-h-[95vh] flex-col rounded-t-[10px] bg-base-100 p-4" | ||
> | ||
{dismissible && ( | ||
<div className="mx-auto mb-8 h-1.5 w-12 flex-shrink-0 rounded-full bg-zinc-300 dark:bg-neutral-800" /> | ||
)} | ||
|
||
{title && <Drawer.Title>{title}</Drawer.Title>} | ||
|
||
{React.isValidElement(content) | ||
? content | ||
: typeof content === 'function' | ||
? React.createElement(content) | ||
: null} | ||
<div ref={setHolderRef} /> | ||
</Drawer.Content> | ||
<Drawer.Overlay | ||
className="fixed inset-0 bg-neutral-800/40" | ||
style={{ | ||
zIndex: overlayZIndex, | ||
}} | ||
/> | ||
</Drawer.Portal> | ||
</Root> | ||
) | ||
} |
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 @@ | ||
export * from './Sheet' |
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
c919584
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
shiro – ./
shiro-git-main-innei.vercel.app
shiro-innei.vercel.app
springtide.vercel.app
innei.in