mirror of
https://github.com/iconify/iconify.git
synced 2024-12-13 14:13:06 +00:00
chore: add customize
callback on searchForIcon
This commit is contained in:
parent
def0990a64
commit
5cab683047
@ -4,6 +4,7 @@ import type { FullIconifyIcon } from '@iconify/utils/lib/icon';
|
||||
import { defaultCustomisations as DefaultIconCustomizations, iconToSVG, getIconData, tryInstallPkg } from '@iconify/utils';
|
||||
import createDebugger from 'debug';
|
||||
import { isPackageExists, resolveModule } from 'local-pkg';
|
||||
import type { FullIconCustomisations } from '@iconify/utils/lib/customisations';
|
||||
|
||||
const debug = createDebugger('@iconify-core:icon');
|
||||
const debugModern = createDebugger('@iconify-core:modern');
|
||||
@ -53,17 +54,15 @@ export async function loadCollection(name: string, autoInstall = false): Promise
|
||||
}
|
||||
}
|
||||
|
||||
export function searchForIcon(iconSet: IconifyJSON, collection: string, ids: string[], scale = 1): string | null {
|
||||
export function searchForIcon(iconSet: IconifyJSON, collection: string, ids: string[], customize?: (defaults: FullIconCustomisations) => void): string | null {
|
||||
let iconData: FullIconifyIcon | null;
|
||||
for (const id of ids) {
|
||||
iconData = getIconData(iconSet, id, true);
|
||||
if (iconData) {
|
||||
debug(`${collection}:${id}`);
|
||||
const { attributes, body } = iconToSVG(iconData, {
|
||||
...DefaultIconCustomizations,
|
||||
height: `${scale}em`,
|
||||
width: `${scale}em`,
|
||||
});
|
||||
const customizations: FullIconCustomisations = { ...DefaultIconCustomizations }
|
||||
customize?.(customizations)
|
||||
const { attributes, body } = iconToSVG(iconData, customizations);
|
||||
return `<svg ${Object.entries(attributes).map(i => `${i[0]}="${i[1]}"`).join(' ')}>${body}</svg>`;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user