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 { defaultCustomisations as DefaultIconCustomizations, iconToSVG, getIconData, tryInstallPkg } from '@iconify/utils';
|
||||||
import createDebugger from 'debug';
|
import createDebugger from 'debug';
|
||||||
import { isPackageExists, resolveModule } from 'local-pkg';
|
import { isPackageExists, resolveModule } from 'local-pkg';
|
||||||
|
import type { FullIconCustomisations } from '@iconify/utils/lib/customisations';
|
||||||
|
|
||||||
const debug = createDebugger('@iconify-core:icon');
|
const debug = createDebugger('@iconify-core:icon');
|
||||||
const debugModern = createDebugger('@iconify-core:modern');
|
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;
|
let iconData: FullIconifyIcon | null;
|
||||||
for (const id of ids) {
|
for (const id of ids) {
|
||||||
iconData = getIconData(iconSet, id, true);
|
iconData = getIconData(iconSet, id, true);
|
||||||
if (iconData) {
|
if (iconData) {
|
||||||
debug(`${collection}:${id}`);
|
debug(`${collection}:${id}`);
|
||||||
const { attributes, body } = iconToSVG(iconData, {
|
const customizations: FullIconCustomisations = { ...DefaultIconCustomizations }
|
||||||
...DefaultIconCustomizations,
|
customize?.(customizations)
|
||||||
height: `${scale}em`,
|
const { attributes, body } = iconToSVG(iconData, customizations);
|
||||||
width: `${scale}em`,
|
|
||||||
});
|
|
||||||
return `<svg ${Object.entries(attributes).map(i => `${i[0]}="${i[1]}"`).join(' ')}>${body}</svg>`;
|
return `<svg ${Object.entries(attributes).map(i => `${i[0]}="${i[1]}"`).join(' ')}>${body}</svg>`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user