
Security News
Open Source Maintainers Feeling the Weight of the EU’s Cyber Resilience Act
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.
react-svgmt
Advanced tools
react-svgmt (SVG Management Tools for React)
npm install react-svgmt@latest
Import the SvgLoader
and SvgProxy
elements
import { SvgLoader, SvgProxy } from 'react-svgmt';
Example: Create a list CSS selectors and update each one
function App() {
//We want to update only elements that match this selectors
const selectors = ["rect:nth-child(1)", "rect:nth-child(4)"];
return (
<div className="App">
<SvgLoader width="100" height="100" path="/sample1.svg">
<SvgProxy selector="rect" fill="red" />
{selectors.map((selector, ix) => (
<SvgProxy key={ix} selector={selector} fill="blue" />
))}
</SvgLoader>
</div>
);
}
If the path
prop is used, then the asset will be fetched from the url.
<SvgLoader path="svg public url here">
<SvgProxy selector="#Star" stroke={this.state.strokeColor} />
</SvgLoader>
There are two ways to load an SVG file:
path
prop)svgXML
prop)More features, API and examples see https://hugozap.github.io/react-svgmt
This library doesn't store previous elements state. Say you want to update some elements fill color and then change the selector to update another set of elements.
Don't expect the original element attributes to be reset back to their original state. You need to add a "reset" SvgProxy so all elements attributes are reseted before the additional SvgProxies are processed.
Check this CodeSandbox for an example.
This project is sponsored by Diagram.codes Studio
Author:
Special thanks (for contributing to the first version of this library) to:
The ajax loading bits are based on:
FAQs
Convenient SVG loading and manipulation from react
The npm package react-svgmt receives a total of 5,307 weekly downloads. As such, react-svgmt popularity was classified as popular.
We found that react-svgmt demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.