@@ -62,14 +62,14 @@ type VariantOptions<V> = {
6262
6363type CompoundVariant < V > = {
6464 variants : Partial < {
65- [ P in keyof V ] : keyof V [ P ] ;
65+ [ P in keyof V ] : keyof V [ P ] | boolean ;
6666 } > ;
6767 style : StyleObject ;
6868} ;
6969
7070// DefaultVariants type
7171type DefaultVariants < V > = Partial < {
72- [ P in keyof V ] : keyof V [ P ] ;
72+ [ P in keyof V ] : keyof V [ P ] | boolean ;
7373} > ;
7474
7575// VariantStyleConfig type
@@ -97,7 +97,7 @@ export type VariantProps<Component extends (...args: any) => any> = Omit<
9797 * Creates a function that generates styles based on variants
9898 */
9999function styles < V extends VariantOptions < V > > ( config : VariantStyleConfig < V > ) {
100- type VariantProps = { [ P in keyof V ] : keyof V [ P ] | ( string & { } ) } ;
100+ type VariantProps = { [ P in keyof V ] : keyof V [ P ] | boolean | ( string & { } ) } ;
101101 type DefaultProps = NonNullable < typeof config . defaultVariants > ;
102102 type Props = OptionalIfHasDefault < VariantProps , DefaultProps > ;
103103
@@ -117,12 +117,24 @@ function styles<V extends VariantOptions<V>>(config: VariantStyleConfig<V>) {
117117 for ( const [ propName , value ] of Object . entries ( mergedProps ) as [ keyof V , any ] [ ] ) {
118118 const variantGroup = config . variants [ propName ] ;
119119 if ( variantGroup ) {
120- const variantValue = value || config . defaultVariants ?. [ propName ] ;
121- if ( variantValue && variantGroup [ variantValue as keyof typeof variantGroup ] ) {
122- styles = {
123- ...styles ,
124- ...variantGroup [ variantValue as keyof typeof variantGroup ] ,
125- } ;
120+ // Handle boolean variants
121+ if ( typeof value === 'boolean' ) {
122+ const booleanValue = value ? 'true' : 'false' ;
123+ if ( variantGroup [ booleanValue as keyof typeof variantGroup ] ) {
124+ styles = {
125+ ...styles ,
126+ ...variantGroup [ booleanValue as keyof typeof variantGroup ] ,
127+ } ;
128+ }
129+ } else {
130+ // Handle string/enum variants
131+ const variantValue = value || config . defaultVariants ?. [ propName ] ;
132+ if ( variantValue && variantGroup [ variantValue as keyof typeof variantGroup ] ) {
133+ styles = {
134+ ...styles ,
135+ ...variantGroup [ variantValue as keyof typeof variantGroup ] ,
136+ } ;
137+ }
126138 }
127139 }
128140 }
@@ -132,7 +144,13 @@ function styles<V extends VariantOptions<V>>(config: VariantStyleConfig<V>) {
132144 for ( const compound of config . compoundVariants ) {
133145 if (
134146 Object . entries ( compound . variants ) . every (
135- ( [ propName , value ] : [ string , unknown ] ) => mergedProps [ propName as keyof V ] === value ,
147+ ( [ propName , value ] : [ string , unknown ] ) => {
148+ // Handle boolean values in compound variants
149+ if ( typeof value === 'boolean' ) {
150+ return mergedProps [ propName as keyof V ] === value ;
151+ }
152+ return mergedProps [ propName as keyof V ] === value ;
153+ }
136154 )
137155 ) {
138156 styles = {
0 commit comments