mirror of
https://github.com/iconify/iconify.git
synced 2025-01-06 07:20:40 +00:00
Web component: fix custom dimensions when rendering span
This commit is contained in:
parent
1c980b75a8
commit
1c17fa6e42
@ -30,6 +30,13 @@ for (const prefix in propsToAddTo) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fix size: add 'px' to numbers
|
||||
*/
|
||||
function fixSize(value: string): string {
|
||||
return value + (value.match(/^[-0-9.]+$/) ? 'px' : '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Render node as <span>
|
||||
*/
|
||||
@ -60,8 +67,8 @@ export function renderSPAN(
|
||||
const svgStyle = node.style;
|
||||
const styles: Record<string, string> = {
|
||||
'--svg': url,
|
||||
'width': renderAttribs.width,
|
||||
'height': renderAttribs.height,
|
||||
'width': fixSize(renderAttribs.width),
|
||||
'height': fixSize(renderAttribs.height),
|
||||
...(useMask ? monotoneProps : coloredProps),
|
||||
};
|
||||
|
||||
|
@ -119,7 +119,7 @@ describe('Testing rendering loaded icon', () => {
|
||||
|
||||
// Test HTML
|
||||
expect(node.innerHTML).toBe(
|
||||
`<style>${expectedInline}</style><span style="--svg: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cg /%3E%3C/svg%3E"); background-color: transparent; background-repeat: no-repeat; background-size: 100% 100%;"></span>`
|
||||
`<style>${expectedInline}</style><span style="--svg: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cg /%3E%3C/svg%3E"); width: 24px; height: 24px; background-color: transparent; background-repeat: no-repeat; background-size: 100% 100%;"></span>`
|
||||
);
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user