2
0
mirror of https://github.com/iconify/iconify.git synced 2024-11-16 09:37:09 +00:00

chore(tailwind): allow scale 0 in plugin

This commit is contained in:
Vjacheslav Trushkin 2024-05-10 15:20:32 +03:00
parent f6eb380836
commit dde22dea42
3 changed files with 42 additions and 17 deletions

View File

@ -32,6 +32,12 @@
></span> ></span>
</span> </span>
</p> </p>
<p>
Using width/height to resize icon:
<span
class="iconify-nosize mdi-light--home h-12 w-12 text-blue-600"
></span>
</p>
</section> </section>
<section class="mb-2"> <section class="mb-2">
<h1 class="text-2xl">Dynamic selectors plugin, custom options</h1> <h1 class="text-2xl">Dynamic selectors plugin, custom options</h1>
@ -98,7 +104,9 @@
</p> </p>
<p> <p>
Custom size set via width/height: Custom size set via width/height:
<span class="h-12 w-12 scaled-icon-[mdi-light--forum]"></span> <span
class="h-12 w-12 scaled-icon-[mdi-light--forum] text-red-600"
></span>
</p> </p>
</section> </section>
</body> </body>

View File

@ -84,6 +84,14 @@ module.exports = {
}, },
], ],
}), }),
// Main plugin, no size
addIconSelectors({
maskSelector: '.iconify-nosize',
backgroundSelector: '',
scale: 0,
// Empty prefixes list: reusing data from plugin above
prefixes: [],
}),
// Plugin with clean selectors: requires writing all used icons in first parameter // Plugin with clean selectors: requires writing all used icons in first parameter
addCleanIconSelectors(['mdi-light:home']), addCleanIconSelectors(['mdi-light:home']),
// Plugin with dynamic selectors // Plugin with dynamic selectors

View File

@ -29,12 +29,19 @@ export function getCSSRulesForPlugin(options: IconifyPluginOptions) {
const varName = fullOptions.varName || 'svg'; const varName = fullOptions.varName || 'svg';
// Scale icons // Scale icons
const overrideRules: Record<string, string> = fullOptions.scale const scale = fullOptions.scale ?? 1;
? { const adjustScale = (obj: Record<string, string>) => {
width: fullOptions.scale + 'em', if (!scale) {
height: fullOptions.scale + 'em', // Delete width and height
} delete obj['width'];
: {}; delete obj['height'];
} else if (scale !== 1) {
// Set custom width and height
obj['width'] = scale + 'em';
obj['height'] = scale + 'em';
}
return obj;
};
// Add common rules // Add common rules
const maskSelector = fullOptions.maskSelector ?? '.iconify'; const maskSelector = fullOptions.maskSelector ?? '.iconify';
@ -42,21 +49,23 @@ export function getCSSRulesForPlugin(options: IconifyPluginOptions) {
fullOptions.backgroundSelector ?? '.iconify-color'; fullOptions.backgroundSelector ?? '.iconify-color';
if (maskSelector) { if (maskSelector) {
rules[maskSelector] = Object.assign( rules[maskSelector] = Object.assign(
getCommonCSSRules({ adjustScale(
mode: 'mask', getCommonCSSRules({
varName, mode: 'mask',
}), varName,
overrideRules, })
),
fullOptions.extraMaskRules || {} fullOptions.extraMaskRules || {}
); );
} }
if (backgroundSelector) { if (backgroundSelector) {
rules[backgroundSelector] = Object.assign( rules[backgroundSelector] = Object.assign(
getCommonCSSRules({ adjustScale(
mode: 'background', getCommonCSSRules({
varName, mode: 'background',
}), varName,
overrideRules, })
),
fullOptions.extraBackgroundRules || {} fullOptions.extraBackgroundRules || {}
); );
} }