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

Need a video how to use this :c #18

Closed
IRediTOTO opened this issue Apr 10, 2020 · 3 comments
Closed

Need a video how to use this :c #18

IRediTOTO opened this issue Apr 10, 2020 · 3 comments

Comments

@IRediTOTO
Copy link

hello, thank you for made this. But I can't understand how to config it right? If have time, can you please make a video how to use it? :(
Thank you.

@innocenzi
Copy link
Owner

Hi, I'm sorry but I won't be able to do that, as I am unable to properly vocally speak english.

However I am willing to help you there if you share details on what you tried and what didn't work.

@IRediTOTO
Copy link
Author

I trying make dark mode :D
I did by manual
image

It work ok :) But I like to use yours, I tried but so hard to setup with me :|

@innocenzi
Copy link
Owner

So, you will need another file. This file will contain the configuration for this plugin, so your themes.

  1. Create a theme.config.js at the root of your project.

  2. Open it and add this line, which will import what is necessary to build your theme:

// theme.config.js
const { ThemeBuilder, Theme } = require('tailwindcss-theming');
  1. Then declare a new theme. In this case we'll do the light one:
// theme.config.js
const { ThemeBuilder, Theme } = require('tailwindcss-theming');

const lightTheme = new Theme()
  .name('light')
  .default()
  .assignable()
  .colors({
    'background':'#313131',
    'surface':'#212121',
    'on-background':'#ffffff',
    'on-surface':'#ffffff',
  })
;

With this theme, you'll have four color utilities, so you'll be able to use, for instance, .bg-background for your backgrounds, and .text-on-background for the text colorson your background.

  1. We are not done yet, we need a dark theme. Just add one:
// theme.config.js
const { ThemeBuilder, Theme } = require('tailwindcss-theming');

const lightTheme = new Theme()
// ...

const darkTheme = new Theme()
  .name('dark')
  .colors({
    'background':'#ffffff',
    'surface':'#1c1c1c1',
    'on-background':'#111111',
    'on-surface':'#313131',
  })
;
  1. Now you have two variables, darkTheme and lightTheme, that contain your themes. You need to export an object which contain these two themes. You do that with the ThemeBuilder:
// theme.config.js
const { ThemeBuilder, Theme } = require('tailwindcss-theming');

const lightTheme = new Theme()
// ...

const darkTheme = new Theme()
// ...

module.exports = new ThemeBuilder()
  .asDataThemeAttribute()
  .default(lightTheme)
  .dark(darkTheme);
  1. Last step, go back in your Tailwind config, and import this file as a plugin:
module.exports = {
  theme: {},
  variants: {},
  plugins: [
    require('./theme.config.js')
  ],
};

And you're done. Use attribute data-theme="dark" to apply the dark theme, or setup your browser to use the darktheme since it's enabled with the prefers-color-scheme media query.

https://github.com/hawezo/tailwindcss-theming/blob/master/docs/setup.md

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

2 participants