1- import  {  css ,  styled  }  from  'styled-components' ; 
1+ import  {  css ,  styled ,   DefaultTheme  }  from  'styled-components' ; 
22
33import  {  Flex ,  FlexComponent ,  FlexProps  }  from  '../../primitives/Flex' ; 
44import  {  Typography  }  from  '../../primitives/Typography' ; 
55import  {  DefaultThemeOrCSSProp  }  from  '../../types' ; 
66
77type  BadgeSize  =  'S'  |  'M' ; 
88
9+ type  BadgeVariant  =  'success'  |  'primary'  |  'danger'  |  'warning'  |  'neutral'  |  'secondary'  |  'alternative' ; 
10+ 
911interface  BadgeProps  extends  FlexProps  { 
1012  /** 
1113   * If `true`, it changes the `backgroundColor` to `primary200` and the `textColor` to `primary600` 
1214   */ 
1315  active ?: boolean ; 
16+ 
1417  backgroundColor ?: DefaultThemeOrCSSProp < 'colors' ,  'background' > ; 
1518  /** 
1619   * @default  'M' 
1720   */ 
1821  size ?: BadgeSize ; 
22+ 
1923  textColor ?: DefaultThemeOrCSSProp < 'colors' ,  'color' > ; 
24+ 
25+   /** 
26+    * @default  'neutral' 
27+    */ 
28+   variant ?: BadgeVariant ; 
2029} 
2130
2231const  Badge  =  ( { 
2332  active =  false , 
2433  size =  'M' , 
2534  textColor =  'neutral600' , 
2635  backgroundColor =  'neutral150' , 
36+   variant, 
2737  children, 
2838  minWidth =  5 , 
2939  ...props 
3040} : BadgeProps )  =>  { 
3141  const  paddingX  =  size  ===  'S'  ? 1  : 2 ; 
3242
43+   const  overridedColors  =  variant 
44+     ? { 
45+         backgroundColor : `${ variant }  200`  satisfies  keyof  DefaultTheme [ 'colors' ] , 
46+         textColor : `${ variant }  700`  satisfies  keyof  DefaultTheme [ 'colors' ] , 
47+       } 
48+     : { 
49+         backgroundColor, 
50+         textColor, 
51+       } ; 
52+ 
3353  return  ( 
3454    < Base 
3555      inline 
@@ -38,11 +58,11 @@ const Badge = ({
3858      minWidth = { minWidth } 
3959      paddingLeft = { paddingX } 
4060      paddingRight = { paddingX } 
41-       background = { active  ? 'primary200'  : backgroundColor } 
61+       background = { active  ? 'primary200'  : overridedColors . backgroundColor } 
4262      $size = { size } 
4363      { ...props } 
4464    > 
45-       < Typography  variant = "sigma"  textColor = { active  ? 'primary600'  : textColor }  lineHeight = "1rem" > 
65+       < Typography  variant = "sigma"  textColor = { active  ? 'primary600'  : overridedColors . textColor }  lineHeight = "1rem" > 
4666        { children } 
4767      </ Typography > 
4868    </ Base > 
0 commit comments