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

Option to remove [data-theme] from being added #367

Open
exoRift opened this issue Jun 15, 2023 · 3 comments
Open

Option to remove [data-theme] from being added #367

exoRift opened this issue Jun 15, 2023 · 3 comments

Comments

@exoRift
Copy link

exoRift commented Jun 15, 2023

Considering the fact that repainting (by calling paint() again) doesn't update the theme (which is an issue in and of itself),

I would like an option that does not set the data-theme attribute at all so that it can be determined by the Tailwind theme provider what styles to apply to the heatmap.

For now, I have to use this workaround:

).then(() => (cal.current as any).calendarPainter.root?.attr('data-theme', null))

@wa0x6e
Copy link
Owner

wa0x6e commented Jun 17, 2023

You're right about the theme not being updated when calling paint again. I have created an issue for that.

Regarding the data-theme presence, can you not just override your tailwind theme css, like the docs website is doing ? (https://cal-heatmap.com/assets/css/styles.a42314ed.css)

@exoRift
Copy link
Author

exoRift commented Jun 18, 2023

I can override it, it's just extra work. However, I guess it's not entirely necessary if the updating for the theme is fixed

@yasso1am
Copy link

yasso1am commented Feb 8, 2024

In case anyone else comes across this and didn't understand the approach above in the context of React:

If you are trying to dynamically adjust the theme when a user toggles dark/light mode on your page, you can do this in a non-standard-react way.

const [themeMode] = useLocalstorageState('theme', 'light');
const prevThemeMode = useRef(themeMode);
  useEffect(() => {
    if (prevThemeMode.current !== themeMode) {
      // there is no built in way to dynamically update the theme, and we don't want to destroy/repaint the entire calendar as that leads to some odd behaviors
      // @ts-ignore
      calInstance.calendarPainter.root?.attr('data-theme', themeMode);
      prevThemeMode.current = themeMode;
    }
  }, [themeMode, prevThemeMode]);

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

No branches or pull requests

3 participants