@thecb/components 7.10.0 → 7.10.1-beta.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": "7.10.0",
3
+ "version": "7.10.1-beta.0",
4
4
  "description": "Common lib for CityBase react components",
5
5
  "main": "dist/index.cjs.js",
6
6
  "typings": "dist/index.d.ts",
package/src/.DS_Store ADDED
Binary file
Binary file
@@ -14,6 +14,7 @@ const CheckboxContainer = styled.div`
14
14
  const CheckboxLabelContainer = styled.label`
15
15
  display: flex;
16
16
  align-items: center;
17
+ column-gap: 1rem;
17
18
  `;
18
19
 
19
20
  const CheckboxIcon = styled.svg`
@@ -44,7 +45,6 @@ const HiddenCheckbox = styled.input.attrs({ type: "checkbox" })`
44
45
 
45
46
  const StyledCheckbox = styled.div`
46
47
  display: inline-block;
47
- margin-right: 16px;
48
48
  width: 24px;
49
49
  height: 24px;
50
50
  border-radius: 2px;
@@ -92,6 +92,7 @@ const Checkbox = ({
92
92
  themeValues,
93
93
  hidden = false,
94
94
  error = false,
95
+ checkboxMargin = "0 16px 0 0",
95
96
  extraStyles,
96
97
  textExtraStyles
97
98
  }) => {
@@ -112,7 +113,7 @@ const Checkbox = ({
112
113
  onKeyDown={e => handleClick(e, onChange)}
113
114
  hiddenStyles={hidden}
114
115
  background={themeValues.backgroundColor}
115
- extraStyles={`outline: none; ${extraStyles}`}
116
+ extraStyles={`outline: none; ${extraStyles}; margin: ${checkboxMargin};`}
116
117
  >
117
118
  <CheckboxLabelContainer>
118
119
  <CheckboxContainer data-qa="Checkbox">
@@ -125,7 +126,7 @@ const Checkbox = ({
125
126
  onChange={onChange}
126
127
  tabIndex="-1"
127
128
  aria-invalid={error}
128
- aria-describedby={`${name}-error-message`}
129
+ aria-describedby={error ? `${name}-error-message` : ""}
129
130
  />
130
131
  <StyledCheckbox
131
132
  error={error}
@@ -149,20 +150,22 @@ const Checkbox = ({
149
150
  </CheckboxIcon>
150
151
  </StyledCheckbox>
151
152
  </CheckboxContainer>
152
- <Text
153
- variant="p"
154
- weight={themeValues.textFontWeight}
155
- color={themeValues.textColor}
156
- extraStyles={
157
- textExtraStyles
158
- ? `${textExtraStyles} ${disabled &&
159
- `color: #6e727e; background-color: #f7f7f7;`} `
160
- : `margin-left: 1rem ${disabled &&
161
- `color: #6e727e; background-color: #f7f7f7;`}`
162
- }
163
- >
164
- {title}
165
- </Text>
153
+ {title && (
154
+ <Text
155
+ variant="p"
156
+ weight={themeValues.textFontWeight}
157
+ color={themeValues.textColor}
158
+ extraStyles={
159
+ textExtraStyles
160
+ ? `${textExtraStyles} ${disabled &&
161
+ `color: #6e727e; background-color: #f7f7f7;`} `
162
+ : `margin-left: 1rem ${disabled &&
163
+ `color: #6e727e; background-color: #f7f7f7;`}`
164
+ }
165
+ >
166
+ {title}
167
+ </Text>
168
+ )}
166
169
  </CheckboxLabelContainer>
167
170
  </Box>
168
171
  );
@@ -31,7 +31,6 @@ import {
31
31
  DuplicateIcon,
32
32
  ErroredIcon,
33
33
  FailedIcon,
34
- PencilIcon,
35
34
  PendingIcon,
36
35
  RefundIcon,
37
36
  RejectedIcon,
@@ -76,7 +75,6 @@ export const chargebackReversalIcon = () => <ChargebackReversalIcon />;
76
75
  export const duplicateIcon = () => <DuplicateIcon />;
77
76
  export const erroredIcon = () => <ErroredIcon />;
78
77
  export const failedIcon = () => <FailedIcon />;
79
- export const pencilIcon = () => <PencilIcon />;
80
78
  export const pendingIcon = () => <PendingIcon />;
81
79
  export const refundIcon = () => <RefundIcon />;
82
80
  export const rejectedIcon = () => <RejectedIcon />;
@@ -35,7 +35,6 @@ import DuplicateIcon from "./DuplicateIcon";
35
35
  import ErroredIcon from "./ErroredIcon";
36
36
  import ExternalLinkIcon from "./ExternalLinkIcon";
37
37
  import FailedIcon from "./FailedIcon";
38
- import PencilIcon from "./PencilIcon";
39
38
  import PendingIcon from "./PendingIcon";
40
39
  import RefundIcon from "./RefundIcon";
41
40
  import RejectedIcon from "./RejectedIcon";
@@ -119,7 +118,6 @@ export {
119
118
  ErroredIcon,
120
119
  ExternalLinkIcon,
121
120
  FailedIcon,
122
- PencilIcon,
123
121
  PendingIcon,
124
122
  RefundIcon,
125
123
  RejectedIcon,
@@ -1,45 +1,14 @@
1
- import React, { useState } from "react";
2
- import Checkbox from "../../atoms/checkbox";
3
- import { Box, Stack } from "../../atoms/layouts";
4
- import DisplayBox from "../../atoms/display-box";
5
- import TermsAndConditionsModal from "../../molecules/terms-and-conditions-modal";
1
+ import React from "react";
2
+ import TermsAndConditionsControlV1 from "./TermsAndConditionsControlV1";
3
+ import TermsAndConditionsControlV2 from "./TermsAndConditionsControlV2";
6
4
 
7
- const TermsAndConditions = ({
8
- onCheck,
9
- isChecked,
10
- html,
11
- terms,
12
- error = false,
13
- linkVariant
14
- }) => {
15
- const [showTerms, toggleShowTerms] = useState(false);
16
- return (
17
- <DisplayBox>
18
- <Stack>
19
- <Checkbox
20
- name="terms"
21
- title="Terms and Conditions"
22
- error={error}
23
- checked={isChecked}
24
- onChange={onCheck}
25
- />
26
- <Box padding="0 0 0 58px">
27
- <Stack>
28
- <Box padding="0">{html}</Box>
29
- {terms && (
30
- <TermsAndConditionsModal
31
- link="Learn More"
32
- terms={terms}
33
- isOpen={showTerms}
34
- toggleOpen={toggleShowTerms}
35
- linkVariant={linkVariant}
36
- />
37
- )}
38
- </Stack>
39
- </Box>
40
- </Stack>
41
- </DisplayBox>
42
- );
5
+ const TermsAndConditions = ({ version = "v1", ...rest }) => {
6
+ const TermsAndConditionsControl =
7
+ version === "v1"
8
+ ? TermsAndConditionsControlV1
9
+ : TermsAndConditionsControlV2;
10
+
11
+ return <TermsAndConditionsControl {...rest} />;
43
12
  };
44
13
 
45
14
  export default TermsAndConditions;
@@ -0,0 +1,45 @@
1
+ import React, { useState } from "react";
2
+ import Checkbox from "../../atoms/checkbox";
3
+ import { Box, Stack } from "../../atoms/layouts";
4
+ import DisplayBox from "../../atoms/display-box";
5
+ import TermsAndConditionsModal from "../../molecules/terms-and-conditions-modal";
6
+
7
+ const TermsAndConditionsControlV1 = ({
8
+ onCheck,
9
+ isChecked,
10
+ html,
11
+ terms,
12
+ error = false,
13
+ linkVariant
14
+ }) => {
15
+ const [showTerms, toggleShowTerms] = useState(false);
16
+ return (
17
+ <DisplayBox>
18
+ <Stack>
19
+ <Checkbox
20
+ name="terms"
21
+ title="Terms and Conditions"
22
+ error={error}
23
+ checked={isChecked}
24
+ onChange={onCheck}
25
+ />
26
+ <Box padding="0 0 0 58px">
27
+ <Stack>
28
+ <Box padding="0">{html}</Box>
29
+ {terms && (
30
+ <TermsAndConditionsModal
31
+ link="Learn More"
32
+ terms={terms}
33
+ isOpen={showTerms}
34
+ toggleOpen={toggleShowTerms}
35
+ linkVariant={linkVariant}
36
+ />
37
+ )}
38
+ </Stack>
39
+ </Box>
40
+ </Stack>
41
+ </DisplayBox>
42
+ );
43
+ };
44
+
45
+ export default TermsAndConditionsControlV1;
@@ -0,0 +1,89 @@
1
+ import React, { useState } from "react";
2
+ import Checkbox from "../../atoms/checkbox";
3
+ import { Box, Stack, Cluster } from "../../atoms/layouts";
4
+ import Text from "../../atoms/text";
5
+ import TermsAndConditionsModal from "../terms-and-conditions-modal";
6
+ import {
7
+ ATHENS_GREY,
8
+ CHARADE_GREY,
9
+ ERROR_COLOR
10
+ } from "../../../constants/colors";
11
+ import { generateShadows } from "../../../util/generateShadows";
12
+
13
+ const TermsAndConditionsControlV2 = ({
14
+ showCheckbox = true,
15
+ onCheck,
16
+ isChecked,
17
+ hasError,
18
+ errorMessage = "Please accept Terms and Conditions",
19
+ description = "",
20
+ linkText = "Terms and Conditions",
21
+ html,
22
+ terms,
23
+ id = "terms-and-conditions",
24
+ displayInline = true,
25
+ modalVariant = "default",
26
+ containerBackground = ATHENS_GREY,
27
+ checkboxMargin = "4px 8px 4px 4px",
28
+ modalTitle = "Terms and Conditions"
29
+ }) => {
30
+ const [showTerms, toggleShowTerms] = useState(false);
31
+ const standardBoxShadow = generateShadows().standard.base;
32
+
33
+ return (
34
+ <Box
35
+ padding={displayInline ? "0" : "1.5rem"}
36
+ minWidth={displayInline ? "0" : "100%"}
37
+ background={displayInline ? "transparent" : containerBackground}
38
+ boxShadow={displayInline ? "none" : standardBoxShadow}
39
+ borderRadius={displayInline ? "0" : "4px"}
40
+ >
41
+ <Stack childGap="0">
42
+ {html && <Box padding="0">{html}</Box>}
43
+ <Cluster justify="flex-start" align="center" nowrap>
44
+ {showCheckbox && (
45
+ <Checkbox
46
+ name={id}
47
+ error={hasError}
48
+ checked={isChecked}
49
+ onChange={onCheck}
50
+ checkboxMargin={checkboxMargin}
51
+ extraStyles={`align-self: flex-start;`}
52
+ />
53
+ )}
54
+ <Stack childGap="0.25rem" fullHeight>
55
+ <Cluster
56
+ justify="flex-start"
57
+ align="center"
58
+ nowrap
59
+ extraStyles={`padding-right: 2px; > div > * { margin: 4px 2px; };`}
60
+ >
61
+ {description && <Text color={CHARADE_GREY}>{description}</Text>}
62
+ {terms && (
63
+ <TermsAndConditionsModal
64
+ link={linkText}
65
+ terms={terms}
66
+ isOpen={showTerms}
67
+ toggleOpen={toggleShowTerms}
68
+ linkVariant={modalVariant}
69
+ title={modalTitle}
70
+ />
71
+ )}
72
+ </Cluster>
73
+ {showCheckbox && hasError && (
74
+ <Text
75
+ variant="pXS"
76
+ color={ERROR_COLOR}
77
+ id={`${id}-error-message`}
78
+ >
79
+ {errorMessage}
80
+ </Text>
81
+ )}
82
+ </Stack>
83
+ </Cluster>
84
+ </Stack>
85
+ </Box>
86
+ );
87
+ };
88
+
89
+ export default TermsAndConditionsControlV2;
@@ -0,0 +1,60 @@
1
+ /*
2
+
3
+ A utility function that can generate box-shadow values for components
4
+ Takes a string representing an rgb color value and returns an object
5
+ with values for standard, inset, and overlay shadows.
6
+
7
+ The objects for standard and inset shadows contain versions approiate
8
+ for base, hover, and active interaction states.
9
+
10
+ */
11
+
12
+ /*
13
+ Function to convert string representing rgb color to rgba value with provided opacity
14
+ ("rgb(41, 42, 51)", "0.1") => "rgba(41, 42, 51, 0.1)"
15
+
16
+ */
17
+ const rgbToRgba = (rgbValue = "", opacity = "") => {
18
+ if (
19
+ typeof rgbValue !== "string" ||
20
+ typeof opacity !== "string" ||
21
+ rgbValue.charAt(0) === "#"
22
+ ) {
23
+ return "";
24
+ }
25
+ return `${rgbValue.slice(0, 3)}a${rgbValue.slice(
26
+ 3,
27
+ -1
28
+ )}, ${opacity}${rgbValue.slice(-1)}`;
29
+ };
30
+
31
+ export const generateShadows = baseColorRGB => {
32
+ const colorTen = rgbToRgba(baseColorRGB, "0.1") || "rgba(41, 42, 51, 0.1)";
33
+ const colorTwenty = rgbToRgba(baseColorRGB, "0.2") || "rgba(41, 42, 51, 0.2)";
34
+ const colorTwentyFive =
35
+ rgbToRgba(baseColorRGB, "0.25") || "rgba(41, 42, 51, 0.25)";
36
+ const colorThirty = rgbToRgba(baseColorRGB, "0.3") || "rgba(41, 42, 51, 0.3)";
37
+ const blackTwentyFive = "rgba(0, 0, 0, 0.25)";
38
+
39
+ const standard = {
40
+ base: `0px 1px 2px 0px ${colorTen}, 0px 2px 6px 0px ${colorTwenty}, inset 0px 1px 0px 0px ${colorTen}`,
41
+ hover: `0px 1px 2px 0px ${colorTwenty}, 0px 4px 8px 0px ${blackTwentyFive}, 0px 6px 12px 0px ${colorTen}`,
42
+ active: `0px 2px 8px 0px ${colorTwenty}, 0px 4px 8px 0px ${colorThirty}, 0px 6px 12px 0px ${colorTwentyFive}`
43
+ };
44
+
45
+ const inset = {
46
+ base: `0px 1px 2px 0px ${colorTen}, 0px 2px 4px 0px ${colorTwenty}, inset 0px 1px 0px 0px ${colorTen}`,
47
+ hover: `0px 1px 2px 0px ${colorTen}, 0px 2px 4px 0px ${colorTwentyFive}, 0px 4px 8px 0px ${colorTen}`,
48
+ active: `0px 1px 2px 2px ${colorTwenty}, 0px 3px 6px 0px ${colorThirty}, 0px 4px 8px 0px ${colorTwenty}`
49
+ };
50
+
51
+ const overlay = {
52
+ base: `0px 7px 32px 0px ${colorTwenty}, 0px 1px 4px 0px ${colorTwenty}, 0px 1px 8px -1px ${colorThirty}`
53
+ };
54
+
55
+ return {
56
+ standard,
57
+ inset,
58
+ overlay
59
+ };
60
+ };
@@ -1,22 +0,0 @@
1
- import React from "react";
2
- import { fallbackValues } from "./Icons.theme";
3
- import { themeComponent } from "../../../util/themeUtils";
4
-
5
- const PencilIcon = ({ ariaLabel = "Edit", themeValues }) => (
6
- <svg
7
- aria-label={ariaLabel}
8
- width="24px"
9
- height="24px"
10
- fill="none"
11
- xmlns="http://www.w3.org/2000/svg"
12
- >
13
- <path
14
- fillRule="evenodd"
15
- clipRule="evenodd"
16
- d="M19.74 6.84a.885.885 0 0 1 0 1.253l-1.626 1.626-3.333-3.333 1.626-1.626a.885.885 0 0 1 1.253 0l2.08 2.08ZM4 20.5v-3.333l9.83-9.83 3.333 3.333-9.83 9.83H4Z"
17
- fill={themeValues.subIconColor}
18
- />
19
- </svg>
20
- );
21
-
22
- export default themeComponent(PencilIcon, "Icons", fallbackValues, "info");