Skip to content

Commit

Permalink
feat: ThemeSelector 영역 외 클릭 시 창 닫기
Browse files Browse the repository at this point in the history
  • Loading branch information
taboowiths committed Oct 5, 2024
1 parent e03075f commit 7bd6aa5
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions packages/view/src/components/ThemeSelector/ThemeSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useState } from "react";
import { useEffect, useRef, useState } from "react";
import "./ThemeSelector.scss";
import AutoAwesomeIcon from "@mui/icons-material/AutoAwesome";
import CloseIcon from "@mui/icons-material/Close";
Expand Down Expand Up @@ -98,18 +98,34 @@ const ThemeIcons = ({ title, value, colors, onClick }: ThemeIconsProps) => {

const ThemeSelector = () => {
const [isOpen, setIsOpen] = useState<boolean>(false);
const themeSelectorRef = useRef<HTMLDivElement>(null);

const handleTheme = (value: string) => {
setCustomTheme(value);
document.documentElement.setAttribute("custom-type", value);
};

useEffect(() => {
const handleClickOutside = (event: MouseEvent) => {
if (themeSelectorRef.current && !themeSelectorRef.current.contains(event.target as Node)) {
setIsOpen(false);
}
};
document.addEventListener("mousedown", handleClickOutside);
return () => {
document.removeEventListener("mousedown", handleClickOutside);
};
}, []);

useEffect(() => {
document.documentElement.setAttribute("custom-type", window.theme);
}, []);

return (
<div className="theme-selector">
<div
className="theme-selector"
ref={themeSelectorRef}
>
<AutoAwesomeIcon onClick={() => setIsOpen(true)} />
{isOpen && (
<div className="theme-selector__container">
Expand Down

0 comments on commit 7bd6aa5

Please sign in to comment.