Skip to content

Commit

Permalink
Allow variant to be an at-rule without a prelude
Browse files Browse the repository at this point in the history
  • Loading branch information
thecrypticace committed Jul 11, 2023
1 parent bc1af02 commit d8998a1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/lib/setupContextUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ export function parseVariant(variant) {
return ({ format }) => format(str)
}

let [, name, params] = /@(.*?)( .+|[({].*)/g.exec(str)
return ({ wrap }) => wrap(postcss.atRule({ name, params: params.trim() }))
let [, name, params] = /@(\S*)( .+|[({].*)?/g.exec(str)
return ({ wrap }) => wrap(postcss.atRule({ name, params: params?.trim() ?? '' }))
})
.reverse()

Expand Down
25 changes: 25 additions & 0 deletions tests/variants.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,31 @@ test('order matters and produces different behaviour', () => {
})

describe('custom advanced variants', () => {
test('at-rules without params', () => {
let config = {
content: [
{
raw: html` <div class="ogre:text-center"></div> `,
},
],
plugins: [
function ({ addVariant }) {
addVariant('ogre', '@layer')
},
],
}

return run('@tailwind components; @tailwind utilities', config).then((result) => {
return expect(result.css).toMatchFormattedCss(css`
@layer {
.ogre\:text-center {
text-align: center;
}
}
`)
})
})

test('prose-headings usage on its own', () => {
let config = {
content: [
Expand Down

0 comments on commit d8998a1

Please sign in to comment.