Created
November 10, 2023 03:24
-
-
Save wangpin34/40f2a5508eaf375de69c7514a758d12f to your computer and use it in GitHub Desktop.
handwrite several classes of tailwindcss in unocss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* eslint-disable no-useless-escape */ | |
// uno.config.ts | |
import { defineConfig } from 'unocss' | |
function spaceToRem(space: string) { | |
const num = parseInt(space) | |
if (!isNaN(num)) { | |
return `${num * 0.25}rem` | |
} | |
return space | |
} | |
export default defineConfig({ | |
presets: [], | |
rules: [ | |
[/^m-\[([^\[\]]+)\]$/, ([, val]) => ({ margin: val })], | |
[/^mt-\[([^\[\]]+)\]$/, ([, val]) => ({ 'margin-top': val })], | |
[/^mb-\[([^\[\]]+)\]$/, ([, val]) => ({ 'margin-bottom': val })], | |
[/^my-\[([^\[\]]+)\]$/, ([, val]) => ({ 'margin-top': val, 'margin-bottom': val })], | |
[/^ml-\[([^\[\]]+)\]$/, ([, val]) => ({ 'margin-left': val })], | |
[/^mr-\[([^\[\]]+)\]$/, ([, val]) => ({ 'margin-right': val })], | |
[/^mx-\[([^\[\]]+)\]$/, ([, val]) => ({ 'margin-left': val, 'margin-right': val })], | |
[/^gap-\[([^\[\]]+)\]$/, ([,val]) => ({gap: val})], | |
[/^m-([\d]+)$/, ([,val]) => ({margin: spaceToRem(val)})], | |
[/^mt-([\d]+)$/, ([,val]) => ({'margin-top': spaceToRem(val)})], | |
[/^mb-([\d]+)$/, ([,val]) => ({'margin-bottom': spaceToRem(val)})], | |
[/^ml-([\d]+)$/, ([,val]) => ({'margin-left': spaceToRem(val)})], | |
[/^mr-([\d]+)$/, ([,val]) => ({'margin-right': spaceToRem(val)})], | |
[/^mx-([\d]+)$/, ([,val]) => ({'margin-left': spaceToRem(val), 'margin-right': spaceToRem(val)})], | |
[/^my-([\d]+)$/, ([,val]) => ({'margin-top': spaceToRem(val), 'margin-bottom': spaceToRem(val) })], | |
[/^gap-([\d]+)$/, ([,val]) => ({gap: spaceToRem(val)})], | |
['flex', { display: 'flex' }], | |
['flex-col', {'flex-direction': 'column'}], | |
['flex-row', {'flex-direction': 'row'}], | |
] | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment