next-plugin-perfect-dark-mode
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

next-plugin-perfect-dark-mode

Version Size

This plugin makes it easy to add perfect-dark-mode to Next.js.

Installation

You do not need to add perfect-dark-mode to <head> like you do for react-perfect-dark-mode. This plugin provides InjectPerfectDarkMode to do that.

yarn add next-plugin-perfect-dark-mode

You must render InjectPerfectDarkMode on any page you use it on.

import Head from 'next/head'
import { InjectPerfectDarkMode } from 'next-plugin-perfect-dark-mode'

// In the Next.js blog starter you would add this to pages/index.js
// In other setups it would probably make sense to add to wherever your SEO component is.
export default function Home() {
  return (
    <div className="container">
      <Head>
        <title>Create Next App</title>
        <link rel="icon" href="/favicon.ico" />
      </Head>
      {/* Add this line. */}
      <InjectPerfectDarkMode />
      {/* The rest... */}
    </div>
  )
}

Usage

In a component you can use the hook:

import React from 'react'
import { usePerfectDarkMode } from 'next-plugin-perfect-dark-mode'

export const Toggle = () => {
  const { mode, updateMode } = usePerfectDarkMode()
  return (
    <button
      style={{ visibility: mode !== undefined ? 'visible' : 'hidden' }}
      onClick={() =>
        updateMode(
          (mode, modes, modeIndex) => modes[(modeIndex + 1) % modes.length],
        )
      }
    >
      {mode}
    </button>
  )
}

Readme

Keywords

Package Sidebar

Install

npm i next-plugin-perfect-dark-mode

Weekly Downloads

0

Version

2.0.0

License

MIT

Unpacked Size

4.41 kB

Total Files

7

Last publish

Collaborators

  • dylanvann