question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Wrapping container for SVG

See original GitHub issue

Thanks in advance on this. I am trying to add a container around the exported SVG. In this case a <div>. So what is returned would look like this:

<div>
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" {...props}>
         .......
    </svg>
</div>

I am following the example under Custom Templates and looked through the issues and found this solution thinking it would work. Cannot use JSX in custom template

function template({ template }, opts, { imports, componentName, props, jsx, exports }) {
  const jsxTemplate = template.smart({ plugins: ['jsx'] });
  return jsxTemplate.ast`${imports}
  const ${componentName} = (${props}) => <div>{${jsx}}</div>
  ${exports}
`;
}

module.exports = template;

But I end up with

<div>
    {
        <svg>

Is there a way to prepend and append content before the ${jsx} is returned?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
bkilraincommented, Jun 7, 2021

I’m also experiencing this problem. If @gregberge 's suggested fix here doesn’t work, can this ticket be reclassified as a bug?

0reactions
stale[bot]commented, Aug 7, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

resize svg wrapped in div that is wrapped in div - Stack Overflow
I was using nested SVGs before and now I'm told I have to use nested divs with inline SVG. Basically, I need the...
Read more >
SVG ONLY Parchment Paper Plastic Wrap and Aluminum Foil ...
This is my own design for an organizer to hold my parchment paper, plastic wrap and aluminum foil rolls. It can be wall...
Read more >
How to make an svg scale with its parent container
The <svg> element wraps the rectangle image. The SVG element occupies 100% width of the parent container and its height is auto-adjusted ...
Read more >
32 SVG Bags,Boxes,Containers,3D etc ideas - Pinterest
Jul 13, 2015 - Explore Pat Root's board "SVG Bags,Boxes,Containers,3D etc", followed by 523 people on Pinterest. See more ideas about box template,...
Read more >
Resizing an SVG When the Window is Resized in d3.js - Chartio
The browser doesn't inherently associate a width or height with an SVG unless you ... The SVG object needs to be wrapped in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found