Created
April 19, 2022 17:21
-
-
Save onmax/6e626ac62d8f5edb9b4f1a9ffac13227 to your computer and use it in GitHub Desktop.
A custom UnoCSS rule to be able to select items like `nth-2:text-blue` or `nth-9:rounded-9`
This file contains hidden or 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
import { defineConfig, toEscapedSelector: e } from 'unocss' | |
// See it in action: | |
// https://unocss.antfu.me/?html=DwVwNgBAdgLgFgWgEwC4YFMAeMECMwjrTwIDMKuA5ngUZQE4CWAJhAywgMYD2YAzmQgAHMAENO6BIwwBbARNjp6ERH07106KACgIetqKEJMCACwA%2BXRGBhG5gJKyIARmAB6W5b027j9DIgkd08rHwcnUmC7bXdwcyA&config=JYWwDg9gTgLgBAbzgEwKYDNgDtUGEJaYDmANHDBAKIDOAxgIZirIDKqANqrRVAFxyo4AXzjooEEHADkAVywRa1alIBQK1AA9IsFBnoz28NJhz5CwIgAoEKuHCgHU1fgG1bduC4D0APSwwACwAdAFpLIOQAagBKIN5LADoAKmiAEi8yemoATyxaOEsXMmQyKABdMgQoegB3Nk5uaDJaAmoYB25cFhYyIlQcap4haLgAXgA%2BRDh3DzgWrDb7RzG4WvpgeEs%2BgfoeBLB6KGpUABUIAGt%2Byyho6JmPKFQYGSgsOAADVIRUa9r6rh40REkySvH8ARCtACwHYyEsX2QwymXwcnBcAAYyi4AExlERCd73IQVdxlFTDIA&options=N4IgzgLgTglgxhEAuaBXApgXyA | |
export default defineConfig({ | |
rules: [ | |
[/^nth\-(\d+)\:(.*)$/, async ([, d, r], {rawSelector, constructCSS, generator}) => { | |
const rule = await (generator.parseToken(r)) | |
return `${e(rawSelector)} > *:nth-child(${d}) { ${rule[0][2]} }` | |
}], | |
] | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Could you give me your opinion on mine :