Skip to content

Commit ae1db1a

Browse files
Merge pull request #109 from RyanClementsHax/fix-bugs
Fix bugs
2 parents 5594272 + 10fb07f commit ae1db1a

File tree

48 files changed

+1163
-162
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1163
-162
lines changed

README.md

+2-28
Original file line numberDiff line numberDiff line change
@@ -504,8 +504,6 @@ module.exports = {
504504
```
505505

506506
> Notice how we needed to set `color.primary` to a callback function. This is to properly handle opacity. See [Opacity](docs/themingColors.md#opacity) for more details.
507-
> \
508-
> Because it creates a theme extension for you, this is why it overwrites whatever is in the normal theme extension upon collision. See [This plugin's config overwrites what is in the normal tailwind config n collision](docs/config.md#this-plugins-config-overwrites-what-is-in-the-normal-tailwind-config-n-collision) for more details.
509507
510508
It also injects css variables with proper scoping into tailwind's [base layer](https://tailwindcss.com/docs/adding-custom-styles#using-css-and-layer).
511509

@@ -720,7 +718,7 @@ require('tailwindcss-themer')({
720718

721719
The above config would generate a css variable of the name `--colors-myBrand-primary-500`. If for some reason, [camelCasing](https://en.wikipedia.org/wiki/Camel_case) is converted to [kebab-casing](https://www.theserverside.com/definition/Kebab-case), make sure you have tailwind `v3.0.12` or later installed as that version fixed that bug.
722720

723-
If you use `DEFAULT` anywhere on a path to a variable, it is dropped off of the generated css variable name.
721+
If you use `DEFAULT` as a leaf value, it is dropped off of the generated css variable name.
724722

725723
```js
726724
require('tailwindcss-themer')({
@@ -741,31 +739,7 @@ require('tailwindcss-themer')({
741739
})
742740
```
743741

744-
The above config would generate a css variable of the name `--colors-brand1-primary`.
745-
746-
Because of the way `DEFAULT` works, it is possible to have naming collisions. It is on the user of this plugin to ensure that none happen.
747-
748-
```js
749-
require('tailwindcss-themer')({
750-
defaultTheme: {
751-
extend: {
752-
colors: {
753-
brand1: {
754-
DEFAULT: {
755-
primary: {
756-
DEFAULT: 'red'
757-
}
758-
},
759-
primary: 'blue'
760-
}
761-
}
762-
}
763-
}
764-
// ...
765-
})
766-
```
767-
768-
`colors.brand1.DEFAULT.primary.DEFAULT` and `colors.brand1.primary` both would generate a css variable named `--colors-brand1-primary`. See [Default key](docs/config.md#default-key) for more details.
742+
The above config would generate a css variable of the name `--colors-brand1-DEFAULT-primary`. See [Default key](docs/config.md#default-key) for more details.
769743

770744
If anywhere in the path, an array is encountered, the index is used in the generated css variable name.
771745

docs/config.md

+68-109
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# Config <!-- omit in toc -->
22

33
- [Themes named `"dark"`](#themes-named-dark)
4-
- [This plugin's config overwrites what is in the normal tailwind config on collision](#this-plugins-config-overwrites-what-is-in-the-normal-tailwind-config-on-collision)
4+
- [Collisions with the normal tailwind config](#collisions-with-the-normal-tailwind-config)
5+
- [This plugin's config overwrites what is in the normal tailwind config on collision](#this-plugins-config-overwrites-what-is-in-the-normal-tailwind-config-on-collision)
6+
- [This plugin's config is overwritten by what is in the normal tailwind extension config on collison](#this-plugins-config-is-overwritten-by-what-is-in-the-normal-tailwind-extension-config-on-collison)
57
- [Extend](#extend)
68
- [Valid primitives](#valid-primitives)
79
- [DEFAULT key](#default-key)
810
- [Shorthand](#shorthand)
9-
- [Gotcha's](#gotchas)
1011
- [Callbacks](#callbacks)
1112
- [Config mismatches](#config-mismatches)
1213
- [Referencing tailwind's default theme](#referencing-tailwinds-default-theme)
@@ -77,21 +78,21 @@ Because tailwind automatically adds the `dark` variant for users, defining a the
7778

7879
Therefore, attempting to use `selectors` or `mediaQuery` for a theme named `dark` won't work at all. To prevent users of this plugin from encountering these silent bugs, this plugin crashes when that happens.
7980

80-
## This plugin's config overwrites what is in the normal tailwind config on collision
81+
## Collisions with the normal tailwind config
82+
83+
### This plugin's config overwrites what is in the normal tailwind config on collision
8184

8285
Any config specified in this plugin's config, overwrites what is in the normal tailwind config if there is a collision.
8386

8487
```js
8588
// tailwind.config.js
8689
module.exports = {
8790
theme: {
88-
extend: {
89-
colors: {
90-
// clobbered
91-
primary: 'blue',
92-
// not clobbered
93-
secondary: 'green'
94-
}
91+
colors: {
92+
// clobbered
93+
primary: 'blue',
94+
// not clobbered
95+
secondary: 'green'
9596
}
9697
},
9798
plugins: [
@@ -114,6 +115,53 @@ module.exports = {
114115

115116
If you want to use the default tailwind config in your theme configuration, see [Overwriting tailwind defaults](#overwriting-tailwind-defaults) and [Referencing tailwind's default theme](#referencing-tailwinds-default-theme).
116117

118+
### This plugin's config is overwritten by what is in the normal tailwind extension config on collison
119+
120+
In contrast to the normal tailwind config values as specified above, anything in the `theme.extend` value takes precendence over anything this plugin outputs.
121+
122+
```js
123+
// tailwind.config.js
124+
module.exports = {
125+
theme: {
126+
extend: {
127+
// nothing in here is clobbered
128+
colors: {
129+
primary: 'blue',
130+
secondary: 'green'
131+
}
132+
}
133+
},
134+
plugins: [
135+
require('tailwindcss-themer')({
136+
defaultTheme: {
137+
extend: {
138+
colors: {
139+
// clobbered
140+
primary: 'red',
141+
// clobbered
142+
secondary: 'yellow'
143+
}
144+
}
145+
},
146+
themes: [
147+
{
148+
name: 'my-theme',
149+
extend: {
150+
colors: {
151+
// clobbered
152+
primary: 'brown',
153+
// clobbered
154+
secondary: 'orange'
155+
}
156+
}
157+
}
158+
]
159+
})
160+
// ...
161+
]
162+
}
163+
```
164+
117165
## Extend
118166

119167
- This takes an object representing a [tailwind extension](https://tailwindcss.com/docs/theme#extending-the-default-theme)
@@ -169,7 +217,7 @@ require('tailwindcss-themer')({
169217
```
170218

171219
```html
172-
<!DOCTYPE html>
220+
<!doctype html>
173221
<html lang="en">
174222
<head>
175223
<!-- ... -->
@@ -184,7 +232,7 @@ require('tailwindcss-themer')({
184232
```
185233

186234
```html
187-
<!DOCTYPE html>
235+
<!doctype html>
188236
<html lang="en">
189237
<head>
190238
<!-- ... -->
@@ -199,7 +247,7 @@ require('tailwindcss-themer')({
199247
```
200248

201249
```html
202-
<!DOCTYPE html>
250+
<!doctype html>
203251
<html lang="en">
204252
<head>
205253
<!-- ... -->
@@ -260,40 +308,40 @@ require('tailwindcss-themer')({
260308
You would then use the tailwind classes as normal
261309

262310
```html
263-
<!DOCTYPE html>
311+
<!doctype html>
264312
<html lang="en">
265313
<head>
266314
<!-- ... -->
267315
</head>
268316
<body>
269317
<!-- this has a border radius of .25rem since that is the default -->
270-
<input aria-label="my input" class="border rounded-woahh" />
318+
<input aria-label="my input" class="rounded-woahh border" />
271319
</body>
272320
</html>
273321
```
274322

275323
```html
276-
<!DOCTYPE html>
324+
<!doctype html>
277325
<html lang="en">
278326
<head>
279327
<!-- ... -->
280328
</head>
281329
<body class="special-border-radius">
282330
<!-- this has a border radius of .5rem as specified in the special-border-radius config -->
283-
<input aria-label="my input" class="border rounded-woahh" />
331+
<input aria-label="my input" class="rounded-woahh border" />
284332
</body>
285333
</html>
286334
```
287335

288336
```html
289-
<!DOCTYPE html>
337+
<!doctype html>
290338
<html lang="en">
291339
<head>
292340
<!-- ... -->
293341
</head>
294342
<body class="double-border-radius">
295343
<!-- this has a border radius of 1rem as specified in the double-border-radius config -->
296-
<input aria-label="my input" class="border rounded-woahh" />
344+
<input aria-label="my input" class="rounded-woahh border" />
297345
</body>
298346
</html>
299347
```
@@ -377,7 +425,7 @@ Anything that can be parsed as a color is handled in a special way. See [Theming
377425

378426
### DEFAULT key
379427

380-
Tailwind lets you specify default values for certain configuration.
428+
Tailwind lets you specify [default values for certain configuration](https://tailwindcss.com/docs/theme#core-plugins).
381429

382430
For example, if you had a palette, but wanted to specify a default value for that palette, you could use the `DEFAULT` key.
383431

@@ -443,63 +491,6 @@ require('tailwindcss-themer')({
443491

444492
Styles like `text-primary` will now be themed.
445493

446-
`DEFAULT` doesn't have to be set to a string. It could also be set to other values like objects.
447-
448-
```js
449-
require('tailwindcss-themer')({
450-
// ...
451-
themes: [
452-
{
453-
name: 'my-theme',
454-
extend: {
455-
colors: {
456-
primary: {
457-
DEFAULT: {
458-
100: '#000111'
459-
//...
460-
},
461-
brand1: {
462-
// ...
463-
},
464-
brand2: {
465-
// ...
466-
}
467-
}
468-
}
469-
}
470-
}
471-
]
472-
})
473-
```
474-
475-
This generates classes like `text-primary-100`, `text-primary-brand1-200`, etc.
476-
477-
You can even nest them.
478-
479-
```js
480-
require('tailwindcss-themer')({
481-
// ...
482-
themes: [
483-
{
484-
name: 'my-theme',
485-
extend: {
486-
colors: {
487-
brand1: {
488-
DEFAULT: {
489-
primary: {
490-
DEFAULT: 'red'
491-
}
492-
}
493-
}
494-
}
495-
}
496-
}
497-
]
498-
})
499-
```
500-
501-
This will generate classess like `text-brand1-primary`.
502-
503494
#### Shorthand
504495

505496
Because of how `DEFAULT` works, you can specify single default values as strings if that is the only value in the object.
@@ -542,38 +533,6 @@ require('tailwindcss-themer')({
542533
})
543534
```
544535

545-
#### Gotcha's
546-
547-
Because of how `DEFAULT` works, it is possible to have naming collisions.
548-
549-
Take the following for an example.
550-
551-
```js
552-
require('tailwindcss-themer')({
553-
// ...
554-
themes: [
555-
{
556-
name: 'my-theme',
557-
extend: {
558-
colors: {
559-
primary: {
560-
DEFAULT: {
561-
fontColor: 'red'
562-
},
563-
fontColor: {
564-
DEFAULT: 'red'
565-
}
566-
}
567-
}
568-
}
569-
}
570-
// ...
571-
]
572-
})
573-
```
574-
575-
`colors.primary.DEFAULT.fontColor` and `colors.primary.fontColor.DEFAULT` both create classes like `text-primary-fontColor`. It is on the consumer of this plugin to make sure these naming collisions don't happen.
576-
577536
### Callbacks
578537

579538
Tailwind [supports top level callbacks](https://tailwindcss.com/docs/theme#referencing-other-values) for referrencing other values in your config. This plugin supports that too.

docs/themingColors.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ require('tailwindcss-themer')({
1616
},
1717
foo: {
1818
bar: {
19-
DEFAULT: {
20-
bazz: 'rgb(35, 0, 75)' // also parsed as a color
21-
}
19+
bazz: 'rgb(35, 0, 75)' // also parsed as a color
2220
}
2321
}
2422
}

0 commit comments

Comments
 (0)