refactor: adjust styling of back top top button (#5469)

* refactor: css variables for back to top button

* refactor: adjust back to top button styling

* Update from PR feedback

* err... darker.

* swap secondary color for emphasis scale

* reduce contrast further

* Add new translations

* Cleanup CSS

* Remove active state

Co-authored-by: Alexey Pyltsyn <lex61rus@gmail.com>
This commit is contained in:
Don 2021-09-11 09:09:58 -04:00 committed by GitHub
parent 9a089d4886
commit b6d0378704
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 57 additions and 25 deletions

View file

@ -1,5 +1,6 @@
{ {
"theme.AnnouncementBar.closeButtonAriaLabel": "إغلاق", "theme.AnnouncementBar.closeButtonAriaLabel": "إغلاق",
"theme.BackToTopButton.buttonAriaLabel": "Scroll back to top",
"theme.CodeBlock.copied": "تم النسخ", "theme.CodeBlock.copied": "تم النسخ",
"theme.CodeBlock.copy": "نسخ", "theme.CodeBlock.copy": "نسخ",
"theme.CodeBlock.copyButtonAriaLabel": "نسخ الرمز إلى الحافظة", "theme.CodeBlock.copyButtonAriaLabel": "نسخ الرمز إلى الحافظة",

View file

@ -1,6 +1,7 @@
{ {
"theme.AnnouncementBar.closeButtonAriaLabel": "Close", "theme.AnnouncementBar.closeButtonAriaLabel": "Close",
"theme.AnnouncementBar.closeButtonAriaLabel___DESCRIPTION": "The ARIA label for close button of announcement bar", "theme.AnnouncementBar.closeButtonAriaLabel___DESCRIPTION": "The ARIA label for close button of announcement bar",
"theme.BackToTopButton.buttonAriaLabel": "Scroll back to top",
"theme.CodeBlock.copied": "Copied", "theme.CodeBlock.copied": "Copied",
"theme.CodeBlock.copied___DESCRIPTION": "The copied button label on code blocks", "theme.CodeBlock.copied___DESCRIPTION": "The copied button label on code blocks",
"theme.CodeBlock.copy": "Copy", "theme.CodeBlock.copy": "Copy",
@ -96,7 +97,7 @@
"theme.docs.versions.latestVersionLinkLabel": "latest version", "theme.docs.versions.latestVersionLinkLabel": "latest version",
"theme.docs.versions.latestVersionLinkLabel___DESCRIPTION": "The label used for the latest version suggestion link label", "theme.docs.versions.latestVersionLinkLabel___DESCRIPTION": "The label used for the latest version suggestion link label",
"theme.docs.versions.latestVersionSuggestionLabel": "For up-to-date documentation, see the {latestVersionLink} ({versionLabel}).", "theme.docs.versions.latestVersionSuggestionLabel": "For up-to-date documentation, see the {latestVersionLink} ({versionLabel}).",
"theme.docs.versions.latestVersionSuggestionLabel___DESCRIPTION": "The label used to tell the user to check the latest version", "theme.docs.versions.latestVersionSuggestionLabel___DESCRIPTION": "The label userd to tell the user that he's browsing an unmaintained doc version",
"theme.docs.versions.unmaintainedVersionLabel": "This is documentation for {siteTitle} {versionLabel}, which is no longer actively maintained.", "theme.docs.versions.unmaintainedVersionLabel": "This is documentation for {siteTitle} {versionLabel}, which is no longer actively maintained.",
"theme.docs.versions.unmaintainedVersionLabel___DESCRIPTION": "The label used to tell the user that he's browsing an unmaintained doc version", "theme.docs.versions.unmaintainedVersionLabel___DESCRIPTION": "The label used to tell the user that he's browsing an unmaintained doc version",
"theme.docs.versions.unreleasedVersionLabel": "This is unreleased documentation for {siteTitle} {versionLabel} version.", "theme.docs.versions.unreleasedVersionLabel": "This is unreleased documentation for {siteTitle} {versionLabel} version.",

View file

@ -1,5 +1,6 @@
{ {
"theme.AnnouncementBar.closeButtonAriaLabel": "বন্ধ করুন", "theme.AnnouncementBar.closeButtonAriaLabel": "বন্ধ করুন",
"theme.BackToTopButton.buttonAriaLabel": "Scroll back to top",
"theme.CodeBlock.copied": "কপিড", "theme.CodeBlock.copied": "কপিড",
"theme.CodeBlock.copy": "কপি", "theme.CodeBlock.copy": "কপি",
"theme.CodeBlock.copyButtonAriaLabel": "ক্লিপবোর্ডে কোড কপি করুন", "theme.CodeBlock.copyButtonAriaLabel": "ক্লিপবোর্ডে কোড কপি করুন",

View file

@ -1,5 +1,6 @@
{ {
"theme.AnnouncementBar.closeButtonAriaLabel": "Zavřít", "theme.AnnouncementBar.closeButtonAriaLabel": "Zavřít",
"theme.BackToTopButton.buttonAriaLabel": "Scroll back to top",
"theme.CodeBlock.copied": "Zkopírováno", "theme.CodeBlock.copied": "Zkopírováno",
"theme.CodeBlock.copy": "Zkopírovat", "theme.CodeBlock.copy": "Zkopírovat",
"theme.CodeBlock.copyButtonAriaLabel": "Zkopírovat kód do schránky", "theme.CodeBlock.copyButtonAriaLabel": "Zkopírovat kód do schránky",

View file

@ -1,5 +1,6 @@
{ {
"theme.AnnouncementBar.closeButtonAriaLabel": "Luk", "theme.AnnouncementBar.closeButtonAriaLabel": "Luk",
"theme.BackToTopButton.buttonAriaLabel": "Scroll back to top",
"theme.CodeBlock.copied": "Kopieret", "theme.CodeBlock.copied": "Kopieret",
"theme.CodeBlock.copy": "Kopier", "theme.CodeBlock.copy": "Kopier",
"theme.CodeBlock.copyButtonAriaLabel": "Kopier kode til udklipsholder", "theme.CodeBlock.copyButtonAriaLabel": "Kopier kode til udklipsholder",

View file

@ -1,5 +1,6 @@
{ {
"theme.AnnouncementBar.closeButtonAriaLabel": "Schließen", "theme.AnnouncementBar.closeButtonAriaLabel": "Schließen",
"theme.BackToTopButton.buttonAriaLabel": "Scroll back to top",
"theme.CodeBlock.copied": "Kopiert", "theme.CodeBlock.copied": "Kopiert",
"theme.CodeBlock.copy": "Kopieren", "theme.CodeBlock.copy": "Kopieren",
"theme.CodeBlock.copyButtonAriaLabel": "In die Zwischenablage kopieren", "theme.CodeBlock.copyButtonAriaLabel": "In die Zwischenablage kopieren",

View file

@ -1,5 +1,6 @@
{ {
"theme.AnnouncementBar.closeButtonAriaLabel": "Cerrar", "theme.AnnouncementBar.closeButtonAriaLabel": "Cerrar",
"theme.BackToTopButton.buttonAriaLabel": "Scroll back to top",
"theme.CodeBlock.copied": "Copiado", "theme.CodeBlock.copied": "Copiado",
"theme.CodeBlock.copy": "Copiar", "theme.CodeBlock.copy": "Copiar",
"theme.CodeBlock.copyButtonAriaLabel": "Copiar código al portapaples", "theme.CodeBlock.copyButtonAriaLabel": "Copiar código al portapaples",

View file

@ -1,5 +1,6 @@
{ {
"theme.AnnouncementBar.closeButtonAriaLabel": "بستن", "theme.AnnouncementBar.closeButtonAriaLabel": "بستن",
"theme.BackToTopButton.buttonAriaLabel": "Scroll back to top",
"theme.CodeBlock.copied": "کپی شد", "theme.CodeBlock.copied": "کپی شد",
"theme.CodeBlock.copy": "کپی", "theme.CodeBlock.copy": "کپی",
"theme.CodeBlock.copyButtonAriaLabel": "کپی به کلیپ بورد", "theme.CodeBlock.copyButtonAriaLabel": "کپی به کلیپ بورد",

View file

@ -1,5 +1,6 @@
{ {
"theme.AnnouncementBar.closeButtonAriaLabel": "Isara", "theme.AnnouncementBar.closeButtonAriaLabel": "Isara",
"theme.BackToTopButton.buttonAriaLabel": "Scroll back to top",
"theme.CodeBlock.copied": "Kinopya", "theme.CodeBlock.copied": "Kinopya",
"theme.CodeBlock.copy": "Kopyahin", "theme.CodeBlock.copy": "Kopyahin",
"theme.CodeBlock.copyButtonAriaLabel": "Kopyahin ang code sa clipboard", "theme.CodeBlock.copyButtonAriaLabel": "Kopyahin ang code sa clipboard",

View file

@ -1,5 +1,6 @@
{ {
"theme.AnnouncementBar.closeButtonAriaLabel": "Fermer", "theme.AnnouncementBar.closeButtonAriaLabel": "Fermer",
"theme.BackToTopButton.buttonAriaLabel": "Scroll back to top",
"theme.CodeBlock.copied": "Copié", "theme.CodeBlock.copied": "Copié",
"theme.CodeBlock.copy": "Copier", "theme.CodeBlock.copy": "Copier",
"theme.CodeBlock.copyButtonAriaLabel": "Copier le code", "theme.CodeBlock.copyButtonAriaLabel": "Copier le code",

View file

@ -1,5 +1,6 @@
{ {
"theme.AnnouncementBar.closeButtonAriaLabel": "סגור", "theme.AnnouncementBar.closeButtonAriaLabel": "סגור",
"theme.BackToTopButton.buttonAriaLabel": "Scroll back to top",
"theme.CodeBlock.copied": "הועתק", "theme.CodeBlock.copied": "הועתק",
"theme.CodeBlock.copy": "העתק", "theme.CodeBlock.copy": "העתק",
"theme.CodeBlock.copyButtonAriaLabel": "העתק קוד ללוח העריכה", "theme.CodeBlock.copyButtonAriaLabel": "העתק קוד ללוח העריכה",

View file

@ -1,5 +1,6 @@
{ {
"theme.AnnouncementBar.closeButtonAriaLabel": "बंद करे", "theme.AnnouncementBar.closeButtonAriaLabel": "बंद करे",
"theme.BackToTopButton.buttonAriaLabel": "Scroll back to top",
"theme.CodeBlock.copied": "कॉपीड", "theme.CodeBlock.copied": "कॉपीड",
"theme.CodeBlock.copy": "कॉपी", "theme.CodeBlock.copy": "कॉपी",
"theme.CodeBlock.copyButtonAriaLabel": "क्लिपबोर्ड पर कोड कॉपी करें", "theme.CodeBlock.copyButtonAriaLabel": "क्लिपबोर्ड पर कोड कॉपी करें",

View file

@ -1,5 +1,6 @@
{ {
"theme.AnnouncementBar.closeButtonAriaLabel": "閉じる", "theme.AnnouncementBar.closeButtonAriaLabel": "閉じる",
"theme.BackToTopButton.buttonAriaLabel": "Scroll back to top",
"theme.CodeBlock.copied": "コピーしました", "theme.CodeBlock.copied": "コピーしました",
"theme.CodeBlock.copy": "コピー", "theme.CodeBlock.copy": "コピー",
"theme.CodeBlock.copyButtonAriaLabel": "クリップボードにコードをコピー", "theme.CodeBlock.copyButtonAriaLabel": "クリップボードにコードをコピー",

View file

@ -1,5 +1,6 @@
{ {
"theme.AnnouncementBar.closeButtonAriaLabel": "닫기", "theme.AnnouncementBar.closeButtonAriaLabel": "닫기",
"theme.BackToTopButton.buttonAriaLabel": "Scroll back to top",
"theme.CodeBlock.copied": "복사했습니다", "theme.CodeBlock.copied": "복사했습니다",
"theme.CodeBlock.copy": "복사", "theme.CodeBlock.copy": "복사",
"theme.CodeBlock.copyButtonAriaLabel": "클립보드에 코드 복사", "theme.CodeBlock.copyButtonAriaLabel": "클립보드에 코드 복사",

View file

@ -1,5 +1,6 @@
{ {
"theme.AnnouncementBar.closeButtonAriaLabel": "Zamknij", "theme.AnnouncementBar.closeButtonAriaLabel": "Zamknij",
"theme.BackToTopButton.buttonAriaLabel": "Scroll back to top",
"theme.CodeBlock.copied": "Skopiowano!", "theme.CodeBlock.copied": "Skopiowano!",
"theme.CodeBlock.copy": "Kopiuj", "theme.CodeBlock.copy": "Kopiuj",
"theme.CodeBlock.copyButtonAriaLabel": "Kopiuj do schowka", "theme.CodeBlock.copyButtonAriaLabel": "Kopiuj do schowka",

View file

@ -1,5 +1,6 @@
{ {
"theme.AnnouncementBar.closeButtonAriaLabel": "Fechar", "theme.AnnouncementBar.closeButtonAriaLabel": "Fechar",
"theme.BackToTopButton.buttonAriaLabel": "Scroll back to top",
"theme.CodeBlock.copied": "Copiado", "theme.CodeBlock.copied": "Copiado",
"theme.CodeBlock.copy": "Copiar", "theme.CodeBlock.copy": "Copiar",
"theme.CodeBlock.copyButtonAriaLabel": "Copiar código para a área de transferência", "theme.CodeBlock.copyButtonAriaLabel": "Copiar código para a área de transferência",

View file

@ -1,5 +1,6 @@
{ {
"theme.AnnouncementBar.closeButtonAriaLabel": "Fechar", "theme.AnnouncementBar.closeButtonAriaLabel": "Fechar",
"theme.BackToTopButton.buttonAriaLabel": "Scroll back to top",
"theme.CodeBlock.copied": "Copiado", "theme.CodeBlock.copied": "Copiado",
"theme.CodeBlock.copy": "Copiar", "theme.CodeBlock.copy": "Copiar",
"theme.CodeBlock.copyButtonAriaLabel": "Copiar código para a área de transferência", "theme.CodeBlock.copyButtonAriaLabel": "Copiar código para a área de transferência",

View file

@ -1,5 +1,6 @@
{ {
"theme.AnnouncementBar.closeButtonAriaLabel": "Закрыть", "theme.AnnouncementBar.closeButtonAriaLabel": "Закрыть",
"theme.BackToTopButton.buttonAriaLabel": "Scroll back to top",
"theme.CodeBlock.copied": "Скопировано", "theme.CodeBlock.copied": "Скопировано",
"theme.CodeBlock.copy": "Скопировать", "theme.CodeBlock.copy": "Скопировать",
"theme.CodeBlock.copyButtonAriaLabel": "Скопировать в буфер обмена", "theme.CodeBlock.copyButtonAriaLabel": "Скопировать в буфер обмена",

View file

@ -1,5 +1,6 @@
{ {
"theme.AnnouncementBar.closeButtonAriaLabel": "Kapat", "theme.AnnouncementBar.closeButtonAriaLabel": "Kapat",
"theme.BackToTopButton.buttonAriaLabel": "Scroll back to top",
"theme.CodeBlock.copied": "Kopyalandı", "theme.CodeBlock.copied": "Kopyalandı",
"theme.CodeBlock.copy": "Kopyala", "theme.CodeBlock.copy": "Kopyala",
"theme.CodeBlock.copyButtonAriaLabel": "Kodu panoya kopyala", "theme.CodeBlock.copyButtonAriaLabel": "Kodu panoya kopyala",

View file

@ -1,5 +1,6 @@
{ {
"theme.AnnouncementBar.closeButtonAriaLabel": "Đóng", "theme.AnnouncementBar.closeButtonAriaLabel": "Đóng",
"theme.BackToTopButton.buttonAriaLabel": "Scroll back to top",
"theme.CodeBlock.copied": "Đã sao chép", "theme.CodeBlock.copied": "Đã sao chép",
"theme.CodeBlock.copy": "Sao chép", "theme.CodeBlock.copy": "Sao chép",
"theme.CodeBlock.copyButtonAriaLabel": "Sao chép code vào bộ nhớ tạm", "theme.CodeBlock.copyButtonAriaLabel": "Sao chép code vào bộ nhớ tạm",

View file

@ -1,5 +1,6 @@
{ {
"theme.AnnouncementBar.closeButtonAriaLabel": "关闭", "theme.AnnouncementBar.closeButtonAriaLabel": "关闭",
"theme.BackToTopButton.buttonAriaLabel": "Scroll back to top",
"theme.CodeBlock.copied": "复制成功", "theme.CodeBlock.copied": "复制成功",
"theme.CodeBlock.copy": "复制", "theme.CodeBlock.copy": "复制",
"theme.CodeBlock.copyButtonAriaLabel": "复制代码到剪贴板", "theme.CodeBlock.copyButtonAriaLabel": "复制代码到剪贴板",

View file

@ -1,5 +1,6 @@
{ {
"theme.AnnouncementBar.closeButtonAriaLabel": "關閉", "theme.AnnouncementBar.closeButtonAriaLabel": "關閉",
"theme.BackToTopButton.buttonAriaLabel": "Scroll back to top",
"theme.CodeBlock.copied": "複製成功", "theme.CodeBlock.copied": "複製成功",
"theme.CodeBlock.copy": "複製", "theme.CodeBlock.copy": "複製",
"theme.CodeBlock.copyButtonAriaLabel": "複製代碼至剪貼簿", "theme.CodeBlock.copyButtonAriaLabel": "複製代碼至剪貼簿",

View file

@ -8,9 +8,11 @@
import React, {useRef, useState} from 'react'; import React, {useRef, useState} from 'react';
import clsx from 'clsx'; import clsx from 'clsx';
import {useLocation} from '@docusaurus/router'; import {useLocation} from '@docusaurus/router';
import {translate} from '@docusaurus/Translate';
import useScrollPosition from '@theme/hooks/useScrollPosition'; import useScrollPosition from '@theme/hooks/useScrollPosition';
import styles from './styles.module.css'; import styles from './styles.module.css';
import {ThemeClassNames} from '@docusaurus/theme-common';
const threshold = 300; const threshold = 300;
@ -106,18 +108,22 @@ function BackToTopButton(): JSX.Element {
return ( return (
<button <button
className={clsx('clean-btn', styles.backToTopButton, { aria-label={translate({
[styles.backToTopButtonShow]: show, id: 'theme.BackToTopButton.buttonAriaLabel',
message: 'Scroll back to top',
description: 'The ARIA label for the back to top button',
})} })}
className={clsx(
'clean-btn',
ThemeClassNames.common.backToTopButton,
styles.backToTopButton,
{
[styles.backToTopButtonShow]: show,
},
)}
type="button" type="button"
onClick={() => smoothScrollTop()}> onClick={() => smoothScrollTop()}
<svg viewBox="0 0 24 24" width="28"> />
<path
d="M7.41 15.41L12 10.83l4.59 4.58L18 14l-6-6-6 6z"
fill="currentColor"
/>
</svg>
</button>
); );
} }

View file

@ -5,32 +5,35 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*/ */
:root {
--docusaurus-btt-background: var(--ifm-color-primary);
--docusaurus-btt-color: #fff;
}
.backToTopButton { .backToTopButton {
display: flex;
align-items: center;
justify-content: center;
position: fixed; position: fixed;
right: 1.3rem; right: 1.3rem;
bottom: 1.3rem; bottom: 1.3rem;
border-radius: 50%; border-radius: 50%;
background: var(--docusaurus-btt-background); background-color: var(--ifm-color-emphasis-200);
color: var(--docusaurus-btt-color);
width: 3rem; width: 3rem;
height: 3rem; height: 3rem;
z-index: var(--ifm-z-index-fixed); z-index: var(--ifm-z-index-fixed);
box-shadow: 0 0.125rem 0.3125rem 0 rgba(0, 0, 0, 0.3); box-shadow: var(--ifm-global-shadow-lw);
transition: all var(--ifm-transition-fast) ease-in-out; transition: all var(--ifm-transition-fast)
var(--ifm-transition-timing-default);
opacity: 0; opacity: 0;
transform: scale(0); transform: scale(0);
} }
.backToTopButton:not(:focus):hover { .backToTopButton:after {
opacity: 0.8; content: ' ';
display: inline-block;
mask: var(--ifm-menu-link-sublist-icon) 50% / 2rem 2rem no-repeat;
background-color: var(--ifm-color-emphasis-1000);
width: 100%;
height: 100%;
}
@media (hover: hover) {
.backToTopButton:hover {
background-color: var(--ifm-color-emphasis-300);
}
} }
.backToTopButtonShow { .backToTopButtonShow {

View file

@ -33,6 +33,7 @@ export const ThemeClassNames = {
common: { common: {
editThisPage: 'theme-edit-this-page', editThisPage: 'theme-edit-this-page',
lastUpdated: 'theme-last-updated', lastUpdated: 'theme-last-updated',
backToTopButton: 'theme-back-to-top-button',
}, },
layout: { layout: {
// TODO add other stable classNames here // TODO add other stable classNames here