@rqbazan/set-initial-color-mode

1.2.1 • Public • Published

Set Initial Color Mode 🌗

Inspiration

The Quest for the Perfect Dark Mode by Josh Comeau

Usage

Plain HTML

<script src="https://unpkg.com/@rqbazan/set-initial-color-mode/dist/browser.js" />

Next.js

import NextDocument, { Head, Html, Main, NextScript } from "next/document";
import { getJsText } from "@rqbazan/set-initial-color-mode";

export default class Document extends NextDocument {
  render() {
    return (
      <Html lang="en">
        <Head>
          <script
            id="set-initial-color-mode"
            dangerouslySetInnerHTML={{ __html: getJsText() }}
          />
        </Head>
        <body>
          <Main />
          <NextScript />
        </body>
      </Html>
    );
  }
}

React.js

import * as React from "react";
import { useColorModeToggle } from "@rqbazan/set-initial-color-mode";

function Switch() {
  const { onToggle } = useColorModeToggle();

  return <input type="checkbox" onClick={onToggle} />;
}

Readme

Keywords

none

Package Sidebar

Install

npm i @rqbazan/set-initial-color-mode

Weekly Downloads

1

Version

1.2.1

License

MIT

Unpacked Size

8.65 kB

Total Files

10

Last publish

Collaborators

  • rqbazan