diff --git a/packages/components/src/animations/back-to-top.ts b/packages/components/src/animations/back-to-top.ts
deleted file mode 100644
index 209e51e27d..0000000000
--- a/packages/components/src/animations/back-to-top.ts
+++ /dev/null
@@ -1,31 +0,0 @@
-export const showUp = (
- el: HTMLElement,
- translateSize: string = '8rem',
- easing: string = 'ease',
- duration: number = 500,
- fill = 'forwards' as FillMode,
-): Animation => {
- return el.animate(
- [
- { transform: `translateY(${translateSize})`, opacity: '0%' },
- { transform: 'translateY(0)', opacity: '100%' },
- ],
- { duration: duration, easing, fill: fill },
- );
-};
-
-export const hideDown = (
- el: HTMLElement,
- translateSize: string = '8rem',
- easing: string = 'ease',
- duration: number = 500,
- fill = 'forwards' as FillMode,
-): Animation => {
- return el.animate(
- [
- { transform: 'translateY(0)', opacity: '100%' },
- { transform: `translateY(${translateSize})`, opacity: '0%' },
- ],
- { duration: duration, easing, fill: fill },
- );
-};
diff --git a/packages/components/src/animations/slide.ts b/packages/components/src/animations/slide.ts
new file mode 100644
index 0000000000..dd8f1355c1
--- /dev/null
+++ b/packages/components/src/animations/slide.ts
@@ -0,0 +1,31 @@
+const easing: string = 'ease';
+const duration: number = 500;
+const fill: FillMode = 'forwards';
+
+export const slideUp = (el: HTMLElement, translateSize: string = '8rem'): Animation => {
+ return el.animate(
+ [
+ { transform: `translateY(${translateSize})` }, // Starting position (no translation)
+ { transform: 'translateY(0)' }, // End position
+ ],
+ {
+ duration: duration,
+ easing,
+ fill,
+ },
+ );
+};
+
+export const slideDown = (el: HTMLElement, translateSize: string = '8rem'): Animation => {
+ return el.animate(
+ [
+ { transform: 'translateY(0)' }, // Starting position (no translation)
+ { transform: `translateY(${translateSize})` }, // End position
+ ],
+ {
+ duration: duration,
+ easing,
+ fill,
+ },
+ );
+};
diff --git a/packages/components/src/components.d.ts b/packages/components/src/components.d.ts
index c4578da381..bb72ebc77f 100644
--- a/packages/components/src/components.d.ts
+++ b/packages/components/src/components.d.ts
@@ -94,6 +94,7 @@ export namespace Components {
"userid"?: string;
}
interface PostBackToTop {
+ "bttptitle": string;
}
interface PostBreadcrumbItem {
/**
@@ -880,6 +881,7 @@ declare namespace LocalJSX {
"userid"?: string;
}
interface PostBackToTop {
+ "bttptitle"?: string;
}
interface PostBreadcrumbItem {
/**
diff --git a/packages/components/src/components/post-back-to-top/post-back-to-top.scss b/packages/components/src/components/post-back-to-top/post-back-to-top.scss
index d46f5db4f4..24530cdf61 100644
--- a/packages/components/src/components/post-back-to-top/post-back-to-top.scss
+++ b/packages/components/src/components/post-back-to-top/post-back-to-top.scss
@@ -19,12 +19,11 @@ tokens.$default-map: (
post-floating-button-hover-border: #504f4b,
post-floating-button-hover-fg: #504f4b,
post-floating-button-hover-bg: white,
- post-floating-button-translate-y: 36px
+ post-floating-button-translate-y: 8rem
);
:host {
- --post-floating-button-translate-y: tokens.get('post-floating-button-translate-y');
-
+ --post-floating-button-translate-y: #{tokens.get('post-floating-button-translate-y')};
position: fixed;
bottom: tokens.get('post-floating-button-position-bottom');
right: tokens.get('post-floating-button-position-right');
diff --git a/packages/components/src/components/post-back-to-top/post-back-to-top.tsx b/packages/components/src/components/post-back-to-top/post-back-to-top.tsx
index c1dbe70fa9..0defb8033f 100644
--- a/packages/components/src/components/post-back-to-top/post-back-to-top.tsx
+++ b/packages/components/src/components/post-back-to-top/post-back-to-top.tsx
@@ -1,5 +1,5 @@
-import { Component, Element, Host, State, h, Watch } from '@stencil/core';
-import { showUp, hideDown } from '@/animations/back-to-top';
+import { Component, Element, Host, State, h, Watch, Prop } from '@stencil/core';
+import { slideUp, slideDown } from '@/animations/slide';
// Token for different translate values depending on the breakpoint
@@ -11,33 +11,27 @@ import { showUp, hideDown } from '@/animations/back-to-top';
export class PostBackToTop {
@Element() el: HTMLElement;
+ @Prop() bttptitle: string;
+
@State() belowFold: boolean = false;
- @State() translateY: string = '';
- getFoldHeight(): number {
- return window.innerHeight;
- }
+ private translateY: string;
- getScrollPositionPercentage(): number {
- // Window.innerHeight is the foldHeight
- return (window.scrollY / this.getFoldHeight()) * 100;
- }
-
- calcIfIsBelowFold(): boolean {
- return this.getScrollPositionPercentage() > 100;
+ IsBelowFold(): boolean {
+ return window.scrollY > window.innerHeight;
}
handleScroll = () => {
- this.belowFold = this.calcIfIsBelowFold();
+ this.belowFold = this.IsBelowFold();
};
// Watch for changes in belowFold
@Watch('belowFold')
watchBelowFold(newValue: boolean) {
if (newValue) {
- showUp(this.el, this.translateY);
+ slideUp(this.el, this.translateY);
} else {
- hideDown(this.el, this.translateY);
+ slideDown(this.el, this.translateY);
}
}
@@ -50,24 +44,23 @@ export class PostBackToTop {
// Set the initial state
componentWillLoad() {
- this.belowFold = this.calcIfIsBelowFold();
- if (!this.belowFold) {
- this.el.style.transform = `translateY(${this.translateY})`;
- }
-
- const translateYValue = window
- .getComputedStyle(this.el)
- .getPropertyValue('--post-floating-button-translate-y');
- console.log(translateYValue);
- this.translateY = translateYValue;
+ this.belowFold = this.IsBelowFold();
}
componentDidLoad() {
window.addEventListener('scroll', this.handleScroll, false);
+ this.translateY = window
+ .getComputedStyle(this.el)
+ .getPropertyValue('--post-floating-button-translate-y');
+
+ if (!this.belowFold) {
+ this.el.style.transform = `translateY(${this.translateY})`;
+ }
+
// Initial load
if (this.belowFold) {
- showUp(this.el, this.translateY);
+ slideUp(this.el, this.translateY);
}
}
@@ -85,7 +78,7 @@ export class PostBackToTop {
onClick={this.scrollToTop}
>