nextra icon indicating copy to clipboard operation
nextra copied to clipboard

Default Dark Mode

Open rajansagarwal opened this issue 2 years ago • 4 comments

tried using next-themes and ThemeProvider to make add default dark mode, but it wouldn't work. what i noticed is that i can only customize the body with css/scss (the stuff within the page and on the mdx files), rather than the entire page.

could someone please guide me on how to implement this?

rajansagarwal avatar Nov 20 '21 17:11 rajansagarwal

hi @itsrajan , which theme, doc or blog

geekplux avatar Nov 24 '21 14:11 geekplux

hi @itsrajan , which theme, doc or blog

Docs theme :)

rajansagarwal avatar Nov 24 '21 15:11 rajansagarwal

You can temporarily set the default theme by inserting the code below into the head element of theme.config.js.

<script
  lang="javascript"
  dangerouslySetInnerHTML={{
    __html: `if (!window.localStorage.getItem("theme_default")) {
      window.localStorage.setItem("theme", "dark");
      window.localStorage.setItem("theme_default", "dark");
      document.documentElement.classList.add("dark");
      document.documentElement.classList.remove("light");
    }`,
  }}
/>;

hmmhmmhm avatar Apr 26 '22 15:04 hmmhmmhm

would be cool to have this as a config option though! @shuding

wottpal avatar Sep 10 '22 13:09 wottpal

https://nextra.site/docs/docs-theme/theme-configuration#dark-mode-and-themes

You can pass

nextThemes: {
  defaultTheme: 'dark'
}

shuding avatar Jan 21 '23 19:01 shuding

where can I pass this? for reference I'm trying to do it to this template template

adesai1000 avatar Mar 04 '23 13:03 adesai1000

You can temporarily set the default theme by inserting the code below into the head element of theme.config.js.

<script
  lang="javascript"
  dangerouslySetInnerHTML={{
    __html: `if (!window.localStorage.getItem("theme_default")) {
      window.localStorage.setItem("theme", "dark");
      window.localStorage.setItem("theme_default", "dark");
      document.documentElement.classList.add("dark");
      document.documentElement.classList.remove("light");
    }`,
  }}
/>;

This is a disaster, since I ran this code, all my next.js programs for local debugging, are in dark mode! Can you tell me how to clear this effect? Much appreciated.

Pathsis avatar Mar 24 '23 11:03 Pathsis

https://nextra.site/docs/docs-theme/theme-configuration#dark-mode-and-themes

You can pass

nextThemes: {
  defaultTheme: 'dark'
}

This exactly work!

nurwah1d avatar Nov 26 '23 08:11 nurwah1d

This is theme.config.js | Where to put it ?

const YEAR = new Date().getFullYear()

export default {

  footer: (
    <small style={{ display: 'block', marginTop: '8rem' }}>
      <time>{YEAR}</time> © Monish Nule 
      <a href="#"_blank">Source</a>
      <style jsx>{`
        a {
          float: right;
        }
        @media screen and (max-width: 480px) {
          article {
            padding-top: 2rem;
            padding-bottom: 4rem;
          }
        }
      `}</style>
       
    </small>
  )

imonish8 avatar Apr 07 '24 05:04 imonish8

It's just a crappy program, what's there to waste time on it?

This is theme.config.js | Where to put it ?

const YEAR = new Date().getFullYear()

export default {

  footer: (
    <small style={{ display: 'block', marginTop: '8rem' }}>
      <time>{YEAR}</time> © Monish Nule 
      <a href="#"_blank">Source</a>
      <style jsx>{`
        a {
          float: right;
        }
        @media screen and (max-width: 480px) {
          article {
            padding-top: 2rem;
            padding-bottom: 4rem;
          }
        }
      `}</style>
       
    </small>
  )

It's just a crappy program, what's there to waste time on it?

Pathsis avatar Apr 07 '24 07:04 Pathsis

It's just a crappy program, what's there to waste time on it?

This is theme.config.js | Where to put it ?

const YEAR = new Date().getFullYear()

export default {

  footer: (
    <small style={{ display: 'block', marginTop: '8rem' }}>
      <time>{YEAR}</time> © Monish Nule 
      <a href="#"_blank">Source</a>
      <style jsx>{`
        a {
          float: right;
        }
        @media screen and (max-width: 480px) {
          article {
            padding-top: 2rem;
            padding-bottom: 4rem;
          }
        }
      `}</style>
       
    </small>
  )

It's just a crappy program, what's there to waste time on it?

where should I place the dark mode code from Nextra? I want to add a toggle in there for dark mode.

imonish8 avatar Apr 07 '24 07:04 imonish8