NotionX / NotionX/react-notion-x

support darkmode automatically

Open
#483 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
5.4k
Forks
645
PR merge metrics
No merged PRs in 30d

Description

react-notion-x render dark-mode by a property named darkMode. if i want set light\dark mode automatically by browser behavior from window.matchMedia('(prefers-color-scheme: dark)').matches. i should managed it by a state:

const [dark, setDark] = useState<boolean>(true)
  useEffect(function () {
    const darkMode =
      window?.matchMedia &&
      window.matchMedia('(prefers-color-scheme: dark)').matches
    setDark(darkMode)
  }, [])

The result is that light-mode will be render at first time, and then the dark-mode view will be rendered Immediately followed.
I think it's a bad case for users extremely in deep-night.

So, why not set the default css variable by media-query and use the darkMode property to override it. like this:

:root{
  --bg-color: white;
}

@media (prefers-color-scheme: dark) {
  :root{
    --bg-color: black;
  }
}

.notion.dark-mode{
    --bg-color: black;
}

.notion.dark-light{
  --bg-color: white;
}

{
  darkMode: true |  false  |  "auto" //  add an `auto` property to prevent flashing at first paint.
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing how the darkMode property is handled and how the renderer's dark and light styles are applied. Check the browser prefers-color-scheme behavior and the proposed CSS-variable approach, then define how an "auto" value should interact with explicit true or false values. Done means automatic mode avoids the initial light-mode flash while explicit modes still override it.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.