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:
parent
84b4fab85f
commit
439a862a1a
@ -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()
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user