Socket
Socket
Sign inDemoInstall

@unocss/transformer-attributify-jsx-babel

Package Overview
Dependencies
Maintainers
1
Versions
87
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@unocss/transformer-attributify-jsx-babel

Support valueless attributify in JSX/TSX.


Version published
Weekly downloads
159K
decreased by-6.31%
Maintainers
1
Weekly downloads
 
Created
Source

@unocss/transformer-attributify-jsx-babel

Support valueless attributify in JSX/TSX.

export function Component() {
  return (
    <div text-red text-center text-5xl animate-bounce>
      unocss
    </div>
  )
}

Will be transformed to:

export function Component() {
  return (
    <div text-red="" text-center="" text-5xl="" animate-bounce="">
      unocss
    </div>
  )
}
Without this transformer

JSX by default will treat valueless attributes as boolean attributes.

export function Component() {
  return (
    <div text-red={true} text-center={true} text-5xl={true} animate-bounce={true}>
      unocss
    </div>
  )
}

Install

npm i -D @unocss/transformer-attributify-jsx-babel
// uno.config.js
import { defineConfig, presetAttributify } from 'unocss'
import transformerAttributifyJsx from '@unocss/transformer-attributify-jsx-babel'

export default defineConfig({
  // ...
  presets: [
    // ...
    presetAttributify()
  ],
  transformers: [
    transformerAttributifyJsx(), // <--
  ],
})

Caveats

⚠️ The rules are almost the same as those of preset-attributify, but there are several precautions

<div translate-x-100% /> <!-- cannot end with `%` -->

<div translate-x-[100px] /> <!-- cannot contain `[` or `]` -->

Instead, you may want to use valued attributes instead:

<div translate="x-100%" />

<div translate="x-[100px]" />

Blocklist

This transformer will only transform attributes that are valid UnoCSS utilities. You can also blocklist bypass some attributes from been transformed.

transformerAttributifyJsx({
  blocklist: [/text-[a-zA-Z]*/, 'text-5xl']
})
<div text-red text-center text-5xl animate-bounce>
  unocss
</div>

Will be compiled to:

<div text-red text-center text-5xl animate-bounce="">
  unocss
</div>

License

MIT License © 2022-PRESENT Anthony Fu

Keywords

FAQs

Package last updated on 15 May 2023

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