Skip to content

Commit dd4466f

Browse files
committed
feat: Change how plug-in options are set
BREAKING CHANGE: Change how plug-in options are set
1 parent cab2d1c commit dd4466f

File tree

4 files changed

+38
-31
lines changed

4 files changed

+38
-31
lines changed

README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,16 @@ module.exports = {
4242
},
4343
},
4444

45-
// You can set up your own pseudo-classes and pseudo-elements.
46-
customPseudoClasses: ['foo'],
47-
customPseudoElements: ['bar'],
48-
4945
plugins: [
50-
require('tailwindcss-pseudo-elements'),
46+
require('tailwindcss-pseudo-elements')({
47+
// You can set up your own pseudo-classes and pseudo-elements. (string[])
48+
customPseudoClasses: ['foo'],
49+
customPseudoElements: ['bar'],
50+
// Configuration of the Content Property Utilities (boolean | { prefix: string })
51+
contentUtilities: {
52+
prefix: 'tw-content',
53+
},
54+
}),
5155
// This plugin is useful in combination with tailwindcss-aspect-ratio.
5256
require('tailwindcss-aspect-ratio')({
5357
ratios: {

index.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,12 @@ const tailwindcssPlugin = require('tailwindcss/plugin')
33
const addContentUtilities = require('./content-utilities')
44
const { pseudoElements, pseudoClasses } = require('./lib')
55

6-
const plugin = (options = {}) => {
7-
const { contentUtilities = true } = options
8-
9-
return tailwindcssPlugin(({ addUtilities, addVariant, e, config }) => {
10-
const customPseudoElements = config
11-
? config('customPseudoElements') || []
12-
: []
13-
const customPseudoClasses = config
14-
? config('customPseudoClasses') || []
15-
: []
6+
const plugin = tailwindcssPlugin.withOptions((options = {}) => {
7+
return ({ addUtilities, addVariant, e }) => {
8+
const customPseudoElements = options.customPseudoElements || []
9+
const customPseudoClasses = options.customPseudoClasses || []
10+
const contentUtilities =
11+
options.contentUtilities || options.contentUtilities !== false
1612

1713
if (!Array.isArray(customPseudoElements)) {
1814
throw new Error('`customElements` must be an array of string.')
@@ -62,7 +58,7 @@ const plugin = (options = {}) => {
6258
pseudoClasses: mergedPseudoClasses,
6359
})
6460
}
65-
})
66-
}
61+
}
62+
})
6763

6864
module.exports = plugin

test/plugin.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ const { assert } = require('chai')
22
const postcss = require('postcss')
33
const tailwindcss = require('tailwindcss')
44

5+
const plugin = require('..')
6+
57
const baseConfig = require('./tailwind.config')
68

79
const createProcessor = (config = {}) => {
@@ -55,21 +57,23 @@ describe('with pseudo-classes', () => {
5557
})
5658

5759
describe('with configuration', () => {
58-
it('@tailwind', async () => {
60+
it('Turn off the Content Property Utilities', async () => {
5961
const testData = `@tailwind utilities;`
60-
const { css } = await createProcessor().process(testData, {
62+
const options = {
63+
customPseudoClasses: ['foo'],
64+
customPseudoElements: ['bar'],
65+
contentUtilities: false,
66+
}
67+
const { css } = await createProcessor({
68+
plugins: [plugin(options)],
69+
}).process(testData, {
6170
from: '',
6271
to: '',
6372
})
64-
assert.include(css, '.foo\\:bar\\:text-black:foo::bar')
65-
})
6673

67-
it('@variants', async () => {
68-
const testData = `@variants foo_bar{.text-blue{color:blue}}`
69-
const { css } = await createProcessor().process(testData, {
70-
from: '',
71-
to: '',
72-
})
73-
assert.include(css, '.foo\\:bar\\:text-blue:foo::bar')
74+
assert.notInclude(
75+
css,
76+
'.content-before::before {\n content: attr(tw-content-before)\n}'
77+
)
7478
})
7579
})

test/tailwind.config.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ module.exports = {
1212
modules: {
1313
textColors: ['before', 'after', 'hover_before', 'hover_after', 'foo_bar'],
1414
},
15-
plugins: [plugin()],
16-
customPseudoClasses: ['foo'],
17-
customPseudoElements: ['bar'],
15+
plugins: [
16+
plugin({
17+
customPseudoClasses: ['foo'],
18+
customPseudoElements: ['bar'],
19+
}),
20+
],
1821
}

0 commit comments

Comments
 (0)