@@ -19,59 +19,56 @@ const DxcChip = ({
1919
2020 return (
2121 < ThemeProvider theme = { colorsTheme . chip } >
22- < StyledDxcChip disabled = { disabled } margin = { margin } >
22+ < Chip disabled = { disabled } margin = { margin } >
2323 { prefixIcon && (
2424 < IconContainer
25+ role = { typeof onClickPrefix === "function" ? "button" : undefined }
2526 disabled = { disabled }
26- prefixIcon
27- label = { label }
27+ interactuable = { typeof onClickPrefix === "function" && ! disabled }
2828 tabIndex = { typeof onClickPrefix === "function" && ! disabled ? tabIndex : - 1 }
2929 onClick = { ( ) => onClickPrefix && ! disabled && onClickPrefix ( ) }
30- interactuable = { typeof onClickPrefix === "function" && ! disabled }
3130 >
3231 { typeof prefixIcon === "string" ? < img src = { prefixIcon } /> : prefixIcon }
3332 </ IconContainer >
3433 ) }
35- { label && < ChipTextContainer disabled = { disabled } > { label } </ ChipTextContainer > }
34+ { label && < LabelContainer disabled = { disabled } > { label } </ LabelContainer > }
3635 { suffixIcon && (
3736 < IconContainer
37+ role = { typeof onClickSuffix === "function" ? "button" : undefined }
3838 disabled = { disabled }
39- suffixIcon
40- label = { label }
41- tabIndex = { typeof onClickSuffix === "function" && ! disabled ? tabIndex : - 1 }
42- onClick = { ( ) => onClickSuffix && ! disabled && onClickSuffix ( ) }
4339 interactuable = { typeof onClickSuffix === "function" && ! disabled }
40+ tabIndex = { typeof onClickSuffix === "function" && ! disabled ? tabIndex : - 1 }
41+ onClick = { ( ) => ! disabled && onClickSuffix ?.( ) }
4442 >
4543 { typeof suffixIcon === "string" ? < img src = { suffixIcon } /> : suffixIcon }
4644 </ IconContainer >
4745 ) }
48- </ StyledDxcChip >
46+ </ Chip >
4947 </ ThemeProvider >
5048 ) ;
5149} ;
5250
53- const getCursor = ( interactuable , disabled ) => {
54- if ( disabled ) return "cursor: not-allowed;" ;
55- else if ( interactuable ) return "cursor: pointer;" ;
56- else return "cursor: default; outline:none;" ;
57- } ;
51+ const calculateWidth = ( margin : ChipPropsType [ "margin" ] ) =>
52+ `calc(100% - ${ getMargin ( margin , "left" ) } - ${ getMargin ( margin , "right" ) } )` ;
5853
59- const StyledDxcChip = styled . div < { margin : ChipPropsType [ "margin" ] ; disabled : ChipPropsType [ "disabled" ] } > `
54+ const Chip = styled . div < { margin : ChipPropsType [ "margin" ] ; disabled : ChipPropsType [ "disabled" ] } > `
55+ box-sizing: border-box;
6056 display: inline-flex;
6157 align-items: center;
58+ gap: ${ ( props ) => props . theme . iconSpacing } ;
6259 min-height: 40px;
63- max-width: ${ ( { margin } ) => `calc(100% - 40px - ${ getMargin ( margin , "left" ) } - ${ getMargin ( margin , "right" ) } )` } ;
60+ max-width: ${ ( props ) => calculateWidth ( props . margin ) } ;
6461 background-color: ${ ( props ) =>
6562 ( props . disabled && props . theme . disabledBackgroundColor ) || props . theme . backgroundColor } ;
6663 border-radius: ${ ( props ) => props . theme . borderRadius } ;
6764 border-width: ${ ( props ) => props . theme . borderThickness } ;
6865 border-style: ${ ( props ) => props . theme . borderStyle } ;
6966 border-color: ${ ( props ) => props . theme . borderColor } ;
67+
7068 padding-top: ${ ( props ) => props . theme . contentPaddingTop } ;
7169 padding-bottom: ${ ( props ) => props . theme . contentPaddingBottom } ;
7270 padding-left: ${ ( props ) => props . theme . contentPaddingLeft } ;
7371 padding-right: ${ ( props ) => props . theme . contentPaddingRight } ;
74-
7572 margin: ${ ( props ) => ( props . margin && typeof props . margin !== "object" ? spaces [ props . margin ] : "0px" ) } ;
7673 margin-top: ${ ( props ) =>
7774 props . margin && typeof props . margin === "object" && props . margin . top ? spaces [ props . margin . top ] : "" } ;
@@ -84,44 +81,41 @@ const StyledDxcChip = styled.div<{ margin: ChipPropsType["margin"]; disabled: Ch
8481 cursor: ${ ( { disabled } ) => disabled && "not-allowed" } ;
8582` ;
8683
87- const ChipTextContainer = styled . span < { disabled : ChipPropsType [ "disabled" ] } > `
84+ const LabelContainer = styled . span < { disabled : ChipPropsType [ "disabled" ] } > `
8885 font-size: ${ ( props ) => props . theme . fontSize } ;
8986 font-family: ${ ( props ) => props . theme . fontFamily } ;
9087 font-weight: ${ ( props ) => props . theme . fontWeight } ;
9188 font-style: ${ ( props ) => props . theme . fontStyle } ;
9289 color: ${ ( props ) => ( props . disabled ? props . theme . disabledFontColor : props . theme . fontColor ) } ;
93- cursor: ${ ( { disabled } ) => ( disabled && "not-allowed" ) || "default" } ;
9490 text-overflow: ellipsis;
9591 white-space: nowrap;
9692 overflow: hidden;
9793` ;
9894
9995const IconContainer = styled . div < {
100- prefixIcon ?: ChipPropsType [ "prefixIcon" ] ;
101- label : ChipPropsType [ "label" ] ;
102- suffixIcon ?: ChipPropsType [ "suffixIcon" ] ;
10396 disabled : ChipPropsType [ "disabled" ] ;
10497 interactuable : boolean ;
10598} > `
10699 display: flex;
107- ${ ( props ) =>
108- props . prefixIcon
109- ? `margin-right: ${ ( ( props . label || props . suffixIcon ) && props . theme . iconSpacing ) || ( props . prefixIcon && "0" ) } ;`
110- : `margin-left: ${ ( ( props . label || props . prefixIcon ) && props . theme . iconSpacing ) || ( props . prefixIcon && "0" ) } ;` }
100+ border-radius: 0.25rem;
111101 color: ${ ( props ) => ( props . disabled ? props . theme . disabledIconColor : props . theme . iconColor ) } ;
112- ${ ( props ) => getCursor ( props . interactuable , props . disabled ) }
102+ ${ ( { interactuable } ) => interactuable && "cursor: pointer;" }
103+
104+ ${ ( props ) =>
105+ props . interactuable &&
106+ `
107+ &:hover {
108+ color: ${ props . theme . hoverIconColor } ;
109+ }
110+ &:focus,
111+ &:focus-visible {
112+ outline: ${ props . theme . focusBorderThickness } solid ${ props . theme . focusColor } ;
113+ }
114+ &:active {
115+ color: ${ props . theme . activeIconColor } ;
116+ }
117+ ` }
113118
114- &:hover {
115- color: ${ ( props ) => ! props . disabled && props . theme . hoverIconColor } ;
116- }
117- &:focus {
118- outline-color: ${ ( props ) => ! props . disabled && props . theme . focusColor } ;
119- outline-width: ${ ( props ) => ! props . disabled && props . theme . focusBorderThickness } ;
120- ${ ( props ) => props . disabled && "outline: none;" }
121- }
122- &:active {
123- color: ${ ( props ) => ! props . disabled && props . theme . activeIconColor } ;
124- }
125119 img,
126120 svg {
127121 width: ${ ( props ) => props . theme . iconSize } ;
0 commit comments