Attributify JSX transformer
JSX/TSX'te değersiz attributify desteği: @unocss/transformer-attributify-jsx.
Presentation
jsx
export function Component() {
return (
<div text-red text-center text-5xl animate-bounce>
unocss
</div>
)
}Şuna dönüştürülecektir:
jsx
export function Component() {
return (
<div text-red="" text-center="" text-5xl="" animate-bounce="">
unocss
</div>
)
}Bu dönüştürücü olmadan, JSX değersiz öznitelikleri boolean öznitelikler olarak ele alır.
jsx
export function Component() {
return (
<div text-red={true} text-center={true} text-5xl={true} animate-bounce={true}>
unocss
</div>
)
}Installation
bash
pnpm add -D @unocss/transformer-attributify-jsxbash
yarn add -D @unocss/transformer-attributify-jsxbash
npm install -D @unocss/transformer-attributify-jsxbash
bun add -D @unocss/transformer-attributify-jsxts
import { defineConfig, presetAttributify } from 'unocss'
import transformerAttributifyJsx from '@unocss/transformer-attributify-jsx'
export default defineConfig({
// ...
presets: [
// ...
presetAttributify(),
],
transformers: [
transformerAttributifyJsx(), // <--
],
})TIP
Bu preset unocss paketine dahildir, oradan da içe aktarabilirsiniz:
ts
import { transformerAttributifyJsx } from 'unocss'Caveats
WARNING
Kurallar neredeyse Attributify preset ile aynıdır, ancak birkaç dikkat edilmesi gereken nokta vardır.
html
<div translate-x-100% />
<!-- `%` ile bitemez -->
<div translate-x-[100px] />
<!-- `[` veya `]` içeremez -->Bunun yerine, değerli öznitelikler kullanmak isteyebilirsiniz:
html
<div translate="x-100%" />
<div translate="x-[100px]" />Blocklist
Bu dönüştürücü yalnızca geçerli UnoCSS yardımcı programları olan öznitelikleri dönüştürür. Dönüştürülmesinden bazı öznitelikleri atlamak için blocklist kullanabilirsiniz.
js
transformerAttributifyJsx({
blocklist: [/text-[a-zA-Z]*/, 'text-5xl']
})jsx
<div text-red text-center text-5xl animate-bounce>
unocss
</div>Şuna derlenecektir:
html
<div text-red text-center text-5xl animate-bounce="">unocss</div>