mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-02-25 01:08:50 +01:00
Test memoize svg icon
This commit is contained in:
parent
1adcca5666
commit
92c0a8b4f0
1 changed files with 42 additions and 10 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
import moize from 'moize';
|
||||||
import { useEffect, useRef, useState } from 'preact/hooks';
|
import { useEffect, useRef, useState } from 'preact/hooks';
|
||||||
|
|
||||||
const SIZES = {
|
const SIZES = {
|
||||||
|
@ -110,6 +111,29 @@ export const ICONS = {
|
||||||
|
|
||||||
const ICONDATA = {};
|
const ICONDATA = {};
|
||||||
|
|
||||||
|
// Memoize the dangerouslySetInnerHTML of the SVGs
|
||||||
|
const SVGICon = moize(
|
||||||
|
function ({ size, width, height, body, rotate, flip }) {
|
||||||
|
return (
|
||||||
|
<svg
|
||||||
|
width={size}
|
||||||
|
height={size}
|
||||||
|
viewBox={`0 0 ${width} ${height}`}
|
||||||
|
dangerouslySetInnerHTML={{ __html: body }}
|
||||||
|
style={{
|
||||||
|
transform: `${rotate ? `rotate(${rotate})` : ''} ${
|
||||||
|
flip ? `scaleX(-1)` : ''
|
||||||
|
}`,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
{
|
||||||
|
isShallowEqual: true,
|
||||||
|
maxSize: Object.keys(ICONS).length,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
function Icon({
|
function Icon({
|
||||||
icon,
|
icon,
|
||||||
size = 'm',
|
size = 'm',
|
||||||
|
@ -150,16 +174,24 @@ function Icon({
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{iconData && (
|
{iconData && (
|
||||||
<svg
|
// <svg
|
||||||
width={iconSize}
|
// width={iconSize}
|
||||||
height={iconSize}
|
// height={iconSize}
|
||||||
viewBox={`0 0 ${iconData.width} ${iconData.height}`}
|
// viewBox={`0 0 ${iconData.width} ${iconData.height}`}
|
||||||
dangerouslySetInnerHTML={{ __html: iconData.body }}
|
// dangerouslySetInnerHTML={{ __html: iconData.body }}
|
||||||
style={{
|
// style={{
|
||||||
transform: `${rotate ? `rotate(${rotate})` : ''} ${
|
// transform: `${rotate ? `rotate(${rotate})` : ''} ${
|
||||||
flip ? `scaleX(-1)` : ''
|
// flip ? `scaleX(-1)` : ''
|
||||||
}`,
|
// }`,
|
||||||
}}
|
// }}
|
||||||
|
// />
|
||||||
|
<SVGICon
|
||||||
|
size={iconSize}
|
||||||
|
width={iconData.width}
|
||||||
|
height={iconData.height}
|
||||||
|
body={iconData.body}
|
||||||
|
rotate={rotate}
|
||||||
|
flip={flip}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</span>
|
</span>
|
||||||
|
|
Loading…
Reference in a new issue