-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
146 additions
and
5 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
** | ||
** Back To Top button for scrolling to the top | ||
** | ||
*/ | ||
|
||
document.addEventListener('DOMContentLoaded', () => { | ||
const backToTopBtn = document | ||
.getElementById('BackToTop') | ||
.querySelector('button') | ||
const alwaysVisible = backToTopBtn.classList.contains('always-visible') | ||
const threshold = 300 | ||
|
||
const onScroll = () => { | ||
if (!alwaysVisible) { | ||
showBackToTop = window.scrollY > threshold | ||
showBackToTop | ||
? (backToTopBtn.style.display = 'block') | ||
: (backToTopBtn.style.display = 'none') | ||
} | ||
} | ||
|
||
const scrollToTop = () => { | ||
window.scrollTo({ top: 0, behavior: 'smooth' }) | ||
} | ||
|
||
window.addEventListener('scroll', onScroll) | ||
backToTopBtn.addEventListener('click', scrollToTop) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
.BlockBackToTop { | ||
> button { | ||
@apply hidden; | ||
|
||
&.always-visible { | ||
@apply block; | ||
} | ||
} | ||
|
||
.IconDropdown { | ||
@apply transform rotate-180 text-sm; | ||
|
||
@screen sm { | ||
@apply mr-2; | ||
} | ||
} | ||
|
||
.label-text { | ||
@apply hidden; | ||
|
||
@screen sm { | ||
@apply block; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
storybook/stories/components/BlockBackToTop/BlockBackToTop.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { BaseButtonTemplate } from '../BaseButton/BaseButton' | ||
|
||
export const BlockBackToTopTemplate = ({ alwaysVisible }) => { | ||
return `<div id="BackToTop" class="BlockBackToTop"> | ||
${BaseButtonTemplate({ | ||
variant: 'primary', | ||
cssClass: `z-60 ${alwaysVisible ? 'always-visible' : ''}`, | ||
compact: true, | ||
icon: 'dropdown', | ||
iconBefore: true, | ||
label: 'Back to top', | ||
})} | ||
</div>` | ||
} |
23 changes: 23 additions & 0 deletions
23
storybook/stories/components/BlockBackToTop/BlockBackToTop.stories.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { BlockBackToTopTemplate } from './BlockBackToTop.js' | ||
|
||
export default { | ||
title: 'Components/Blocks/BlockBackToTop', | ||
argTypes: { | ||
alwaysVisible: { | ||
type: 'boolean', | ||
description: 'Toggles visibility based on the scrolling position.', | ||
}, | ||
}, | ||
parameters: { | ||
viewMode: 'docs', | ||
docs: { | ||
description: { | ||
component: 'Allows users to scroll back to the top of the page', | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
export const Default = BlockBackToTopTemplate.bind({}) | ||
Default.storyName = 'BlockBackToTop' | ||
Default.args = { alwaysVisible: true } |