2
0
mirror of https://github.com/iconify/iconify.git synced 2025-01-10 08:34:04 +00:00
iconify/plugins/tailwind/src/plugin.ts

38 lines
952 B
TypeScript
Raw Normal View History

2023-01-11 15:42:21 +00:00
import plugin from 'tailwindcss/plugin';
import { getCSSRulesForIcons } from './clean';
import { getDynamicCSSRules } from './dynamic';
import type {
CleanIconifyPluginOptions,
DynamicIconifyPluginOptions,
} from './options';
2023-01-11 15:42:21 +00:00
/**
* Generate styles for dynamic selector: class="icon-[mdi-light--home]"
2023-01-11 15:42:21 +00:00
*/
export function addDynamicIconSelectors(options?: DynamicIconifyPluginOptions) {
const prefix = options?.prefix || 'icon';
return plugin(({ matchComponents }) => {
matchComponents({
[prefix]: (icon: string) => getDynamicCSSRules(icon, options),
});
});
}
/**
* Generate styles for preset list of icons
*/
export function addCleanIconSelectors(
icons: string[] | string,
options?: CleanIconifyPluginOptions
2023-01-11 15:42:21 +00:00
) {
const rules = getCSSRulesForIcons(icons, options);
return plugin(({ addUtilities }) => {
addUtilities(rules);
2023-01-11 15:42:21 +00:00
});
}
/**
* Export types
2023-01-11 15:42:21 +00:00
*/
export type { CleanIconifyPluginOptions, DynamicIconifyPluginOptions };