Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/wgao19/sun-moon-toggle

🌚🌝 Hipster dark mode with `mix-blend-mode`
https://github.com/wgao19/sun-moon-toggle

Last synced: about 2 months ago
JSON representation

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

Awesome Lists containing this project

README

        

# 🌚🌝 Sun Moon Toggle

![](https://i.imgur.com/vzexItp.gif)

## 🦄 How it works

The CSS property `mix-blend-mode` ([browser support](https://caniuse.com/#feat=css-mixblendmode)) 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:

- [A Work in Progress](https://dev.wgao19.cc)

You may read more about it in the following articles:

- [Sun Moon Blending Mode](https://dev.wgao19.cc/2019-05-04__sun-moon-blending-mode/)
- [Friends don't let friends implement dark mode alone](https://www.chenhuijing.com/blog/friends-dont-let-friends-implement-dark-mode-alone/#%F0%9F%8E%AE)

## 🛠 Installation

```shell
$ yarn add sun-moon-toggle
```

## 🦊 Example

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

const Layout = () => (


{/* put it before other content */}


Hello, it's me





Wrap emojis in a class
🌝🌚




)
```

## 🍱 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](https://i.imgur.com/CsEehnx.gif)), `'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 |