@thecb/components 11.8.0-beta.7 → 11.8.0-beta.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +11 -10
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +11 -10
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/molecules/tooltip/Tooltip.js +14 -13
- package/src/components/molecules/tooltip/Tooltip.stories.js +136 -96
- package/src/components/molecules/tooltip/index.d.ts +18 -18
package/package.json
CHANGED
|
@@ -60,7 +60,7 @@ const Tooltip = ({
|
|
|
60
60
|
|
|
61
61
|
const {
|
|
62
62
|
borderColor,
|
|
63
|
-
popoverTriggerColor,
|
|
63
|
+
popoverTriggerColor: tooltipTriggerColor,
|
|
64
64
|
hoverColor,
|
|
65
65
|
activeColor
|
|
66
66
|
} = themeValues;
|
|
@@ -107,25 +107,24 @@ const Tooltip = ({
|
|
|
107
107
|
ref={closeTimeoutRef}
|
|
108
108
|
padding="0"
|
|
109
109
|
extraStyles={`position: relative; ${containerExtraStyles}`}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
onMouseLeave={handleMouseLeave}
|
|
113
|
-
onKeyDown={handleKeyboardEvent}
|
|
110
|
+
onMouseEnter={() => handleMouseEnter(true)}
|
|
111
|
+
onMouseLeave={() => handleMouseLeave(false)}
|
|
114
112
|
data-qa="tooltip-container"
|
|
115
113
|
>
|
|
116
114
|
<ButtonWithAction
|
|
117
115
|
aria-describedby={tooltipID}
|
|
116
|
+
onKeyDown={handleKeyboardEvent}
|
|
118
117
|
variant={triggerButtonVariant}
|
|
119
118
|
onFocus={() => handleToggleTooltip(true)}
|
|
120
119
|
onBlur={() => handleToggleTooltip(false)}
|
|
121
120
|
onTouchStart={() => handleToggleTooltip(true)}
|
|
122
121
|
data-qa="tooltip-trigger"
|
|
123
|
-
contentOverride
|
|
122
|
+
contentOverride={true}
|
|
124
123
|
>
|
|
125
124
|
{hasIconTrigger === true && (
|
|
126
125
|
<>
|
|
127
126
|
<Box aria-label="Open tooltip">
|
|
128
|
-
<IconTrigger color={
|
|
127
|
+
<IconTrigger color={tooltipTriggerColor} />
|
|
129
128
|
</Box>
|
|
130
129
|
<Box padding="0" srOnly>
|
|
131
130
|
<Text>{iconHelpText}</Text>
|
|
@@ -134,15 +133,17 @@ const Tooltip = ({
|
|
|
134
133
|
)}
|
|
135
134
|
{hasIconTrigger === false && (
|
|
136
135
|
<Text
|
|
137
|
-
color={
|
|
136
|
+
color={tooltipTriggerColor}
|
|
138
137
|
extraStyles={`
|
|
138
|
+
color: ${tooltipTriggerColor};
|
|
139
139
|
&:visited {
|
|
140
|
-
color: ${
|
|
140
|
+
color: ${tooltipTriggerColor};
|
|
141
141
|
}
|
|
142
142
|
&:hover {
|
|
143
143
|
color: ${hoverColor};
|
|
144
144
|
}
|
|
145
|
-
&:active
|
|
145
|
+
&:active,
|
|
146
|
+
&:focus {
|
|
146
147
|
color: ${activeColor};
|
|
147
148
|
}
|
|
148
149
|
${triggerExtraStyles};
|
|
@@ -159,10 +160,10 @@ const Tooltip = ({
|
|
|
159
160
|
data-qa="tooltip-contents"
|
|
160
161
|
extraStyles={`
|
|
161
162
|
position: absolute;
|
|
162
|
-
display: ${tooltipOpen ? "block" : "none"};
|
|
163
|
+
display: ${tooltipOpen ? "block" : "none"};
|
|
163
164
|
top: ${top};
|
|
164
|
-
right: ${right};
|
|
165
|
-
bottom: ${bottom};
|
|
165
|
+
right: ${right};
|
|
166
|
+
bottom: ${bottom};
|
|
166
167
|
left: ${left};
|
|
167
168
|
height: ${height};
|
|
168
169
|
`}
|
|
@@ -1,52 +1,61 @@
|
|
|
1
|
+
import React from "react";
|
|
1
2
|
import Tooltip from "./Tooltip";
|
|
2
3
|
import WarningIconXS from "../../atoms/icons/WarningIconXS";
|
|
3
|
-
|
|
4
|
+
|
|
5
|
+
const meta = {
|
|
4
6
|
title: "Molecules/Tooltip",
|
|
5
7
|
component: Tooltip,
|
|
6
|
-
tags: ["!autodocs"],
|
|
7
8
|
parameters: {
|
|
8
|
-
layout: "centered"
|
|
9
|
-
controls: { expanded: true }
|
|
9
|
+
layout: "centered"
|
|
10
10
|
},
|
|
11
|
+
tags: ["!autodocs"],
|
|
12
|
+
decorators: [
|
|
13
|
+
Story => (
|
|
14
|
+
<div style={{ padding: "120px 300px" }}>
|
|
15
|
+
<Story />
|
|
16
|
+
</div>
|
|
17
|
+
)
|
|
18
|
+
],
|
|
11
19
|
args: {
|
|
12
|
-
|
|
13
|
-
tooltipContent: "",
|
|
20
|
+
tooltipID: "tooltip-id",
|
|
14
21
|
hasIconTrigger: false,
|
|
15
22
|
IconTrigger: WarningIconXS,
|
|
16
23
|
iconHelpText: "Open the tooltip",
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
24
|
+
triggerText: "Hover me",
|
|
25
|
+
tooltipContent: "The contents of the tooltip go here.",
|
|
26
|
+
contentPosition: {
|
|
27
|
+
top: "-110px",
|
|
28
|
+
right: "auto",
|
|
29
|
+
bottom: "auto",
|
|
30
|
+
left: "-225px"
|
|
31
|
+
},
|
|
32
|
+
arrowDirection: "down",
|
|
33
|
+
arrowPosition: {
|
|
34
|
+
arrowTop: "auto",
|
|
35
|
+
arrowRight: "10px",
|
|
36
|
+
arrowBottom: "-8px",
|
|
37
|
+
arrowLeft: "auto"
|
|
38
|
+
},
|
|
20
39
|
minWidth: "250px",
|
|
21
40
|
maxWidth: "300px",
|
|
22
41
|
height: "auto",
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
buttonExtraStyles: undefined,
|
|
27
|
-
backgroundColor: "white",
|
|
28
|
-
borderColor: "rgba(255, 255, 255, 0.85)",
|
|
29
|
-
contentExtraStyles: undefined
|
|
42
|
+
containerExtraStyles: "",
|
|
43
|
+
triggerExtraStyles: "",
|
|
44
|
+
triggerButtonVariant: "smallGhost"
|
|
30
45
|
},
|
|
31
46
|
argTypes: {
|
|
32
|
-
|
|
47
|
+
tooltipID: {
|
|
33
48
|
description:
|
|
34
|
-
"
|
|
49
|
+
"Unique ID linking the trigger to the tooltip content for accessibility",
|
|
35
50
|
table: {
|
|
36
51
|
type: { summary: "string" },
|
|
37
|
-
defaultValue: { summary:
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
tooltipContent: {
|
|
41
|
-
description: "Content of the tooltip",
|
|
42
|
-
table: {
|
|
43
|
-
type: { summary: "string" },
|
|
44
|
-
defaultValue: { summary: "" }
|
|
52
|
+
defaultValue: { summary: undefined }
|
|
45
53
|
}
|
|
46
54
|
},
|
|
47
55
|
hasIconTrigger: {
|
|
48
56
|
description:
|
|
49
|
-
"
|
|
57
|
+
"When true, renders an icon as the tooltip trigger instead of text",
|
|
58
|
+
control: { type: "boolean" },
|
|
50
59
|
table: {
|
|
51
60
|
type: { summary: "boolean" },
|
|
52
61
|
defaultValue: { summary: false }
|
|
@@ -54,142 +63,173 @@ export default {
|
|
|
54
63
|
},
|
|
55
64
|
IconTrigger: {
|
|
56
65
|
description:
|
|
57
|
-
"
|
|
66
|
+
"Icon component rendered as the trigger when hasIconTrigger is true",
|
|
58
67
|
table: {
|
|
59
68
|
type: { summary: "React Component" },
|
|
60
69
|
defaultValue: { summary: "WarningIconXS" }
|
|
61
70
|
}
|
|
62
71
|
},
|
|
63
72
|
iconHelpText: {
|
|
64
|
-
description: "
|
|
73
|
+
description: "Screen reader text for the icon trigger",
|
|
65
74
|
table: {
|
|
66
75
|
type: { summary: "string" },
|
|
67
76
|
defaultValue: { summary: "Open the tooltip" }
|
|
68
77
|
}
|
|
69
78
|
},
|
|
70
|
-
|
|
79
|
+
triggerText: {
|
|
71
80
|
description:
|
|
72
|
-
"
|
|
81
|
+
"Text rendered as the tooltip trigger when hasIconTrigger is false",
|
|
82
|
+
table: {
|
|
83
|
+
type: { summary: "string | JSX.Element" },
|
|
84
|
+
defaultValue: { summary: "Open the tooltip" }
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
tooltipContent: {
|
|
88
|
+
description: "The content displayed inside the tooltip",
|
|
73
89
|
table: {
|
|
74
90
|
type: { summary: "string" },
|
|
75
|
-
defaultValue: { summary: "tooltip
|
|
91
|
+
defaultValue: { summary: "The contents of the tooltip go here." }
|
|
76
92
|
}
|
|
77
93
|
},
|
|
78
|
-
|
|
94
|
+
contentPosition: {
|
|
79
95
|
description:
|
|
80
|
-
"
|
|
96
|
+
"CSS position values (top, right, bottom, left) for the tooltip content box relative to the trigger",
|
|
81
97
|
table: {
|
|
82
|
-
type: { summary: "
|
|
83
|
-
defaultValue: {
|
|
98
|
+
type: { summary: "object" },
|
|
99
|
+
defaultValue: {
|
|
100
|
+
summary: `{ top: "-110px", right: "auto", bottom: "auto", left: "-225px" }`
|
|
101
|
+
}
|
|
84
102
|
}
|
|
85
103
|
},
|
|
86
|
-
|
|
87
|
-
description: "
|
|
104
|
+
arrowDirection: {
|
|
105
|
+
description: "Direction the tooltip arrow points (up, down, left, right)",
|
|
106
|
+
control: { type: "select" },
|
|
107
|
+
options: ["up", "down", "left", "right"],
|
|
88
108
|
table: {
|
|
89
|
-
type: { summary: "
|
|
90
|
-
defaultValue: { summary:
|
|
109
|
+
type: { summary: "string" },
|
|
110
|
+
defaultValue: { summary: "down" }
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
arrowPosition: {
|
|
114
|
+
description:
|
|
115
|
+
"CSS position values (arrowTop, arrowRight, arrowBottom, arrowLeft) for the arrow element",
|
|
116
|
+
table: {
|
|
117
|
+
type: { summary: "object" },
|
|
118
|
+
defaultValue: {
|
|
119
|
+
summary: `{ arrowTop: "auto", arrowRight: "10px", arrowBottom: "-8px", arrowLeft: "auto" }`
|
|
120
|
+
}
|
|
91
121
|
}
|
|
92
122
|
},
|
|
93
123
|
minWidth: {
|
|
94
|
-
description: "Minimum width of the tooltip
|
|
124
|
+
description: "Minimum width of the tooltip content box",
|
|
95
125
|
table: {
|
|
96
126
|
type: { summary: "string" },
|
|
97
127
|
defaultValue: { summary: "250px" }
|
|
98
128
|
}
|
|
99
129
|
},
|
|
100
130
|
maxWidth: {
|
|
101
|
-
description: "Maximum width of the tooltip
|
|
131
|
+
description: "Maximum width of the tooltip content box",
|
|
102
132
|
table: {
|
|
103
133
|
type: { summary: "string" },
|
|
104
134
|
defaultValue: { summary: "300px" }
|
|
105
135
|
}
|
|
106
136
|
},
|
|
107
137
|
height: {
|
|
108
|
-
description: "Height of the tooltip
|
|
138
|
+
description: "Height of the tooltip content box",
|
|
109
139
|
table: {
|
|
110
140
|
type: { summary: "string" },
|
|
111
141
|
defaultValue: { summary: "auto" }
|
|
112
142
|
}
|
|
113
143
|
},
|
|
114
|
-
|
|
144
|
+
containerExtraStyles: {
|
|
115
145
|
description:
|
|
116
|
-
"
|
|
117
|
-
table: {
|
|
118
|
-
type: { summary: "Object" },
|
|
119
|
-
defaultValue: { summary: undefined }
|
|
120
|
-
}
|
|
121
|
-
},
|
|
122
|
-
arrowPosition: {
|
|
123
|
-
description:
|
|
124
|
-
"Object containing values for arrowTop/arrowRight/arrowBottom/arrowLeft position of arrow on tooltip",
|
|
125
|
-
table: {
|
|
126
|
-
type: { summary: "Object" },
|
|
127
|
-
defaultValue: { summary: undefined }
|
|
128
|
-
}
|
|
129
|
-
},
|
|
130
|
-
arrowDirection: {
|
|
131
|
-
description: "Direction the tooltip arrow points",
|
|
146
|
+
"Additional CSS string applied to the tooltip container element",
|
|
132
147
|
table: {
|
|
133
148
|
type: { summary: "string" },
|
|
134
|
-
defaultValue: { summary: "
|
|
149
|
+
defaultValue: { summary: '""' }
|
|
135
150
|
}
|
|
136
151
|
},
|
|
137
|
-
|
|
138
|
-
description:
|
|
139
|
-
"Extra styles to apply to the button that wraps tooltip trigger",
|
|
152
|
+
triggerExtraStyles: {
|
|
153
|
+
description: "Additional CSS string applied to the text trigger element",
|
|
140
154
|
table: {
|
|
141
155
|
type: { summary: "string" },
|
|
142
|
-
defaultValue: { summary:
|
|
156
|
+
defaultValue: { summary: '""' }
|
|
143
157
|
}
|
|
144
158
|
},
|
|
145
|
-
|
|
146
|
-
description:
|
|
147
|
-
|
|
148
|
-
type: { summary: "string" },
|
|
149
|
-
defaultValue: { summary: "white" }
|
|
150
|
-
}
|
|
151
|
-
},
|
|
152
|
-
borderColor: {
|
|
153
|
-
description: "Color of the tooltip arrow",
|
|
154
|
-
table: {
|
|
155
|
-
type: { summary: "string" },
|
|
156
|
-
defaultValue: { summary: "rgba(255, 255, 255, 0.85)" }
|
|
157
|
-
}
|
|
158
|
-
},
|
|
159
|
-
contentExtraStyles: {
|
|
160
|
-
description: "Extra styles to apply to the tooltip content box",
|
|
159
|
+
triggerButtonVariant: {
|
|
160
|
+
description:
|
|
161
|
+
"Button variant applied to the trigger ButtonWithAction element",
|
|
161
162
|
table: {
|
|
162
163
|
type: { summary: "string" },
|
|
163
|
-
defaultValue: { summary:
|
|
164
|
+
defaultValue: { summary: "smallGhost" }
|
|
164
165
|
}
|
|
165
166
|
}
|
|
166
167
|
}
|
|
167
168
|
};
|
|
168
169
|
|
|
169
|
-
export
|
|
170
|
+
export default meta;
|
|
171
|
+
|
|
172
|
+
export const Basic = {
|
|
170
173
|
args: {
|
|
171
|
-
|
|
174
|
+
tooltipID: "tooltip-basic",
|
|
175
|
+
triggerText: "How basic is this?",
|
|
172
176
|
tooltipContent:
|
|
173
|
-
"
|
|
177
|
+
"This is a detailed explanation of a feature or term that the user may need more context about."
|
|
174
178
|
}
|
|
175
179
|
};
|
|
176
180
|
|
|
177
|
-
export const
|
|
181
|
+
export const TooltipBelow = {
|
|
178
182
|
args: {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
+
tooltipID: "tooltip-below",
|
|
184
|
+
contentPosition: {
|
|
185
|
+
top: "50px",
|
|
186
|
+
right: "auto",
|
|
187
|
+
bottom: "auto",
|
|
188
|
+
left: "-225px"
|
|
189
|
+
},
|
|
190
|
+
arrowDirection: "up",
|
|
191
|
+
arrowPosition: {
|
|
192
|
+
arrowTop: "-8px",
|
|
193
|
+
arrowRight: "10px",
|
|
194
|
+
arrowBottom: "auto",
|
|
195
|
+
arrowLeft: "auto"
|
|
196
|
+
}
|
|
183
197
|
}
|
|
184
198
|
};
|
|
185
199
|
|
|
186
|
-
export const
|
|
200
|
+
export const TooltipRight = {
|
|
187
201
|
args: {
|
|
188
|
-
|
|
202
|
+
tooltipID: "tooltip-right",
|
|
203
|
+
contentPosition: {
|
|
204
|
+
top: "-40px",
|
|
205
|
+
right: "auto",
|
|
206
|
+
bottom: "auto",
|
|
207
|
+
left: "calc(100% + 12px)"
|
|
208
|
+
},
|
|
209
|
+
arrowDirection: "left",
|
|
210
|
+
arrowPosition: {
|
|
211
|
+
arrowTop: "50%",
|
|
212
|
+
arrowRight: "auto",
|
|
213
|
+
arrowBottom: "auto",
|
|
214
|
+
arrowLeft: "-8px"
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
export const CustomContent = {
|
|
220
|
+
args: {
|
|
221
|
+
tooltipID: "tooltip-custom-content",
|
|
222
|
+
triggerText: "What is this?",
|
|
189
223
|
tooltipContent:
|
|
190
|
-
"
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
224
|
+
"This is a detailed explanation of a feature or term that the user may need more context about."
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
export const CustomWidth = {
|
|
229
|
+
args: {
|
|
230
|
+
tooltipID: "tooltip-custom-width",
|
|
231
|
+
minWidth: "150px",
|
|
232
|
+
maxWidth: "200px",
|
|
233
|
+
tooltipContent: "A narrower tooltip."
|
|
194
234
|
}
|
|
195
235
|
};
|
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import Expand from "../../../util/expand";
|
|
3
|
-
|
|
4
3
|
export interface TooltipProps {
|
|
4
|
+
tooltipID: string;
|
|
5
|
+
hasIconTrigger?: boolean;
|
|
6
|
+
IconTrigger?: React.FC<React.SVGProps<SVGSVGElement>>;
|
|
7
|
+
iconHelpText?: string;
|
|
5
8
|
triggerText?: string | JSX.Element;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
tooltipContent: string;
|
|
10
|
+
contentPosition?: {
|
|
11
|
+
top: string;
|
|
12
|
+
right: string;
|
|
13
|
+
bottom: string;
|
|
14
|
+
left: string;
|
|
15
|
+
};
|
|
16
|
+
arrowDirection?: string;
|
|
13
17
|
arrowPosition?: {
|
|
14
18
|
arrowTop: string;
|
|
15
19
|
arrowRight: string;
|
|
16
20
|
arrowBottom: string;
|
|
17
21
|
arrowLeft: string;
|
|
18
22
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
iconHelpText?: string;
|
|
26
|
-
iconColor?: string;
|
|
27
|
-
tooltipID: string;
|
|
28
|
-
tooltipContentExtraStyles?: string;
|
|
23
|
+
minWidth?: string;
|
|
24
|
+
maxWidth?: string;
|
|
25
|
+
height?: string;
|
|
26
|
+
containerExtraStyles?: string;
|
|
27
|
+
triggerExtraStyles?: string;
|
|
28
|
+
triggerButtonVariant?: string;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
export const Tooltip: React.FC<Expand<TooltipProps> &
|