GithubHelp home page GithubHelp logo

cctoni / tailwindcss-dark-mode Goto Github PK

View Code? Open in Web Editor NEW

This project forked from chancearthur/tailwindcss-dark-mode

0.0 0.0 0.0 21 KB

๐ŸŒš A Tailwind CSS plugin that adds variants for dark mode

License: MIT License

JavaScript 100.00%

tailwindcss-dark-mode's Introduction

Tailwind CSS Dark Mode

Installation

yarn add tailwindcss-dark-mode --dev

Add the plugin to the plugins array in your Tailwind configuration.

plugins: [
  require('tailwindcss-dark-mode')()
]

Usage

Styles generated by this plugin are only used if the mode-dark class is applied to the <html> element. How you do that is up to you. dark-mode.js is provided as an option, which is a simple script that enables dark mode from 6 PM to 6 AM in the user's timezone.

Available Variants

Variants for dark mode are based on Tailwind's own variants...

  • dark
  • dark-hover
  • dark-focus
  • dark-active
  • dark-group-hover
  • dark-focus-within

... and are used in the same way.

<div class="bg-white dark:bg-black">
  <p class="text-black dark:text-white">
    My eyes are grateful.

    <a ... class="text-blue-300 hover:text-blue-400 dark:text-blue-700 dark-hover:text-blue-600">
      Learn more
    </a>
  </p>
</div>

Enabling Variants

As with existing variants such as hover and focus, variants for dark mode must be enabled in your Tailwind configuration for any utilities that need them.

variants: {
  backgroundColor: ['dark', 'dark-hover', 'dark-group-hover'],
  borderColor: ['dark', 'dark-focus', 'dark-focus-within'],
  textColor: ['dark', 'dark-hover', 'dark-active']
}

PurgeCSS

If you are using PurgeCSS, you should either add mode-dark to the whitelist array...

whitelist: ['mode-dark']

... or add dark-mode.js to the content array.

content: [
  '**/*.js',
  './node_modules/tailwindcss-dark-mode/dark-mode.js'
]

Otherwise, PurgeCSS will assume that any classes related to dark mode should be removed, as the mode-dark class is only applied when the page is loaded.

tailwindcss-dark-mode's People

Contributors

chancearthur avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.