-
Notifications
You must be signed in to change notification settings - Fork 654
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Дополняет текст * Причёсывет демку * Делает дополнения, улучшает демо * Добавляет новую демку * Изменяет высоту демки * Добавляет начертание * Добавляет `aria-controls`
- Loading branch information
1 parent
5384b46
commit 32c8b72
Showing
3 changed files
with
255 additions
and
42 deletions.
There are no files selected for viewing
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,171 @@ | ||
<!DOCTYPE html> | ||
<html lang="ru"> | ||
<head> | ||
<title>Всплывающее уведомление (тост) — <output> — Дока</title> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<link rel="preconnect" href="https://fonts.googleapis.com"> | ||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> | ||
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap"> | ||
<style> | ||
*, *::before, *::after { | ||
margin: 0; | ||
padding: 0; | ||
box-sizing: border-box; | ||
} | ||
|
||
html { | ||
color-scheme: dark; | ||
font-size: 18px; | ||
} | ||
|
||
body { | ||
min-height: 100vh; | ||
padding: 50px; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
background-color: #18191C; | ||
color: #FFFFFF; | ||
font-family: "Roboto", sans-serif; | ||
} | ||
|
||
.container { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
max-width: 480px; | ||
width: 100%; | ||
} | ||
|
||
.button { | ||
display: block; | ||
width: 210px; | ||
border: 2px solid transparent; | ||
border-radius: 6px; | ||
padding: 9px 15px; | ||
color: #000000; | ||
font-size: 1rem; | ||
font-weight: 300; | ||
font-family: inherit; | ||
transition: background-color 0.2s linear; | ||
} | ||
|
||
.toast__button { | ||
display: block; | ||
position: absolute; | ||
right: 0; | ||
top: 0; | ||
bottom: 0; | ||
margin: auto; | ||
padding: 10px 10px; | ||
color: #000000; | ||
border: 0; | ||
border-left: 2px solid #FFFFFF; | ||
font-size: 1rem; | ||
font-weight: 300; | ||
font-family: inherit; | ||
transition: background-color 0.2s linear; | ||
z-index: 1; | ||
} | ||
|
||
.button-orange { | ||
background-color: #FF8630; | ||
} | ||
|
||
.button:hover, .toast__button:hover { | ||
background-color: #FFFFFF; | ||
cursor: pointer; | ||
transition: background-color 0.2s linear; | ||
} | ||
|
||
.button:focus-visible, .toast__button:focus-visible { | ||
border: 2px solid #FFFFFF; | ||
outline: none; | ||
} | ||
|
||
.button:focus, .toast__button:focus { | ||
border: 2px solid #FFFFFF; | ||
outline: none; | ||
} | ||
|
||
.toast { | ||
position: fixed; | ||
bottom: .4em; | ||
left: 0; | ||
right: 0; | ||
max-width: 500px; | ||
margin: auto; | ||
padding: 10px 40px; | ||
text-align: left; | ||
font-size: calc(1rem - 2px); | ||
color: #000000; | ||
background-color: #FFFFFF; | ||
opacity: 0; | ||
transform: translateY(0); | ||
transition: | ||
transform .2s ease-in-out, | ||
opacity .2s ease-in-out; | ||
} | ||
|
||
.toast.toast--open { | ||
opacity: 1; | ||
transform: translateY(-4em); | ||
} | ||
|
||
@media (max-width: 768px) { | ||
body { | ||
padding: 30px; | ||
} | ||
|
||
.toast { | ||
max-width: 100%; | ||
} | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<button class="button button-orange" onclick="show()" aria-controls="message">Сохранить</button> | ||
<div class="toast"> | ||
<output role="status" id="message"></output> | ||
<button class="toast__button button-orange" onclick="dismiss()" aria-label="Закрыть">X</button> | ||
</div> | ||
</div> | ||
<script> | ||
const toastContainer = document.querySelector('.toast') | ||
const toastMessage = toastContainer.querySelector('output') | ||
const showedToastMessage = 'toast--open' | ||
let timer = undefined | ||
let init | ||
|
||
const show = function () { | ||
if (typeof timer === 'number') { | ||
clear() | ||
} | ||
init = event.target | ||
toastMessage.innerHTML = '<p>' + 'Документ успешно сохранён.' + '</p>' | ||
toastContainer.classList.add(showedToastMessage) | ||
timer = setTimeout(autoDismiss, 5000) | ||
} | ||
|
||
const clear = function () { | ||
window.clearTimeout(timer) | ||
} | ||
|
||
const dismiss = function ( ) { | ||
init.focus() | ||
autoDismiss() | ||
} | ||
|
||
const autoDismiss = function () { | ||
toastContainer.classList.remove(showedToastMessage) | ||
|
||
timer = setTimeout(function () { | ||
toastMessage.innerHTML = '' | ||
timer = undefined | ||
}, 1000) | ||
} | ||
</script> | ||
</body> | ||
</html> |
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