Created
August 16, 2019 13:59
-
-
Save tomaash/a1a1c957432665dd9e00ac09a41f55d7 to your computer and use it in GitHub Desktop.
tailwind children variants
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
variants: { | |
margin: ['responsive', 'children', 'not-first', 'not-last'], | |
padding: ['responsive', 'children', 'not-first', 'not-last'], | |
borderWidth: ['responsive', 'children', 'not-first', 'not-last'] | |
}, | |
plugins: [ | |
/** | |
* | |
* Usage example for children variants | |
* | |
* <div className='children:pl-4 not-first:pt-8 not-last:border-b'> | |
* {['a', 'b', 'c'].map(x => ( | |
* <h1>{x}</h1> | |
* ))} | |
* </div> | |
* | |
*/ | |
function({ addVariant, e }) { | |
addVariant('children', ({ modifySelectors, separator }) => { | |
modifySelectors(({ className }) => { | |
return `.${e(`children${separator}${className}`)} >*` | |
}) | |
}) | |
addVariant('not-first', ({ modifySelectors, separator }) => { | |
modifySelectors(({ className }) => { | |
return `.${e(`not-first${separator}${className}`)} >*:not(:first-child)` | |
}) | |
}) | |
addVariant('not-last', ({ modifySelectors, separator }) => { | |
modifySelectors(({ className }) => { | |
return `.${e(`not-last${separator}${className}`)} >*:not(:last-child)` | |
}) | |
}) | |
} | |
], | |
important: true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment