r/reactjs • u/rumborghini • Jul 20 '22
Show /r/reactjs I’ve built a fully themeable and accessible dark mode toggle component for React. [Details in the comments]
39
23
9
3
3
3
u/FacuBustamaante Jul 21 '22
Messirve.
GitHub??
1
u/rumborghini Jul 21 '22
All the links are in the comment above, but here you go:
🗄 Repository: GitHub
💻 Live Demo: CodeSandbox
🖼 Storybook: Netlify
6
u/nastyklad Jul 20 '22
Nice! It could awesome if the toggle turned into a little sun with rays as opposed to the moon
2
u/rumborghini Jul 20 '22
Thanks for the feedback!
-8
u/whatisboom Jul 20 '22
I think reversing the direction of the moon would make it more obvious it’s a moon too
10
1
u/TxFilmmaker Jul 30 '22
I didn't catch that it was a moon at first. Thought it was a mis-drawn icon. Love the idea, though.
2
2
2
2
2
2
u/liquidheaven Jul 21 '22
Does it need to be gray and black or colors are customizable?
2
u/rumborghini Jul 21 '22
Hey! The size, colors and labels are all customisable. More info here https://github.com/anatoliygatt/dark-mode-toggle#%EF%B8%8F-configuration
4
u/stechu Jul 20 '22
Looks good. why not cursor:pointer?
6
u/rumborghini Jul 20 '22
Thank you! It actually is, in my implementation, the video is from Dribbble, and since it’s the only difference I thought that it’s not worth re-shooting the demo.
4
2
2
1
1
1
1
u/ReAethered Jul 21 '22
Hey does anyone know what the scripts/build.ts does? I see that it's used in the esbuild command but I have no clue what it does.
2
u/rumborghini Jul 21 '22
Not sure what you mean, if you want to know exactly what it does, go and read the esbuild docs https://esbuild.github.io/api/
0
2
1
1
1
1
1
1
u/Sphism Jul 20 '22
Oh the dark side highlight is a moon... looks like the light side is more highlighted with the large white area...
Looks great though
0
u/BarbacJoe08 Jul 21 '22
First, this is great! But one of the major points of the article you link to is to utilize the users `prefers-color-scheme`, which it looks like you aren't using. Are you planning on adding "OS-level preference"?
2
u/rumborghini Jul 21 '22
Thank you! I'm not linking to any articles here.
dark-mode-toggleis a controlled React component, so you can query the preferred color scheme with a hook like https://github.com/anatoliygatt/use-prefers-color-scheme and set themodeprop to whatever value you like, as long as it is eitherdarkorlight😉.1
u/BarbacJoe08 Jul 21 '22
👍 didn't know that hook existed, that's sweet!
As for the article, I mean the dribble article that you mentioned you took inspiration from.
1
u/rumborghini Jul 21 '22
Oh, I see. Well, again, you can implement it in any way you want. The value for the
modecan come from the media query, from the local storage or from the backend.
-4
u/AgileChaos Jul 20 '22
Only thing wrong with this is that label on left should be "right" and right one should be "wrong".
2
u/rumborghini Jul 20 '22
There is no right or wrong here :) Though I see where you are coming from.
-1
0
26
u/rumborghini Jul 20 '22
Hey, r/reactjs!
I’ve built a fully themeable and accessible dark mode toggle component for React. Inspired by Tim Silva’s Dark/Light Mode Toggle Switch Pattern A11y Dribbble shot.
🔑 Key Benefits
⌨️ Type-Safe: Written in TypeScript.
🎨 Themable: Fully customisable look and feel.
♿️ Accessible: Complies with the accessibility best practices.
🗄 Repository: GitHub
💻 Live Demo: CodeSandbox
🖼 Storybook: Netlify
🙋🏼♂️ I hope you will find it useful! Feedback and questions are welcome.