@thecb/components 11.8.0-beta.4 → 11.8.0-beta.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thecb/components",
3
- "version": "11.8.0-beta.4",
3
+ "version": "11.8.0-beta.6",
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,39 +4,27 @@ 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";
8
- import { ESCAPE } from "../../../constants/keyboard";
7
+ import { noop, arrowBorder } from "../../../util/general";
9
8
  import { fallbackValues } from "./Tooltip.theme";
10
9
  import WarningIconXS from "../../atoms/icons/WarningIconXS";
11
- import { SELECTIVE_YELLOW } from "../../../constants/colors";
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
10
 
27
11
  const Tooltip = ({
12
+ tooltipContainerExtraStyles = "",
28
13
  themeValues,
29
- triggerText = "",
30
- content = "",
14
+ tooltipID = "tooltip-content",
31
15
  hasIconTrigger = false,
32
16
  IconTrigger = WarningIconXS,
33
- iconHelpText = "",
34
- tooltipID = "tooltip-content",
35
- extraStyles = "",
36
- textExtraStyles = "",
37
- minWidth = "250px",
38
- maxWidth = "300px",
39
- height = "auto",
17
+ iconHelpText = "Open the tooltip",
18
+ tooltipContent = "",
19
+ tooltipTriggerText = "",
20
+ triggerTextExtraStyles = "",
21
+ contentExtraStyles = "",
22
+ contentPosition = {
23
+ top: "-110px",
24
+ right: "auto",
25
+ bottom: "auto",
26
+ left: "-225px"
27
+ },
40
28
  arrowDirection = "down",
41
29
  arrowPosition = {
42
30
  arrowTop: "auto",
@@ -44,20 +32,15 @@ const Tooltip = ({
44
32
  arrowBottom: "-8px",
45
33
  arrowLeft: "auto"
46
34
  },
47
- position = {
48
- top: "-110px",
49
- right: "auto",
50
- bottom: "auto",
51
- left: "-225px"
52
- },
53
- iconColor = SELECTIVE_YELLOW,
35
+ minWidth = "250px",
36
+ maxWidth = "300px",
37
+ height = "auto",
54
38
  buttonExtraStyles,
55
39
  backgroundColor = "white",
56
- borderColor = "rgba(255, 255, 255, 0.85)",
57
- tooltipContentExtraStyles
40
+ borderColor = "rgba(255, 255, 255, 0.85)"
58
41
  }) => {
59
42
  const { hoverColor, activeColor, tooltipTriggerColor } = themeValues;
60
- const { top, right, bottom, left } = position ?? {};
43
+ const { top, right, bottom, left } = contentPosition ?? {};
61
44
  const { arrowTop, arrowRight, arrowBottom, arrowLeft } = arrowPosition ?? {};
62
45
 
63
46
  const [tooltipOpen, setTooltipOpen] = useState(false);
@@ -69,13 +52,16 @@ const Tooltip = ({
69
52
  };
70
53
 
71
54
  const handleKeyboardEvent = e => {
72
- if (e.keyCode === ESCAPE || e.keyCode === 9) {
55
+ if (e.key === "Escape") {
73
56
  handleToggleTooltip(false);
74
57
  }
75
58
  };
76
59
 
77
60
  return (
78
- <Box padding="0" extraStyles={`position: relative; ${extraStyles}`}>
61
+ <Box
62
+ padding="0"
63
+ extraStyles={`position: relative; ${tooltipContainerExtraStyles}`}
64
+ >
79
65
  <ButtonWithAction
80
66
  action={() => noop}
81
67
  onFocus={() => handleToggleTooltip(true)}
@@ -93,16 +79,21 @@ const Tooltip = ({
93
79
  >
94
80
  {hasIconTrigger && (
95
81
  <>
96
- <Box aria-label="Trigger Popover">
97
- <IconTrigger color={iconColor} />
82
+ <Box aria-label="Open tooltip">
83
+ <IconTrigger color={tooltipTriggerColor} />
98
84
  </Box>
99
- <Box padding="0" srOnly aria-hidden="true">
85
+ <Box padding="0" srOnly>
100
86
  <Text>{iconHelpText}</Text>
101
87
  </Box>
102
88
  </>
103
89
  )}
104
90
  {!hasIconTrigger && (
105
- <Text extraStyles={textExtraStyles}>{triggerText}</Text>
91
+ <Text
92
+ extraStyles={`color: ${tooltipTriggerColor}; &:hover {
93
+ ${hoverColor}; &:active ${activeColor}; ${triggerTextExtraStyles}`}
94
+ >
95
+ {tooltipTriggerText}
96
+ </Text>
106
97
  )}
107
98
  </ButtonWithAction>
108
99
  <Box
@@ -122,10 +113,10 @@ const Tooltip = ({
122
113
  bottom: ${bottom};
123
114
  left: ${left};
124
115
  height: ${height};
125
- ${tooltipContentExtraStyles};
116
+ ${contentExtraStyles};
126
117
  `}
127
118
  >
128
- <Paragraph>{content}</Paragraph>
119
+ <Paragraph>{tooltipContent}</Paragraph>
129
120
  <Box
130
121
  padding="0"
131
122
  extraStyles={`
@@ -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 `icon` prop. The trigger is rendered as a `ButtonWithAction` with the `smallGhost` variant.
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
 
@@ -9,36 +9,35 @@ export default {
9
9
  controls: { expanded: true }
10
10
  },
11
11
  args: {
12
- triggerText: "",
13
- content: "",
12
+ tooltipTriggerText: "",
13
+ tooltipContent: "",
14
14
  hasIconTrigger: false,
15
15
  IconTrigger: WarningIconXS,
16
- iconHelpText: "",
17
- tooltipID: 0,
18
- extraStyles: undefined,
19
- textExtraStyles: undefined,
16
+ iconHelpText: "Open the tooltip",
17
+ tooltipID: "tooltip-content",
18
+ tooltipContainerExtraStyles: undefined,
19
+ triggerTextExtraStyles: undefined,
20
20
  minWidth: "250px",
21
21
  maxWidth: "300px",
22
22
  height: "auto",
23
- position: undefined,
23
+ contentPosition: undefined,
24
24
  arrowPosition: undefined,
25
25
  arrowDirection: "down",
26
- transform: "none",
27
26
  buttonExtraStyles: undefined,
28
27
  backgroundColor: "white",
29
28
  borderColor: "rgba(255, 255, 255, 0.85)",
30
- tooltipExtraStyles: undefined
29
+ contentExtraStyles: undefined
31
30
  },
32
31
  argTypes: {
33
- triggerText: {
32
+ tooltipTriggerText: {
34
33
  description:
35
- "Text element that tooltip is anchored to. Only used if hasIcon is false.",
34
+ "Text element that tooltip is anchored to. Only used if hasIconTrigger is false.",
36
35
  table: {
37
36
  type: { summary: "string" },
38
37
  defaultValue: { summary: "" }
39
38
  }
40
39
  },
41
- content: {
40
+ tooltipContent: {
42
41
  description: "Content of the tooltip",
43
42
  table: {
44
43
  type: { summary: "string" },
@@ -65,18 +64,18 @@ export default {
65
64
  description: "Accessible description of the icon",
66
65
  table: {
67
66
  type: { summary: "string" },
68
- defaultValue: { summary: undefined }
67
+ defaultValue: { summary: "Open the tooltip" }
69
68
  }
70
69
  },
71
70
  tooltipID: {
72
71
  description:
73
72
  "ID value for tooltip. Use if displaying multiple tooltips on the same page.",
74
73
  table: {
75
- type: { summary: "number" },
76
- defaultValue: { summary: 0 }
74
+ type: { summary: "string" },
75
+ defaultValue: { summary: "tooltip-content" }
77
76
  }
78
77
  },
79
- extraStyles: {
78
+ tooltipContainerExtraStyles: {
80
79
  description:
81
80
  "Extra CSS styles to apply to the wrapper component around the trigger and tooltip",
82
81
  table: {
@@ -84,7 +83,7 @@ export default {
84
83
  defaultValue: { summary: undefined }
85
84
  }
86
85
  },
87
- textExtraStyles: {
86
+ triggerTextExtraStyles: {
88
87
  description: "Extra styles to apply to the text trigger of the tooltip",
89
88
  table: {
90
89
  type: { summary: "CSS string" },
@@ -112,7 +111,7 @@ export default {
112
111
  defaultValue: { summary: "auto" }
113
112
  }
114
113
  },
115
- position: {
114
+ contentPosition: {
116
115
  description:
117
116
  "Object containing values for top/right/bottom/left position of tooltip relative to trigger",
118
117
  table: {
@@ -135,13 +134,6 @@ export default {
135
134
  defaultValue: { summary: "down" }
136
135
  }
137
136
  },
138
- transform: {
139
- description: "CSS transform to apply to tooltip",
140
- table: {
141
- type: { summary: "string" },
142
- defaultValue: { summary: undefined }
143
- }
144
- },
145
137
  buttonExtraStyles: {
146
138
  description:
147
139
  "Extra styles to apply to the button that wraps tooltip trigger",
@@ -164,8 +156,8 @@ export default {
164
156
  defaultValue: { summary: "rgba(255, 255, 255, 0.85)" }
165
157
  }
166
158
  },
167
- tooltipExtraStyles: {
168
- description: "Extra styles to apply to the tooltip",
159
+ contentExtraStyles: {
160
+ description: "Extra styles to apply to the tooltip content box",
169
161
  table: {
170
162
  type: { summary: "string" },
171
163
  defaultValue: { summary: undefined }
@@ -176,8 +168,8 @@ export default {
176
168
 
177
169
  export const BasicTooltip = {
178
170
  args: {
179
- triggerText: "Help",
180
- content:
171
+ tooltipTriggerText: "Help",
172
+ tooltipContent:
181
173
  "Contact support at 1-800-CTY-VILL for help with your account balance."
182
174
  }
183
175
  };
@@ -186,17 +178,17 @@ export const IconTooltip = {
186
178
  args: {
187
179
  hasIconTrigger: true,
188
180
  IconTrigger: WarningIconXS,
189
- content:
181
+ tooltipContent:
190
182
  "Contact support at 1-800-CTY-VILL for help with your account balance."
191
183
  }
192
184
  };
193
185
 
194
186
  export const UnderneathTooltip = {
195
187
  args: {
196
- triggerText: "What's this?",
197
- content:
188
+ tooltipTriggerText: "What's this?",
189
+ tooltipContent:
198
190
  "Contact support at 1-800-CTY-VILL for help with your account balance.",
199
- position: { top: "50px", left: "-100px" },
191
+ contentPosition: { top: "50px", left: "-100px" },
200
192
  arrowPosition: { arrowTop: "-8px", arrowLeft: "50%" },
201
193
  arrowDirection: "up"
202
194
  }
@@ -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
- tooltipExtraStyles?: string;
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" role="main">
39
+ <Box padding="0" minWidth="100%" key="content-box">
40
40
  {subHeader && !(isMobile && hideMobileSubHeader) ? (
41
41
  subHeader
42
42
  ) : (
@@ -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
+ };