picocss/scss/components/_modal.scss

170 lines
3.8 KiB
SCSS
Raw Normal View History

2022-10-22 15:39:36 +07:00
@use "sass:map";
2022-10-22 13:11:51 +07:00
@use "../settings" as *;
2022-10-22 11:44:10 +07:00
2022-10-23 10:47:50 +07:00
@if map.get($modules, "components/modal") {
/**
* Modal (<dialog>)
*/
2021-10-24 15:24:57 +07:00
2022-10-23 10:47:50 +07:00
:root {
2023-12-28 13:21:52 +07:00
#{$css-var-prefix}scrollbar-width: 0px;
2022-10-23 10:47:50 +07:00
}
2022-10-23 10:47:50 +07:00
dialog {
display: flex;
z-index: 999;
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
align-items: center;
justify-content: center;
width: inherit;
min-width: 100%;
height: inherit;
min-height: 100%;
2024-01-01 21:49:46 +07:00
padding: 0;
2022-10-23 10:47:50 +07:00
border: 0;
2023-12-28 13:21:52 +07:00
backdrop-filter: var(#{$css-var-prefix}modal-overlay-backdrop-filter);
background-color: var(#{$css-var-prefix}modal-overlay-background-color);
color: var(#{$css-var-prefix}color);
2022-10-23 10:47:50 +07:00
// Content
article {
$close-selector: if($enable-classes, ".close, a[rel='prev']", "a[rel='prev']");
2023-02-12 08:36:44 +07:00
width: 100%;
2023-12-28 13:21:52 +07:00
max-height: calc(100vh - var(#{$css-var-prefix}spacing) * 2);
margin: var(#{$css-var-prefix}spacing);
2022-10-23 10:47:50 +07:00
overflow: auto;
@if map.get($breakpoints, "sm") {
@media (min-width: map.get(map.get($breakpoints, "sm"), "breakpoint")) {
max-width: map.get(map.get($breakpoints, "sm"), "viewport");
}
2021-10-24 15:24:57 +07:00
}
2022-10-23 10:47:50 +07:00
@if map.get($breakpoints, "md") {
@media (min-width: map.get(map.get($breakpoints, "md"), "breakpoint")) {
max-width: map.get(map.get($breakpoints, "md"), "viewport");
}
2021-10-24 15:24:57 +07:00
}
2022-10-23 10:47:50 +07:00
> header {
2023-12-28 15:32:12 +07:00
> * {
margin-bottom: 0;
}
#{$close-selector} {
margin: 0;
margin-left: var(#{$css-var-prefix}spacing);
float: right;
2022-10-23 10:47:50 +07:00
}
2021-10-24 15:24:57 +07:00
}
2022-10-23 10:47:50 +07:00
> footer {
text-align: right;
2021-10-31 09:24:46 +07:00
2023-03-25 12:35:22 +07:00
button,
2022-10-23 10:47:50 +07:00
[role="button"] {
margin-bottom: 0;
2022-10-23 10:47:50 +07:00
&:not(:first-of-type) {
2023-12-28 13:21:52 +07:00
margin-left: calc(var(#{$css-var-prefix}spacing) * 0.5);
2022-10-23 10:47:50 +07:00
}
2021-11-08 00:02:42 +07:00
}
}
2022-10-23 10:47:50 +07:00
// Close icon
#{$close-selector} {
display: block;
width: 1rem;
height: 1rem;
margin-top: calc(var(#{$css-var-prefix}spacing) * -1);
margin-bottom: var(#{$css-var-prefix}spacing);
margin-left: auto;
background-image: var(#{$css-var-prefix}icon-close);
background-position: center;
background-size: auto 1rem;
background-repeat: no-repeat;
opacity: 0.5;
@if $enable-transitions {
transition: opacity var(#{$css-var-prefix}transition);
}
2022-10-23 10:47:50 +07:00
&:is([aria-current]:not([aria-current="false"]), :hover, :active, :focus) {
opacity: 1;
2021-12-19 10:40:54 +07:00
}
2021-11-08 00:02:42 +07:00
}
}
2022-10-23 10:47:50 +07:00
// Closed state
&:not([open]),
&[open="false"] {
display: none;
}
2021-10-31 09:24:46 +07:00
}
2021-10-24 15:24:57 +07:00
2022-10-23 10:47:50 +07:00
// Utilities
@if $enable-classes {
.modal-is-open {
2023-12-28 13:21:52 +07:00
padding-right: var(#{$css-var-prefix}scrollbar-width, 0px);
2022-10-23 10:47:50 +07:00
overflow: hidden;
pointer-events: none;
touch-action: none;
2021-11-08 00:02:42 +07:00
2022-10-23 10:47:50 +07:00
dialog {
pointer-events: auto;
2023-04-01 10:10:09 +07:00
touch-action: auto;
2022-10-23 10:47:50 +07:00
}
2021-12-19 10:40:54 +07:00
}
2021-10-24 15:24:57 +07:00
}
2021-11-08 00:02:42 +07:00
2022-10-23 10:47:50 +07:00
// Animations
@if $enable-classes and $enable-transitions {
$animation-duration: 0.2s;
2022-10-23 10:47:50 +07:00
:where(.modal-is-opening, .modal-is-closing) {
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
2022-10-23 10:47:50 +07:00
dialog {
animation-duration: ($animation-duration * 4);
animation-name: modal-overlay;
2022-10-23 10:47:50 +07:00
> article {
animation-delay: $animation-duration;
animation-name: modal;
}
2021-11-08 00:02:42 +07:00
}
}
2022-10-23 10:47:50 +07:00
.modal-is-closing {
dialog,
dialog > article {
animation-delay: 0s;
animation-direction: reverse;
}
2021-11-08 00:02:42 +07:00
}
2022-10-23 10:47:50 +07:00
@keyframes modal-overlay {
from {
backdrop-filter: none;
background-color: transparent;
}
2021-11-08 00:02:42 +07:00
}
2022-10-23 10:47:50 +07:00
@keyframes modal {
from {
transform: translateY(-100%);
opacity: 0;
}
2021-11-08 00:02:42 +07:00
}
}
2022-10-15 23:22:12 +07:00
}