Skip to content

Commit 4c2a1a9

Browse files
author
Sam Goody
committed
BREAKING: Remove child-{psuedo-class} custom variants.
1 parent 1d83f09 commit 4c2a1a9

File tree

3 files changed

+15
-98
lines changed

3 files changed

+15
-98
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,19 @@ I might eventually implement it, even though it is not a tailwind style rule at
278278

279279
## Changes from earlier versions.
280280

281+
[Modifiers such as :hover](https://tailwindcss.com/docs/hover-focus-and-other-states) must be set *first* (eg. hover:child:shadow) for it [to be applied to the children](https://tailwindcss.com/docs/hover-focus-and-other-states#ordering-stacked-modifiers).
282+
283+
In earlier versions, we created custom variants for all modifiers, so that you can use the form `child-hover`, which is easier to read, and matches group and peer:
284+
285+
```html
286+
<input class="peer">
287+
<p class="peer-hover:shadow">p has shadow when hovering on input</p>
288+
289+
<div class="group">
290+
<p class="group-hover:shadow">p has shadow when hovering over div</p>
291+
</div>
292+
```
293+
281294
#### Matching selector on child
282295

283296
Earlier versions limitted matching children to those havng a class `.child`.

dist/index.js

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -29,63 +29,7 @@ const aliases = Object.entries({
2929
"&": ["heir", "descendant"],
3030
"& ~": ["sibling", "twin"]
3131
});
32-
const psuedo = [
33-
...[
34-
"active",
35-
"focus",
36-
"focus-within",
37-
"focus-visible",
38-
"hover",
39-
"disabled",
40-
"first-of-type",
41-
"last-of-type",
42-
"only-of-type",
43-
"autofill",
44-
"checked",
45-
"default",
46-
"indeterminate",
47-
"placeholder-shown",
48-
"required",
49-
"valid",
50-
"invalid",
51-
"in-range",
52-
"out-of-range",
53-
"read-only",
54-
"empty",
55-
"visited",
56-
"target"
57-
].map((v) => [v, v]),
58-
...[
59-
"before",
60-
"after",
61-
"first-letter",
62-
"first-line",
63-
"marker",
64-
"selection",
65-
"placeholder"
66-
].map((v) => [v, `:${v}`]),
67-
...[
68-
["open", "open"],
69-
["rtl", 'dir="rtl"'],
70-
["ltr", 'dir="ltr"']
71-
].map((v) => [v[0], "", `[${v[1]}]`]),
72-
...[
73-
["first", "first-child"],
74-
["last", "last-child"],
75-
["only", "only-child"],
76-
["odd", "nth-child(odd)"],
77-
["even", "nth-child(even)"],
78-
["not-first", "not(:first-child)"],
79-
["not-last", "not(:last-child)"],
80-
["file", "file-selector-button"]
81-
]
82-
];
83-
let variants = psuedo.flatMap(([pstate, pclass, pselector]) => aliases.flatMap(([prefix, newvariants]) => newvariants.map((newvariant) => [
84-
`${newvariant}-${pstate}`,
85-
`${prefix} .${newvariant}` + (pselector || `:${pclass}`)
86-
])));
87-
let basic = aliases.flatMap(([k, v]) => v.map((i) => [i, `${k} :where(:not(.not-${i}))`]));
88-
variants.unshift(...basic);
32+
let variants = aliases.flatMap(([k, v]) => v.map((i) => [i, `${k} :where(:not(.not-${i}))`]));
8933
const els = [
9034
"address",
9135
"article",

src/index.mjs

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,49 +6,9 @@ const aliases = Object.entries({
66
":where(&) ~ ": ['sibling', 'twin'],
77
})
88

9-
// Handle all tailwind psuedoclasses, see:
10-
// https://tailwindcss.com/docs/hover-focus-and-other-states#quick-reference
11-
const psuedo = [
12-
... [
13-
'active', 'focus', 'focus-within', 'focus-visible', 'hover', 'disabled', // Interactive
14-
'first-of-type', 'last-of-type', 'only-of-type', // Positional
15-
'autofill', 'checked', 'default', 'indeterminate', 'placeholder-shown', // Forms
16-
'required', 'valid', 'invalid', 'in-range', 'out-of-range', 'read-only', // Forms
17-
'empty', 'visited', 'target', // State
18-
].map(v => [v, v]),
19-
... [ // Pseudo-elements
20-
'before', 'after', 'first-letter', 'first-line', 'marker', 'selection', 'placeholder'
21-
].map(v => [v, `:${v}`]),
22-
... [ // Attributes
23-
['open', 'open'],
24-
['rtl', 'dir="rtl"'],
25-
['ltr', 'dir="ltr"'],
26-
].map(v => [v[0], '', `[${v[1]}]`]),
27-
... [ // Positional
28-
['first', 'first-child'],
29-
['last', 'last-child'],
30-
['only', 'only-child'],
31-
['odd', 'nth-child(odd)'],
32-
['even', 'nth-child(even)'],
33-
['not-first', 'not(:first-child)'],
34-
['not-last', 'not(:last-child)'],
35-
['file', 'file-selector-button'],
36-
],
37-
]
38-
39-
// convert ['hover', 'hover'] -> ['children-hover', '& > .children:hover']
40-
let variants = psuedo.flatMap(([pstate, pclass, pselector]) =>
41-
aliases.flatMap(([prefix, newvariants]) =>
42-
newvariants.map(newvariant => [
43-
`${newvariant}-${pstate}`,
44-
`${prefix} :where(.${newvariant}` + (pselector || `:${pclass}`) + ')'
45-
])))
46-
47-
let basic = aliases
9+
let variants = aliases
4810
.flatMap(([k, v]) => v.map(i => [i, `${k} :where(:not(.not-${i}))`]));
4911

50-
variants.unshift(...basic);
51-
5212
// list of elements from https://developer.mozilla.org/en-US/docs/Web/HTML/Element
5313
// For each of these we do not need explicit sign-in
5414
const els = [

0 commit comments

Comments
 (0)