2
0
mirror of https://github.com/iconify/iconify.git synced 2024-12-12 13:47:49 +00:00

chore(utils): apply scale to customised size

This commit is contained in:
Vjacheslav Trushkin 2024-07-29 10:42:23 +03:00
parent 84b4fab85f
commit 439a862a1a
2 changed files with 23 additions and 2 deletions

View File

@ -1,6 +1,7 @@
import type { IconifyJSON, IconifyIcon } from '@iconify/types'; import type { IconifyJSON, IconifyIcon } from '@iconify/types';
import { iconToSVG, isUnsetKeyword } from '../svg/build'; import { iconToSVG, isUnsetKeyword } from '../svg/build';
import { getIconData } from '../icon-set/get-icon'; import { getIconData } from '../icon-set/get-icon';
import { calculateSize } from '../svg/size';
import { mergeIconProps } from './utils'; import { mergeIconProps } from './utils';
import createDebugger from 'debug'; import createDebugger from 'debug';
import { defaultIconCustomisations } from '../customisations/defaults'; import { defaultIconCustomisations } from '../customisations/defaults';
@ -56,7 +57,11 @@ export async function searchForIcon(
if (typeof scale === 'number') { if (typeof scale === 'number') {
// Scale icon, unless scale is 0 // Scale icon, unless scale is 0
if (scale) { if (scale) {
value = `${scale}em`; value = calculateSize(
// Base on result from iconToSVG() or 1em
defaultValue ?? '1em',
scale
);
} }
} else { } else {
// Use result from iconToSVG() // Use result from iconToSVG()

View File

@ -100,7 +100,7 @@ describe('Testing loadIcon with @iconify-json/flat-color-icons>', () => {
expect(result && result.includes('height="1em"')).toBeTruthy(); 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', { const result = await loadNodeIcon('flat-color-icons', 'up-right', {
customizations: { customizations: {
customize(props) { customize(props) {
@ -115,6 +115,22 @@ describe('Testing loadIcon with @iconify-json/flat-color-icons>', () => {
expect(result && result.includes('height="1em"')).toBeTruthy(); 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 () => { test('loadIcon with 0 scale', async () => {
const result = await loadNodeIcon('flat-color-icons', 'up-right', { const result = await loadNodeIcon('flat-color-icons', 'up-right', {
scale: 0, scale: 0,