11export type { ClassNames } from "./defs"
2- import { dehash , wrapper } from "./core"
3- import type { ClassNamesMap , ClassNamed , GetClassKeys } from "./defs"
2+ import { dehash , wrapper , joinWithLead } from "./core"
3+ import type { ClassNamesMap , ClassNamed , GetClassKeys , ClassValue , ReactRelated } from "./defs"
44
55export default classNamingBasic
66
77/**
88 * Makes `className` string from imported CSS
9- * @example <div className={classNaming<string>({ClassName})} />
10- * @example <div {...classNaming({ClassName})} />
9+ * @example <div className={`${classNamingBasic({ClassName})}` } />
10+ * @example <div {...classNamingBasic({ClassName})} />
11+ * @example const cn = classNamingBasic({C1})({C2}); <div {...cn({C3})({C4})} />
1112 */
12- function classNamingBasic < Return , ClassKeys extends string = string > (
13- classnames : ClassNamesMap < string extends Return ? ClassKeys : GetClassKeys < Return > >
14- ) : Return extends string ? string : ClassNamed
13+ function classNamingBasic < Source extends ReactRelated > (
14+ classnames : ClassNamesMap < GetClassKeys < Source > >
15+ ) : ClassNamingChain
1516
1617/**
1718 * Makes `className` string from imported CSS
18- * @example <div className={classNaming<string>({ClassName})} />
19- * @example <div {...classNaming({ClassName})} />
19+ * @example <div className={`${classNamingBasic({ClassName})}` } />
20+ * @example <div {...classNamingBasic({ClassName})} />
21+ * @example const cn = classNamingBasic({C1})({C2}); <div {...cn({C3})({C4})} />
2022 */
21- function classNamingBasic < Return , ClassKeys extends string = string > (
23+ function classNamingBasic < Source extends ReactRelated > (
2224 propagatedClassName : undefined | string ,
23- classnames : ClassNamesMap < string extends Return ? ClassKeys : GetClassKeys < Return > >
24- ) : Return extends string ? string : ClassNamed
25+ classnames : ClassNamesMap < GetClassKeys < Source > >
26+ ) : ClassNamingChain
2527
2628function classNamingBasic (
2729 arg0 : undefined | string | ClassNamesMap < string > ,
@@ -30,24 +32,20 @@ function classNamingBasic(
3032 const classnames = typeof arg0 === "object" ? arg0 : arg1
3133 , className = typeof arg0 === "object" ? undefined : arg0
3234
33- return _classNaming ( classnames ! , className , { } )
35+ return _classNaming ( classnames ! , className )
3436}
3537
36- function _classNaming < T extends Partial < ClassNamed > > (
37- classnames : ClassNamesMap < string > ,
38- className : undefined | string ,
39- destination : T
40- ) : T & ClassNamed {
41-
42- // TODO For propagation
43- // $defineProperty(
44- // classnames,
45- // "toString",
46- // {
47- // value: undefined
48- // }
49- // )
50- // $assign(destination, {classnames})
51-
52- return wrapper ( className , dehash ( classnames ) , destination )
38+ function _classNaming (
39+ classes : ClassNamesMap < string > ,
40+ propagate : undefined | string ,
41+ ) : ClassNamingChain {
42+ const className = joinWithLead ( propagate , dehash ( classes ) )
43+ , host : ClassNamingCall = classes => _classNaming ( classes , className )
44+
45+ return wrapper ( className , [ ] , host )
46+ }
47+
48+ type ClassNamingChain = ClassNamingCall & {
49+ className : string
5350}
51+ type ClassNamingCall = ( classes : Record < string , ClassValue > ) => ClassNamingChain
0 commit comments