@@ -541,19 +541,16 @@ function variantToRecipeTone(
541541 }
542542}
543543
544- function resolveChipColor ( theme : Theme , variant : unknown , kind : "badge" | "tag" ) : Rgb24 {
544+ function resolveTagColor ( theme : Theme , variant : unknown ) : Rgb24 {
545545 const colorTokens = getColorTokens ( theme ) ;
546546 if ( colorTokens !== null ) {
547547 const tone = variantToRecipeTone ( variant ) ;
548- const bgStyle = (
549- kind === "badge" ? badgeRecipe ( colorTokens , { tone } ) . bg : tagRecipe ( colorTokens , { tone } ) . bg
550- ) as { bg ?: unknown } ;
548+ const bgStyle = tagRecipe ( colorTokens , { tone } ) . bg as { bg ?: unknown } ;
551549 if ( typeof bgStyle . bg === "number" ) {
552550 return bgStyle . bg ;
553551 }
554552 }
555- const fallbackTone =
556- kind === "badge" || variant === "primary" ? ( "primary" as const ) : ( "secondary" as const ) ;
553+ const fallbackTone = variant === "primary" ? ( "primary" as const ) : ( "secondary" as const ) ;
557554 return variantToThemeColor ( theme , variant , fallbackTone ) ;
558555}
559556
@@ -887,12 +884,35 @@ export function renderTextWidgets(
887884 const props = vnode . props as { text ?: unknown ; variant ?: unknown ; style ?: unknown } ;
888885 const text = readString ( props . text ) ?? "" ;
889886 const ownStyle = asTextStyle ( props . style , theme ) ;
890- const color = resolveChipColor ( theme , props . variant , "badge" ) ;
891- const chipStyle = mergeTextStyle (
892- mergeTextStyle ( parentStyle , { fg : color , bold : true } ) ,
893- ownStyle ,
894- ) ;
895- maybeFillOwnBackground ( builder , rect , ownStyle , chipStyle ) ;
887+ const colorTokens = getColorTokens ( theme ) ;
888+ const recipeResult =
889+ colorTokens !== null
890+ ? badgeRecipe ( colorTokens , { tone : variantToRecipeTone ( props . variant ) } )
891+ : null ;
892+ const fallbackStyle = mergeTextStyle ( parentStyle , {
893+ fg : variantToThemeColor ( theme , props . variant , "primary" ) ,
894+ bold : true ,
895+ } ) ;
896+ const chipBaseStyle =
897+ recipeResult !== null
898+ ? mergeTextStyle (
899+ parentStyle ,
900+ recipeResult . bg . bg !== undefined
901+ ? { ...recipeResult . text , bg : recipeResult . bg . bg }
902+ : recipeResult . text ,
903+ )
904+ : fallbackStyle ;
905+ const chipStyle = ownStyle ? mergeTextStyle ( chipBaseStyle , ownStyle ) : chipBaseStyle ;
906+ if ( recipeResult ?. bg . bg !== undefined ) {
907+ const bgBaseStyle = mergeTextStyle ( parentStyle , recipeResult . bg ) ;
908+ const bgStyle = mergeTextStyle (
909+ bgBaseStyle ,
910+ ownStyle && ownStyle . bg !== undefined ? { bg : ownStyle . bg } : undefined ,
911+ ) ;
912+ builder . fillRect ( rect . x , rect . y , rect . w , rect . h , bgStyle ) ;
913+ } else {
914+ maybeFillOwnBackground ( builder , rect , ownStyle , chipStyle ) ;
915+ }
896916 const content = `( ${ text } )` ;
897917 const segments : StyledSegment [ ] = [ { text : content , style : chipStyle } ] ;
898918
@@ -1014,7 +1034,7 @@ export function renderTextWidgets(
10141034 const text = readString ( props . text ) ?? "" ;
10151035 const removable = props . removable === true ;
10161036 const ownStyle = asTextStyle ( props . style , theme ) ;
1017- const variantColor = resolveChipColor ( theme , props . variant , "tag" ) ;
1037+ const variantColor = resolveTagColor ( theme , props . variant ) ;
10181038 const chipStyle = mergeTextStyle (
10191039 mergeTextStyle ( parentStyle , { fg : variantColor , bold : true } ) ,
10201040 ownStyle ,
0 commit comments