Skip to content

🌚🌝 Hipster dark mode with `mix-blend-mode`

Notifications You must be signed in to change notification settings

wgao19/sun-moon-toggle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

35 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🌚🌝 Sun Moon Toggle

πŸ¦„ How it works

The CSS property mix-blend-mode (browser support) specifies how colors blend when graphics are stacked together. In brief, covering your site with a layer same as your background color and using mix-blend-mode: difference will automatically yield a black background while preserving the contrast with the foreground.

We're using mix-blend-mode: exclusion which is a lower contrast version of mix-blend-mode: difference.

Site that uses this:

You may read more about it in the following articles:

πŸ›  Installation

$ yarn add sun-moon-toggle

🦊 Example

import React from 'react'
import SunMoonToggle from 'sun-moon-toggle'

const Layout = () => (
  <div>
    {/* put it before other content */}
    <SunMoonToggle background="#efefef" style={{ right: '1rem' }} />
    <main>
      <h1>Hello, it's me</h1>
      <img {/** img is by default escaped */} />
      <iframe {/** iframe also */} />
      <p>
        Wrap emojis in a class
        <span class="emoji">🌝🌚</span>
      </p>
    </main>
  </div>
)

🍱 Props

Props Type Optional Default What it does
backgroundColor string Yes 'white' Background color of your site, used to compute the dark color while preserving the contrast to your foreground
type 'default', 'hipster' Yes 'default' 'default' uses opacity (see gif here), 'hipster' uses the expansion effect (gif above)
style object Yes undefined In case you need to move the toggle, use this prop to set position on the screen

About

🌚🌝 Hipster dark mode with `mix-blend-mode`

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published