jjranalli / nightwind

An automatic, customisable, overridable Tailwind dark mode plugin
https://nightwindcss.com
MIT License
713 stars 45 forks source link

Enhance init() to allow a similar style to overreacted.io #42

Open osukaa opened 2 years ago

osukaa commented 2 years ago

I'm enhancing theinit() method from the helper, to copy a similar style of what is done in the overreacted.io style. By adding

Simplified version of overreacted.io Layout.js

class Layout extends React.Component {
  state = {
    theme: null,
  };
  componentDidMount() {
    this.setState({ theme: window.__theme });
    window.__onThemeChange = () => {
      this.setState({ theme: window.__theme });
    };
  }
}

This should be a non-breaking change, and backwards compatible

jjranalli commented 2 years ago

Sweet, thanks for the PR @osukaa! At a first glance it seems fine to me, will give it a try later today and if all goes well I'll include it in v1.1.13.

In the meantime, it would be great if you could also update the Helper readme section to briefly describe these additional features.

osukaa commented 2 years ago

I've added the documentation as an example!

osukaa commented 2 years ago

@jjranalli any updates around this PR?