@@ -12,14 +12,11 @@ type ProBadgeSize = 'tiny' | 'small' | 'regular' | 'large';
1212interface ProBadgeBaseProps {
1313 size ?: ProBadgeSize ;
1414 textOnly ?: boolean ;
15- children ?: React . ReactNode ;
16- content ?: React . ReactNode ;
1715}
1816
1917interface ProBadgeWithContent extends ProBadgeBaseProps {
2018 content : React . ReactNode ;
2119 children ?: never ;
22- textOnly ?: boolean ;
2320}
2421
2522interface ProBadgeWithChildren extends ProBadgeBaseProps {
@@ -28,34 +25,41 @@ interface ProBadgeWithChildren extends ProBadgeBaseProps {
2825 textOnly ?: never ;
2926}
3027
31- type ProBadgeProps = ProBadgeWithContent | ProBadgeWithChildren ;
28+ interface ProBadgeIconOnly extends ProBadgeBaseProps {
29+ content ?: never ;
30+ children ?: never ;
31+ textOnly ?: never ;
32+ }
33+
34+ type ProBadgeProps = ProBadgeWithContent | ProBadgeWithChildren | ProBadgeIconOnly ;
3235
3336const ProBadge = ( { children, content, size = 'regular' , textOnly } : ProBadgeProps ) => {
37+ const hasChildren = isDefined ( children ) ;
38+ const iconOnly = ! hasChildren && ! isDefined ( content ) ;
39+
40+ const icon = (
41+ < SVGIcon
42+ name = { size === 'tiny' ? 'crownRoundedSmall' : 'crownRounded' }
43+ width = { hasChildren ? ( size === 'tiny' ? badgeSizes [ size ] . iconSize : 16 ) : badgeSizes [ size ] . iconSize }
44+ height = { hasChildren ? undefined : badgeSizes [ size ] . iconSize }
45+ />
46+ ) ;
47+
3448 return (
35- < div css = { styles . wrapper ( { hasChildren : isDefined ( children ) , size } ) } >
49+ < div css = { styles . wrapper ( { hasChildren, iconOnly , size } ) } >
3650 { children }
37- < Show when = { ! isDefined ( children ) && ! textOnly } >
38- < SVGIcon
39- name = { size === 'tiny' ? 'crownRoundedSmall' : 'crownRounded' }
40- width = { badgeSizes [ size ] . iconSize }
41- height = { badgeSizes [ size ] . iconSize }
42- />
43- </ Show >
51+
52+ < Show when = { ! hasChildren && ! textOnly && ! iconOnly } > { icon } </ Show >
53+
4454 < div
4555 css = { styles . content ( {
46- hasChildren : isDefined ( children ) ,
56+ hasChildren,
57+ iconOnly,
4758 size,
4859 textOnly,
4960 } ) }
5061 >
51- { isDefined ( children ) ? (
52- < SVGIcon
53- name = { size === 'tiny' ? 'crownRoundedSmall' : 'crownRounded' }
54- width = { size === 'tiny' ? badgeSizes [ size ] . iconSize : 16 }
55- />
56- ) : (
57- content
58- ) }
62+ { hasChildren || iconOnly ? icon : content }
5963 </ div >
6064 </ div >
6165 ) ;
@@ -99,14 +103,23 @@ const badgeSizes = {
99103} ;
100104
101105const styles = {
102- wrapper : ( { hasChildren, size = 'regular' } : { hasChildren : boolean ; size ?: ProBadgeSize } ) => css `
106+ wrapper : ( {
107+ hasChildren,
108+ iconOnly,
109+ size = 'regular' ,
110+ } : {
111+ hasChildren : boolean ;
112+ iconOnly : boolean ;
113+ size ?: ProBadgeSize ;
114+ } ) => css `
103115 position : relative;
104116
105117 svg {
106118 flex-shrink : 0 ;
107119 }
108120
109121 ${ ! hasChildren &&
122+ ! iconOnly &&
110123 css `
111124 height : ${ badgeSizes [ size ] . height } ;
112125 display : inline-flex;
@@ -119,10 +132,12 @@ const styles = {
119132 ` ,
120133 content : ( {
121134 hasChildren,
135+ iconOnly,
122136 size = 'regular' ,
123137 textOnly,
124138 } : {
125139 hasChildren : boolean ;
140+ iconOnly : boolean ;
126141 size ?: ProBadgeSize ;
127142 textOnly ?: boolean ;
128143 } ) => css `
@@ -134,6 +149,7 @@ const styles = {
134149 transform : translateX (50% ) translateY (-50% );
135150
136151 ${ ! hasChildren &&
152+ ! iconOnly &&
137153 css `
138154 display : inline-flex;
139155 position : static;
@@ -151,5 +167,12 @@ const styles = {
151167 margin : 0 ;
152168 ` }
153169 ` }
170+
171+ ${ iconOnly &&
172+ css `
173+ position : static;
174+ transform : none;
175+ display : inline-flex;
176+ ` }
154177 ` ,
155178} ;
0 commit comments