Skip to content

Instantly share code, notes, and snippets.

View EdPike365's full-sized avatar

EdPike365 EdPike365

View GitHub Profile
@EdPike365
EdPike365 / DarkModeToggle.js
Created March 2, 2021 03:31
A CSS based Toggle for switching between Dark and Light Mode
import React from "react"
import styled from "@emotion/styled"
import useDarkMode from "use-dark-mode"
//This widget was based on https://codepen.io/Qvcool/pen/bdzVYW, with some modifications
//A real benefit of this approach is that it can also be used with a radio button set
//A real warning on this is it uses some CSS "tricks".
//Also I have yet to get the unicode sequences (or Font Awesome) references to work for the icons
//In the meantime, just copy and paste unicode characters.
@EdPike365
EdPike365 / DarkModeBrowserPref.js
Last active March 1, 2021 20:09
React Hook to detect Dark Mode preference
import React, { useEffect, useState } from "react"
//This will show the "prefers-color-scheme" value for this browser, reactively
//NOTE: Hook functions must use camel case because of linting rules.
function DarkModePreferredStatus() {
//NOTES ON INTERACTIONS WITH CHROME DEV TOOLS:
//On Windows 10, Chrome gets its settings from the OS via Settings> Colors
// options: light, dark, custom
//This value can be overridden using Chrome dev tools emulator