1
1
const plugin = require ( "tailwindcss/plugin" )
2
2
3
- module . exports = plugin ( ( { addVariant, e } ) => {
4
- [
3
+ module . exports = plugin ( ( { addVariant } ) => {
4
+ const addAriaVariant = ( name , value ) => {
5
+ addVariant ( name , `[${ name } ="${ value } "]&` )
6
+ addVariant ( `peer-${ name } ` , `:merge(.peer)[${ name } ="${ value } "] ~ &` )
7
+ addVariant ( `group-${ name } ` , `:merge(.group)[${ name } ="${ value } "] &` )
8
+ }
9
+
10
+ const booleans = [
5
11
"atomic" ,
6
12
"busy" ,
7
13
"checked" ,
@@ -20,22 +26,11 @@ module.exports = plugin(({ addVariant, e }) => {
20
26
"readonly" ,
21
27
"required" ,
22
28
"selected" ,
23
- ] . forEach ( boolean => {
24
- const selector = `aria-${ boolean } `
25
- addVariant ( selector , ( { modifySelectors, separator } ) =>
26
- modifySelectors ( ( { className } ) => `[${ selector } ="true"].${ e ( `${ selector } ${ separator } ${ className } ` ) } ` )
27
- )
28
-
29
- const groupSelector = `group-aria-${ boolean } `
30
- addVariant ( groupSelector , ( { modifySelectors, separator } ) =>
31
- modifySelectors ( ( { className } ) => `.group[aria-${ boolean } ="true"] .${ e ( `${ groupSelector } ${ separator } ${ className } ` ) } ` )
32
- )
29
+ ]
33
30
34
- const peerSelector = `peer-aria-${ boolean } `
35
- addVariant ( peerSelector , ( { modifySelectors, separator } ) =>
36
- modifySelectors ( ( { className } ) => `.peer[aria-${ boolean } ="true"] ~ .${ e ( `${ peerSelector } ${ separator } ${ className } ` ) } ` )
37
- )
38
- } )
31
+ for ( const attribute of booleans ) {
32
+ addAriaVariant ( `aria-${ attribute } ` , "true" )
33
+ }
39
34
40
35
const enumerables = {
41
36
autocomplete : [ "both" , "inline" , "list" , "none" ] ,
@@ -49,20 +44,7 @@ module.exports = plugin(({ addVariant, e }) => {
49
44
50
45
for ( const [ attribute , values ] of Object . entries ( enumerables ) ) {
51
46
for ( const value of values ) {
52
- const selector = `aria-${ attribute } -${ value } `
53
- addVariant ( selector , ( { modifySelectors, separator } ) =>
54
- modifySelectors ( ( { className } ) => `[aria-${ attribute } ="${ value } "].${ e ( `${ selector } ${ separator } ${ className } ` ) } ` )
55
- )
56
-
57
- const groupSelector = `group-aria-${ attribute } -${ value } `
58
- addVariant ( groupSelector , ( { modifySelectors, separator } ) =>
59
- modifySelectors ( ( { className } ) => `.group[aria-${ attribute } ="${ value } "] .${ e ( `${ groupSelector } ${ separator } ${ className } ` ) } ` )
60
- )
61
-
62
- const peerSelector = `peer-aria-${ attribute } -${ value } `
63
- addVariant ( peerSelector , ( { modifySelectors, separator } ) =>
64
- modifySelectors ( ( { className } ) => `.peer[aria-${ attribute } ="${ value } "] ~ .${ e ( `${ peerSelector } ${ separator } ${ className } ` ) } ` )
65
- )
47
+ addAriaVariant ( `aria-${ attribute } -${ value } ` , value )
66
48
}
67
49
}
68
50
} )
0 commit comments