File tree 3 files changed +79
-6
lines changed
src/components/CardHorizontal
3 files changed +79
-6
lines changed Original file line number Diff line number Diff line change @@ -13,5 +13,7 @@ export const Playground = {
13
13
description : "A description very interesting that presumably relates to the card." ,
14
14
disabled : false ,
15
15
isSelected : false ,
16
+ badgeText : null ,
17
+ badgeIcon : null ,
16
18
} ,
17
19
} ;
Original file line number Diff line number Diff line change @@ -13,9 +13,11 @@ describe("CardHorizontal Component", () => {
13
13
title,
14
14
icon : "warning" ,
15
15
description : "" ,
16
+ badgeText : "" ,
16
17
} ) ;
17
18
18
19
expect ( screen . getByText ( title ) ) . toBeDefined ( ) ;
20
+ expect ( screen . queryByTestId ( "horizontal-card-badge" ) ) . toBeNull ( ) ;
19
21
} ) ;
20
22
21
23
it ( "should render the description when provided" , ( ) => {
@@ -28,5 +30,29 @@ describe("CardHorizontal Component", () => {
28
30
29
31
expect ( screen . getByText ( description ) ) . toBeDefined ( ) ;
30
32
} ) ;
33
+
34
+ it ( "should render the badge when provided" , ( ) => {
35
+ const description = "This is the card description" ;
36
+ renderCard ( {
37
+ icon : "warning" ,
38
+ title : "title" ,
39
+ description,
40
+ badgeText : "Badge" ,
41
+ } ) ;
42
+
43
+ expect ( screen . getByText ( "title" ) ) . toBeDefined ( ) ;
44
+ expect ( screen . getByTestId ( "horizontal-card-badge" ) ) . toBeDefined ( ) ;
45
+ } ) ;
46
+ it ( "should not render the badge when badgeText is provided and not title" , ( ) => {
47
+ const description = "This is the card description" ;
48
+ renderCard ( {
49
+ icon : "warning" ,
50
+ title : "" ,
51
+ description,
52
+ badgeText : "Badge" ,
53
+ } ) ;
54
+
55
+ expect ( screen . queryByTestId ( "horizontal-card-badge" ) ) . toBeNull ( ) ;
56
+ } ) ;
31
57
} ) ;
32
58
} ) ;
Original file line number Diff line number Diff line change 1
1
import { HTMLAttributes , ReactNode } from "react" ;
2
2
import { styled } from "styled-components" ;
3
- import { Icon , IconName } from "@/components" ;
3
+ import {
4
+ Badge ,
5
+ BadgeState ,
6
+ Container ,
7
+ HorizontalDirection ,
8
+ Icon ,
9
+ IconName ,
10
+ } from "@/components" ;
4
11
5
12
type CardColor = "default" | "muted" ;
6
13
@@ -13,13 +20,13 @@ export interface CardHorizontalProps
13
20
isSelected ?: boolean ;
14
21
children ?: ReactNode ;
15
22
color ?: CardColor ;
23
+ badgeText ?: string ;
24
+ badgeState ?: BadgeState ;
25
+ badgeIcon ?: IconName ;
26
+ badgeIconDir ?: HorizontalDirection ;
16
27
}
17
28
18
29
const Header = styled . div `
19
- display: flex;
20
- flex-direction: column;
21
- align-items: start;
22
- width: 100%;
23
30
max-width: 100%;
24
31
gap: inherit;
25
32
` ;
@@ -136,6 +143,10 @@ export const CardHorizontal = ({
136
143
isSelected,
137
144
children,
138
145
color = "default" ,
146
+ badgeText,
147
+ badgeState,
148
+ badgeIcon,
149
+ badgeIconDir,
139
150
...props
140
151
} : CardHorizontalProps ) => {
141
152
return (
@@ -153,7 +164,41 @@ export const CardHorizontal = ({
153
164
/>
154
165
) }
155
166
< ContentWrapper >
156
- { title && < Header > { title } </ Header > }
167
+ { title && (
168
+ < Header
169
+ as = { Container }
170
+ isResponsive = { false }
171
+ gap = "xs"
172
+ justifyContent = "space-between"
173
+ fillWidth
174
+ >
175
+ < Container
176
+ orientation = "horizontal"
177
+ gap = "xs"
178
+ isResponsive = { false }
179
+ fillWidth = { false }
180
+ grow = "1"
181
+ >
182
+ { title }
183
+ </ Container >
184
+ { badgeText && (
185
+ < Container
186
+ isResponsive = { false }
187
+ justifyContent = "end"
188
+ fillWidth = { false }
189
+ data-testid = "horizontal-card-badge"
190
+ >
191
+ < Badge
192
+ text = { badgeText }
193
+ size = "md"
194
+ state = { badgeState }
195
+ icon = { badgeIcon }
196
+ iconDir = { badgeIconDir }
197
+ />
198
+ </ Container >
199
+ ) }
200
+ </ Header >
201
+ ) }
157
202
158
203
{ description && < Description > { description } </ Description > }
159
204
{ children && < Description > { children } </ Description > }
You can’t perform that action at this time.
0 commit comments