Skip to content

Commit

Permalink
Add handler for closing drawer easily
Browse files Browse the repository at this point in the history
  • Loading branch information
marshallku committed Feb 11, 2024
1 parent 71183c6 commit 30d5d44
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions apps/blog/src/components/DrawerContent/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";

import Link from "next/link";
import { Dispatch, SetStateAction, useCallback, useRef } from "react";
import { Dispatch, MouseEventHandler, SetStateAction, useCallback, useRef } from "react";
import { Icon, IconProps } from "@marshallku/icon";
import { classNames } from "@marshallku/utils";
import Hamburger from "#components/Hamburger";
Expand All @@ -24,6 +24,12 @@ function DrawerContent({ opened, closeDrawer, willClose, setWillClose }: DrawerC
setWillClose(true);
}, [closeDrawer, setWillClose]);

const handleClick: MouseEventHandler<HTMLDivElement> = useCallback((e) => {
if (e.target === containerRef.current) {
close();
}
}, [close]);

const List = useCallback(
({
icon,
Expand All @@ -47,7 +53,7 @@ function DrawerContent({ opened, closeDrawer, willClose, setWillClose }: DrawerC
);

return (
<div className={cx("", opened && "--opened", willClose && "--close")} ref={containerRef}>
<div className={cx("", opened && "--opened", willClose && "--close")} ref={containerRef} onClick={handleClick}>
<Hamburger onClick={close} opened={!willClose} className={cx("__hamburger")} />
<nav className={cx("__nav")}>
<ul className={cx("__item")}>
Expand Down

0 comments on commit 30d5d44

Please sign in to comment.