@@ -3,34 +3,35 @@ import {Box, Box2} from './box'
33import Text from './text'
44import * as Styles from '../styles'
55
6+ const Kb = {
7+ Box,
8+ Box2,
9+ Text,
10+ }
11+
612export type Badge2Props = {
713 badgeNumber ?: number
814 className ?: string
9- fontSize : number
10- height : number
11- leftRightPadding : number
15+ fontSize ? : number
16+ height ? : number
17+ leftRightPadding ? : number
1218 containerStyle ?: Styles . StylesCrossPlatform
1319 badgeStyle ?: Styles . StylesCrossPlatform
1420 badgeNumberStyle ?: Styles . StylesCrossPlatform
1521 border ?: boolean
1622}
1723
18- export default class Badge extends React . Component < Badge2Props > {
19- static defaultProps = {
20- fontSize : Styles . isMobile ? 12 : 10 ,
21- height : Styles . isMobile ? 20 : 16 ,
22- leftRightPadding : Styles . isPhone ? 5 : 4 ,
23- }
24-
25- render ( ) {
26- return this . props . border ? this . renderWithBorder ( ) : this . renderNoBorder ( )
27- }
24+ const Badge = React . memo ( function Badge ( p : Badge2Props ) {
25+ const { border, containerStyle, className, badgeNumberStyle, badgeNumber, badgeStyle} = p
26+ const fontSize = p . fontSize ?? ( Styles . isMobile ? 12 : 10 )
27+ const height = p . height ?? ( Styles . isMobile ? 20 : 16 )
28+ const leftRightPadding = p . leftRightPadding ?? ( Styles . isPhone ? 5 : 4 )
2829
29- renderWithBorder ( ) {
30- const outerSize = this . props . height
31- const innerSize = this . props . border ? this . props . height - 3 : this . props . height
30+ if ( border ) {
31+ const outerSize = height
32+ const innerSize = border ? height - 3 : height
3233 return (
33- < Box2
34+ < Kb . Box2
3435 direction = "vertical"
3536 centerChildren = { true }
3637 style = { Styles . collapseStyles ( [
@@ -40,93 +41,88 @@ export default class Badge extends React.Component<Badge2Props> {
4041 height : outerSize ,
4142 minWidth : outerSize ,
4243 } ,
43- this . props . containerStyle ,
44+ containerStyle ,
4445 ] ) }
4546 >
46- < Box
47- className = { this . props . className }
47+ < Kb . Box
48+ className = { className }
4849 style = { Styles . collapseStyles ( [
4950 styles . badge ,
5051 {
5152 borderRadius : innerSize ,
5253 height : innerSize ,
5354 minWidth : innerSize ,
54- paddingLeft : this . props . leftRightPadding ,
55- paddingRight : this . props . leftRightPadding ,
55+ paddingLeft : leftRightPadding ,
56+ paddingRight : leftRightPadding ,
5657 } ,
57- this . props . badgeStyle ,
58+ badgeStyle ,
5859 ] ) }
5960 >
60- { ! ! this . props . badgeNumber && (
61- < Text
61+ { ! ! badgeNumber && (
62+ < Kb . Text
6263 center = { true }
6364 type = "BodyTinyBold"
6465 style = { Styles . collapseStyles ( [
6566 styles . text ,
6667 {
67- fontSize : this . props . fontSize ,
68- height : this . props . height ,
69- lineHeight : Styles . isMobile ? this . props . height : `${ this . props . height } px` , // likely unneeded
68+ fontSize : fontSize ,
69+ height : height ,
70+ lineHeight : Styles . isMobile ? height : `${ height } px` , // likely unneeded
7071 } ,
71- this . props . badgeNumberStyle ,
72+ badgeNumberStyle ,
7273 ] as any ) }
7374 >
74- { this . props . badgeNumber }
75- </ Text >
75+ { badgeNumber }
76+ </ Kb . Text >
7677 ) }
77- </ Box >
78- </ Box2 >
78+ </ Kb . Box >
79+ </ Kb . Box2 >
7980 )
80- }
81-
82- renderNoBorder ( ) {
81+ } else {
8382 return (
84- < Box
85- className = { this . props . className }
83+ < Kb . Box
84+ className = { className }
8685 style = { Styles . collapseStyles ( [
8786 styles . badge ,
8887 {
89- borderRadius : this . props . height ,
90- height : this . props . height ,
91- minWidth : this . props . height ,
92- paddingLeft : this . props . leftRightPadding ,
93- paddingRight : this . props . leftRightPadding ,
88+ borderRadius : height ,
89+ height : height ,
90+ minWidth : height ,
91+ paddingLeft : leftRightPadding ,
92+ paddingRight : leftRightPadding ,
9493 } ,
95- this . props . badgeStyle ,
94+ badgeStyle ,
9695 ] ) }
9796 >
98- { ! ! this . props . badgeNumber && (
99- < Text
97+ { ! ! badgeNumber && (
98+ < Kb . Text
10099 center = { true }
101100 type = "BodyTinyBold"
102101 style = { Styles . collapseStyles ( [
103102 styles . text ,
104103 {
105- fontSize : this . props . fontSize ,
106- height : this . props . height ,
107- lineHeight : Styles . isMobile ? this . props . height : `${ this . props . height } px` ,
104+ fontSize : fontSize ,
105+ height : height ,
106+ lineHeight : Styles . isMobile ? height : `${ height } px` ,
108107 } ,
109- this . props . badgeNumberStyle ,
108+ badgeNumberStyle ,
110109 ] as any ) }
111110 >
112- { this . props . badgeNumber }
113- </ Text >
111+ { badgeNumber }
112+ </ Kb . Text >
114113 ) }
115- </ Box >
114+ </ Kb . Box >
116115 )
117116 }
118- }
117+ } )
118+ export default Badge
119119
120120const styles = Styles . styleSheetCreate ( ( ) => ( {
121121 badge : {
122122 ...Styles . globalStyles . flexBoxRow ,
123123 ...Styles . globalStyles . flexBoxCenter ,
124124 backgroundColor : Styles . globalColors . orange ,
125125 } ,
126- container : {
127- backgroundColor : Styles . globalColors . white ,
128- } ,
129- text : {
130- color : Styles . globalColors . white ,
131- } ,
126+ container : { backgroundColor : Styles . globalColors . white } ,
127+ text : { color : Styles . globalColors . white } ,
132128} ) )
0 commit comments