@thecb/components 7.10.1-beta.2 → 7.10.1-beta.4

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.1-beta.2",
3
+ "version": "7.10.1-beta.4",
4
4
  "description": "Common lib for CityBase react components",
5
5
  "main": "dist/index.cjs.js",
6
6
  "typings": "dist/index.d.ts",
@@ -9,6 +9,7 @@ import {
9
9
  ERROR_COLOR
10
10
  } from "../../../constants/colors";
11
11
  import { generateShadows } from "../../../util/generateShadows";
12
+ import useScrollTo from "../../../util/useScrollTo";
12
13
 
13
14
  const TermsAndConditionsControlV2 = ({
14
15
  showCheckbox = true,
@@ -30,6 +31,13 @@ const TermsAndConditionsControlV2 = ({
30
31
  const [showTerms, toggleShowTerms] = useState(false);
31
32
  const standardBoxShadow = generateShadows().standard.base;
32
33
 
34
+ const toggleTerms = termsOpen => {
35
+ toggleShowTerms(termsOpen);
36
+ if (termsOpen) {
37
+ useScrollTo("terms-body-text", 0, 0, "smooth", 100);
38
+ }
39
+ };
40
+
33
41
  return (
34
42
  <Box
35
43
  padding={displayInline ? "0" : "1.5rem"}
@@ -64,7 +72,7 @@ const TermsAndConditionsControlV2 = ({
64
72
  link={linkText}
65
73
  terms={terms}
66
74
  isOpen={showTerms}
67
- toggleOpen={toggleShowTerms}
75
+ toggleOpen={toggleTerms}
68
76
  linkVariant={modalVariant}
69
77
  title={modalTitle}
70
78
  />
@@ -0,0 +1,22 @@
1
+ /*
2
+ Hook that takes an ID selector for an element on the screen
3
+ And optionally values for top position, left position, smooth behavior
4
+ Finds element on screen and scrolls it to the provided coordinates
5
+
6
+ (string, number, number, string, number) => undefined;
7
+ */
8
+
9
+ const useScrollTo = (id, top = 0, left = 0, behavior = "auto", delay) => {
10
+ let scrollItem;
11
+ if (delay) {
12
+ setTimeout(() => {
13
+ scrollItem = document.getElementById(id);
14
+ scrollItem?.scrollTo({ top, left, behavior });
15
+ }, delay);
16
+ } else {
17
+ scrollItem = document.getElementById(id);
18
+ scrollItem?.scrollTo({ top, left, behavior });
19
+ }
20
+ };
21
+
22
+ export default useScrollTo;