Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Children prop for SVG components #975

Open
romulof opened this issue Sep 23, 2024 · 0 comments
Open

Children prop for SVG components #975

romulof opened this issue Sep 23, 2024 · 0 comments

Comments

@romulof
Copy link

romulof commented Sep 23, 2024

🚀 Feature Proposal

When converting an SVG into a React component, allow children props so we can inject nodes into the rendered SVG element.

Motivation

Check the example bellow:

Example

Lets say I have an SVG with some <symbol> elements:

<svg xmlns="http://www.w3.org/2000/svg">
  <symbol id="foo"><text>foo</text></symbol>
  <symbol id="bar"><text>bar</text></symbol>
</svg>

Then I would be able to use like this:

import SvgSymbols from './symbols.svg';

export function Foo() {
  return (
    <SvgSymbols>
      <use xlinkHref="#foo" />
    </SvgSymbols>
  );
}

export function Bar() {
  return (
    <SvgSymbols>
      <use xlinkHref="#bar" />
    </SvgSymbols>
  );
}

Pitch

Why does this feature belong in the SVGR ecosystem?

It allows some level of customization on top of the static SVG component.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant