Tagify preset
Điều này cho phép chế độ tagify cho các preset khác.
Cài đặt
bash
pnpm add -D @unocss/preset-tagifybash
yarn add -D @unocss/preset-tagifybash
npm install -D @unocss/preset-tagifybash
bun add -D @unocss/preset-tagifyts
import presetTagify from '@unocss/preset-tagify'
import { defineConfig } from 'unocss'
export default defineConfig({
presets: [
presetTagify({ /* options */ }),
// ...other presets
],
})Chế độ Tagify
Preset này có thể hữu ích khi bạn chỉ cần áp dụng một quy tắc unocss duy nhất cho một phần tử.
html
<span class="text-red"> red text </span>
<div class="flex">flexbox</div>
I'm feeling <span class="i-line-md-emoji-grin"></span> today!Với chế độ tagify, bạn có thể nhúng kiểu CSS vào thẻ HTML:
html
<text-red> red text </text-red>
<flex> flexbox </flex>
I'm feeling <i-line-md-emoji-grin /> today!HTML ở trên hoạt động chính xác như bạn mong đợi.
Với tiền tố
js
presetTagify({
prefix: 'un-'
})html
<!-- this will be matched -->
<un-flex> </un-flex>
<!-- this will not be matched -->
<flex> </flex>Thuộc tính bổ sung
Bạn có thể chèn các thuộc tính bổ sung vào các quy tắc được khớp:
js
presetTagify({
// adds display: inline-block to matched icons
extraProperties: matched => matched.startsWith('i-')
? { display: 'inline-block' }
: { }
})js
presetTagify({
// extraProperties can also be a plain object
extraProperties: { display: 'block' }
})Tùy chọn
prefix
- Kiểu:
string
Tiền tố dùng cho biến thể tagify.
excludedTags
- Kiểu:
string[] | RegExp[] - Mặc định:
['b', /^h\d+$/, 'table']
Các thẻ được loại trừ khỏi xử lý.
extraProperties
- Kiểu:
Record<string, string> | ((matched: string) => Partial<Record<string, string>>)
Các thuộc tính CSS bổ sung để áp dụng cho các quy tắc được khớp.
defaultExtractor
- Kiểu:
boolean - Mặc định:
true
Bật trình trích xuất mặc định.