Skip to content

Commit 7bca48f

Browse files
refactor: extract loadSvgWithFill to shared svg.utils and update icon shape and fab button components
1 parent f75e20f commit 7bca48f

4 files changed

Lines changed: 17 additions & 17 deletions

File tree

src/common/components/mock-components/front-components/icon/icon-shape.business.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,5 @@
11
import { IconSize } from '@/core/model';
22

3-
export const loadSvgWithFill = async (url: string, fillColor: string) => {
4-
const response = await fetch(url);
5-
const svgText = await response.text();
6-
7-
const modifiedSvg = svgText.replace(/fill="[^"]*"/g, `fill="${fillColor}"`);
8-
9-
const svgBlob = new Blob([modifiedSvg], { type: 'image/svg+xml' });
10-
const objectURL = URL.createObjectURL(svgBlob);
11-
12-
const img = new window.Image();
13-
img.src = objectURL;
14-
15-
return img;
16-
};
17-
183
export const returnIconSize = (iconSize: IconSize): number[] => {
194
switch (iconSize) {
205
case 'XS':

src/common/components/mock-components/front-components/icon/icon-shape.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import { useModalDialogContext } from '@/core/providers/model-dialog-providers/m
77
import { IconModal } from '@/pods/properties/components/icon-selector/modal';
88
import { useCanvasContext } from '@/core/providers';
99
import { useGroupShapeProps } from '../../mock-components.utils';
10-
import { loadSvgWithFill, returnIconSize } from './icon-shape.business';
10+
import { returnIconSize } from './icon-shape.business';
11+
import { loadSvgWithFill } from '@/common/utils/svg.utils';
1112

1213
const iconShapeRestrictions: ShapeSizeRestrictions = {
1314
minWidth: 25,

src/common/components/mock-components/front-rich-components/fab-button/fab-button.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import { fitSizeToShapeSizeRestrictions } from '@/common/utils/shapes';
66
import { useShapeProps } from '@/common/components/shapes/use-shape-props.hook';
77
import { useGroupShapeProps } from '../../mock-components.utils';
88
import { BASIC_SHAPE } from '../../front-components/shape.const';
9-
import { loadSvgWithFill } from '../../front-components/icon/icon-shape.business';
109
import { IconModal } from '@/pods/properties/components/icon-selector/modal';
1110
import { useModalDialogContext } from '@/core/providers/model-dialog-providers/model-dialog.provider';
1211
import { useCanvasContext } from '@/core/providers';
12+
import { loadSvgWithFill } from '@/common/utils/svg.utils';
1313

1414
const fabButtonShapeRestrictions: ShapeSizeRestrictions = {
1515
minWidth: 25,

src/common/utils/svg.utils.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export const loadSvgWithFill = async (url: string, fillColor: string) => {
2+
const response = await fetch(url);
3+
const svgText = await response.text();
4+
5+
const modifiedSvg = svgText.replace(/fill="[^"]*"/g, `fill="${fillColor}"`);
6+
7+
const svgBlob = new Blob([modifiedSvg], { type: 'image/svg+xml' });
8+
const objectURL = URL.createObjectURL(svgBlob);
9+
10+
const img = new window.Image();
11+
img.src = objectURL;
12+
13+
return img;
14+
};

0 commit comments

Comments
 (0)