Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@svgr/babel-plugin-add-jsx-attribute

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@svgr/babel-plugin-add-jsx-attribute

Add JSX attribute

  • 6.5.1
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is @svgr/babel-plugin-add-jsx-attribute?

@svgr/babel-plugin-add-jsx-attribute is a Babel plugin designed to add specific JSX attributes to SVG elements. This is particularly useful when working with SVGs in React projects, as it allows for the automatic addition of attributes like className, style, or any other custom attribute to SVG elements during the build process.

What are @svgr/babel-plugin-add-jsx-attribute's main functionalities?

Add Static Attribute

This feature allows you to add a static attribute to specified SVG elements. In this example, a className attribute with the value 'my-svg-class' is added to all <svg> elements.

module.exports = {
  plugins: [
    [
      '@svgr/babel-plugin-add-jsx-attribute',
      {
        elements: ['svg'],
        attributes: [{ name: 'className', value: 'my-svg-class' }]
      }
    ]
  ]
};

Add Dynamic Attribute

This feature allows you to add dynamic attributes to specified SVG elements. In this example, a data-id attribute with a dynamic value '{id}' is added to all <svg> elements.

module.exports = {
  plugins: [
    [
      '@svgr/babel-plugin-add-jsx-attribute',
      {
        elements: ['svg'],
        attributes: [{ name: 'data-id', value: '{id}' }]
      }
    ]
  ]
};

Add Multiple Attributes

This feature allows you to add multiple attributes to specified SVG elements. In this example, both className and role attributes are added to all <svg> elements.

module.exports = {
  plugins: [
    [
      '@svgr/babel-plugin-add-jsx-attribute',
      {
        elements: ['svg'],
        attributes: [
          { name: 'className', value: 'my-svg-class' },
          { name: 'role', value: 'img' }
        ]
      }
    ]
  ]
};

Other packages similar to @svgr/babel-plugin-add-jsx-attribute

Keywords

FAQs

Package last updated on 27 Oct 2022

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc