11const plugin = require ( "tailwindcss/plugin" )
22
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 = [
511 "atomic" ,
612 "busy" ,
713 "checked" ,
@@ -20,22 +26,11 @@ module.exports = plugin(({ addVariant, e }) => {
2026 "readonly" ,
2127 "required" ,
2228 "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+ ]
3330
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+ }
3934
4035 const enumerables = {
4136 autocomplete : [ "both" , "inline" , "list" , "none" ] ,
@@ -49,20 +44,7 @@ module.exports = plugin(({ addVariant, e }) => {
4944
5045 for ( const [ attribute , values ] of Object . entries ( enumerables ) ) {
5146 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 )
6648 }
6749 }
6850} )
0 commit comments