0.60.0 • Published 2 days ago

@unocss/transformer-attributify-jsx-babel v0.60.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 days ago

@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>
  )
}

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

0.60.0

2 days ago

0.59.4

22 days ago

0.59.3

24 days ago

0.59.2

28 days ago

0.59.1

29 days ago

0.59.0

1 month ago

0.58.9

1 month ago

0.59.0-beta.1

1 month ago

0.58.8

1 month ago

0.58.7

1 month ago

0.58.6

2 months ago

0.58.5

3 months ago

0.58.4

4 months ago

0.58.3

4 months ago

0.58.2

4 months ago

0.58.1

5 months ago

0.57.4

6 months ago

0.55.6

8 months ago

0.57.5

6 months ago

0.55.7

8 months ago

0.57.2

6 months ago

0.55.4

8 months ago

0.53.6

10 months ago

0.57.3

6 months ago

0.55.5

8 months ago

0.57.0

7 months ago

0.55.2

9 months ago

0.57.1

7 months ago

0.55.3

9 months ago

0.53.5

10 months ago

0.55.0

9 months ago

0.55.1

9 months ago

0.57.6

6 months ago

0.57.7

6 months ago

0.56.5

7 months ago

0.56.3

8 months ago

0.56.4

8 months ago

0.56.1

8 months ago

0.54.3

9 months ago

0.58.0

5 months ago

0.56.2

8 months ago

0.54.1

9 months ago

0.56.0

8 months ago

0.54.2

9 months ago

0.54.0

10 months ago

0.53.4

11 months ago

0.52.7

11 months ago

0.52.5

12 months ago

0.52.6

11 months ago

0.52.3

12 months ago

0.53.3

11 months ago

0.52.4

12 months ago

0.51.13

12 months ago

0.53.0

11 months ago

0.52.1

12 months ago

0.53.1

11 months ago

0.52.2

12 months ago

0.52.0

12 months ago

0.51.12

1 year ago

0.51.11

1 year ago

0.51.8

1 year ago

0.51.7

1 year ago

0.51.6

1 year ago

0.51.5

1 year ago

0.51.4

1 year ago

0.51.3

1 year ago

0.51.2

1 year ago

0.51.1

1 year ago

0.51.0

1 year ago

0.50.8

1 year ago