2
0
mirror of https://github.com/iconify/iconify.git synced 2025-01-06 07:20:40 +00:00

feat: provide collection and icon names to transform customization

This commit is contained in:
Joaquín Sánchez Jiménez 2022-03-24 21:16:13 +01:00
parent 877d84eebc
commit 36af258071
5 changed files with 18 additions and 10 deletions

View File

@ -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)

View File

@ -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<string>;
transform?: (
svg: string,
collection: string,
icon: string
) => Awaitable<string>;
/**
* Change default icon customizations values.
*

View File

@ -44,8 +44,8 @@ describe('Testing getCustomIcon', () => {
width: '4em',
height: '4em',
},
transform(icon) {
return icon.replace(
transform(svg) {
return svg.replace(
'<svg ',
'<svg width="1em" height="1em" '
);

View File

@ -46,8 +46,8 @@ describe('Testing loadIcon with @iconify-json/flat-color-icons>', () => {
class: 'clazz2',
},
// it will never be called, it is not a custom icon
transform(icon) {
return icon.replace(
transform(svg) {
return svg.replace(
'<svg ',
'<svg width="4em" height="4em" '
);
@ -72,8 +72,8 @@ describe('Testing loadIcon with @iconify-json/flat-color-icons>', () => {
class: 'clazz2',
},
// it will never be called, it is not a custom icon
transform(icon) {
return icon.replace(
transform(svg) {
return svg.replace(
'<svg ',
'<svg width="4em" height="4em" '
);

View File

@ -48,8 +48,8 @@ describe('Testing loadIcon', () => {
},
},
customizations: {
transform(icon) {
return icon.replace(
transform(svg) {
return svg.replace(
'<svg ',
'<svg width="1em" height="1em" '
);