generated from Pettor/template-web-component-react
-
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.
Merge pull request #8 from Pettor/feature/drawer
feat: use drawer for application menu
- Loading branch information
Showing
14 changed files
with
59 additions
and
102 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
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,4 @@ | ||
import { atom } from "jotai"; | ||
|
||
export const drawerOpenedAtom = atom(false); | ||
export const toggleDrawerAtom = atom(null, (_get, set) => set(drawerOpenedAtom, (prev) => !prev)); |
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,34 @@ | ||
import { useRef, type ReactElement } from "react"; | ||
import { FolderPlusIcon } from "@heroicons/react/24/solid"; | ||
import { useAtomValue, useSetAtom } from "jotai"; | ||
import { useOnClickOutside } from "usehooks-ts"; | ||
import { drawerOpenedAtom, toggleDrawerAtom } from "../atoms/DrawerAtoms"; | ||
|
||
export interface AppDrawerProps { | ||
onNewImage: () => void; | ||
} | ||
|
||
export function AppDrawer({ onNewImage }: AppDrawerProps): ReactElement { | ||
const drawerState = useAtomValue(drawerOpenedAtom); | ||
const swapDrawer = useSetAtom(toggleDrawerAtom); | ||
const menuRef = useRef<HTMLUListElement>(null); | ||
useOnClickOutside(menuRef, () => drawerState && swapDrawer()); | ||
|
||
return ( | ||
<div className="drawer z-30"> | ||
<input id="my-drawer" type="checkbox" checked={drawerState} className="drawer-toggle" /> | ||
<div className="drawer-side"> | ||
<label htmlFor="my-drawer" aria-label="close sidebar" className="drawer-overlay" /> | ||
|
||
<ul ref={menuRef} className="menu min-h-full w-60 bg-base-200 p-4 text-base text-base-content md:w-80"> | ||
<li onClick={onNewImage}> | ||
<a> | ||
<FolderPlusIcon className="h-6 w-6" /> | ||
New Image | ||
</a> | ||
</li> | ||
</ul> | ||
</div> | ||
</div> | ||
); | ||
} |
42 changes: 7 additions & 35 deletions
42
src/components/library/image-editor/toolbar/ToolbarMenu.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 |
---|---|---|
@@ -1,46 +1,18 @@ | ||
import type { MouseEvent } from "react"; | ||
import { useState, type ReactElement, useRef } from "react"; | ||
import { type ReactElement } from "react"; | ||
import { Bars3Icon } from "@heroicons/react/24/solid"; | ||
import { useOnClickOutside } from "usehooks-ts"; | ||
import { useSetAtom } from "jotai"; | ||
import { toggleDrawerAtom } from "../atoms/DrawerAtoms"; | ||
|
||
export interface ToolbarMenuProps { | ||
onNewImage: () => void; | ||
} | ||
|
||
export function ToolbarMenu({ onNewImage }: ToolbarMenuProps): ReactElement { | ||
const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null); | ||
const menuRef = useRef<HTMLUListElement>(null); | ||
useOnClickOutside(menuRef, () => setAnchorEl(null)); | ||
|
||
function handleMenuClick(event: MouseEvent): void { | ||
if (anchorEl) { | ||
setAnchorEl(null); | ||
return; | ||
} | ||
|
||
setAnchorEl(event.currentTarget as HTMLElement); | ||
} | ||
|
||
function contextMenu(): ReactElement { | ||
return ( | ||
<div className="absolute bottom-16 right-5 z-10 md:left-5 md:top-16"> | ||
<ul ref={menuRef} className="menu w-56 rounded-box bg-base-200 shadow-xl"> | ||
<li onClick={onNewImage}> | ||
<a>New Image</a> | ||
</li> | ||
</ul> | ||
</div> | ||
); | ||
} | ||
export function ToolbarMenu(): ReactElement { | ||
const toggleDrawer = useSetAtom(toggleDrawerAtom); | ||
|
||
return ( | ||
<div className="absolute z-20 flex items-center justify-center p-4 max-sm:bottom-0 max-sm:right-0"> | ||
<div className="glass navbar flex h-10 min-h-0 rounded-box bg-base-300 bg-opacity-80 shadow-xl md:h-12 dark:bg-opacity-80 dark:bg-none"> | ||
<button className="btn btn-square btn-ghost btn-sm" onClick={handleMenuClick}> | ||
<div className="glass navbar flex h-10 min-h-0 rounded-box bg-base-300 bg-opacity-80 shadow-xl dark:bg-opacity-80 dark:bg-none md:h-12"> | ||
<button className="btn btn-square btn-ghost btn-sm" onClick={toggleDrawer}> | ||
<Bars3Icon className="h-4 w-4 md:h-6 md:w-6" /> | ||
</button> | ||
</div> | ||
{anchorEl && contextMenu()} | ||
</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
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