@@ -108,7 +108,8 @@ function styles<V extends VariantOptions<V>>(config: VariantStyleConfig<V>) {
108
108
type Props = OptionalIfHasDefault < VariantProps , DefaultProps > ;
109
109
110
110
return ( props ?: Props ) : StyleProp < ResolvedStyle > => {
111
- // Start with base styles
111
+ // We'll build up styles in the correct hierarchy: base → variants → compound variants
112
+ // Base styles (lowest priority)
112
113
let stylesObj : StyleObject = {
113
114
...( config . base || { } ) ,
114
115
} ;
@@ -119,7 +120,7 @@ function styles<V extends VariantOptions<V>>(config: VariantStyleConfig<V>) {
119
120
...props ,
120
121
} as VariantProps ;
121
122
122
- // Apply variant styles
123
+ // Apply variant styles (overrides base styles)
123
124
for ( const [ propName , value ] of Object . entries ( mergedProps ) as [
124
125
keyof V ,
125
126
keyof VariantProps [ keyof V ] | boolean ,
@@ -148,7 +149,7 @@ function styles<V extends VariantOptions<V>>(config: VariantStyleConfig<V>) {
148
149
}
149
150
}
150
151
151
- // Apply compound variants
152
+ // Apply compound variants (highest priority before inline styles)
152
153
if ( config . compoundVariants ) {
153
154
for ( const compound of config . compoundVariants ) {
154
155
if (
@@ -328,11 +329,10 @@ export function defineTokens<T extends TokenConfig>(tokenConfig: T): CreateToken
328
329
style : resolvedStyle as ResolvedStyle ,
329
330
} ) ;
330
331
331
- // Merge the StyleSheet style with any style passed in props
332
+ // Styles hierarchy: base styles → variants → compound variants → inline styles
333
+ // Inline styles (propStyle) must have highest priority, so they come last in the array
332
334
const mergedStyle = propStyle
333
- ? Array . isArray ( propStyle )
334
- ? [ styles . style , ...propStyle ]
335
- : [ styles . style , propStyle ]
335
+ ? [ styles . style , ...( Array . isArray ( propStyle ) ? propStyle : [ propStyle ] ) ]
336
336
: styles . style ;
337
337
338
338
// We need to cast here to handle the component props correctly
0 commit comments