From 36af2580711f42f3b95257a147a92283e303addf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaqu=C3=ADn=20S=C3=A1nchez=20Jim=C3=A9nez?= Date: Thu, 24 Mar 2022 21:16:13 +0100 Subject: [PATCH] feat: provide collection and icon names to `transform` customization --- packages/utils/src/loader/custom.ts | 4 +++- packages/utils/src/loader/types.ts | 8 +++++++- packages/utils/tests/get-custom-icon-test.ts | 4 ++-- packages/utils/tests/iconify-icon-test.ts | 8 ++++---- packages/utils/tests/load-icon-test.ts | 4 ++-- 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/packages/utils/src/loader/custom.ts b/packages/utils/src/loader/custom.ts index 1cec45f..3ace3d1 100644 --- a/packages/utils/src/loader/custom.ts +++ b/packages/utils/src/loader/custom.ts @@ -38,7 +38,9 @@ export async function getCustomIcon( } const { transform } = options?.customizations ?? {}; result = - typeof transform === 'function' ? await transform(result) : result; + typeof transform === 'function' + ? await transform(result, collection, icon) + : result; return await mergeIconProps( options?.customizations?.trimCustomSvg === true ? trimSVG(result) diff --git a/packages/utils/src/loader/types.ts b/packages/utils/src/loader/types.ts index 8d5c51e..ad7e92a 100644 --- a/packages/utils/src/loader/types.ts +++ b/packages/utils/src/loader/types.ts @@ -42,9 +42,15 @@ export type IconCustomizations = { * **WARNING**: `transform` will be only applied when using `custom` icon collection: it will be applied only when using `getCustomIcon` and excluded when using `searchForIcon`. * * @param svg The loaded `svg` + * @param collection The name of the collection + * @param icon The name of the icon * @return The transformed `svg`. */ - transform?: (svg: string) => Awaitable; + transform?: ( + svg: string, + collection: string, + icon: string + ) => Awaitable; /** * Change default icon customizations values. * diff --git a/packages/utils/tests/get-custom-icon-test.ts b/packages/utils/tests/get-custom-icon-test.ts index b5fafd1..5c6de76 100644 --- a/packages/utils/tests/get-custom-icon-test.ts +++ b/packages/utils/tests/get-custom-icon-test.ts @@ -44,8 +44,8 @@ describe('Testing getCustomIcon', () => { width: '4em', height: '4em', }, - transform(icon) { - return icon.replace( + transform(svg) { + return svg.replace( '', () => { class: 'clazz2', }, // it will never be called, it is not a custom icon - transform(icon) { - return icon.replace( + transform(svg) { + return svg.replace( '', () => { class: 'clazz2', }, // it will never be called, it is not a custom icon - transform(icon) { - return icon.replace( + transform(svg) { + return svg.replace( ' { }, }, customizations: { - transform(icon) { - return icon.replace( + transform(svg) { + return svg.replace( '