@empathyco/x-tailwindcss
Version:
Empathy X Tailwind plugin
50 lines (46 loc) • 1.99 kB
JavaScript
;
var xUtils = require('@empathyco/x-utils');
var plugin$1 = require('tailwindcss/plugin');
var components = require('./components.js');
var dynamicComponents = require('./dynamic-components.js');
var dynamicUtilities = require('./dynamic-utilities.js');
var theme = require('./theme.js');
var utilities = require('./utilities.js');
/**
* Defines the x-tailwind plugin as a Tailwind {@link plugin} that can be invoked passing a
* configuration object to customize it. The plugin is bundled with generated static and dynamic
* components and utilities, all based on the plugin's theme.
*
* @public
*/
var plugin = plugin$1.withOptions(() => {
/**
* Registers the generated CSS for the components and utilities of the plugin to the
* respective Tailwind layer. It depends on the plugin's theme, affecting
* the color, spacing, etc... Of the styles generated in this step.
*
* @param helpers - The {@link TailwindHelpers}.
* @internal
*/
return function (helpers) {
/* Add components */
helpers.addComponents(components(helpers), { respectPrefix: false });
/* Add dynamic components */
xUtils.forEach(dynamicComponents(helpers), (key, { styles, values }) => {
helpers.matchComponents({ [key]: styles }, { respectPrefix: false, values: values !== null && values !== void 0 ? values : undefined });
});
/* Add dynamic utilities */
xUtils.forEach(dynamicUtilities(helpers), (key, { styles, values }) => {
helpers.matchUtilities({ [key]: styles }, { respectPrefix: false, values: values !== null && values !== void 0 ? values : undefined });
});
/* Add utilities */
helpers.addUtilities(utilities(helpers), { respectPrefix: false });
/* Add variant to selected */
helpers.addVariant('selected', '&.x-selected');
};
}, () => {
return {
theme: { x: theme },
};
});
module.exports = plugin;