Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve before and after variants #5820

Merged
merged 10 commits into from
Oct 18, 2021
Prev Previous commit
Next Next commit
add content: var(--tw-content) for before/after variants
  • Loading branch information
RobinMalfait committed Oct 18, 2021
commit 39f75cd654e811c7e73d45cd9506f266be78f32a
31 changes: 29 additions & 2 deletions src/corePlugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,35 @@ export let variantPlugins = {

addVariant('file', '&::file-selector-button')

addVariant('before', '&::before')
addVariant('after', '&::after')
addVariant('before', ({ container }) => {
container.walkRules((rule) => {
let foundContent = false
rule.walkDecls('content', () => {
foundContent = true
})

if (!foundContent) {
rule.prepend(postcss.decl({ prop: 'content', value: 'var(--tw-content)' }))
}
})

return '&::before'
})

addVariant('after', ({ container }) => {
container.walkRules((rule) => {
let foundContent = false
rule.walkDecls('content', () => {
foundContent = true
})

if (!foundContent) {
rule.prepend(postcss.decl({ prop: 'content', value: 'var(--tw-content)' }))
}
})

return '&::after'
})
},

pseudoClassVariants: ({ addVariant }) => {
Expand Down
1 change: 0 additions & 1 deletion src/css/preflight.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
::before,
::after {
--tw-content: '';
content: var(--tw-content);
}

/*
Expand Down