All Projects โ†’ xeoneux โ†’ Next Dark Mode

xeoneux / Next Dark Mode

Licence: mit
๐ŸŒ‘ Enable dark mode for Next.js apps

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Next Dark Mode

React Next Boilerplate
๐Ÿš€ A basis for reducing the configuration of your projects with nextJS, best development practices and popular libraries in the developer community.
Stars: โœญ 129 (-3.01%)
Mutual labels:  nextjs, styled-components, css-in-js, emotion
tsstyled
A small, fast, and simple CSS-in-JS solution for React.
Stars: โœญ 52 (-60.9%)
Mutual labels:  styled-components, emotion, css-in-js
Styled Ppx
Typed styled components in Reason, OCaml and ReScript
Stars: โœญ 236 (+77.44%)
Mutual labels:  styled-components, css-in-js, emotion
Horror
๐Ÿ˜ฑ React HTML elements with CSS-in-JS
Stars: โœญ 78 (-41.35%)
Mutual labels:  styled-components, css-in-js, emotion
Onno
Responsive style props for building themed design systems
Stars: โœญ 95 (-28.57%)
Mutual labels:  styled-components, css-in-js, emotion
Styled Components Vs Emotion
a short doc comparing the popular CSS-in-JS libraries styled-components and emotion
Stars: โœญ 204 (+53.38%)
Mutual labels:  styled-components, css-in-js, emotion
satchel
The little bag of CSS-in-JS superpowers
Stars: โœญ 14 (-89.47%)
Mutual labels:  styled-components, emotion, css-in-js
Styled-Responsive-Media-Queries
Responsive Media Queries for Emotion styled or styled-components โ€” Standard size from Chrome DevTools.
Stars: โœญ 33 (-75.19%)
Mutual labels:  styled-components, emotion, css-in-js
Styled Breakpoints
Simple and powerful tool for creating breakpoints in styled components and emotion. ๐Ÿ’…
Stars: โœญ 428 (+221.8%)
Mutual labels:  styled-components, css-in-js, emotion
Xstyled
A utility-first CSS-in-JS framework built for React. ๐Ÿ’…๐Ÿ‘ฉโ€๐ŸŽคโšก๏ธ
Stars: โœญ 1,835 (+1279.7%)
Mutual labels:  styled-components, css-in-js, emotion
Design System Utils
๐Ÿ‘ฉโ€๐ŸŽจ Access your design tokens with ease
Stars: โœญ 465 (+249.62%)
Mutual labels:  styled-components, css-in-js, emotion
Grid
This package has moved and renamed
Stars: โœญ 2,079 (+1463.16%)
Mutual labels:  styled-components, css-in-js, emotion
Filbert Js
A lightweight(~1kb) css-in-js framework
Stars: โœญ 167 (+25.56%)
Mutual labels:  styled-components, css-in-js, emotion
Css In React
๐Ÿญ CSS in React - Learn the best CSS in JS frameworks by example
Stars: โœญ 101 (-24.06%)
Mutual labels:  styled-components, css-in-js, emotion
Goober
๐Ÿฅœ goober, a less than 1KB ๐ŸŽ‰ css-in-js alternative with a familiar API
Stars: โœญ 2,317 (+1642.11%)
Mutual labels:  styled-components, css-in-js, emotion
Twin.macro
๐Ÿฆนโ€โ™‚๏ธ Twin blends the magic of Tailwind with the flexibility of css-in-js (emotion, styled-components, stitches and goober) at build time.
Stars: โœญ 5,137 (+3762.41%)
Mutual labels:  styled-components, css-in-js, emotion
Styled Tools
Useful interpolated functions for CSS-in-JS
Stars: โœญ 761 (+472.18%)
Mutual labels:  styled-components, css-in-js, emotion
Styled System
โฌข Style props for rapid UI development
Stars: โœญ 7,126 (+5257.89%)
Mutual labels:  styled-components, css-in-js, emotion
Placeline Nextjs
HyperTrack Placeline web application sample using NextJS, Ant-Design, Styled-Components, and Heroku
Stars: โœญ 88 (-33.83%)
Mutual labels:  nextjs, styled-components
Next Starter
Next.js Starter using GraphQL, MobX (Next.js, TypeScript, Babel, Express.js, Apollo Client, React Apollo, React Apollo Hooks, GraphQL Codegen, MobX, mobx-state-tree, styled-components, next-optimized-images, Serverless Framework, AWS Lambda, Dotenv)
Stars: โœญ 90 (-32.33%)
Mutual labels:  nextjs, styled-components

next-dark-mode

๐ŸŒ“ Theme your Next.js apps with a Dark Mode

license npm bundle size npm version

Contents:

Features

Auto mode

next-dark-mode optionally supports auto mode which automatically switches the user's theme as per the color mode selected on their operating system.

Windows and macOS both support setting the dark or light mode based on the time of the day.

It is achieved via prefers-color-scheme media query.

No page load glitch

next-dark-mode uses configurable cookies to persist the state of the current theme, one for the auto mode and the other for the dark mode.

This prevents the common page load glitch with the local storage approach where the app loads on the client and then the state of the user's theme is fetched.

You can see it in this implementation by Pantaley Stoyanov.

NOTE: This library is not compatible with Next.js 9's Auto Partial Static Export feature as it has to read the cookies in getInitialProps function, which makes all pages incompatible with Automatic Partial Static Export feature.

Requirements

To use next-dark-mode, you must use [email protected] or greater which includes Hooks.

Installation

$ yarn add next-dark-mode

or

$ npm install next-dark-mode

Usage

  1. Wrap your _app.js component (located in /pages) with the HOC withDarkMode

    // _app.js
    import App from 'next/app'
    import withDarkMode from 'next-dark-mode'
    
    export default withDarkMode(App)
    
  2. You can now use the useDarkMode hook anywhere in your app

    import { useDarkMode } from 'next-dark-mode'
    
    const MyComponent = props => {
      const {
        autoModeActive,    // boolean - whether the auto mode is active or not
        autoModeSupported, // boolean - whether the auto mode is supported on this browser
        darkModeActive,    // boolean - whether the dark mode is active or not
        switchToAutoMode,  // function - toggles the auto mode on
        switchToDarkMode,  // function - toggles the dark mode on
        switchToLightMode, // function - toggles the light mode on
      } = useDarkMode()
    
     ...
    }
    

With CSS-in-JS libraries (like emotion or styled-components)

  1. Wrap your _app.js component (located in /pages) with the HOC withDarkMode and pass the values to the ThemeProvider so that you can use it in your components

    // _app.js
    import { ThemeProvider } from '@emotion/react' // or styled-components
    import withDarkMode from 'next-dark-mode'
    
    function MyApp({ Component, darkMode, pageProps }) {
      const { autoModeActive, autoModeSupported, darkModeActive } = darkMode
    
      return (
        <ThemeProvider theme={{ darkMode: darkModeActive, ...(other values) }}>
          <Component {...pageProps} />
        </ThemeProvider>
      )
    }
    
    export default withDarkMode(MyApp)
    

Configuration

The withDarkMode function accepts a config object as its second argument. Every key is optional with default values mentioned:

  • autoModeCookieName: string - Name of the cookie used to determine whether the auto preset is enabled. Defaults to 'autoMode'.
  • cookieOptions: object - Configuration options for the cookies that gets set on the client. Defaults to { sameSite: 'lax' }.
  • darkModeCookieName: string - Name of the cookie used to determine whether the dark preset is enabled. Defaults to 'darkMode'.
  • defaultMode: string - Determines the default color mode when there's no cookie set on the client. This usually happens on the first ever page load. It can either be 'dark' or 'light' and it defaults to 'light'.

Resources

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].