@thecb/components 7.10.1-beta.3 → 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.3",
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
  />
@@ -4,7 +4,6 @@ import Text from "../../atoms/text";
4
4
  import { Box } from "../../atoms/layouts";
5
5
  import { fallbackValues } from "./TermsAndConditionsModal.theme";
6
6
  import { themeComponent } from "../../../util/themeUtils";
7
- import useScrollTo from "../../../util/useScrollTo";
8
7
 
9
8
  const TermsAndConditionsModal = ({
10
9
  link,
@@ -21,10 +20,7 @@ const TermsAndConditionsModal = ({
21
20
  <Modal
22
21
  modalOpen={isOpen}
23
22
  hideModal={() => toggleOpen(false)}
24
- showModal={() => {
25
- toggleOpen(true);
26
- useScrollTo("terms-body-text", 0, 0, false);
27
- }}
23
+ showModal={() => toggleOpen(true)}
28
24
  modalHeaderText={title}
29
25
  modalBodyText={
30
26
  <Box
@@ -3,12 +3,20 @@
3
3
  And optionally values for top position, left position, smooth behavior
4
4
  Finds element on screen and scrolls it to the provided coordinates
5
5
 
6
- (string, number, number, boolean) => undefined;
6
+ (string, number, number, string, number) => undefined;
7
7
  */
8
8
 
9
- const useScrollTo = (id, top = 0, left = 0, smooth = false) => {
10
- const scrollItem = document.getElementById(id);
11
- scrollItem?.scrollTo({ top, left, smooth });
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
+ }
12
20
  };
13
21
 
14
22
  export default useScrollTo;