mirror of
https://github.com/tailwindlabs/tailwindcss.git
synced 2025-12-08 21:36:08 +00:00
Add corePlugins function to plugin API
This commit is contained in:
parent
c2b0407ffd
commit
652100e2d5
@ -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(
|
||||
[
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user