2.0.0 • Published 1 year ago

next-plugin-perfect-dark-mode v2.0.0

Weekly downloads
5
License
MIT
Repository
github
Last release
1 year ago

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>
  )
}
2.0.0

1 year ago

1.0.0

3 years ago

0.0.25

3 years ago

0.0.19

3 years ago

0.0.18

4 years ago

0.0.17

4 years ago

0.0.13

4 years ago

0.0.14

4 years ago

0.0.15

4 years ago

0.0.12

4 years ago

0.0.11

4 years ago

0.0.10

4 years ago