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 flexBasisPlugin = plugin(function ({ addBase, addUtilities }) {
let values = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100];
let flexBasisPlugin = plugin.withOptions(
function (options) {
return function ({ addUtilities }) {
let values = options?.values ?? [10, 20, 30, 40, 50, 60, 70, 80, 90, 100];
values.forEach((value) => {
addUtilities({ [`.flex-basis-${value}`]: { flexBasis: `${value}%` } });
});
});
values.forEach((value) => {
addUtilities({ [`.flex-basis-${value}`]: { flexBasis: `${value}%` } });
});
};
},
function (options) {
return {
values: options?.values ?? [],
};
}
);
module.exports = flexBasisPlugin;