Skip to content

Commit 9aa1ebf

Browse files
committed
Added DxcTooltip to button component
1 parent c2b6ec9 commit 9aa1ebf

File tree

2 files changed

+43
-42
lines changed

2 files changed

+43
-42
lines changed

lib/src/button/Button.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ describe("Button component tests", () => {
2222

2323
const button = getByRole("button");
2424
expect(button.getAttribute("aria-label")).toBe("Go home");
25-
expect(button.getAttribute("title")).toBe("Go home");
2625
expect(button.getAttribute("tabindex")).toBe("1");
2726
});
2827
});

lib/src/button/Button.tsx

Lines changed: 43 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { getMargin } from "../common/utils";
55
import useTheme from "../useTheme";
66
import ButtonPropsType from "./types";
77
import DxcIcon from "../icon/Icon";
8+
import DxcTooltip from "../tooltip/Tooltip";
89

910
const DxcButton = ({
1011
label = "",
@@ -23,25 +24,26 @@ const DxcButton = ({
2324

2425
return (
2526
<ThemeProvider theme={colorsTheme.button}>
26-
<Button
27-
aria-label={title}
28-
disabled={disabled}
29-
onClick={() => {
30-
onClick();
31-
}}
32-
tabIndex={disabled ? -1 : tabIndex}
33-
title={title}
34-
type={type}
35-
$mode={mode !== "primary" && mode !== "secondary" && mode !== "text" ? "primary" : mode}
36-
hasLabel={label ? true : false}
37-
hasIcon={icon ? true : false}
38-
iconPosition={iconPosition}
39-
size={size}
40-
margin={margin}
41-
>
42-
{label && <LabelContainer>{label}</LabelContainer>}
43-
{icon && <IconContainer>{typeof icon === "string" ? <DxcIcon icon={icon} /> : icon}</IconContainer>}
44-
</Button>
27+
<DxcTooltip label={title}>
28+
<Button
29+
aria-label={title}
30+
disabled={disabled}
31+
onClick={() => {
32+
onClick();
33+
}}
34+
tabIndex={disabled ? -1 : tabIndex}
35+
type={type}
36+
$mode={mode !== "primary" && mode !== "secondary" && mode !== "text" ? "primary" : mode}
37+
hasLabel={label ? true : false}
38+
hasIcon={icon ? true : false}
39+
iconPosition={iconPosition}
40+
size={size}
41+
margin={margin}
42+
>
43+
{label && <LabelContainer>{label}</LabelContainer>}
44+
{icon && <IconContainer>{typeof icon === "string" ? <DxcIcon icon={icon} /> : icon}</IconContainer>}
45+
</Button>
46+
</DxcTooltip>
4547
</ThemeProvider>
4648
);
4749
};
@@ -65,29 +67,29 @@ const getButtonStyles = ($mode: ButtonPropsType["mode"], theme: AdvancedTheme["b
6567
$mode === "primary"
6668
? theme.primaryBorderRadius
6769
: $mode === "secondary"
68-
? theme.secondaryBorderRadius
69-
: theme.textBorderRadius
70+
? theme.secondaryBorderRadius
71+
: theme.textBorderRadius
7072
};
7173
border-width: ${
7274
$mode === "primary"
7375
? theme.primaryBorderThickness
7476
: $mode === "secondary"
75-
? theme.secondaryBorderThickness
76-
: theme.textBorderThickness
77+
? theme.secondaryBorderThickness
78+
: theme.textBorderThickness
7779
};
7880
border-style: ${
7981
$mode === "primary"
8082
? theme.primaryBorderStyle
8183
: $mode === "secondary"
82-
? theme.secondaryBorderStyle
83-
: theme.textBorderStyle
84+
? theme.secondaryBorderStyle
85+
: theme.textBorderStyle
8486
};
8587
font-family: ${
8688
$mode === "primary"
8789
? theme.primaryFontFamily
8890
: $mode === "secondary"
89-
? theme.secondaryFontFamily
90-
: theme.textFontFamily
91+
? theme.secondaryFontFamily
92+
: theme.textFontFamily
9193
};
9294
font-size: ${
9395
$mode === "primary" ? theme.primaryFontSize : $mode === "secondary" ? theme.secondaryFontSize : theme.textFontSize
@@ -96,22 +98,22 @@ const getButtonStyles = ($mode: ButtonPropsType["mode"], theme: AdvancedTheme["b
9698
$mode === "primary"
9799
? theme.primaryFontWeight
98100
: $mode === "secondary"
99-
? theme.secondaryFontWeight
100-
: theme.textFontWeight
101+
? theme.secondaryFontWeight
102+
: theme.textFontWeight
101103
};
102104
background-color: ${
103105
$mode === "primary"
104106
? theme.primaryBackgroundColor
105107
: $mode === "secondary"
106-
? theme.secondaryBackgroundColor
107-
: theme.textBackgroundColor
108+
? theme.secondaryBackgroundColor
109+
: theme.textBackgroundColor
108110
};
109111
color: ${
110112
$mode === "primary"
111113
? theme.primaryFontColor
112114
: $mode === "secondary"
113-
? theme.secondaryFontColor
114-
: theme.textFontColor
115+
? theme.secondaryFontColor
116+
: theme.textFontColor
115117
};
116118
`;
117119

@@ -125,8 +127,8 @@ const getButtonStates = (
125127
$mode === "primary"
126128
? theme.primaryHoverBackgroundColor
127129
: $mode === "secondary"
128-
? theme.secondaryHoverBackgroundColor
129-
: theme.textHoverBackgroundColor
130+
? theme.secondaryHoverBackgroundColor
131+
: theme.textHoverBackgroundColor
130132
};
131133
color: ${$mode === "secondary" ? theme.secondaryHoverFontColor : ""};
132134
}
@@ -138,8 +140,8 @@ const getButtonStates = (
138140
$mode === "primary"
139141
? theme.primaryActiveBackgroundColor
140142
: $mode === "secondary"
141-
? theme.secondaryActiveBackgroundColor
142-
: theme.textActiveBackgroundColor
143+
? theme.secondaryActiveBackgroundColor
144+
: theme.textActiveBackgroundColor
143145
};
144146
color: ${$mode === "secondary" ? theme.secondaryHoverFontColor : ""};
145147
border-color: ${$mode === "secondary" ? "transparent" : ""};
@@ -152,15 +154,15 @@ const getButtonStates = (
152154
$mode === "primary"
153155
? theme.primaryDisabledBackgroundColor
154156
: $mode === "secondary"
155-
? theme.secondaryDisabledBackgroundColor
156-
: theme.textDisabledBackgroundColor
157+
? theme.secondaryDisabledBackgroundColor
158+
: theme.textDisabledBackgroundColor
157159
};
158160
color: ${
159161
$mode === "primary"
160162
? theme.primaryDisabledFontColor
161163
: $mode === "secondary"
162-
? theme.secondaryDisabledFontColor
163-
: theme.textDisabledFontColor
164+
? theme.secondaryDisabledFontColor
165+
: theme.textDisabledFontColor
164166
};
165167
border-color: ${$mode === "secondary" ? theme.secondaryDisabledBorderColor : ""};
166168
}

0 commit comments

Comments
 (0)