Giter VIP home page Giter VIP logo

tailwind-themes's Introduction

Tailwind themes

Dark mode in Tailwind is a little bit weird. You can only have 2 themes, light a nd dark, and you have to use the dark: directive for every element that you want to behave in dark mode.

Can't we do better? Well, yes, even the Tailwind labs released a video explaining how to have custom themes. But if you are like me and do not want to touch CSS even with a stick, or you want propper lsp support for your custom colors, you are out of luck.

This plugin aims to solve this issues, it allows you to define your themes in the tailwind.config.{ts/js} file and the propper css and autocompletions will be generated.

// tailwind.config.ts
//
// Keep in mind that if you are using ts, you should include this file in your
// `tsconfig.json`.

import type { Config } from "tailwindcss";
import { configThemes, themesPlugin } from "tw-themes";

// Define your themes
const config = configThemes({
  themes: {
    light: {
      base: "#fff",
      primary: "#000",
    },
    dark: {
      base: "#000",
      primary: "#fff",
    },
    yellow: {
      base: "#333",
      primary: "#fbbf24",
      // Every theme should have the same color names, if you were to delete
      // any color in this configuration, typescript would shout at you.
    },
  },
  options: {
    // Notice how the LSP helps you autocomplete the themes.

    // asRoot: "yellow", // :root { /* yellow theme variables */ }
    prefersDark: "dark", // @media prefers-color-scheme dark { /* dark theme variables */ }
    prefersLight: "light", // @media prefers-color-scheme light { /* light theme variables */ }

    // attribute: "data-theme", // will output a class called `[data-theme="YOUR_THEME_NAME"]` for each of your themes (DEFAULT).
    // attribute: "class", // will output a class called `.YOUR_THEME_NAME` for each of your themes.
    // attribute: "data-colorscheme", // will output a class called `[data-colorscheme="YOUR_THEME_NAME"]` for each of your themes.
    // attribute: "myrandomattribute", // will output a class called `[myrandomattribute="YOUR_THEME_NAME"]` for each of your themes, IDK why you would do this, but you can.

    // the themes that are not mentioned in the options will create a class
    // called `[data-theme="<ThemeName>"]` by default, or it will use the
    // attribute variable to set the class name.
  },
});

export default {
  content: [`src/**/*.{ts,tsx}`],
  theme: {
    extend: {},
  },
  // Use the plugin passing the config.
  plugins: [themesPlugin(config)],
} satisfies Config;

tailwind-themes's People

Contributors

juancortelezzi avatar turbobot-temp avatar

Watchers

James Cloos avatar  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.