From 439a862a1a0f0679038a0272bf06a9f277a50756 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Mon, 29 Jul 2024 10:42:23 +0300 Subject: [PATCH] chore(utils): apply scale to customised size --- packages/utils/src/loader/modern.ts | 7 ++++++- packages/utils/tests/iconify-icon-test.ts | 18 +++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/packages/utils/src/loader/modern.ts b/packages/utils/src/loader/modern.ts index 3da6df2..cfe9a61 100644 --- a/packages/utils/src/loader/modern.ts +++ b/packages/utils/src/loader/modern.ts @@ -1,6 +1,7 @@ import type { IconifyJSON, IconifyIcon } from '@iconify/types'; import { iconToSVG, isUnsetKeyword } from '../svg/build'; import { getIconData } from '../icon-set/get-icon'; +import { calculateSize } from '../svg/size'; import { mergeIconProps } from './utils'; import createDebugger from 'debug'; import { defaultIconCustomisations } from '../customisations/defaults'; @@ -56,7 +57,11 @@ export async function searchForIcon( if (typeof scale === 'number') { // Scale icon, unless scale is 0 if (scale) { - value = `${scale}em`; + value = calculateSize( + // Base on result from iconToSVG() or 1em + defaultValue ?? '1em', + scale + ); } } else { // Use result from iconToSVG() diff --git a/packages/utils/tests/iconify-icon-test.ts b/packages/utils/tests/iconify-icon-test.ts index def4e47..24d300e 100644 --- a/packages/utils/tests/iconify-icon-test.ts +++ b/packages/utils/tests/iconify-icon-test.ts @@ -100,7 +100,7 @@ describe('Testing loadIcon with @iconify-json/flat-color-icons>', () => { expect(result && result.includes('height="1em"')).toBeTruthy(); }); - test('loadIcon with custom width/height', async () => { + test.only('loadIcon with custom width/height', async () => { const result = await loadNodeIcon('flat-color-icons', 'up-right', { customizations: { customize(props) { @@ -115,6 +115,22 @@ describe('Testing loadIcon with @iconify-json/flat-color-icons>', () => { expect(result && result.includes('height="1em"')).toBeTruthy(); }); + test('loadIcon with custom width/height and scale', async () => { + const result = await loadNodeIcon('flat-color-icons', 'up-right', { + customizations: { + customize(props) { + props.width = '3em'; + props.height = '2em'; + return props; + }, + }, + scale: 1.5, + }); + expect(result).toBeTruthy(); + expect(result && result.includes('width="4.5em"')).toBeTruthy(); + expect(result && result.includes('height="3em"')).toBeTruthy(); + }); + test('loadIcon with 0 scale', async () => { const result = await loadNodeIcon('flat-color-icons', 'up-right', { scale: 0,