Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dark Mode #69

Closed
pspeter3 opened this issue Sep 11, 2020 · 32 comments
Closed

Dark Mode #69

pspeter3 opened this issue Sep 11, 2020 · 32 comments

Comments

@pspeter3
Copy link

Given that the typography sets colors for elements, how should those colors change with the new experimental dark mode?

@pspeter3
Copy link
Author

I followed @stefanzweifel's article https://stefanzweifel.io/posts/2020/07/20/add-dark-mode-support-to-at-tailwindcsstypography/. Instead of adding a dark as a theme, you need to add dark as a variant for the typography plugin.

@dkast
Copy link

dkast commented Sep 14, 2020

Hi, @pspeter3 do you think you could share your dark variant config of your tailwind.config.js? I'm kinda lost with this, an example would be very helpful. Thanks!

@stefanzweifel
Copy link

@dkast Author of that blog post here. Here's an example tailwind.config.js where you configure both light and dark version of the typography plugin.

Light settings go to default.
Dark settings go to dark.

module.exports = {
    theme: {

        typography: (theme) => ({
            default: {
                css: {
                    color: theme('colors.gray.900'),

                    a: {
                        color: theme('colors.blue.500'),
                        '&:hover': {
                            color: theme('colors.blue.700'),
                        },
                    },
                },
            },

            dark: {
                css: {
                    color: theme('colors.gray.100'),

                    a: {
                        color: theme('colors.blue.100'),
                        '&:hover': {
                            color: theme('colors.blue.100'),
                        },
                    },
                },
            },
        }),

    },

    plugins: [
        require('@tailwindcss/typography')({
            modifiers: [],
        }),
    ]
}

@dkast
Copy link

dkast commented Sep 14, 2020

@stefanzweifel awesome, thank you!

@pspeter3
Copy link
Author

pspeter3 commented Sep 15, 2020

I think as an extension, if you want to use the experimental darkModeVariant, you likely want to add the following to your config:

{
  // ...rest of config
  variants: {
    typography: ["responsive", "dark"]
  }
}

@pspeter3
Copy link
Author

I am curious though what the Tailwind team thinks the right colors for text should be in dark mode. I suspect it will depend on the new color palette as well.

@vinayakkulkarni
Copy link

const defaultTheme = require('tailwindcss/defaultTheme');

module.exports = {
  experimental: {
    darkModeVariant: true,
  },
  dark: 'class',
  future: {
    defaultLineHeights: true,
    standardFontWeights: true,
    removeDeprecatedGapUtilities: true,
    purgeLayersByDefault: true,
  },
  theme: {
    extend: {
      colors: {
        twitter: '#1DA1F2',
        linkedIn: '#2867B2',
        github: '#333333',
        ...defaultTheme.colors,
      },
      fontFamily: {
        sans: ['Inter var', ...defaultTheme.fontFamily.sans],
      },
    },
    typography: (theme) => ({
      dark: {
        css: {
          color: theme('colors.gray.100'),
          a: {
            color: theme('colors.blue.100'),
            '&:hover': {
              color: theme('colors.blue.100'),
            },
          },
        },
      },
    }),
  },
  plugins: [
    require('@tailwindcss/ui'),
    require('@tailwindcss/custom-forms'),
    require('@tailwindcss/typography')({
      modifiers: [],
    }),
  ],
};
      <article
        class="prose dark:prose-dark dark:text-gray-100"
      >
	  ...
	  </article>

Unfortunately, this doesn't seem to work!

I'm using color-mode nuxt module ( https://color-mode.nuxtjs.org/#tailwind-v18 )

@jhull
Copy link

jhull commented Oct 31, 2020

Same problem here.

    typography: (theme) => ({
      default: {
        css: {
          color: theme('colors.gray-500')
        },
      }

is changing colors in light mode nicely (if I change above value), but under dark key nothing is changed (with prose dark:prose-dark as shown above).

Same setup with nuxt and color-mode module.

@jacobdalamb
Copy link

jacobdalamb commented Nov 25, 2020

okay valid but this is a feature request and a workaround would be

'@media (prefers-color-scheme: dark)': {
              h1: {
                color: '#d4d4d8',
              },
              h2: {
                color: '#d4d4d8',
              },
              a: {
                color: '#d4d4d8',
              },
              color: '#d4d4d8',
            },

@chiefpansancolt
Copy link

Since the dark mode is now GA in 2.0 typography with prose should have a module apart that is configurable and documented on the usage of dark mode with it.

@Apostolique
Copy link

@vinayakkulkarni @jhull You forgot to enable the variant:

  variants: {
    extend: {
      typography: ['dark']
    }
  },

@MatthewCaseres
Copy link

agree that there should be documentation on the subject. I found a good config for 2.0 at the bottom of this closed issue: #94

@Bilal-io
Copy link

Bilal-io commented Dec 30, 2020

@benji014628 seems like extending typography works when you do DEFAULT uppercase.
I am still trying to understand how to extend dark mode.

@jacobdalamb
Copy link

@benji014628 well with TailwindCSS 2.0 you need to do that

@MildTomato
Copy link

Also came here wondering if tailwind2.0 dark mode support was officially supported with this plugin ?

@adamwathan
Copy link
Member

adamwathan commented Dec 31, 2020

Haven't added it by default but it's 100% possible to add with all of the existing options in Tailwind + the plugin. Here's a quick 5 minute version:

https://play.tailwindcss.com/xTOjz3kR3m?file=config

The steps to do this were:

  1. Enable dark mode in Tailwind, documented here: https://tailwindcss.com/docs/dark-mode
  2. Add a "light" text modifier for the plugin, documented here: https://github.com/tailwindlabs/tailwindcss-typography#adding-new-modifiers
  3. Enable the "dark" variant for the typography plugin, documented here: https://tailwindcss.com/docs/dark-mode#enabling-for-other-utilities

@kripod
Copy link

kripod commented Dec 31, 2020

@adamwathan Thank you for providing clear instructions about how it should be done. Based on that, I’ve just opened #122 to address this issue for everyone.

@MildTomato
Copy link

I have a feeling it wasn't working for me because i didn't have the following imports in CSS

@tailwind base;
@tailwind components;
@tailwind utilities;

I was hoping to use this only importing the css classes required for typography.

@Bilal-io
Copy link

I got it to work.
Here is a working solution https://github.com/Bilal-io/bilalkhoukhi.com
prose and dark:prose-dark are applied in the post-layout.tsx
Theme switcher is in the header.tsx

@10thfloor
Copy link

10thfloor commented Feb 11, 2021

Haven't added it by default but it's 100% possible to add with all of the existing options in Tailwind + the plugin. Here's a quick 5 minute version:

https://play.tailwindcss.com/xTOjz3kR3m?file=config

The steps to do this were:

  1. Enable dark mode in Tailwind, documented here: https://tailwindcss.com/docs/dark-mode
  2. Add a "light" text modifier for the plugin, documented here: https://github.com/tailwindlabs/tailwindcss-typography#adding-new-modifiers
  3. Enable the "dark" variant for the typography plugin, documented here: https://tailwindcss.com/docs/dark-mode#enabling-for-other-utilities

Thank you for all you do. I nearly quit my job and moved into the forest after trying to figure this out. 😅

@gildesmarais
Copy link

Haven't added it by default but it's 100% possible to add with all of the existing options in Tailwind + the plugin. Here's a quick 5 minute version:

[...]

Thank you for the step by step instructions. I feel these steps should be mentioned in README instead of being tucked away in a comment inside this issue. Tailwind lists "dark mode" as core concept and thus the typography plugin should make that core concept easy to adapt.

pspeter3 added a commit to pspeter3/tailwindcss-typography that referenced this issue Feb 12, 2021
Add it to the README so people do not need to find tailwindlabs#69
@pspeter3
Copy link
Author

I added a quick PR for the documentation in case that's helpful @adamwathan

@jjranalli
Copy link

Just wanted to let everyone know that you can also use Nightwind to easily manage the dark mode in Typography.

You can define every single color, or just let it automatically generate a dark mode for you (which should be fine in most cases).

Relevant section of the docs

@vesper8
Copy link

vesper8 commented Apr 15, 2021

I've been using the solution proposed by Adam above and it seems to work very well, but today I opened the website in Facebook's embedded browser and the colours were quite wrong. It looks good in every other browser I've tried

tmr08c added a commit to tmr08c/tmr08c.github.io that referenced this issue Sep 5, 2021
Use Tailwind 2.0's ability to use class-based dark mode.

The dark-mode switch comes from:

- https://github.com/donavon/use-dark-mode
- https://github.com/wKovacs64/gatsby-plugin-use-dark-mode
- https://github.com/JoseRFelix/react-toggle-dark-mode

To extend tailwind-typography, use the CSS @adamwathan shared in [this
comment](tailwindlabs/tailwindcss-typography#69 (comment)).
tmr08c added a commit to tmr08c/tmr08c.github.io that referenced this issue Sep 5, 2021
Use Tailwind 2.0's ability to use class-based dark mode.

The dark-mode switch comes from:

- https://github.com/donavon/use-dark-mode
- https://github.com/wKovacs64/gatsby-plugin-use-dark-mode
- https://github.com/JoseRFelix/react-toggle-dark-mode

To extend tailwind-typography, use the CSS @adamwathan shared in [this
comment](tailwindlabs/tailwindcss-typography#69 (comment)).
@vidhanio
Copy link

How would this work in terms of the new Tailwind 3.0?

@pspeter3
Copy link
Author

Per #216, I think you use dark:prose-invert?

@vidhanio
Copy link

Wow, completely missed that. That cut my className length by at least 200 characters 😄, thanks a ton!

@adamwathan
Copy link
Member

Gonna close this I guess 😅 Enjoy!

@beeman
Copy link

beeman commented Dec 20, 2021

Thanks @adamwathan and the rest of the team! 🎉

There's even a video on how to use it!

https://www.youtube.com/watch?v=GEYkwfYytAM

@danjac
Copy link

danjac commented Jan 8, 2022

I don't think the dark:prose-invert solution works with the tailwindcss/typography version currently bundled with latest Tailwind standalone.

@rjitsu
Copy link

rjitsu commented Jan 15, 2022

+1 on that.

I don't think the dark:prose-invert solution works with the tailwindcss/typography version currently bundled with latest Tailwind standalone.

@danjac
Copy link

danjac commented Jan 15, 2022

I've made a separate bug report for the standalone issue:

#233

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests