refactor: flex basis plugin with options

This commit is contained in:
Oliver Davies 2022-09-09 18:00:00 +01:00
parent 317e1c10b7
commit 649fce7b67

View file

@ -1,11 +1,21 @@
let plugin = require("tailwindcss/plugin"); let plugin = require("tailwindcss/plugin");
let flexBasisPlugin = plugin(function ({ addBase, addUtilities }) { let flexBasisPlugin = plugin.withOptions(
let values = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]; function (options) {
return function ({ addUtilities }) {
let values = options?.values ?? [10, 20, 30, 40, 50, 60, 70, 80, 90, 100];
values.forEach((value) => { values.forEach((value) => {
addUtilities({ [`.flex-basis-${value}`]: { flexBasis: `${value}%` } }); addUtilities({ [`.flex-basis-${value}`]: { flexBasis: `${value}%` } });
}); });
}); };
},
function (options) {
return {
values: options?.values ?? [],
};
}
);
module.exports = flexBasisPlugin; module.exports = flexBasisPlugin;