Socket
Socket
Sign inDemoInstall

babel-plugin-transform-react-styled-components-qa

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-transform-react-styled-components-qa

Add data-qa property to styled-components via .attrs using the component name


Version published
Weekly downloads
8.4K
increased by23.48%
Maintainers
1
Weekly downloads
 
Created

Readme

Source

babel-plugin-transform-react-styled-components-qa

This plugin adds data-qa props to styled-component using .attrs.

This plugin can be used with babel-plugin-transform-react-qa-classes to provide support for both styled-components and React components.

Standard HTML Tags

In

const Component = styled.p`
    color: red;
`

Out

const Component = styled.p.attrs({
    "data-qa": "Component"
})`
    color: red;
`

Computed Property is also supported

In

const tagName = 'h1'
const Component = styled[tagName]`
    background: 'pink';
`

Out

const tagName = 'h1'
const Component = styled[tagName].attrs({
    "data-qa": "Component"
})`
    background: 'pink';
`

data-qa is append after other attributes defined by users

In

const PasswordInput = styled.input.attrs({
    type: 'password'
})`
    font-size: 14px;
    line-height: 2em;
`

Out

const PasswordInput = styled.input.attrs({
    type: 'password',
    "data-qa": "PasswordInput"
})`
    font-size: 14px;
    line-height: 2em;
`

Usage

This plugin is intended to be use in pre-production environment.
Using this plugin with SSR could result in larger payload due to the extra attribute.

.babelrc
{
    "env": {
        "dev": {
            plugins: [
                ["transform-react-styled-components-qa", {
                    "attribute": "data-qa",
                    "format": "kebab"
                }]
            ]
        }
    }
}

Options

attribute : (string)

The attribute name to be used instead of data-qa.

format : (string)

Support values: kebab, camel, snake, pascal
Default value: kebab

Keywords

FAQs

Package last updated on 02 Sep 2021

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc