@@ -95,7 +95,7 @@ export const gale = <T extends string>(
9595 componentStylesToGaleStringCache . set ( STUB_COMPONENT_STYLES_KEY , c ) ;
9696 galeStringCache = c ;
9797 }
98- const mFunction = ( classes : string ) : string => {
98+ const mFunction = ( ... classes : string [ ] ) : string => {
9999 return computeClassesWithCache (
100100 projectStyles ,
101101 STUB_COMPONENT_STYLES_KEY ,
@@ -128,7 +128,7 @@ export const gale = <T extends string>(
128128 componentStylesToGaleStringCache . set ( componentStyles , c ) ;
129129 galeStringCache = c ;
130130 }
131- const mFunction = ( classes : string ) : string => {
131+ const mFunction = ( ... classes : string [ ] ) : string => {
132132 return computeClassesWithCache (
133133 projectStyles ,
134134 componentStyles ,
@@ -144,14 +144,15 @@ export const gale = <T extends string>(
144144 projectStyles : Record < string , string > ,
145145 componentStyles : Record < string , string > ,
146146 cache : Map < string , string > ,
147- classes : string ,
147+ classes : ( string | undefined | null | false ) [ ] ,
148148 ) : string => {
149- const cached = cache . get ( classes ) ;
149+ const classesConcatenated = classes . filter ( Boolean ) . join ( " " ) ;
150+ const cached = cache . get ( classesConcatenated ) ;
150151 if ( cached !== undefined ) {
151152 return cached ;
152153 }
153154 const parsed : string [ ] = [ ] ;
154- for ( const p of classes . split ( " " ) ) {
155+ for ( const p of classesConcatenated . split ( " " ) ) {
155156 const slotName = p . trim ( ) ;
156157 if ( ! slotName ) {
157158 continue ;
@@ -166,7 +167,7 @@ export const gale = <T extends string>(
166167 }
167168
168169 const result = mergeClasses ( ...parsed ) ;
169- cache . set ( classes , result ) ;
170+ cache . set ( classesConcatenated , result ) ;
170171 return result ;
171172 } ;
172173
@@ -188,7 +189,9 @@ export type GaleKeys<T extends string> = T | GaleBuiltinKey;
188189/** Hook to be called inside a component to get the `m` function. See {@link gale} */
189190export type GaleHook < T extends string > = ( ) => GaleFn < T > ;
190191/** The `m` function that turns a style string into class names */
191- export type GaleFn < T extends string > = < K extends string > ( classes : GaleString < K , T , [ ] > ) => string ;
192+ export type GaleFn < T extends string > = < K extends string > (
193+ ...classes : ( GaleString < K , T , [ ] > | undefined | null | false ) [ ]
194+ ) => string ;
192195
193196/** Type-safe, space-separated style idents */
194197export type GaleString < K extends string , T extends string , S extends string [ ] > = K extends S [ number ]
@@ -362,14 +365,3 @@ export const GALE_BUILTIN_STYLES = {
362365} as const satisfies Record < string , GriffelStyle > ;
363366
364367type GaleBuiltinKey = keyof typeof GALE_BUILTIN_STYLES ;
365- // // type A = Validate<"margin-0", Keys>;
366- // // type B = Validate<"foo", Keys>;
367- // // type C = Validate<"foo bar", Keys>;
368- // // type D = Validate<"margin-0 padding-0", Keys>;
369- // // type E = Validate<"margin-0 0", Keys>;
370- // // type F = Validate<"0 padding-0", Keys>;
371- //
372- // const testFunc = <T extends string>(exp: Validate<T, Keys>): void => {
373- // }
374- //
375- // testFunc("margin-0");
0 commit comments