Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
thecrypticace committed Jun 14, 2022
1 parent 22eaad1 commit 3325948
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
20 changes: 5 additions & 15 deletions src/corePlugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,11 @@ export let variantPlugins = {
[
'visited',
({ container }) => {
let toRemove = ['--tw-text-opacity', '--tw-border-opacity', '--tw-bg-opacity']

container.walkDecls((decl) => {
if (toRemove.includes(decl.prop)) {
decl.remove()

return
}

for (const varName of toRemove) {
if (decl.value.includes(`/ var(${varName})`)) {
decl.value = decl.value.replace(`/ var(${varName})`, '')
}
}
})
removeAlphaVariables(container, [
'--tw-text-opacity',
'--tw-border-opacity',
'--tw-bg-opacity',
])

return '&:visited'
},
Expand Down
24 changes: 24 additions & 0 deletions src/util/removeAlphaVariables.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* This function removes any uses of CSS variables used as an alpha channel
*
* This is required for selectors like `:visited` which do not allow
* changes in opacity or external control using CSS variables.
*
* @param {import('postcss').Container} container
* @param {string[]} toRemove
*/
export function removeAlphaVariables(container, toRemove) {
container.walkDecls((decl) => {
if (toRemove.includes(decl.prop)) {
decl.remove()

return
}

for (const varName of toRemove) {
if (decl.value.includes(`/ var(${varName})`)) {
decl.value = decl.value.replace(`/ var(${varName})`, '')
}
}
})
}

0 comments on commit 3325948

Please sign in to comment.