自動完成
可以針對 UnoCSS 在 playground 和 VS Code 擴充功能 中的智慧建議自訂自動完成。
ts
autocomplete: {
templates: [
// theme inferring
'bg-$color/<opacity>',
// short hands
'text-<font-size>',
// logic OR groups
'(b|border)-(solid|dashed|dotted|double|hidden|none)',
// constants
'w-half',
],
shorthands: {
// equal to `opacity: "(0|10|20|30|40|50|60|70|90|100)"`
'opacity': Array.from({ length: 11 }, (_, i) => i * 10),
'font-size': '(xs|sm|base|lg|xl|2xl|3xl|4xl|5xl|6xl|7xl|8xl|9xl)',
// override built-in short hands
'num': '(0|1|2|3|4|5|6|7|8|9)',
},
extractors: [
// ...extractors
],
}
templates
使用簡單的 DSL 來指定自動完成建議。shorthands
是一個速記名稱到其模板的映射。如果是Array
,它將是一個邏輯 OR 群組。extractors
用於提取可能的類別,並將類別名稱樣式的建議轉換為正確的格式。例如,您可以查看我們如何實作 attributify 自動完成提取器如需更多說明,請參閱這裡。