@thecb/components 11.8.0-beta.4 → 11.8.0-beta.5
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 +22 -37
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +22 -37
- package/dist/index.esm.js.map +1 -1
- package/package.json +3 -3
- package/src/components/molecules/popover/Popover.js +1 -15
- package/src/components/molecules/tooltip/Tooltip.js +10 -19
- package/src/components/molecules/tooltip/Tooltip.mdx +1 -1
- package/src/components/molecules/tooltip/Tooltip.stories.js +15 -15
- package/src/components/molecules/tooltip/index.d.ts +6 -5
- package/src/components/templates/sidebar-stack-content/SidebarStackContent.js +1 -1
- package/src/util/general.js +14 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thecb/components",
|
|
3
|
-
"version": "11.8.0-beta.
|
|
3
|
+
"version": "11.8.0-beta.5",
|
|
4
4
|
"description": "Common lib for CityBase react components",
|
|
5
5
|
"main": "dist/index.cjs.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -81,8 +81,8 @@
|
|
|
81
81
|
"vite": "^5.2.11"
|
|
82
82
|
},
|
|
83
83
|
"peerDependencies": {
|
|
84
|
-
"react": "^16.13.1",
|
|
85
|
-
"react-dom": "^16.13.1",
|
|
84
|
+
"react": "^16.13.1 || ^17.0.0",
|
|
85
|
+
"react-dom": "^16.13.1 || ^17.0.0",
|
|
86
86
|
"react-router-dom": "^6.3.0",
|
|
87
87
|
"styled-components": "^5.1.1",
|
|
88
88
|
"styled-theming": "^2.2.0"
|
|
@@ -5,24 +5,10 @@ import Paragraph from "../../atoms/paragraph";
|
|
|
5
5
|
import { Box } from "../../atoms/layouts";
|
|
6
6
|
import ButtonWithAction from "../../atoms/button-with-action";
|
|
7
7
|
import { useOutsideClick } from "../../../hooks";
|
|
8
|
-
import { noop } from "../../../util/general";
|
|
8
|
+
import { noop, arrowBorder } from "../../../util/general";
|
|
9
9
|
import { ESCAPE } from "../../../constants/keyboard";
|
|
10
10
|
import { fallbackValues } from "./Popover.theme";
|
|
11
11
|
|
|
12
|
-
const arrowBorder = (borderColor, direction, width = "8px") => {
|
|
13
|
-
const angle = `${width} solid transparent`;
|
|
14
|
-
const straight = `${width} solid ${borderColor}`;
|
|
15
|
-
if (direction == "down") {
|
|
16
|
-
return `border-left: ${angle}; border-right: ${angle}; border-top: ${straight}`;
|
|
17
|
-
} else if (direction == "up") {
|
|
18
|
-
return `border-left: ${angle}; border-right: ${angle}; border-bottom: ${straight}`;
|
|
19
|
-
} else if (direction == "left") {
|
|
20
|
-
return `border-top: ${angle}; border-bottom: ${angle}; border-right: ${straight}`;
|
|
21
|
-
} else if (direction == "right") {
|
|
22
|
-
return `border-top: ${angle}; border-bottom: ${angle}; border-left: ${straight}`;
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
|
|
26
12
|
const Popover = ({
|
|
27
13
|
themeValues,
|
|
28
14
|
triggerText = "",
|
|
@@ -4,26 +4,12 @@ import Text from "../../atoms/text";
|
|
|
4
4
|
import Paragraph from "../../atoms/paragraph";
|
|
5
5
|
import { Box } from "../../atoms/layouts";
|
|
6
6
|
import ButtonWithAction from "../../atoms/button-with-action";
|
|
7
|
-
import { noop } from "../../../util/general";
|
|
7
|
+
import { noop, arrowBorder } from "../../../util/general";
|
|
8
8
|
import { ESCAPE } from "../../../constants/keyboard";
|
|
9
9
|
import { fallbackValues } from "./Tooltip.theme";
|
|
10
10
|
import WarningIconXS from "../../atoms/icons/WarningIconXS";
|
|
11
11
|
import { SELECTIVE_YELLOW } from "../../../constants/colors";
|
|
12
12
|
|
|
13
|
-
const arrowBorder = (borderColor, direction, width = "8px") => {
|
|
14
|
-
const angle = `${width} solid transparent`;
|
|
15
|
-
const straight = `${width} solid ${borderColor}`;
|
|
16
|
-
if (direction == "down") {
|
|
17
|
-
return `border-left: ${angle}; border-right: ${angle}; border-top: ${straight}`;
|
|
18
|
-
} else if (direction == "up") {
|
|
19
|
-
return `border-left: ${angle}; border-right: ${angle}; border-bottom: ${straight}`;
|
|
20
|
-
} else if (direction == "left") {
|
|
21
|
-
return `border-top: ${angle}; border-bottom: ${angle}; border-right: ${straight}`;
|
|
22
|
-
} else if (direction == "right") {
|
|
23
|
-
return `border-top: ${angle}; border-bottom: ${angle}; border-left: ${straight}`;
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
|
|
27
13
|
const Tooltip = ({
|
|
28
14
|
themeValues,
|
|
29
15
|
triggerText = "",
|
|
@@ -69,7 +55,7 @@ const Tooltip = ({
|
|
|
69
55
|
};
|
|
70
56
|
|
|
71
57
|
const handleKeyboardEvent = e => {
|
|
72
|
-
if (e.
|
|
58
|
+
if (e.key === ESCAPE) {
|
|
73
59
|
handleToggleTooltip(false);
|
|
74
60
|
}
|
|
75
61
|
};
|
|
@@ -93,16 +79,21 @@ const Tooltip = ({
|
|
|
93
79
|
>
|
|
94
80
|
{hasIconTrigger && (
|
|
95
81
|
<>
|
|
96
|
-
<Box aria-label="
|
|
82
|
+
<Box aria-label="Open tooltip">
|
|
97
83
|
<IconTrigger color={iconColor} />
|
|
98
84
|
</Box>
|
|
99
|
-
<Box padding="0" srOnly
|
|
85
|
+
<Box padding="0" srOnly>
|
|
100
86
|
<Text>{iconHelpText}</Text>
|
|
101
87
|
</Box>
|
|
102
88
|
</>
|
|
103
89
|
)}
|
|
104
90
|
{!hasIconTrigger && (
|
|
105
|
-
<Text
|
|
91
|
+
<Text
|
|
92
|
+
extraStyles={`color: ${tooltipTriggerColor}; &:hover {
|
|
93
|
+
${hoverColor}; &:active ${activeColor}; ${textExtraStyles}`}
|
|
94
|
+
>
|
|
95
|
+
{triggerText}
|
|
96
|
+
</Text>
|
|
106
97
|
)}
|
|
107
98
|
</ButtonWithAction>
|
|
108
99
|
<Box
|
|
@@ -6,7 +6,7 @@ import * as TooltipStories from './Tooltip.stories.js';
|
|
|
6
6
|
|
|
7
7
|
<Title />
|
|
8
8
|
|
|
9
|
-
The Tooltip is a fully accessible tooltip widget that displays additional information when a user hovers over or focuses on a specified trigger element. The trigger can either be text supplied using the `triggerText` prop, or a custom Icon component supplied using the `
|
|
9
|
+
The Tooltip is a fully accessible tooltip widget that displays additional information when a user hovers over or focuses on a specified trigger element. The trigger can either be text supplied using the `triggerText` prop, or a custom Icon component supplied using the `IconTrigger` prop. The trigger is rendered as a `ButtonWithAction` with the `smallGhost` variant.
|
|
10
10
|
|
|
11
11
|
The Tooltip uses the WAI-ARIA tooltip pattern (`role="tooltip"` and `aria-describedby`) for accessibility. It can be positioned anywhere around the trigger element using the position props. Content and style of the tooltip are customizable.
|
|
12
12
|
|
|
@@ -14,7 +14,8 @@ export default {
|
|
|
14
14
|
hasIconTrigger: false,
|
|
15
15
|
IconTrigger: WarningIconXS,
|
|
16
16
|
iconHelpText: "",
|
|
17
|
-
|
|
17
|
+
iconColor: undefined,
|
|
18
|
+
tooltipID: "tooltip-content",
|
|
18
19
|
extraStyles: undefined,
|
|
19
20
|
textExtraStyles: undefined,
|
|
20
21
|
minWidth: "250px",
|
|
@@ -23,16 +24,15 @@ export default {
|
|
|
23
24
|
position: undefined,
|
|
24
25
|
arrowPosition: undefined,
|
|
25
26
|
arrowDirection: "down",
|
|
26
|
-
transform: "none",
|
|
27
27
|
buttonExtraStyles: undefined,
|
|
28
28
|
backgroundColor: "white",
|
|
29
29
|
borderColor: "rgba(255, 255, 255, 0.85)",
|
|
30
|
-
|
|
30
|
+
tooltipContentExtraStyles: undefined
|
|
31
31
|
},
|
|
32
32
|
argTypes: {
|
|
33
33
|
triggerText: {
|
|
34
34
|
description:
|
|
35
|
-
"Text element that tooltip is anchored to. Only used if
|
|
35
|
+
"Text element that tooltip is anchored to. Only used if hasIconTrigger is false.",
|
|
36
36
|
table: {
|
|
37
37
|
type: { summary: "string" },
|
|
38
38
|
defaultValue: { summary: "" }
|
|
@@ -68,12 +68,19 @@ export default {
|
|
|
68
68
|
defaultValue: { summary: undefined }
|
|
69
69
|
}
|
|
70
70
|
},
|
|
71
|
+
iconColor: {
|
|
72
|
+
description: "Color of the icon trigger",
|
|
73
|
+
table: {
|
|
74
|
+
type: { summary: "string" },
|
|
75
|
+
defaultValue: { summary: undefined }
|
|
76
|
+
}
|
|
77
|
+
},
|
|
71
78
|
tooltipID: {
|
|
72
79
|
description:
|
|
73
80
|
"ID value for tooltip. Use if displaying multiple tooltips on the same page.",
|
|
74
81
|
table: {
|
|
75
|
-
type: { summary: "
|
|
76
|
-
defaultValue: { summary:
|
|
82
|
+
type: { summary: "string" },
|
|
83
|
+
defaultValue: { summary: "tooltip-content" }
|
|
77
84
|
}
|
|
78
85
|
},
|
|
79
86
|
extraStyles: {
|
|
@@ -135,13 +142,6 @@ export default {
|
|
|
135
142
|
defaultValue: { summary: "down" }
|
|
136
143
|
}
|
|
137
144
|
},
|
|
138
|
-
transform: {
|
|
139
|
-
description: "CSS transform to apply to tooltip",
|
|
140
|
-
table: {
|
|
141
|
-
type: { summary: "string" },
|
|
142
|
-
defaultValue: { summary: undefined }
|
|
143
|
-
}
|
|
144
|
-
},
|
|
145
145
|
buttonExtraStyles: {
|
|
146
146
|
description:
|
|
147
147
|
"Extra styles to apply to the button that wraps tooltip trigger",
|
|
@@ -164,8 +164,8 @@ export default {
|
|
|
164
164
|
defaultValue: { summary: "rgba(255, 255, 255, 0.85)" }
|
|
165
165
|
}
|
|
166
166
|
},
|
|
167
|
-
|
|
168
|
-
description: "Extra styles to apply to the tooltip",
|
|
167
|
+
tooltipContentExtraStyles: {
|
|
168
|
+
description: "Extra styles to apply to the tooltip content box",
|
|
169
169
|
table: {
|
|
170
170
|
type: { summary: "string" },
|
|
171
171
|
defaultValue: { summary: undefined }
|
|
@@ -4,9 +4,6 @@ import Expand from "../../../util/expand";
|
|
|
4
4
|
export interface TooltipProps {
|
|
5
5
|
triggerText?: string | JSX.Element;
|
|
6
6
|
content?: string | JSX.Element;
|
|
7
|
-
hasIcon?: boolean;
|
|
8
|
-
iconHelpText?: string;
|
|
9
|
-
tooltipID?: number;
|
|
10
7
|
extraStyles?: string;
|
|
11
8
|
textExtraStyles?: string;
|
|
12
9
|
minWidth?: string;
|
|
@@ -20,11 +17,15 @@ export interface TooltipProps {
|
|
|
20
17
|
arrowLeft: string;
|
|
21
18
|
};
|
|
22
19
|
arrowDirection?: "left" | "right" | "top" | "bottom";
|
|
23
|
-
transform?: string;
|
|
24
20
|
buttonExtraStyles?: string;
|
|
25
21
|
borderColor?: string;
|
|
26
22
|
backgroundColor?: string;
|
|
27
|
-
|
|
23
|
+
hasIconTrigger?: boolean;
|
|
24
|
+
IconTrigger?: React.FC<React.SVGProps<SVGSVGElement>>;
|
|
25
|
+
iconHelpText?: string;
|
|
26
|
+
iconColor?: string;
|
|
27
|
+
tooltipID: string;
|
|
28
|
+
tooltipContentExtraStyles?: string;
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
export const Tooltip: React.FC<Expand<TooltipProps> &
|
|
@@ -36,7 +36,7 @@ const SidebarStackContent = ({
|
|
|
36
36
|
>
|
|
37
37
|
<Cover centerOverride={!sidebarVerticalCenter} key="page-cover">
|
|
38
38
|
{header ? header : <Box padding="0" key="header-box" />}
|
|
39
|
-
<Box padding="0" minWidth="100%" key="content-box"
|
|
39
|
+
<Box padding="0" minWidth="100%" key="content-box">
|
|
40
40
|
{subHeader && !(isMobile && hideMobileSubHeader) ? (
|
|
41
41
|
subHeader
|
|
42
42
|
) : (
|
package/src/util/general.js
CHANGED
|
@@ -222,3 +222,17 @@ export const adjustHexColor = (hex, percent, action) => {
|
|
|
222
222
|
.slice(1)
|
|
223
223
|
.padStart(6, "0")}`;
|
|
224
224
|
};
|
|
225
|
+
|
|
226
|
+
export const arrowBorder = (borderColor, direction, width = "8px") => {
|
|
227
|
+
const angle = `${width} solid transparent`;
|
|
228
|
+
const straight = `${width} solid ${borderColor}`;
|
|
229
|
+
if (direction == "down") {
|
|
230
|
+
return `border-left: ${angle}; border-right: ${angle}; border-top: ${straight}`;
|
|
231
|
+
} else if (direction == "up") {
|
|
232
|
+
return `border-left: ${angle}; border-right: ${angle}; border-bottom: ${straight}`;
|
|
233
|
+
} else if (direction == "left") {
|
|
234
|
+
return `border-top: ${angle}; border-bottom: ${angle}; border-right: ${straight}`;
|
|
235
|
+
} else if (direction == "right") {
|
|
236
|
+
return `border-top: ${angle}; border-bottom: ${angle}; border-left: ${straight}`;
|
|
237
|
+
}
|
|
238
|
+
};
|