Skip to content

Instantly share code, notes, and snippets.

@tomaash
Created August 16, 2019 13:59
Show Gist options
  • Save tomaash/a1a1c957432665dd9e00ac09a41f55d7 to your computer and use it in GitHub Desktop.
Save tomaash/a1a1c957432665dd9e00ac09a41f55d7 to your computer and use it in GitHub Desktop.
tailwind children variants
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