tailwind-ctp-intellisense/packages/tailwindcss-class-names/src/getVariants.js

41 lines
1.2 KiB
JavaScript
Raw Normal View History

2020-04-11 21:20:45 +00:00
import semver from 'semver'
import dlv from 'dlv'
export default function getVariants({ config, version, postcss }) {
let variants = ['responsive', 'hover']
semver.gte(version, '0.3.0') && variants.push('focus', 'group-hover')
semver.gte(version, '0.5.0') && variants.push('active')
semver.gte(version, '0.7.0') && variants.push('focus-within')
2020-04-12 22:48:57 +00:00
semver.gte(version, '1.0.0-beta.1') && variants.push('default')
2020-04-11 21:20:45 +00:00
semver.gte(version, '1.1.0') &&
variants.push('first', 'last', 'odd', 'even', 'disabled', 'visited')
let plugins = config.plugins
if (!Array.isArray(plugins)) {
plugins = []
}
2020-04-12 22:48:57 +00:00
plugins.forEach((plugin) => {
2020-04-11 21:20:45 +00:00
try {
;(plugin.handler || plugin)({
addUtilities: () => {},
addComponents: () => {},
addBase: () => {},
2020-04-12 22:48:57 +00:00
addVariant: (name) => {
2020-04-11 21:20:45 +00:00
variants.push(name)
},
2020-04-12 22:48:57 +00:00
e: (x) => x,
prefix: (x) => x,
2020-04-11 21:20:45 +00:00
theme: (path, defaultValue) =>
dlv(config, `theme.${path}`, defaultValue),
variants: () => [],
config: (path, defaultValue) => dlv(config, path, defaultValue),
2020-04-12 22:48:57 +00:00
postcss,
2020-04-11 21:20:45 +00:00
})
} catch (_) {
console.error(_)
}
})
return variants
}