admin管理员组文章数量:1317915
I have a Avatar.svg Image which consists of following file content
<?xml version="1.0" encoding="UTF-8"?>
<svg width="32px" height="32px" viewBox="0 0 32 32" version="1.1" xmlns="" xmlns:xlink="">
<!-- Generator: sketchtool 59 (101010) - -->
<title>[email protected]</title>
<desc>Created with sketchtool.</desc>
<g id="Symbols" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="avatar">
<g id="Group-3">
<g id="Group">
<circle id="Oval" fill="#414042" cx="16" cy="16" r="16"></circle>
<text id="GT" font-family="BrandonText-BoldItalic, Brandon Text" font-size="14" font-style="italic" font-weight="bold" letter-spacing="0.7" fill="#F0F1F2">
<tspan x="6.843" y="21">My Text Here</tspan>
</text>
</g>
</g>
</g>
</g>
</svg>
In my React AvatarCircleSVG.js file I have following
import { ReactComponent as AvatarCircle } from './Avatar.svg'
const AvatarCircleSVG = () => {
return (
<AvatarCircle>
<p>IH</p>
</AvatarCircle>
)
}
export default AvatarCircleSVG
I want to show this IH
in svg tspan
circle which i'm passing in its ponent as children
I have a Avatar.svg Image which consists of following file content
<?xml version="1.0" encoding="UTF-8"?>
<svg width="32px" height="32px" viewBox="0 0 32 32" version="1.1" xmlns="http://www.w3/2000/svg" xmlns:xlink="http://www.w3/1999/xlink">
<!-- Generator: sketchtool 59 (101010) - https://sketch. -->
<title>[email protected]</title>
<desc>Created with sketchtool.</desc>
<g id="Symbols" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="avatar">
<g id="Group-3">
<g id="Group">
<circle id="Oval" fill="#414042" cx="16" cy="16" r="16"></circle>
<text id="GT" font-family="BrandonText-BoldItalic, Brandon Text" font-size="14" font-style="italic" font-weight="bold" letter-spacing="0.7" fill="#F0F1F2">
<tspan x="6.843" y="21">My Text Here</tspan>
</text>
</g>
</g>
</g>
</g>
</svg>
In my React AvatarCircleSVG.js file I have following
import { ReactComponent as AvatarCircle } from './Avatar.svg'
const AvatarCircleSVG = () => {
return (
<AvatarCircle>
<p>IH</p>
</AvatarCircle>
)
}
export default AvatarCircleSVG
I want to show this IH
in svg tspan
circle which i'm passing in its ponent as children
1 Answer
Reset to default 9You should wrap your svg
in a react ponent, then you could pass props
or child
to it.
sth like :
import React from 'react';
const AvatarSvg = props => (
<svg
width="32px"
height="32px"
viewBox="0 0 32 32"
version="1.1"
xmlns="http://www.w3/2000/svg"
xmlns:xlink="http://www.w3/1999/xlink"
>
<g
id="Symbols"
stroke="none"
strokeWidth="1"
fill="none"
fillRule="evenodd"
>
<g id="avatar">
<g id="Group-3">
<g id="Group">
<circle id="Oval" fill="#414042" cx="16" cy="16" r="16" />
<text
id="GT"
fontFamily="BrandonText-BoldItalic, Brandon Text"
fontSize="14"
fontStyle="italic"
fontWeight="bold"
letterSpacing="0.7"
fill="#F0F1F2"
>
<tspan x="6.843" y="21">
{props.name}
</tspan>
</text>
</g>
</g>
</g>
</g>
</svg>
);
export default AvatarSvg;
本文标签: javascriptpassing text as prop in SVG fileReactStack Overflow
版权声明:本文标题:javascript - passing text as prop in SVG file - React - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742025095a2415392.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论