Files
headlessui/packages/@headlessui-tailwindcss/src/index.ts
T
Robin Malfait 6253aa52b3 Fix bracket order of not variants (#1621)
* fix order of brackets in selector

* setup tests for `@headlessui/tailwindcss`

* update changelog
2022-06-26 00:48:07 +02:00

37 lines
1.1 KiB
TypeScript

import plugin from 'tailwindcss/plugin'
interface Options {
/**
* The prefix used for the variants. This defaults to `ui`.
*
* Usage example:
* ```html
* <div class="ui-open:underline"></div>
* ```
**/
prefix?: string
}
export default plugin.withOptions<Options>(({ prefix = 'ui' } = {}) => {
return ({ addVariant }) => {
for (let state of ['open', 'checked', 'selected', 'active', 'disabled']) {
// TODO: Once `:has()` is properly supported, then we can switch to this version:
// addVariant(`${prefix}-${state}`, [
// `&[data-headlessui-state~="${state}"]`,
// `:where([data-headlessui-state~="${state}"]):not(:has([data-headlessui-state])) &`,
// ])
// But for now, this will do:
addVariant(`${prefix}-${state}`, [
`&[data-headlessui-state~="${state}"]`,
`:where([data-headlessui-state~="${state}"]) &`,
])
addVariant(`${prefix}-not-${state}`, [
`&[data-headlessui-state]:not([data-headlessui-state~="${state}"])`,
`:where([data-headlessui-state]:not([data-headlessui-state~="${state}"])) &:not([data-headlessui-state])`,
])
}
}
})