1- import type { CreateTVFactory , TV , TVConfig } from './types'
1+ import type { ClassValue , CreateTVFactory , TV , TVConfig } from './types'
22import { defaultConfig } from './constants'
33import { hasSlotOverrides , hasVariantOverrides } from './helpers'
44import { cn , cnBase , createClassMerger , updateTailwindMergeConfig } from './merge'
@@ -13,6 +13,37 @@ import {
1313 resolveResponsiveSettings ,
1414} from './variants'
1515
16+ interface TVExtendShape {
17+ base ?: ClassValue
18+ variants ?: Record < string , any >
19+ defaultVariants ?: Record < string , any >
20+ slots ?: Record < string , any >
21+ compoundVariants ?: any [ ]
22+ compoundSlots ?: any [ ]
23+ }
24+
25+ type TVExtend = TVExtendShape | null
26+
27+ interface TVOptions {
28+ base ?: ClassValue
29+ extend ?: TVExtend
30+ slots ?: Record < string , any > | undefined
31+ variants ?: Record < string , any >
32+ compoundVariants ?: any [ ]
33+ compoundSlots ?: any [ ]
34+ defaultVariants ?: Record < string , any >
35+ }
36+
37+ interface TVProps extends Record < string , any > {
38+ class ?: ClassValue
39+ className ?: ClassValue
40+ }
41+
42+ interface SlotPropsArg extends Record < string , any > {
43+ class ?: ClassValue
44+ className ?: ClassValue
45+ }
46+
1647function mergeSlotDefinitions (
1748 baseSlots : Record < string , any > ,
1849 overrideSlots : Record < string , any > ,
@@ -39,7 +70,7 @@ function assertArray(value: unknown, propName: string): asserts value is any[] {
3970 }
4071}
4172
42- export function tvImplementation ( options : Record < string , any > , configProp ?: TVConfig ) {
73+ export function tvImplementation ( options : TVOptions , configProp ?: TVConfig ) {
4374 const {
4475 extend = null ,
4576 slots : slotProps = { } ,
@@ -51,7 +82,9 @@ export function tvImplementation(options: Record<string, any>, configProp?: TVCo
5182
5283 const config : TVConfig = { ...defaultConfig , ...configProp }
5384
54- const base = extend ?. base ? cnBase ( extend . base , options ?. base ) : options ?. base
85+ const base = extend ?. base
86+ ? cnBase ( extend . base , options ?. base )
87+ : options ?. base
5588
5689 const variants = extend ?. variants && ! isEmptyObject ( extend . variants )
5790 ? mergeObjects ( variantsProps , extend . variants )
@@ -67,14 +100,14 @@ export function tvImplementation(options: Record<string, any>, configProp?: TVCo
67100 const isExtendedSlotsEmpty = isEmptyObject ( extendSlots )
68101 const hasOwnSlots = ! isEmptyObject ( slotProps )
69102
70- const componentSlots = hasOwnSlots
103+ const componentSlots : Record < string , any > = hasOwnSlots
71104 ? {
72105 base : cnBase ( options ?. base , isExtendedSlotsEmpty && extend ?. base ) ,
73106 ...slotProps ,
74107 }
75108 : { }
76109
77- const slots = isExtendedSlotsEmpty
110+ const slots : Record < string , any > = isExtendedSlotsEmpty
78111 ? componentSlots
79112 : mergeSlotDefinitions (
80113 { ...extendSlots } ,
@@ -93,12 +126,12 @@ export function tvImplementation(options: Record<string, any>, configProp?: TVCo
93126 let cachedDefaultResult : any
94127 let hasCachedDefaultResult = false
95128
96- const component = ( propsParam ?: Record < string , any > ) => {
129+ const component = ( propsParam ?: TVProps ) => {
97130 if ( ! propsParam && hasCachedDefaultResult ) {
98131 return cachedDefaultResult
99132 }
100133
101- const props = propsParam ?? { }
134+ const props : Record < string , any > = propsParam ?? { }
102135
103136 assertArray ( compoundVariants , 'compoundVariants' )
104137 assertArray ( compoundSlots , 'compoundSlots' )
@@ -116,7 +149,9 @@ export function tvImplementation(options: Record<string, any>, configProp?: TVCo
116149 config,
117150 props,
118151 variantResponsiveSettings : responsiveState . variantResponsiveSettings ,
119- globalResponsiveSetting : responsiveState . globalResponsiveSetting ,
152+ ...( responsiveState . globalResponsiveSetting === undefined
153+ ? { }
154+ : { globalResponsiveSetting : responsiveState . globalResponsiveSetting } ) ,
120155 } )
121156
122157 const baseVariantClassNames = getVariantClassNames ( context )
@@ -157,12 +192,15 @@ export function tvImplementation(options: Record<string, any>, configProp?: TVCo
157192 )
158193 }
159194
160- const slotsFns : Record < string , any > = { }
195+ const slotsFns : Record <
196+ string ,
197+ ( slotPropsArg ?: SlotPropsArg ) => ReturnType < typeof mergeClasses >
198+ > = { }
161199
162200 for ( const slotKey of slotKeys ) {
163201 const cached = baseSlotOutputs . get ( slotKey )
164202
165- slotsFns [ slotKey ] = ( slotPropsArg ?: Record < string , any > ) => {
203+ slotsFns [ slotKey ] = ( slotPropsArg ?: SlotPropsArg ) => {
166204 if ( ! slotPropsArg || ! hasSlotOverrides ( slotPropsArg ) ) {
167205 return cached
168206 }
0 commit comments