@thecb/components 7.9.2 → 7.9.4-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.9.2",
3
+ "version": "7.9.4-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",
@@ -125,7 +125,7 @@ const Checkbox = ({
125
125
  onChange={onChange}
126
126
  tabIndex="-1"
127
127
  aria-invalid={error}
128
- aria-describedby={`${name}-error-message`}
128
+ aria-describedby={error ? `${name}-error-message` : ""}
129
129
  />
130
130
  <StyledCheckbox
131
131
  error={error}
Binary file
@@ -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,83 @@
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 Paragraph from "../../atoms/paragraph";
6
+ import TermsAndConditionsModal from "../terms-and-conditions-modal";
7
+ import {
8
+ ATHENS_GREY,
9
+ CHARADE_GREY,
10
+ ERROR_COLOR
11
+ } from "../../../constants/colors";
12
+ import { generateShadows } from "../../../util/generateShadows";
13
+
14
+ const TermsAndConditionsControlV2 = ({
15
+ showCheckbox = true,
16
+ onCheck,
17
+ isChecked,
18
+ hasError,
19
+ errorMessage = "Please accept Terms and Conditions",
20
+ description = "",
21
+ linkText = "Terms and Conditions",
22
+ html,
23
+ terms,
24
+ id = "terms-and-conditions",
25
+ displayInline = true,
26
+ modalVariant = "default",
27
+ containerBackground = ATHENS_GREY
28
+ }) => {
29
+ const [showTerms, toggleShowTerms] = useState(false);
30
+ const standardBoxShadow = generateShadows().standard.base;
31
+
32
+ return (
33
+ <Box
34
+ padding={displayInline ? "0" : "1.5rem"}
35
+ minWidth={displayInline ? "0" : "100%"}
36
+ background={displayInline ? "transparent" : containerBackground}
37
+ boxShadow={displayInline ? "none" : standardBoxShadow}
38
+ borderRadius={displayInline ? "0" : "4px"}
39
+ >
40
+ <Stack childGap="0.25rem">
41
+ {html && <Box padding="0">{html}</Box>}
42
+ <Cluster justify="flex-start" align="center" nowrap>
43
+ {showCheckbox && (
44
+ <Checkbox
45
+ name={id}
46
+ title="Terms and Conditions"
47
+ error={hasError}
48
+ checked={isChecked}
49
+ onChange={onCheck}
50
+ />
51
+ )}
52
+ <Stack childGap="0.25rem">
53
+ <Cluster justify="flex-start" align="center" nowrap>
54
+ {description && (
55
+ <Text color={CHARADE_GREY}>{description}&nbsp;</Text>
56
+ )}
57
+ {terms && (
58
+ <TermsAndConditionsModal
59
+ link={linkText}
60
+ terms={terms}
61
+ isOpen={showTerms}
62
+ toggleOpen={toggleShowTerms}
63
+ linkVariant={modalVariant}
64
+ />
65
+ )}
66
+ </Cluster>
67
+ {showCheckbox && hasError && (
68
+ <Text
69
+ variant="pXS"
70
+ color={ERROR_COLOR}
71
+ id={`${id}-error-message`}
72
+ >
73
+ {errorMessage}
74
+ </Text>
75
+ )}
76
+ </Stack>
77
+ </Cluster>
78
+ </Stack>
79
+ </Box>
80
+ );
81
+ };
82
+
83
+ 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
+ };