Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Apply theme to only to active excalidraw component #3446

Merged
merged 8 commits into from
Apr 13, 2021
Merged

Conversation

ad1992
Copy link
Member

@ad1992 ad1992 commented Apr 13, 2021

Make sure theme is only applied to the active Excalidraw component when multiple excalidraw rendered

Exposed a hook that gives access to the current instance, this will be useful when focusing the current instance as well(ex after dialog close, we can expose focus function as well for the same)
Since collab dialog is not in the hierarchy of App.tsx hence had to add a new prop theme so it can be used to add a theme to custom dialogs as well.

Try here

@vercel
Copy link

vercel bot commented Apr 13, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/excalidraw/excalidraw/28wp4vKmj8rM1jALNfe37YEJXtx8
✅ Preview: https://excalidraw-git-aakansha-theme-excalidraw.vercel.app

@dwelle
Copy link
Member

dwelle commented Apr 13, 2021

Conceptually looks fine. But we should name it ExcalidrawContainerContext since it's not an instance. Also, why not store the container value directly instead of wrapping it in {current}?

@ad1992
Copy link
Member Author

ad1992 commented Apr 13, 2021

Conceptually looks fine. But we should name it ExcalidrawContainerContext since it's not an instance. Also, why not store the container value directly instead of wrapping it in {current}?

I am thinking will also expose the focusContainer method when we start storing active element hence keeping key value pairs

@dwelle
Copy link
Member

dwelle commented Apr 13, 2021

I am thinking will also expose the focusContainer method when we start storing active element hence keeping key value pairs

That will mess up with memoization. I'd make it be just the container and if we want to factor out the focusing, we can make it an util method again (but I don't see much reason since it'll be just context?.focus())

@ad1992
Copy link
Member Author

ad1992 commented Apr 13, 2021

I am thinking will also expose the focusContainer method when we start storing active element hence keeping key value pairs

That will mess up with memoization. I'd make it be just the container and if we want to factor out the focusing, we can make it an util method again (but I don't see much reason since it'll be just context?.focus())

I don't think apart from the focus I was planning to expose anything else and one can directly call context.?.focus so should be fine. We can tweak it later if needed.

@ad1992 ad1992 changed the title feat: Apply theme to only current instance of excalidraw fix: Apply theme to only current instance of excalidraw Apr 13, 2021
@ad1992 ad1992 added this to the @excalidraw/excalidraw@0.7.0 milestone Apr 13, 2021
src/components/App.tsx Outdated Show resolved Hide resolved
src/components/Modal.tsx Outdated Show resolved Hide resolved
Comment on lines +70 to +72
const isDarkTheme =
!!excalidrawContainer?.classList.contains("theme--dark") ||
theme === "dark";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we don't want to use theme only (since it's optional), it should nevertheless take precedence since it's explicit, so let's swap the order of checks

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unclear what you mean, theme is given less precedence since its optional over excal container so why we want to check theme first ?

Copy link
Member

@dwelle dwelle Apr 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it's supplied and for some reason isn't matching the container, we should prefer the explicit value. Is there actually a reason why we're supplying it at all? Aren't Modals always part of the component tree? EDIT: forgot about Collab

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I suppose since this isn't public API it doesn't matter, and actually is preferable UX-wise. It'll just mean the app might have slight bugs without us knowing.

Copy link
Member Author

@ad1992 ad1992 Apr 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this isn't public API, if in the future we expose Dialog then it can be helpful for the host but I don't think we will be doing that as the host will always have its own dialogs and since its for excal app itself so I have given preference to excal container over theme.

@ad1992 ad1992 changed the title fix: Apply theme to only current instance of excalidraw fix: Apply theme to only to active excalidraw component Apr 13, 2021
@ad1992 ad1992 merged commit 793b69e into master Apr 13, 2021
@ad1992 ad1992 deleted the aakansha-theme branch April 13, 2021 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants