Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scroll to top button #3667

Merged
merged 5 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions hypha/core/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@ class DropdownMenu(component.Component):

def get_context_data(self, **kwargs) -> dict:
return {"id": str(uuid.uuid4())}


@component.register("scroll-to-top")
class ScrollToTop(component.Component):
template_name = "components/scroll-to-top.html"
14 changes: 14 additions & 0 deletions hypha/core/templates/components/scroll-to-top.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{% load heroicons %}

<template x-teleport="body" x-data="{scrollBackTop: false, lastScrollTop: 0}">
<button
x-show="scrollBackTop"
x-transition
x-transition.duration.500ms
x-on:scroll.window.throttle.50ms="scrollBackTop = (window.pageYOffset < lastScrollTop && window.pageYOffset > window.outerHeight * 0.4) ? true : false; lastScrollTop = window.pageYOffset;"
@click="window.scrollTo({top: 0, behavior: 'smooth'})"
aria-label="Back to top"
class="fixed top-0 right-1/2 px-3 py-2 mt-10 -mr-[64px] text-white bg-light-blue/80 z-30 hover:bg-light-blue hover:text-white hover:shadow-lg transition-all focus:outline-none cursor-pointer shadow-lg rounded-2xl">
{% heroicon_mini "arrow-long-up" class="inline align-text-bottom" size=18 aria_hidden=true %} Back to top
</button>
</template>
4 changes: 4 additions & 0 deletions hypha/templates/base-apply.html
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@

<footer class="footer"></footer>

{% block scroll_to_top %}
{% #scroll-to-top %}
{% endblock scroll_to_top %}

{% cookie_banner %}

<script src="{% static 'js/main.js' %}"></script>
Expand Down