mirror of
https://github.com/iconify/iconify.git
synced 2025-01-08 15:54:09 +00:00
feat: provide collection and icon names to transform
customization
This commit is contained in:
parent
877d84eebc
commit
36af258071
@ -38,7 +38,9 @@ export async function getCustomIcon(
|
|||||||
}
|
}
|
||||||
const { transform } = options?.customizations ?? {};
|
const { transform } = options?.customizations ?? {};
|
||||||
result =
|
result =
|
||||||
typeof transform === 'function' ? await transform(result) : result;
|
typeof transform === 'function'
|
||||||
|
? await transform(result, collection, icon)
|
||||||
|
: result;
|
||||||
return await mergeIconProps(
|
return await mergeIconProps(
|
||||||
options?.customizations?.trimCustomSvg === true
|
options?.customizations?.trimCustomSvg === true
|
||||||
? trimSVG(result)
|
? trimSVG(result)
|
||||||
|
@ -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`.
|
* **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 svg The loaded `svg`
|
||||||
|
* @param collection The name of the collection
|
||||||
|
* @param icon The name of the icon
|
||||||
* @return The transformed `svg`.
|
* @return The transformed `svg`.
|
||||||
*/
|
*/
|
||||||
transform?: (svg: string) => Awaitable<string>;
|
transform?: (
|
||||||
|
svg: string,
|
||||||
|
collection: string,
|
||||||
|
icon: string
|
||||||
|
) => Awaitable<string>;
|
||||||
/**
|
/**
|
||||||
* Change default icon customizations values.
|
* Change default icon customizations values.
|
||||||
*
|
*
|
||||||
|
@ -44,8 +44,8 @@ describe('Testing getCustomIcon', () => {
|
|||||||
width: '4em',
|
width: '4em',
|
||||||
height: '4em',
|
height: '4em',
|
||||||
},
|
},
|
||||||
transform(icon) {
|
transform(svg) {
|
||||||
return icon.replace(
|
return svg.replace(
|
||||||
'<svg ',
|
'<svg ',
|
||||||
'<svg width="1em" height="1em" '
|
'<svg width="1em" height="1em" '
|
||||||
);
|
);
|
||||||
|
@ -46,8 +46,8 @@ describe('Testing loadIcon with @iconify-json/flat-color-icons>', () => {
|
|||||||
class: 'clazz2',
|
class: 'clazz2',
|
||||||
},
|
},
|
||||||
// it will never be called, it is not a custom icon
|
// it will never be called, it is not a custom icon
|
||||||
transform(icon) {
|
transform(svg) {
|
||||||
return icon.replace(
|
return svg.replace(
|
||||||
'<svg ',
|
'<svg ',
|
||||||
'<svg width="4em" height="4em" '
|
'<svg width="4em" height="4em" '
|
||||||
);
|
);
|
||||||
@ -72,8 +72,8 @@ describe('Testing loadIcon with @iconify-json/flat-color-icons>', () => {
|
|||||||
class: 'clazz2',
|
class: 'clazz2',
|
||||||
},
|
},
|
||||||
// it will never be called, it is not a custom icon
|
// it will never be called, it is not a custom icon
|
||||||
transform(icon) {
|
transform(svg) {
|
||||||
return icon.replace(
|
return svg.replace(
|
||||||
'<svg ',
|
'<svg ',
|
||||||
'<svg width="4em" height="4em" '
|
'<svg width="4em" height="4em" '
|
||||||
);
|
);
|
||||||
|
@ -48,8 +48,8 @@ describe('Testing loadIcon', () => {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
customizations: {
|
customizations: {
|
||||||
transform(icon) {
|
transform(svg) {
|
||||||
return icon.replace(
|
return svg.replace(
|
||||||
'<svg ',
|
'<svg ',
|
||||||
'<svg width="1em" height="1em" '
|
'<svg width="1em" height="1em" '
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user