Add corePlugins function to plugin API

This commit is contained in:
Adam Wathan 2020-05-01 14:41:12 -04:00
parent c2b0407ffd
commit 652100e2d5
2 changed files with 63 additions and 0 deletions

View File

@ -744,6 +744,62 @@ test('plugins apply all global variants when variants are configured globally',
`)
})
test('plugins can check if corePlugins are enabled', () => {
const { components, utilities } = processPlugins(
[
function({ addUtilities, corePlugins }) {
addUtilities({
'.test': {
'text-color': corePlugins('textColor') ? 'true' : 'false',
opacity: corePlugins('opacity') ? 'true' : 'false',
},
})
},
],
makeConfig({
corePlugins: { textColor: false },
})
)
expect(components.length).toBe(0)
expect(css(utilities)).toMatchCss(`
@variants {
.test {
text-color: false;
opacity: true
}
}
`)
})
test('plugins can check if corePlugins are enabled when using array white-listing', () => {
const { components, utilities } = processPlugins(
[
function({ addUtilities, corePlugins }) {
addUtilities({
'.test': {
'text-color': corePlugins('textColor') ? 'true' : 'false',
opacity: corePlugins('opacity') ? 'true' : 'false',
},
})
},
],
makeConfig({
corePlugins: ['textColor'],
})
)
expect(components.length).toBe(0)
expect(css(utilities)).toMatchCss(`
@variants {
.test {
text-color: true;
opacity: false
}
}
`)
})
test('plugins can provide fallbacks to keys missing from the config', () => {
const { components, utilities } = processPlugins(
[

View File

@ -41,6 +41,13 @@ export default function(plugins, config) {
postcss,
config: getConfigValue,
theme: (path, defaultValue) => getConfigValue(`theme.${path}`, defaultValue),
corePlugins: path => {
if (Array.isArray(config.corePlugins)) {
return config.corePlugins.includes(path)
}
return getConfigValue(`corePlugins.${path}`, true)
},
variants: (path, defaultValue) => {
if (Array.isArray(config.variants)) {
return config.variants