pico/scss/components/_modal.scss

169 lines
3.1 KiB
SCSS
Raw Normal View History

2021-10-24 15:24:57 +07:00
/**
* Modal (<dialog>)
*/
:root {
--scrollbar-width: 0px;
}
2021-10-24 15:24:57 +07:00
dialog {
2021-11-02 11:04:48 +07:00
display: flex;
2021-11-08 00:02:42 +07:00
z-index: 999;
2021-10-24 15:24:57 +07:00
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
align-items: center;
justify-content: center;
2021-11-02 11:04:48 +07:00
width: inherit;
min-width: 100%;
height: inherit;
min-height: 100%;
2021-10-24 15:24:57 +07:00
padding: var(--spacing);
2022-03-06 10:53:20 +07:00
border: 0;
2022-06-05 10:37:48 +07:00
backdrop-filter: var(--modal-overlay-backdrop-filter);
2021-11-02 11:04:48 +07:00
background-color: var(--modal-overlay-background-color);
color: var(--color);
2021-10-24 15:24:57 +07:00
2021-11-08 00:02:42 +07:00
// Content
2021-10-24 15:24:57 +07:00
article {
2022-01-16 12:43:16 +07:00
max-height: calc(100vh - var(--spacing) * 2);
overflow: auto;
2022-02-28 11:28:33 +07:00
@if map-get($breakpoints, "sm") {
@media (min-width: map-get($breakpoints, "sm")) {
max-width: map-get($viewports, "sm");
2021-10-24 15:24:57 +07:00
}
}
2022-02-28 11:28:33 +07:00
@if map-get($breakpoints, "md") {
@media (min-width: map-get($breakpoints, "md")) {
max-width: map-get($viewports, "md");
2021-10-24 15:24:57 +07:00
}
}
2021-11-08 00:02:42 +07:00
> header,
2021-10-24 15:24:57 +07:00
> footer {
padding: calc(var(--block-spacing-vertical) * 0.5)
var(--block-spacing-horizontal);
2021-11-08 00:02:42 +07:00
}
2021-10-24 15:24:57 +07:00
2021-11-08 00:02:42 +07:00
> header {
.close {
margin: 0;
margin-left: var(--spacing);
float: right;
2021-10-24 15:24:57 +07:00
}
}
2021-11-08 00:02:42 +07:00
> footer {
text-align: right;
2021-10-31 09:24:46 +07:00
2022-02-27 22:43:15 +07:00
[role="button"] {
2021-11-08 00:02:42 +07:00
margin-bottom: 0;
2021-11-08 00:02:42 +07:00
&:not(:first-of-type) {
margin-left: calc(var(--spacing) * 0.5);
}
}
2021-10-31 09:24:46 +07:00
}
2021-11-08 00:02:42 +07:00
p {
&:last-of-type {
margin: 0;
}
2021-10-31 09:24:46 +07:00
}
2021-11-08 00:02:42 +07:00
// Close icon
2021-12-19 10:40:54 +07:00
@if $enable-classes {
.close {
display: block;
width: 1rem;
height: 1rem;
margin-top: calc(var(--block-spacing-vertical) * -0.5);
margin-bottom: var(--typography-spacing-vertical);
margin-left: auto;
background-image: var(--icon-close);
background-position: center;
background-size: auto 1rem;
background-repeat: no-repeat;
opacity: 0.5;
@if $enable-transitions {
transition: opacity var(--transition);
}
2022-03-06 13:37:20 +07:00
&:is([aria-current], :hover, :active, :focus) {
2021-12-19 10:40:54 +07:00
opacity: 1;
}
2021-11-08 00:02:42 +07:00
}
}
}
// Closed state
&:not([open]),
2022-02-27 22:43:15 +07:00
&[open="false"] {
2021-11-08 00:02:42 +07:00
display: none;
2021-10-31 09:24:46 +07:00
}
2021-10-24 15:24:57 +07:00
}
2021-11-08 00:02:42 +07:00
// Utilities
2021-12-19 10:40:54 +07:00
@if $enable-classes {
.modal-is-open {
padding-right: var(--scrollbar-width, 0px);
overflow: hidden;
pointer-events: none;
2021-11-08 00:02:42 +07:00
2021-12-19 10:40:54 +07:00
dialog {
pointer-events: auto;
}
2021-10-24 15:24:57 +07:00
}
2021-11-08 00:02:42 +07:00
}
// Animations
2021-12-19 10:40:54 +07:00
@if ($enable-classes and $enable-transitions) {
$animation-duration: 0.2s;
2022-03-06 13:37:20 +07:00
:where(.modal-is-opening, .modal-is-closing) {
2021-11-08 00:02:42 +07:00
dialog,
dialog > article {
animation-duration: $animation-duration;
animation-timing-function: ease-in-out;
animation-fill-mode: both;
2021-11-08 00:02:42 +07:00
}
dialog {
animation-duration: ($animation-duration * 4);
animation-name: modal-overlay ;
2021-11-08 00:02:42 +07:00
> article {
animation-delay: $animation-duration;
2022-06-05 10:37:48 +07:00
animation-name: modal;
2021-11-08 00:02:42 +07:00
}
}
}
.modal-is-closing {
dialog,
dialog > article {
animation-delay: 0s;
2021-11-08 00:02:42 +07:00
animation-direction: reverse;
}
}
@keyframes modal-overlay {
2021-11-08 00:02:42 +07:00
from {
2022-06-05 10:37:48 +07:00
backdrop-filter: none;
2021-11-08 00:02:42 +07:00
background-color: transparent;
}
}
2022-06-05 10:37:48 +07:00
@keyframes modal {
2021-11-08 00:02:42 +07:00
from {
transform: translateY(-100%);
opacity: 0;
}
}
}