Skip to content

Commit 355c8d5

Browse files
author
requestmethod
committed
update readme
1 parent 433b49e commit 355c8d5

File tree

1 file changed

+37
-8
lines changed

1 file changed

+37
-8
lines changed

README.md

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,49 +4,78 @@ A Tailwind CSS plugin to create themes using CSS classes and variables.
44

55
# Overview
66

7-
Tailwind CSS doesn't support themes by default, but they offer a "[dark mode](https://tailwindcss.com/docs/dark-mode)" feature. This is a utility for specifying dark mode styles, not creating themes. This plugin aims to simplify adding themes with semantic color names that can be updated by passing in theme CSS classes to override styles.
7+
Tailwind offers a "[dark mode](https://tailwindcss.com/docs/dark-mode)" feature, but that's not a true design system theme. CSS variable theming simplifies color management and developer experience by mapping semantic color names to existing design system color scales. Changing a theme becomes as simple as changing one CSS classes.
88

99
### Tailwind CSS "theming" with Dark Mode
1010

1111
```html
1212
<!-- Card example w/ Tailwind CSS dark mode -->
1313

1414
<div class="bg-gray-900 dark:bg-gray-100 p-12">
15-
<h3>Card w/ light theme</h3>
16-
<p class="text-white dark:text-black">
15+
<h3 class="text-white dark:text-black">Card w/ light theme</h3>
16+
<p class="text-white/70 dark:text-black/70">
1717
This card example is styled using Tailwind's default color values with dark
1818
utility classes to modify the colors for dark mode.
1919
</p>
20+
<button class="text-blue-600 dark:text-blue-400">Action text</button>
2021
</div>
2122
```
2223

24+
In the "dark mode" approach, every color classes needs a `dark:` alternative color, resulting in twice the number of classes across your entire code base.
25+
2326
### Tailwind CSS theming with this plugin
2427

2528
```html
2629
<!-- Card example w/ light theme -->
2730

2831
<div class="theme--light bg-background-primary p-12">
29-
<h3>Card w/ light theme</h3>
30-
<p class="text-white">
32+
<h3 class="text-content-primary">Card w/ light theme</h3>
33+
<p class="text-content-secondary">
3134
This card example is styled using Tailwind color values that were set up for
3235
you when you installed the plugin.
3336
</p>
37+
<button class="text-action">Action text</button>
3438
</div>
3539
```
3640

3741
```html
3842
<!-- Card example w/ dark theme -->
3943

4044
<div class="theme--dark bg-background-primary p-12">
41-
<h3>Card w/ light theme</h3>
42-
<p class="text-white">
45+
<h3 class="text-content-primary">Card w/ light theme</h3>
46+
<p class="text-content-secondary">
4347
This card example is styled using Tailwind color values that were set up for
4448
you when you installed the plugin.
4549
</p>
50+
<button class="text-action">Action text</button>
4651
</div>
4752
```
4853

49-
This system avoids dark classes altogether in favor of the theme classes. If you design your app using semantic color names, you get theming for free. This results in a significant reduction in CSS styling because you're not writing color values directly into components.
54+
In the theme approach, we avoid `dark:` classes altogether in favor of the semantic theme class names with a single theme class to define the color mapping. The 2 components above share the same HTML, but the theme class name on the parent div sets the right theme values for all of the nested semantic class names.
55+
56+
Here's the same example in React TypeScript:
57+
58+
```tsx
59+
function Card({ theme }: { theme: "theme--light" | "theme--dark" }) {
60+
return (
61+
<div className={`${themeClass} p-12 bg-background-primary`}>
62+
<h3 className="text-content-primary">Card w/ {theme} theme</h3>
63+
<p className="text-content-secondary">
64+
This card example is styled using Tailwind color values that were set up
65+
for you when you installed the plugin.
66+
</p>
67+
<button className="text-action">Action text</button>
68+
</div>
69+
);
70+
}
71+
72+
<!-- Card example w/ light theme -->
73+
<Card theme="theme--light" />
74+
75+
<!-- Card example w/ dark theme -->
76+
<Card theme="theme--dark" />
77+
78+
```
5079

5180
# Usage
5281

0 commit comments

Comments
 (0)