Skip to content

Commit 892eb99

Browse files
authored
fix: web svg icon path css and div alignment (#2953)
1 parent 4024d1b commit 892eb99

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/components/svgImage/index.web.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ export interface SvgImageProps {
1919
}
2020

2121
function SvgImage(props: SvgImageProps) {
22-
const {data, style = [], tintColor, width, height, ...others} = props;
23-
const [className] = useState(`svg-${new Date().getTime().toString()}`);
22+
const {id, data, style = [], tintColor, width, height, ...others} = props;
23+
const [className] = useState(`svg-${id ? id : new Date().getTime().toString()}`);
2424
const [svgStyleCss, setSvgStyleCss] = useState<string | undefined>(undefined);
2525

2626
useEffect(() => {
@@ -30,8 +30,8 @@ function SvgImage(props: SvgImageProps) {
3030
postcss()
3131
.process({width, height, ...styleObj}, {parser: cssjs})
3232
.then((style: {css: any}) => {
33-
const svgPathCss = styleObj?.tintColor ? `.${className} > svg path {fill: ${styleObj?.tintColor}}` : '';
34-
setSvgStyleCss(`.${className} > svg {${style.css}} ${svgPathCss}}`);
33+
const svgPathCss = styleObj?.tintColor ? `path {fill: ${styleObj?.tintColor}}` : '';
34+
setSvgStyleCss(`.${className} > svg {${style.css}; ${svgPathCss}}`);
3535
});
3636
}
3737
}, [style, className, width, height]);
@@ -54,8 +54,12 @@ function SvgImage(props: SvgImageProps) {
5454
} else if (data && svgStyleCss) {
5555
const svgStyleTag = `<style> ${svgStyleCss} </style>`;
5656
return (
57-
<div
58-
{...others}
57+
<div
58+
style={{
59+
display: 'flex',
60+
justifyContent: 'center',
61+
flexShrink: 0
62+
}}
5963
className={className}
6064
// eslint-disable-next-line react/no-danger
6165
dangerouslySetInnerHTML={{__html: svgStyleTag + data}}

0 commit comments

Comments
 (0)