mirror of
https://github.com/codex-team/codex.docs.git
synced 2025-07-19 05:09:41 +02:00
refactor: delete copy link button from header
This commit is contained in:
parent
b83d468ba0
commit
91ba44a169
3 changed files with 5 additions and 145 deletions
|
@ -1,11 +1,5 @@
|
||||||
<h{{ level }} id="{{ text | urlify }}" class="block-header block-header--{{ level }} block-header--anchor">
|
<h{{ level }} id="{{ text | urlify }}" class="block-header block-header--{{ level }}">
|
||||||
<div class="block-header__copy-link-splash"></div>
|
|
||||||
<div class="block-header__copy-link">
|
|
||||||
<div class="block-header__copy-link-icon--initial">{{ svg('copy') }}</div>
|
|
||||||
<div class="block-header__copy-link-icon--success">{{ svg('check') }}</div>
|
|
||||||
</div>
|
|
||||||
<a href="#{{ text | urlify }}">
|
<a href="#{{ text | urlify }}">
|
||||||
{{ text }}
|
{{ text }}
|
||||||
</a>
|
</a>
|
||||||
</h{{ level }}>
|
</h{{ level }}>
|
||||||
|
|
||||||
|
|
|
@ -20,10 +20,7 @@ export default class Page {
|
||||||
*/
|
*/
|
||||||
static get CSS() {
|
static get CSS() {
|
||||||
return {
|
return {
|
||||||
page: 'page',
|
page: 'page'
|
||||||
copyLinkBtn: 'block-header__copy-link',
|
|
||||||
header: 'block-header--anchor',
|
|
||||||
headerLinkCopied: 'block-header--link-copied',
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,11 +32,11 @@ export default class Page {
|
||||||
this.tableOfContent = this.createTableOfContent();
|
this.tableOfContent = this.createTableOfContent();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add click event listener to capture copy link button clicks
|
* Add click event listener
|
||||||
*/
|
*/
|
||||||
const page = document.querySelector(`.${Page.CSS.page}`);
|
const page = document.querySelector(`.${Page.CSS.page}`);
|
||||||
|
|
||||||
page.addEventListener('click', this.copyAnchorLinkIfNeeded);
|
page.addEventListener('click', (event) => { });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -69,39 +66,11 @@ export default class Page {
|
||||||
try {
|
try {
|
||||||
// eslint-disable-next-line no-new
|
// eslint-disable-next-line no-new
|
||||||
new TableOfContent({
|
new TableOfContent({
|
||||||
tagSelector:
|
tagSelector: '.block-header',
|
||||||
'h2.block-header--anchor,' +
|
|
||||||
'h3.block-header--anchor,' +
|
|
||||||
'h4.block-header--anchor',
|
|
||||||
appendTo: document.getElementById('layout-sidebar-right'),
|
appendTo: document.getElementById('layout-sidebar-right'),
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error); // @todo send to Hawk
|
console.error(error); // @todo send to Hawk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if 'copy link' button was clicked and copies the link to clipboard
|
|
||||||
*
|
|
||||||
* @param e - click event
|
|
||||||
*/
|
|
||||||
copyAnchorLinkIfNeeded = async (e) => {
|
|
||||||
const copyLinkButtonClicked = e.target.closest(`.${Page.CSS.copyLinkBtn}`);
|
|
||||||
|
|
||||||
if (!copyLinkButtonClicked) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const header = e.target.closest(`.${Page.CSS.header}`);
|
|
||||||
const link = header.querySelector('a').href;
|
|
||||||
|
|
||||||
await copyToClipboard(link);
|
|
||||||
header.classList.add(Page.CSS.headerLinkCopied);
|
|
||||||
|
|
||||||
header.addEventListener('mouseleave', () => {
|
|
||||||
setTimeout(() => {
|
|
||||||
header.classList.remove(Page.CSS.headerLinkCopied);
|
|
||||||
}, 500);
|
|
||||||
}, { once: true });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,111 +125,9 @@
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
&--link-copied {
|
|
||||||
.block-header__copy-link,
|
|
||||||
.block-header__copy-link:hover {
|
|
||||||
background: var(--color-success);
|
|
||||||
opacity: 1;
|
|
||||||
animation: check-square-in 250ms ease-in;
|
|
||||||
pointer-events: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.block-header__copy-link-icon--initial {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.block-header__copy-link-icon--success {
|
|
||||||
display: flex;
|
|
||||||
animation: check-sign-in 350ms ease-in forwards;
|
|
||||||
}
|
|
||||||
|
|
||||||
.block-header__copy-link-splash {
|
|
||||||
opacity: 0;
|
|
||||||
visibility: visible;
|
|
||||||
transform: scale(3.5);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&__copy-link-splash {
|
|
||||||
position: absolute;
|
|
||||||
left: 0;
|
|
||||||
width: 28px;
|
|
||||||
height: 28px;
|
|
||||||
background-color: var(--color-success);
|
|
||||||
transform: scale(1);
|
|
||||||
border-radius: 100%;
|
|
||||||
transition: transform 400ms ease-out, opacity 400ms;
|
|
||||||
visibility: hidden;
|
|
||||||
}
|
|
||||||
|
|
||||||
&__copy-link-icon--success {
|
|
||||||
width: 24px;
|
|
||||||
height: 24px;
|
|
||||||
display: none;
|
|
||||||
color: white;
|
|
||||||
}
|
|
||||||
|
|
||||||
&__copy-link-icon--initial {
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
&__copy-link {
|
|
||||||
width: 28px;
|
|
||||||
height: 28px;
|
|
||||||
cursor: pointer;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
border-radius: 8px;
|
|
||||||
@apply --squircle;
|
|
||||||
color: var(--color-text-second);
|
|
||||||
opacity: 0;
|
|
||||||
margin-right: 8px;
|
|
||||||
|
|
||||||
@media (--can-hover) {
|
|
||||||
&:hover {
|
|
||||||
background: var(--color-link-hover);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (--can-hover) {
|
|
||||||
&:hover {
|
|
||||||
.block-header__copy-link {
|
|
||||||
opacity: 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.inline-code {
|
.inline-code {
|
||||||
line-height: inherit;
|
line-height: inherit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes check-sign-in {
|
|
||||||
from {
|
|
||||||
transform: scale(.7);
|
|
||||||
}
|
|
||||||
80% {
|
|
||||||
transform: scale(1.1);
|
|
||||||
}
|
|
||||||
to {
|
|
||||||
transform: none;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@keyframes check-square-in {
|
|
||||||
from {
|
|
||||||
transform: scale(1.05);
|
|
||||||
}
|
|
||||||
80% {
|
|
||||||
transform: scale(.96);
|
|
||||||
}
|
|
||||||
to {
|
|
||||||
transform: none;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -580,4 +478,3 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue