Code Monkey home page Code Monkey logo

Comments (4)

L-Blondy avatar L-Blondy commented on June 3, 2024 3

You might have a js/json file, import it in both tailwind.config.js and your theme switch component.

Note that you need esm support (tailwind >= 3.3.0) to do it with js files, otherwise you should go for json.

colors.js

export const colors = {
    a: {
        primary: 'red'
    },
    b: {
        primary: 'blue'
    },
    c: {
        primary: 'yellow'
    },
}

tailwind.config.js

import { colors } from '...'

export default {
      // ...your config
      plugins: [
         createThemes( colors )
      ],
   };

theme switcher

import { colors } from '...'

console.log( colors )

from tw-colors.

prokopec-simon avatar prokopec-simon commented on June 3, 2024 1

I should have probably left a little more info. I probably would actually need the css variables in my use case. It's a SvelteKit project and to switch the themes I use svg icons imported via unplugin icons. Those come with a wrapper that, atleast to my knowledge, only accepts the actual color for their color attribute.

I couldn't override it manually or with Tailwind, atleast not easily. But it's not a huge deal. I'll probably just have the Theme colors statically defined somewhere.

from tw-colors.

L-Blondy avatar L-Blondy commented on June 3, 2024

Hi Simon,

For a given color only one CSS variable is generated, which changes color depending on the closest theme.

Therefore the only way to access the CSS variable value for a given theme is to use nested themes.

In your case you probably don't need to access the variable at all, you might use the color directly.

<html class="theme-a">
    ...

    <div>
        <button>My theme switcher</button>
    
        <ul>
            <li class="theme-a bg-primary">
                theme-a primary preview
            </li>

            <li class="theme-b bg-primary">
                theme-b primary preview
            </li>

            <li class="theme-c bg-primary">
                theme-c primary preview
            </li>
        </ul>
    <div>

    ...
</html>

Hope that helps!

from tw-colors.

prokopec-simon avatar prokopec-simon commented on June 3, 2024

Yeah, I've came up with something like this and it seems to do the job. Thanks a lot for the super fast and helpful assistance. If you ever need any form of help feel free to hit me up.

from tw-colors.

Related Issues (20)

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.