mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
fix: Apply theme to only to active excalidraw component (#3446)
* feat: Apply theme to only current instance of excalidraw * fix * fix * fix * fix * fix * update changelog * fix
This commit is contained in:
parent
e0a449aa40
commit
793b69e592
6 changed files with 90 additions and 61 deletions
|
@ -4,7 +4,8 @@ import React, { useState, useLayoutEffect, useRef } from "react";
|
|||
import { createPortal } from "react-dom";
|
||||
import clsx from "clsx";
|
||||
import { KEYS } from "../keys";
|
||||
import { useIsMobile } from "../components/App";
|
||||
import { useExcalidrawContainer, useIsMobile } from "./App";
|
||||
import { AppState } from "../types";
|
||||
|
||||
export const Modal = (props: {
|
||||
className?: string;
|
||||
|
@ -12,8 +13,10 @@ export const Modal = (props: {
|
|||
maxWidth?: number;
|
||||
onCloseRequest(): void;
|
||||
labelledBy: string;
|
||||
theme?: AppState["theme"];
|
||||
}) => {
|
||||
const modalRoot = useBodyRoot();
|
||||
const { theme = "light" } = props;
|
||||
const modalRoot = useBodyRoot(theme);
|
||||
|
||||
if (!modalRoot) {
|
||||
return null;
|
||||
|
@ -48,13 +51,15 @@ export const Modal = (props: {
|
|||
);
|
||||
};
|
||||
|
||||
const useBodyRoot = () => {
|
||||
const useBodyRoot = (theme: AppState["theme"]) => {
|
||||
const [div, setDiv] = useState<HTMLDivElement | null>(null);
|
||||
|
||||
const isMobile = useIsMobile();
|
||||
const isMobileRef = useRef(isMobile);
|
||||
isMobileRef.current = isMobile;
|
||||
|
||||
const excalidrawContainer = useExcalidrawContainer();
|
||||
|
||||
useLayoutEffect(() => {
|
||||
if (div) {
|
||||
div.classList.toggle("excalidraw--mobile", isMobile);
|
||||
|
@ -62,9 +67,9 @@ const useBodyRoot = () => {
|
|||
}, [div, isMobile]);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
const isDarkTheme = !!document
|
||||
.querySelector(".excalidraw")
|
||||
?.classList.contains("theme--dark");
|
||||
const isDarkTheme =
|
||||
!!excalidrawContainer?.classList.contains("theme--dark") ||
|
||||
theme === "dark";
|
||||
const div = document.createElement("div");
|
||||
|
||||
div.classList.add("excalidraw", "excalidraw-modal-container");
|
||||
|
@ -81,7 +86,7 @@ const useBodyRoot = () => {
|
|||
return () => {
|
||||
document.body.removeChild(div);
|
||||
};
|
||||
}, []);
|
||||
}, [excalidrawContainer, theme]);
|
||||
|
||||
return div;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue