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

babel-plugin-styled-components-attr

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-styled-components-attr

CSS attr function in your styled components

  • 0.0.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6
increased by100%
Maintainers
1
Weekly downloads
 
Created
Source

babel-plugin-styled-components-attr

use the CSS attr function in your styled-components code.

npm version Build Status codecov

const Input = styled.input`
  color: attr(color);
  width: attr(width %);
  margin: attr(margin px, 16);
`

Install

npm install -S babel-plugin-styled-components-attr

.babelrc

{
  "plugins": [
    "styled-components-attr"
  ]
}
attr

The attr CSS function is supported in a basic capacity. I will be adding more features, but PRs are welcome.

/* get value from `width` prop */
width: attr(width vw);

/* specify type or unit to apply to value */
width: attr(width vw);

/* fallback value if props.width is falsey */
width: attr(width vw, 50);
const H1 = styled.h1`
  font-size: attr(fontSize px);
  margin: attr(margin rem, 4);
  font-family: sans-serif;
  color: ${colors.pink[5]};
  @media (min-width: 680px) {
    color: attr(desktopColor);
  }
`

const Title = ({ title, scale }) => {
  return (
    <H1 fontSize={16 * scale} desktopColor={colors.gray[5]}>
      {title}
    </H1>
  )
}
Value types

checked is supported

  • em
  • ex
  • px
  • rem
  • vw
  • vh
  • vmin
  • vmax
  • mm
  • cm
  • in
  • pt
  • pc
  • %
  • string
  • color
  • url
  • integer
  • number
  • length
  • deg
  • grad
  • rad
  • time
  • s
  • ms
  • frequency
  • Hz
  • kHz

Keywords

FAQs

Package last updated on 13 Jun 2017

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