Skip to content

محول Attributify JSX

دعم attributify بدون قيمة في JSX/TSX: @unocss/transformer-attributify-jsx.

العرض

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

سيتم تحويله إلى:

jsx
export function Component() {
  return (
    <div text-red="" text-center="" text-5xl="" animate-bounce="">
      unocss
    </div>
  )
}
بدون هذا المحول، يعامل JSX السمات بدون قيمة كسمات منطقية.
jsx
export function Component() {
  return (
    <div text-red={true} text-center={true} text-5xl={true} animate-bounce={true}>
      unocss
    </div>
  )
}

التثبيت

bash
pnpm add -D @unocss/transformer-attributify-jsx
bash
yarn add -D @unocss/transformer-attributify-jsx
bash
npm install -D @unocss/transformer-attributify-jsx
bash
bun add -D @unocss/transformer-attributify-jsx
ts
import { defineConfig, presetAttributify } from 'unocss'
import transformerAttributifyJsx from '@unocss/transformer-attributify-jsx'

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

TIP

يتم تضمين هذا الإعداد المسبق في حزمة unocss، يمكنك أيضاً استيراده من هناك:

ts
import { transformerAttributifyJsx } from 'unocss'

المحاذير

WARNING

القواعد هي نفسها تقريباً لتلك الخاصة بـ إعداد Attributify المسبق، لكن هناك عدة احتياطات.

html
<div translate-x-100% />
<!-- لا يمكن أن ينتهي بـ `%` -->

<div translate-x-[100px] />
<!-- لا يمكن أن يحتوي على `[` أو `]` -->

بدلاً من ذلك، قد ترغب في استخدام السمات ذات القيمة:

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

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

القائمة السوداء

سيحول هذا المحول فقط السمات التي هي أدوات UnoCSS صالحة. يمكنك أيضاً blocklist تجاوز بعض السمات من التحويل.

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

سيتم تجميعه إلى:

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

Released under the MIT License.