Skip to content

Instantly share code, notes, and snippets.

@hnordt
Created January 7, 2022 19:54
Show Gist options
  • Save hnordt/6070ed7a164e7bf122174460b8ba18f0 to your computer and use it in GitHub Desktop.
Save hnordt/6070ed7a164e7bf122174460b8ba18f0 to your computer and use it in GitHub Desktop.
// add to your tailwind.config.js
const plugin = require("tailwindcss/plugin")
const radixPlugin = plugin(({ addVariant }) => {
const dataStates = [
"open",
"closed",
"active",
"inactive",
"on",
"off",
"checked",
"unchecked",
"indeterminate",
"loading",
"complete",
"hidden",
"delayed-open",
]
dataStates.forEach((state) => {
// e.g. state-open:text-slate-500
addVariant(`state-${state}`, `&[data-state="${state}"]`)
// e.g. group-state-open:text-slate-500
addVariant(
`group-state-${state}`,
`:merge(.group)[data-state="${state}"] &`
)
})
})
module.exports = {
...yourConfig,
plugins: [
...yourPlugins,
radixPlugin
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment