Skip to content

Commit 6258eec

Browse files
committed
feat: 扩充 unocss 自定义 shortcuts
1 parent ee3ce95 commit 6258eec

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

unocss.config.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,30 @@ export default defineConfig<Theme>({
2222
},
2323
},
2424
shortcuts: [
25-
{
26-
'flex-center': 'flex justify-center items-center',
27-
'flex-col-center': 'flex flex-col justify-center items-center',
28-
},
25+
[/^flex-?(col)?-(start|end|center|baseline|stretch)-?(start|end|center|between|around|evenly|left|right)?$/, ([, col, items, justify]) => {
26+
const cls = ['flex']
27+
if (col === 'col') {
28+
cls.push('flex-col')
29+
}
30+
if (items === 'center' && !justify) {
31+
cls.push('items-center')
32+
cls.push('justify-center')
33+
}
34+
else {
35+
cls.push(`items-${items}`)
36+
if (justify) {
37+
cls.push(`justify-${justify}`)
38+
}
39+
}
40+
return cls.join(' ')
41+
}],
42+
[/^square-\[?(.*?)\]?$/, ([, size]) => `w-${size} h-${size}`],
43+
[/^circle-\[?(.*?)\]?$/, ([, size]) => `square-${size} rounded-full`],
2944
],
3045
preflights: [
3146
{
3247
getCSS: () => {
33-
const returnCss: any = []
48+
const returnCss: string[] = []
3449
// 明亮主题
3550
const lightCss = entriesToCss(Object.entries(lightTheme))
3651
const lightRoots = toArray([`*,::before,::after`, `::backdrop`])

0 commit comments

Comments
 (0)