From 1eabbb5243dc459a0b9958865b32fa638b25f08c Mon Sep 17 00:00:00 2001 From: jin Date: Sat, 16 Dec 2023 15:52:08 +0300 Subject: [PATCH] $mol_style: + [attr] syntax --- style/guard/guard.ts | 3 +++ style/sheet/sheet.ts | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/style/guard/guard.ts b/style/guard/guard.ts index 382c099c141..784e8a938ea 100644 --- a/style/guard/guard.ts +++ b/style/guard/guard.ts @@ -35,6 +35,9 @@ namespace $ { : key extends '@media' ? Medias< View , Config[key] > + : key extends `[${string}]` + ? { [ val in keyof Config[key] ]: $mol_style_guard< View , Config[key][val] > } + : key extends `--${string}` ? any diff --git a/style/sheet/sheet.ts b/style/sheet/sheet.ts index 49460c2738b..9021a93494a 100644 --- a/style/sheet/sheet.ts +++ b/style/sheet/sheet.ts @@ -102,6 +102,15 @@ namespace $ { } + } else if( key[0] === '[' && key[key.length-1] === ']' ) { + + const attr = key.slice( 1, -1 ) + const vals = config[ key as any ] as Record< string, any > + + for( let val in vals ) { + make_class( selector( prefix , path ) + ':where([' + attr + '=' + JSON.stringify( val ) + '])' , [] , vals[val] ) + } + } else { make_class( selector( prefix , path ) + key , [] , (config as any)[key] )