gatsby-core-theme 1.6.8 → 1.6.9

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/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## [1.6.9](https://git.ilcd.rocks/team-floyd/themes/gatsby-themes/compare/v1.6.8...v1.6.9) (2021-11-24)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * scroll-to-top fix ([8f7264c](https://git.ilcd.rocks/team-floyd/themes/gatsby-themes/commit/8f7264cac3d4c0b11daaf1ddf5f08539e1bc5473))
7
+
8
+
9
+ * Merge branch 'master' of git.ilcd.rocks:team-floyd/themes/gatsby-themes ([3d4fc0d](https://git.ilcd.rocks/team-floyd/themes/gatsby-themes/commit/3d4fc0d86f199761b32785f0ced0ae1c8c3c5ebb))
10
+
1
11
  ## [1.6.8](https://git.ilcd.rocks/team-floyd/themes/gatsby-themes/compare/v1.6.7...v1.6.8) (2021-11-24)
2
12
 
3
13
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gatsby-core-theme",
3
- "version": "1.6.8",
3
+ "version": "1.6.9",
4
4
  "description": "Gatsby Theme NPM Package",
5
5
  "main": "index.js",
6
6
  "GATSBY_RECAPTCHA_SITEKEY": "6LfoyvMUAAAAAO4nl_MQnqHb4XdHxEiu5cXgIqeB",
@@ -1,25 +1,42 @@
1
- import React from 'react';
1
+ import React, { useState, useEffect } from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
 
4
- import { registerScroll } from '~helpers/scroll';
5
4
  import styles from './scroll-to-top.module.scss';
6
5
 
7
6
  const ScrollToTop = ({ scrollTo = '0' }) => {
8
- registerScroll();
9
-
10
- function scrollToTop(e) {
11
- e.preventDefault();
12
- window.scrollTo({
13
- top: scrollTo,
14
- behavior: 'smooth',
15
- });
16
- }
7
+ const [showScroll, setShowScroll] = useState(false);
8
+
9
+ const checkScrollTop = () => {
10
+ if (!showScroll && window.pageYOffset > 400) {
11
+ setShowScroll(true);
12
+ } else if (showScroll && window.pageYOffset <= 400) {
13
+ setShowScroll(false);
14
+ }
15
+ };
16
+
17
+ const scrollTop = () => {
18
+ window.scrollTo({ top: scrollTo, behavior: 'smooth' });
19
+ };
20
+
21
+ useEffect(() => {
22
+ if (typeof window !== 'undefined') {
23
+ window.addEventListener('scroll', checkScrollTop);
24
+
25
+ return () => {
26
+ window.removeEventListener('scroll', checkScrollTop);
27
+ };
28
+ }
29
+
30
+ return null;
31
+ });
32
+
17
33
  return (
18
34
  <button
19
35
  type="button"
20
36
  aria-label="Scroll to top"
21
- onClick={(e) => scrollToTop(e)}
37
+ onClick={(e) => scrollTop(e)}
22
38
  className={styles.scrollToTop}
39
+ style={{ display: showScroll ? 'flex' : 'none' }}
23
40
  />
24
41
  );
25
42
  };
@@ -1,3 +1,9 @@
1
+ body[data-scroll='0'] {
2
+ .scrollToTop {
3
+ opacity: 0;
4
+ }
5
+ }
6
+
1
7
  .scrollToTop {
2
8
  z-index: map-get($z-index, scroll-to-top);
3
9
  border-radius: 50%;
@@ -6,9 +12,12 @@
6
12
  width: 64px;
7
13
  height: 64px;
8
14
  text-align: center;
9
-
15
+ bottom: 0;
16
+ position: fixed;
17
+ right: 0;
18
+
10
19
  &:before {
11
- @include arrow(#fff, 2rem, up, false);
20
+ @include arrow(#000, 2rem, up, false);
12
21
  position: absolute;
13
22
  bottom: calc(50% - 1.25rem);
14
23
  left: calc(50% - 1rem);