From e5a8e3a5e16e806e0caab03119697daf7222333a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaqu=C3=ADn=20S=C3=A1nchez=20Jim=C3=A9nez?= Date: Sat, 11 Dec 2021 23:55:47 +0100 Subject: [PATCH] chore: add `customize` callback on `searchForIcon` --- packages/core/src/modern/index.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/core/src/modern/index.ts b/packages/core/src/modern/index.ts index 45f1727..2c7c519 100644 --- a/packages/core/src/modern/index.ts +++ b/packages/core/src/modern/index.ts @@ -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 ` `${i[0]}="${i[1]}"`).join(' ')}>${body}`; } }