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

feat: create a button top #242

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
14 changes: 14 additions & 0 deletions assets/css/button_up.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions assets/css/button_up.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions assets/js/scrollToTop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const button = document.querySelector(".button-up");

const showButtonIfScroll = () => {
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
button.style.display = "block";
} else {
button.style.display = "none";
}
};

const scrollToTop = () => {
window.scrollTo({
top: 0,
behavior: "smooth",
});
};

button.addEventListener("click", scrollToTop);
window.onscroll = () => showButtonIfScroll();
13 changes: 13 additions & 0 deletions assets/sass/button_up.sass
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Acho que o nome button_top ou até scroll_to_top é melhor. Ou talvez até adicionar isso ao assets/sass/style.sass já que é pouca coisa, não?

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@import "variables"

.button-up
background-color: $primary-500
color: $white
Copy link
Contributor

@george-gca george-gca Oct 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ao invés de usar $white e $primary-500 diretamente, é melhor já fazer pensando em possíveis valores diferentes para os temas. Exemplo do que foi feito com a janela de cookies:

Cor pro tema claro:

--cookies-text-color: #{$black}

Cor pro tema escuro:

--cookies-text-color: #{$white}

Como usar a variável:

color: var(--cookies-text-color)

border: none
border-radius: 5px
padding: 10px 20px
cursor: pointer
position: fixed
top: 90%
right: 20px
display: none
8 changes: 7 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link rel="stylesheet" href="assets/css/style.css" />
<link rel="stylesheet" href="assets/css/button_up.css" />
Copy link
Contributor

@george-gca george-gca Oct 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

É melhor adicionar o button_up no sass ao invés de aqui, isso evita ficar criando vários arquivos css sem necessidade, assim

@import "light_theme"


<!-- Phosphor Icons -->
<script src="https://unpkg.com/@phosphor-icons/web"></script>
Expand Down Expand Up @@ -83,9 +84,14 @@ <h2 class="header__subtitle">
</div>
</div>
</div>
<button class="button-up">
Topo
Copy link
Contributor

@george-gca george-gca Oct 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Só uma opinião, será que é necessária a palavra Topo? Porque eu acho que só a setinha é suficiente, e caso a gente adicione outras línguas é mais um lugar pra adicionar um termo traduzido que acho que não é essencial

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@george-gca @esterfania minha única preocupação em não ter nenhum texto é que incluir a palavra "topo" pode ser mais claro para usuários menos familiarizados com ícones, mas acredito que como essa setinha pra voltar ao topo da página é bem comum, pode não ser um grande problema.

<i class="ph ph-arrow-up"></i>
</button>
</main>
<script src="assets/js/script.js" type="module"></script>
<script src="assets/js/cookies.js" type="module"></script>
<script src="assets/js/scrollToTop.js" type="module"></script>
</body>

</html>
</html>