1- import { useContext , useState } from "react" ;
2- import styled , { ThemeProvider } from "styled-components" ;
1+ import { useState } from "react" ;
2+ import styled from "styled-components" ;
33import { spaces } from "../common/variables" ;
44import CardPropsType from "./types" ;
5- import HalstackContext from "../HalstackContext" ;
65
76const Card = styled . div < {
87 hasAction : boolean ;
98 margin : CardPropsType [ "margin" ] ;
109 shadowDepth : 0 | 1 | 2 ;
1110} > `
1211 display: flex;
13- cursor: ${ ( { hasAction } ) => ( hasAction && "pointer" ) || "unset" } ;
12+ cursor: ${ ( { hasAction } ) => ( hasAction ? "pointer" : "unset" ) } ;
1413 outline: ${ ( { hasAction } ) => ! hasAction && "none" } ;
1514 margin: ${ ( { margin } ) => ( margin && typeof margin !== "object" ? spaces [ margin ] : "0px" ) } ;
1615 margin-top: ${ ( { margin } ) => ( margin && typeof margin === "object" && margin . top ? spaces [ margin . top ] : "" ) } ;
@@ -22,9 +21,9 @@ const Card = styled.div<{
2221 ${ ( { hasAction } ) =>
2322 hasAction &&
2423 `:focus {
25- border-radius: var(--border-radius-s);
26- outline: var(--border-width-m) solid var(--border-color-secondary-medium);
24+ outline: var(--border-width-m) var(--border-style-default) var(--border-color-secondary-medium);
2725 }` }
26+ border-radius: var(--border-radius-s);
2827 box-shadow: ${ ( { shadowDepth } ) =>
2928 shadowDepth === 1
3029 ? "var(--shadow-low-x-position) var(--shadow-low-y-position) var(--shadow-low-blur) var(--shadow-low-spread) var(--shadow-dark)"
@@ -38,7 +37,7 @@ const CardContainer = styled.div<{
3837 imagePosition : CardPropsType [ "imagePosition" ] | "none" ;
3938} > `
4039 display: flex;
41- flex-direction: ${ ( props ) => ( props . imagePosition === "after" ? "row-reverse" : "row" ) } ;
40+ flex-direction: ${ ( { imagePosition } ) => ( imagePosition === "after" ? "row-reverse" : "row" ) } ;
4241 height: 220px;
4342 width: 400px;
4443 &:hover {
@@ -60,7 +59,7 @@ const TagImage = styled.img<{ imagePadding: CardPropsType["imagePadding"]; image
6059
6160const ImageContainer = styled . div < { imageBgColor : CardPropsType [ "imageBgColor" ] } > `
6261 align-items: center;
63- background-color: ${ ( { imageBgColor } ) => imageBgColor } ;
62+ background-color: ${ ( { imageBgColor } ) => imageBgColor ?? "transparent" } ;
6463 display: flex;
6564 flex-shrink: 0;
6665 height: 100%;
@@ -74,14 +73,14 @@ const CardContent = styled.div`
7473 display: flex;
7574 flex-direction: column;
7675 flex-shrink: 0;
77- gap: var(--spacing-gap-ml, 16px );
76+ gap: var(--spacing-gap-ml);
7877 overflow: hidden;
7978 padding: var(--spacing-padding-l);
8079` ;
8180
8281const DxcCard = ( {
8382 imageSrc,
84- imageBgColor = "black" ,
83+ imageBgColor,
8584 imagePadding,
8685 imagePosition = "before" ,
8786 linkHref,
@@ -91,33 +90,30 @@ const DxcCard = ({
9190 tabIndex = 0 ,
9291 outlined = true ,
9392 children,
94- } : CardPropsType ) : JSX . Element => {
95- const colorsTheme = useContext ( HalstackContext ) ;
93+ } : CardPropsType ) => {
9694 const [ isHovered , changeIsHovered ] = useState ( false ) ;
9795
9896 return (
99- < ThemeProvider theme = { colorsTheme . card } >
100- < Card
101- hasAction = { onClick || linkHref ? true : false }
102- margin = { margin }
103- onMouseEnter = { ( ) => changeIsHovered ( true ) }
104- onMouseLeave = { ( ) => changeIsHovered ( false ) }
105- onClick = { onClick }
106- tabIndex = { onClick || linkHref ? tabIndex : - 1 }
107- as = { linkHref && "a" }
108- href = { linkHref }
109- shadowDepth = { ! outlined ? 0 : isHovered && ( onClick || linkHref ) ? 2 : 1 }
110- >
111- < CardContainer hasAction = { onClick || linkHref ? true : false } imagePosition = { imageSrc ? imagePosition : "none" } >
112- { imageSrc && (
113- < ImageContainer imageBgColor = { imageBgColor } >
114- < TagImage imagePadding = { imagePadding } imageCover = { imageCover } src = { imageSrc } alt = "Card image" />
115- </ ImageContainer >
116- ) }
117- < CardContent > { children } </ CardContent >
118- </ CardContainer >
119- </ Card >
120- </ ThemeProvider >
97+ < Card
98+ hasAction = { ! ! ( onClick || linkHref ) }
99+ margin = { margin }
100+ onMouseEnter = { ( ) => changeIsHovered ( true ) }
101+ onMouseLeave = { ( ) => changeIsHovered ( false ) }
102+ onClick = { onClick }
103+ tabIndex = { onClick || linkHref ? tabIndex : - 1 }
104+ as = { linkHref && "a" }
105+ href = { linkHref }
106+ shadowDepth = { ! outlined ? 0 : isHovered && ( onClick || linkHref ) ? 2 : 1 }
107+ >
108+ < CardContainer hasAction = { onClick || linkHref ? true : false } imagePosition = { imageSrc ? imagePosition : "none" } >
109+ { imageSrc && (
110+ < ImageContainer imageBgColor = { imageBgColor } >
111+ < TagImage imagePadding = { imagePadding } imageCover = { imageCover } src = { imageSrc } alt = "Card image" />
112+ </ ImageContainer >
113+ ) }
114+ < CardContent > { children } </ CardContent >
115+ </ CardContainer >
116+ </ Card >
121117 ) ;
122118} ;
123119
0 commit comments