@thecb/components 10.12.1-beta.0 → 10.12.1

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": "10.12.1-beta.0",
3
+ "version": "10.12.1",
4
4
  "description": "Common lib for CityBase react components",
5
5
  "main": "dist/index.cjs.js",
6
6
  "typings": "dist/index.d.ts",
@@ -14,6 +14,7 @@ import Stack from "../layouts/Stack";
14
14
  import CardImage from "./CardImage.styled";
15
15
  import CardText from "./CardText";
16
16
  import CardHeader from "./CardHeader";
17
+ import { noop } from "../../../util/general";
17
18
 
18
19
  const Card = ({
19
20
  borderRadius = "4px",
@@ -26,8 +27,12 @@ const Card = ({
26
27
  imgHeight = "150px",
27
28
  imgObjectFit = "none",
28
29
  imgAltText,
30
+ onQuitClick = noop,
29
31
  padding = "24px",
32
+ showQuitLink = false,
30
33
  text,
34
+ textAs = "p",
35
+ titleAs = "h2",
31
36
  titleText,
32
37
  titleVariant = "small",
33
38
  themeValues,
@@ -90,9 +95,13 @@ const Card = ({
90
95
  <Box padding="0" width="100%" extraStyles="flex-basis: 100%;">
91
96
  {text && (
92
97
  <CardText
98
+ onQuitClick={onQuitClick}
93
99
  padding={padding}
100
+ showQuitLink={showQuitLink}
101
+ titleAs={titleAs}
94
102
  titleText={titleText}
95
103
  text={text}
104
+ textAs={textAs}
96
105
  titleVariant={titleVariant}
97
106
  />
98
107
  )}
@@ -10,10 +10,16 @@ import Cover from "../layouts/Cover";
10
10
  import Paragraph from "../paragraph";
11
11
  import Stack from "../layouts/Stack";
12
12
  import Title from "../title";
13
+ import IconQuitLarge from "../../atoms/icons/IconQuitLarge";
14
+ import { Cluster } from "../layouts";
13
15
 
14
16
  export const CardText = ({
17
+ showQuitLink,
18
+ onQuitClick,
19
+ titleAs,
15
20
  padding,
16
21
  text,
22
+ textAs = "p",
17
23
  titleText,
18
24
  titleVariant = "small",
19
25
  themeValues
@@ -22,17 +28,34 @@ export const CardText = ({
22
28
  <Box padding={padding}>
23
29
  <Cover>
24
30
  <Stack>
25
- {titleText && (
26
- <Title
27
- as="p"
28
- variant={titleVariant}
29
- color={themeValues.titleColor}
30
- weight={themeValues.titleWeight}
31
- >
32
- {titleText}
33
- </Title>
34
- )}
35
- <Paragraph color={themeValues.textColor}>{text}</Paragraph>
31
+ <Cluster justify="space-between" align="center" overflow={true}>
32
+ {titleText && (
33
+ <Title
34
+ as={titleAs}
35
+ variant={titleVariant}
36
+ color={themeValues.titleColor}
37
+ weight={themeValues.titleWeight}
38
+ >
39
+ {titleText}
40
+ </Title>
41
+ )}
42
+ {showQuitLink && (
43
+ <Box
44
+ padding="0"
45
+ onClick={onQuitClick}
46
+ onKeyDown={e => e.key === "Enter" && onQuitClick()}
47
+ role="button"
48
+ tabIndex={0}
49
+ aria-label={`Close Card: ${titleText}`}
50
+ extraStyles="cursor: pointer;"
51
+ >
52
+ <IconQuitLarge />
53
+ </Box>
54
+ )}
55
+ </Cluster>
56
+ <Paragraph as={textAs} color={themeValues.textColor}>
57
+ {text}
58
+ </Paragraph>
36
59
  </Stack>
37
60
  </Cover>
38
61
  </Box>
@@ -2,8 +2,10 @@ import React from "react";
2
2
  import Expand from "../../../util/expand";
3
3
 
4
4
  export interface CardProps {
5
- text?: string;
5
+ text?: string | React.ReactNode;
6
+ textAs?: string;
6
7
  titleText?: string;
8
+ titleAs?: string;
7
9
  titleVariant?: string;
8
10
  extraStyles?: string;
9
11
  imgSrc?: string;
@@ -27,6 +29,10 @@ export interface CardProps {
27
29
  borderRadius?: string;
28
30
  width?: string;
29
31
  padding?: string;
32
+ showQuitLink?: boolean;
33
+ onQuitClick?: (
34
+ event: React.MouseEvent<HTMLElement> | React.TouchEvent<HTMLElement>
35
+ ) => void;
30
36
  }
31
37
 
32
38
  export const Card: React.FC<Expand<CardProps> &
@@ -2,7 +2,7 @@ import React, { useState, useEffect, useRef } from "react";
2
2
  import { fallbackValues } from "./MultipleSelectFilter.theme";
3
3
  import { themeComponent } from "../../../util/themeUtils";
4
4
  import { Box } from "../../atoms/layouts";
5
- import { GHOST_GREY, WHITE } from "../../../constants/colors";
5
+ import { GHOST_GREY, WHITE, CHARADE_GREY } from "../../../constants/colors";
6
6
  import { noop } from "../../../util/general";
7
7
  import { FilterContainer } from "./MultipleSelectFilter.styled";
8
8
  import ActionLinkButton from "./__private__/ActionLinkButton";
@@ -10,6 +10,7 @@ import FilterButton from "./__private__/FilterButton";
10
10
  import FilterDropdown from "./__private__/FilterDropdown";
11
11
  import SearchBox from "./__private__/SearchBox";
12
12
  import FilterableList from "./__private__/FilterableList";
13
+ import useOutsideClickHook from "../../../hooks/use-outside-click";
13
14
 
14
15
  const MultipleSelectFilter = ({
15
16
  actions,
@@ -36,7 +37,12 @@ const MultipleSelectFilter = ({
36
37
  const [opened, setOpened] = useState(false);
37
38
  const [appliedOptions, setAppliedOptions] = useState([]);
38
39
 
39
- const containerRef = useRef(null);
40
+ const handleClickOutsideContainer = () => {
41
+ setOpened(false);
42
+ actions.fields.searchTerm.set("");
43
+ onApply(selectedOptions);
44
+ };
45
+ const containerRef = useOutsideClickHook(() => handleClickOutsideContainer());
40
46
  const dropdownRef = useRef(null);
41
47
  const filterButtonRef = useRef(null);
42
48
  const applyFilterButtonRef = useRef(null);
@@ -76,22 +82,8 @@ const MultipleSelectFilter = ({
76
82
  onApply(selectedOptions);
77
83
  }
78
84
  };
79
- const handleClickOutside = event => {
80
- if (
81
- containerRef.current &&
82
- !containerRef.current.contains(event.target) &&
83
- dropdownRef.current &&
84
- !dropdownRef.current.contains(event.target)
85
- ) {
86
- setOpened(false);
87
- actions.fields.searchTerm.set("");
88
- onApply(selectedOptions);
89
- }
90
- };
91
- document.addEventListener("mousedown", handleClickOutside);
92
85
  document.addEventListener("keydown", handleKeyDown);
93
86
  return () => {
94
- document.addEventListener("mousedown", handleClickOutside);
95
87
  document.removeEventListener("keydown", handleKeyDown);
96
88
  };
97
89
  }, []);
@@ -113,7 +105,7 @@ const MultipleSelectFilter = ({
113
105
  ? themeValues.secondaryColor
114
106
  : WHITE
115
107
  }
116
- contentColor={!opened && selectedOptions?.length ? WHITE : "#292A33"}
108
+ contentColor={!opened && selectedOptions?.length ? WHITE : CHARADE_GREY}
117
109
  name={name}
118
110
  filterDropdownID={filterDropdownID}
119
111
  hasIcon={hasIcon}
@@ -18,12 +18,11 @@ const useOutsideClickHook = handler => {
18
18
  if (ref.current && !ref.current.contains(e.target)) {
19
19
  handler();
20
20
  }
21
+ };
21
22
 
22
- document.addEventListener("click", handleOutsideClick, true);
23
-
24
- return () => {
25
- document.removeEventListener("click", handleOutsideClick, true);
26
- };
23
+ document.addEventListener("click", handleOutsideClick, true);
24
+ return () => {
25
+ document.removeEventListener("click", handleOutsideClick, true);
27
26
  };
28
27
  }, [ref]);
29
28