@thecb/components 6.3.0-beta.0 → 6.3.0

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": "6.3.0-beta.0",
3
+ "version": "6.3.0",
4
4
  "description": "Common lib for CityBase react components",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
@@ -17,7 +17,7 @@ const DisplayCard = ({
17
17
  url,
18
18
  link = false,
19
19
  helpText,
20
- usePopover = false,
20
+ hasPopover = false,
21
21
  popoverTriggerText = "",
22
22
  popoverContent = "",
23
23
  popoverExtraStyles,
@@ -34,7 +34,7 @@ const DisplayCard = ({
34
34
  >
35
35
  {title}
36
36
  </Paragraph>
37
- {usePopover && (
37
+ {hasPopover && (
38
38
  <Popover
39
39
  triggerText={popoverTriggerText}
40
40
  content={popoverContent}
@@ -54,9 +54,7 @@ const DisplayCard = ({
54
54
  0px 3px 8px 0px rgb(202, 206, 216)"
55
55
  >
56
56
  <Cluster justify="space-between" align="center">
57
- <Text variant="p" color={CHARADE_GREY}>
58
- {item}
59
- </Text>
57
+ <Text color={CHARADE_GREY}>{item}</Text>
60
58
  {link ? (
61
59
  <ButtonWithLink
62
60
  text={buttonText}
@@ -74,11 +72,7 @@ const DisplayCard = ({
74
72
  extraStyles={`min-width: 0;`}
75
73
  />
76
74
  ) : helpText ? (
77
- <Text
78
- variant="p"
79
- color={STORM_GREY}
80
- extraStyles={`font-style: italic;`}
81
- >
75
+ <Text color={STORM_GREY} extraStyles={`font-style: italic;`}>
82
76
  {helpText}
83
77
  </Text>
84
78
  ) : (
@@ -4,7 +4,7 @@ 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 { useOutsideClickHook } from "../../../util";
7
+ import { useOutsideClick } from "../../../util";
8
8
  import { noop } from "../../../util/general";
9
9
  import { fallbackValues } from "./Popover.theme";
10
10
 
@@ -12,7 +12,7 @@ const Popover = ({
12
12
  themeValues,
13
13
  triggerText = "",
14
14
  content = "",
15
- useIcon = false,
15
+ hasIcon = false,
16
16
  icon: Icon,
17
17
  iconHelpText = "", // for screen-readers, required if using an icon for trigger
18
18
  popoverID = 0,
@@ -22,11 +22,18 @@ const Popover = ({
22
22
  minWidth = "250px",
23
23
  maxWidth = "300px",
24
24
  height = "auto",
25
- position // { top: string, right: string, bottom: string, left: string }
25
+ position, // { top: string, right: string, bottom: string, left: string }
26
+ arrowPosition // { top: string, right: string, bottom: string, left: string }
26
27
  }) => {
27
28
  const { hoverColor, activeColor, popoverTriggerColor } = themeValues;
28
29
  const { top = "-110px", right = "auto", bottom = "auto", left = "-225px" } =
29
30
  position ?? {};
31
+ const {
32
+ arrowTop = "auto",
33
+ arrowRight = "10px",
34
+ arrowBottom = "-8px",
35
+ arrowLeft = "auto"
36
+ } = arrowPosition ?? {};
30
37
 
31
38
  const [popoverOpen, togglePopover] = useState(false);
32
39
 
@@ -43,22 +50,18 @@ const Popover = ({
43
50
  <ButtonWithAction
44
51
  action={() => noop}
45
52
  onFocus={() => {
46
- console.log("on focus") || handleTogglePopover(true);
53
+ handleTogglePopover(true);
47
54
  }}
48
55
  onBlur={() => {
49
- console.log("on blur") || handleTogglePopover(false);
56
+ handleTogglePopover(false);
50
57
  }}
51
58
  onKeyDown={e => {
52
59
  if (e.keyCode === 27) {
53
- console.log("on key down") || handleTogglePopover(false);
60
+ handleTogglePopover(false);
54
61
  }
55
62
  }}
56
- onTouchStart={() =>
57
- console.log("on touch start") || handleTogglePopover(true)
58
- }
59
- onTouchEnd={() =>
60
- console.log("on touch end") || handleTogglePopover(false)
61
- }
63
+ onTouchStart={() => handleTogglePopover(true)}
64
+ onTouchEnd={() => handleTogglePopover(false)}
62
65
  onMouseEnter={() => handleTogglePopover(true)}
63
66
  onMouseLeave={() => handleTogglePopover(false)}
64
67
  contentOverride
@@ -71,13 +74,15 @@ const Popover = ({
71
74
  aria-controls={`Disclosed${popoverID}`}
72
75
  ref={triggerRef}
73
76
  >
74
- {useIcon && <Icon />}
75
- {useIcon && (
76
- <Box padding="0" srOnly>
77
- <Text id={`btnPopover${popoverID}_info`}>{iconHelpText}</Text>
78
- </Box>
77
+ {hasIcon && (
78
+ <>
79
+ <Icon />
80
+ <Box padding="0" srOnly>
81
+ <Text id={`btnPopover${popoverID}_info`}>{iconHelpText}</Text>
82
+ </Box>
83
+ </>
79
84
  )}
80
- {!useIcon && (
85
+ {!hasIcon && (
81
86
  <Text
82
87
  color={popoverTriggerColor}
83
88
  extraStyles={`&:active { color: ${activeColor}; } &:hover { color: ${hoverColor} }; ${textExtraStyles}`}
@@ -109,7 +114,7 @@ const Popover = ({
109
114
  <Paragraph>{content}</Paragraph>
110
115
  <Box
111
116
  padding="0"
112
- extraStyles={`position: absolute; content: ""; width: 0; height: 0; border-left: 8px solid transparent; border-right: 8px solid transparent; border-top: 8px solid rgba(255, 255, 255, 0.85); filter: drop-shadow(2px 8px 14px black); bottom: -8px; right: 10px;`}
117
+ extraStyles={`position: absolute; content: ""; width: 0; height: 0; border-left: 8px solid transparent; border-right: 8px solid transparent; border-top: 8px solid rgba(255, 255, 255, 0.85); filter: drop-shadow(2px 8px 14px black); bottom: ${arrowBottom}; right: ${arrowRight}; top: ${arrowTop}; left: ${arrowLeft};`}
113
118
  />
114
119
  </Box>
115
120
  </Box>
package/src/util/index.js CHANGED
@@ -2,6 +2,6 @@ import * as formats from "./formats";
2
2
  import * as general from "./general";
3
3
  import * as theme from "./themeUtils";
4
4
  import useFocusInvalidInput from "./focusFirstInvalidInputHook";
5
- import useOutsideClickHook from "./useOutsideClickHook";
5
+ import useOutsideClick from "./useOutsideClick";
6
6
 
7
- export { formats, general, theme, useFocusInvalidInput, useOutsideClickHook };
7
+ export { formats, general, theme, useFocusInvalidInput, useOutsideClick };
@@ -1,12 +1,12 @@
1
1
  import { useRef, useEffect } from "react";
2
2
 
3
3
  /*
4
- Hook that assigns an onPointerUp event listener to the main document element
4
+ Hook that assigns a click event listener to the main document element
5
5
  Returns a ref to attach to another element (like an icon/button that triggers a popover)
6
- If a pointerup event gets captured by the document and the assigned element isn't the target
6
+ If a click event gets captured by the document and the assigned element isn't the target
7
7
  hook will run whatever handler is passed (eg a function that closes a popover)
8
8
 
9
- See tooltip component for implementation
9
+ See popover component for implementation
10
10
 
11
11
  */
12
12
 
@@ -16,9 +16,6 @@ const useOutsideClickHook = handler => {
16
16
  useEffect(() => {
17
17
  const handleOutsideClick = e => {
18
18
  if (ref.current && !ref.current.contains(e.target)) {
19
- console.log("in outside click handler");
20
- console.log("ref", ref);
21
- console.log("target", e.target);
22
19
  handler();
23
20
  }
24
21